/* Base Styles */

@use "sass:color";
@use "sass:map";
@use "variables" as *;
@use "mixins" as *;

/* Reset & Base Styles */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  // Square by default, but overridable. This carried !important, which meant
  // nothing could round a corner -- the modal needed its own !important to get
  // 4px, and the retro-rounded utility had to fight the reset to work at all.
  //
  // Deliberately a literal 0 rather than var(--retro-border-radius): this rule
  // matches *every* element on the page, including third-party markup the
  // framework knows nothing about. Setting the token should round RetroCSS
  // components, not everything a consuming app happens to render, so the
  // components opt in individually.
  border-radius: 0;
  box-shadow: none;
  transition: none;
}

html {
  // 100% rather than a hard 16px so the rem scale honours the user's browser
  // font-size setting instead of overriding it.
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

body {
  font-family: var(--retro-font);
  font-size: var(--retro-font-size);
  line-height: var(--retro-line-height);
  color: var(--retro-text);
  background-color: var(--retro-body-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Vertical rhythm.
   The reset above zeroes every margin, and nothing restored it for flow
   content — so every paragraph, list and table in the framework sat flush
   against the next one. Only .retro-prose had spacing. These are the base
   defaults; components that manage their own spacing still override them. */
p,
ul,
ol,
dl,
blockquote,
pre,
figure,
table {
  margin-bottom: var(--retro-spacing-md);
}

// Nested lists belong to their parent item, not the block flow.
li > ul,
li > ol {
  margin-bottom: 0;
}

/* A Win9x etched divider: one dark line with a light one under it. */
hr {
  height: 0;
  margin: var(--retro-spacing-md) 0;
  border: none;
  border-top: 1px solid var(--retro-border-medium);
  border-bottom: 1px solid var(--retro-border-light);
}

/* Links */
a {
  color: var(--retro-primary-text);
  text-decoration: none;
  transition: var(--retro-transition-base);

  &:hover {
    color: var(--retro-primary-text);
    text-decoration: underline;
  }

  @include retro-focus-ring;
}

/* Images */
img {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
  border-style: none;
}

/* Lists */
ul, ol {
  list-style-position: inside;
  padding-inline-start: var(--retro-spacing-md);
}

/* Tables */
table {
  border-collapse: collapse;
  width: 100%;
}

/* Forms */
input,
button,
select,
optgroup,
textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  margin: 0;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
}

/* Code */
code,
pre {
  font-family: var(--retro-font-mono);
  // A single absolute size. This was 0.9em, and .retro-code code added another
  // 0.9em on top, so nested code compounded down to ~11px.
  font-size: var(--retro-font-size-sm);
}

/* Selection */
::selection {
  background-color: var(--retro-primary);
  color: var(--retro-text-inverse);
}

/* Focus Styles.
   :focus-visible, so the ring is there for keyboard and assistive-tech users
   but does not fire on every mouse click. The plain :focus rule is the
   fallback for engines without :focus-visible; :focus:not(:focus-visible)
   removes it again wherever the selector is supported. Note browsers still
   match :focus-visible on text inputs clicked with a mouse, so fields keep
   their ring. */
:focus {
  outline: 2px solid var(--retro-primary);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--retro-primary);
  outline-offset: 2px;
}

/* Print Styles */
@media print {
  *,
  *::before,
  *::after {
    text-shadow: none !important;
    box-shadow: none !important;
  }

  a[href]::after {
    content: " (" attr(href) ")";
  }

  abbr[title]::after {
    content: " (" attr(title) ")";
  }

  pre,
  blockquote {
    border: 1px solid var(--retro-border-light);
    page-break-inside: avoid;
  }

  thead {
    display: table-header-group;
  }

  tr,
  img {
    page-break-inside: avoid;
  }

  img {
    max-width: 100% !important;
  }

  p,
  h2,
  h3 {
    orphans: 3;
    widows: 3;
  }

  h2,
  h3 {
    page-break-after: avoid;
  }
}

/* Common animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from {
    transform: translateY(-10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.retro-tab-content {
  background: var(--retro-bg);
  border: var(--retro-border-width) var(--retro-border-style) var(--retro-border-dark);
  border-top: none;
  padding: var(--retro-spacing-md);
  margin-bottom: var(--retro-spacing-md);
  min-height: 60px;
  box-shadow: var(--retro-box-shadow-subtle);
  display: none;
}

.retro-tab-content.active {
  display: block;
}

// NOTE: a second .retro-toast block used to live here, styled from
// $retro-toast-* SCSS variables (a hardcoded #ffffcc, light-mode only) and
// competing with the tokenized .retro-toast in components/_alert.scss.
// Removed; _alert.scss owns the toast. Only the container stays here.

#retro-toast-container {
  position: fixed;
  bottom: var(--retro-spacing-xl);
  inset-inline-end: var(--retro-spacing-xl);
  z-index: var(--retro-z-index-tooltip);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: none;
}

/* Reduced motion.
   Honours the OS "reduce motion" setting. The blanket rule neutralises every
   transition and animation the framework ships; the three text effects below
   need an explicit `animation: none` on top, because merely shortening them
   leaves a filter applied (hue-rotate) or freezes `alternate-reverse` on a
   doubled-shadow keyframe that is unreadable (glitch). */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .retro-text-rainbow,
  .retro-text-hue-rotate,
  .retro-text-glitch,
  .retro-spinner,
  .retro-progress-bar-striped {
    animation: none !important;
  }

  .retro-text-hue-rotate {
    filter: none !important;
  }

  .retro-text-glitch {
    text-shadow: none !important;
  }
}
