/*
 * MythicHub styles — Direction A "Emerald Arcade" (docs/PLAN.md, D13).
 *
 * One file, no build step, native CSS only: cascade layers, custom properties,
 * nesting. Colours are tokens; nothing below the tokens layer uses a raw hex
 * value.
 *
 * Dark only, for everyone (decided 2026-09-30): no light theme, whatever the
 * visitor's system setting.
 * Gold (--mythic) is reserved for Mythics — never use it for anything else.
 */

@layer reset, tokens, base, layout, components, utilities;

/* ── Fonts (self-hosted, see public/fonts/README.md) ─────────────────────── */

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("fonts/ibm-plex-sans-latin-var.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("fonts/ibm-plex-sans-latin-ext-var.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Chakra Petch";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/chakra-petch-600-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Chakra Petch";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/chakra-petch-600-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Chakra Petch";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/chakra-petch-700-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Chakra Petch";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/chakra-petch-700-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  img, svg, video { display: block; max-width: 100%; height: auto; }
  input, button, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; }
  p, h1, h2, h3, h4 { overflow-wrap: break-word; }
}

/* ── Tokens ──────────────────────────────────────────────────────────────── */

@layer tokens {
  :root {
    color-scheme: dark;

    --ground:   #0A0F0C;
    --surface:  #121A15;
    --raised:   #0E1511;
    --line:     #1F2B24;
    --line-strong: #2A3830;
    --text:     #E8F1EA;
    --muted:    #9DB0A3;

    /* Emerald: the action colour. */
    --accent:        #2FD46B;
    --accent-hover:  #5BE58B;
    --on-accent:     #04130A;
    --accent-soft:   #13261A;

    /* Mythic gold: only ever for Mythics. */
    --mythic:        #F2C14E;
    --mythic-soft:   #2A2210;

    --danger:        #FF8A7A;

    --font-body: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
    --font-display: "Chakra Petch", "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;

    /* Type scale (1.25) */
    --step--1: 0.875rem;
    --step-0: 1rem;
    --step-1: 1.25rem;
    --step-2: 1.5625rem;
    --step-3: 1.953rem;
    --step-4: clamp(2rem, 1.4rem + 2.6vw, 2.75rem);

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;
    --space-8: 4rem;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;
    --content-width: 72rem;
    --header-height: 4.5rem;
    --gutter: clamp(1rem, 0.5rem + 2vw, 2rem);
  }
}

/* ── Base ────────────────────────────────────────────────────────────────── */

@layer base {
  /* The hidden attribute wins over any class's display (e.g. a .cluster that starts hidden). */
  [hidden] { display: none !important; }

  /* scroll-padding keeps #anchor targets from hiding under the sticky bar. */
  html { background: var(--ground); scroll-padding-top: calc(var(--header-height) + var(--space-4)); }

  body {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--ground);
    color: var(--text);
    font-family: var(--font-body);
    font-size: var(--step-0);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
  }

  h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.01em;
    text-wrap: balance;
  }
  h1 { font-size: var(--step-4); }
  h2 { font-size: var(--step-3); }
  h3 { font-size: var(--step-2); }
  h4 { font-size: var(--step-1); font-weight: 600; }

  p { text-wrap: pretty; }

  a {
    color: var(--accent);
    text-underline-offset: 0.18em;
    &:hover { color: var(--accent-hover); }
  }

  :focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: var(--radius-sm);
  }

  ::selection { background: var(--accent); color: var(--on-accent); }

  strong { font-weight: 600; }
  code { font-size: 0.9em; }
}

/* ── Layout ──────────────────────────────────────────────────────────────── */

@layer layout {
  .site-header,
  main {
    width: 100%;
    max-width: calc(var(--content-width) + 2 * var(--gutter));
    margin-inline: auto;
    padding-inline: var(--gutter);
  }

  /* Sticky top bar, full screen width: the crest and wordmark at the screen's
     left edge, navigation at its right edge (not the centred content column). */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-5);
    min-height: var(--header-height);
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--ground) 88%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    max-width: none;
    padding-inline: var(--gutter);
  }

  .site-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    color: var(--text);
    text-decoration: none;
    &:hover { color: var(--text); }
  }
  .site-crest { width: 36px; height: 36px; }
  .wordmark {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: var(--step-2);
    line-height: 1;
    letter-spacing: -0.01em;
  }
  .wordmark-hub { color: var(--accent); }

  .site-nav {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    font-weight: 500;
  }
  .nav-link { color: var(--text); text-decoration: none; &:hover { color: var(--accent); } }
  .nav-user {
    font-family: var(--font-display);
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    &:hover { color: var(--accent); }
  }
  .nav-form { display: contents; }
  .nav-button {
    padding: 0;
    border: 0;
    background: none;
    color: var(--muted);
    font-weight: 500;
    &:hover { color: var(--accent); }
  }

  main {
    flex: 1;
    padding-block: var(--space-7);
  }

  .stack { display: flex; flex-direction: column; gap: var(--space-4); }
  .stack-sm { display: flex; flex-direction: column; gap: var(--space-2); }
  .stack-lg { display: flex; flex-direction: column; gap: var(--space-7); }
  .cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
  .grid-auto {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
    gap: var(--space-4);
  }
}

/* ── Components ──────────────────────────────────────────────────────────── */

@layer components {
  .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 3rem;
    padding: 0 var(--space-5);
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
    text-decoration: none;
    transition: background-color 120ms ease, border-color 120ms ease;
    &:hover { background: var(--accent-hover); color: var(--on-accent); }
    &.is-danger {
      background: var(--danger);
      color: var(--ground);
      &:hover { background: var(--danger); color: var(--ground); opacity: 0.9; }
    }
    &.is-secondary {
      background: transparent;
      border-color: var(--line-strong);
      color: var(--text);
      &:hover { border-color: var(--accent); color: var(--text); }
    }
  }

  .card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
  }

  .eyebrow {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: var(--step--1);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .lede {
    font-size: var(--step-1);
    color: var(--muted);
    max-width: 38rem;
  }

  .muted { color: var(--muted); }

  .notice {
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--line-strong);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    background: var(--surface);
    max-width: 38rem;
  }

  .steps {
    display: grid;
    gap: var(--space-2);
    padding-left: 1.4em;
    max-width: 38rem;
  }

  .facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: var(--space-2) var(--space-5);
    max-width: 44rem;
    & dt { color: var(--muted); }
    & dd { margin: 0; }
  }

  .session-list {
    display: grid;
    gap: var(--space-3);
    padding: 0;
    list-style: none;
    max-width: 44rem;
  }
  .session {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--raised);
  }
  .badge-here {
    margin-left: var(--space-2);
    padding: 0.1em 0.6em;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 600;
  }

  .checkbox {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    & input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
  }

  /* "How it works" on the signed-out landing page: three numbered cards. */
  .how {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
    gap: var(--space-4);
    padding: 0;
    list-style: none;
    & h3 { font-size: var(--step-1); }
  }
  .how-step {
    display: inline-grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    color: var(--accent);
    font-family: var(--font-display);
    font-weight: 700;
  }

  /* Text input: the gamertag search. */
  .input {
    min-height: 3rem;
    padding: 0 var(--space-4);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--raised);
    color: var(--text);
    font: inherit;
    &::placeholder { color: var(--muted); opacity: 0.8; }
    &:hover { border-color: var(--muted); }
    &:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
    &[aria-invalid="true"] { border-color: var(--danger); }
    &::-webkit-search-cancel-button { filter: grayscale(1); }
  }

  .search-card { max-width: 44rem; }
  .search {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    & .input { flex: 1 1 14rem; min-width: 0; }
  }
  .field-error { color: var(--danger); }

  /* ── Profile page (Step 36) ── */
  .profile-head {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: var(--space-5);
    & h1 { overflow-wrap: anywhere; }
  }
  .gamerpic {
    display: block;
    width: 96px;
    height: 96px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    background: var(--line);
    object-fit: cover;
  }
  .profile-facts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-5);
    color: var(--muted);
    & strong { font-family: var(--font-display); font-weight: 700; color: var(--text); }
  }
  .mythic-count, .profile-facts .mythic-count strong { color: var(--mythic); }
  .small { font-size: var(--step--1); }

  .tabs {
    display: flex;
    gap: var(--space-5);
    border-bottom: 1px solid var(--line);
  }
  .tab {
    display: inline-flex;
    align-items: baseline;
    gap: var(--space-2);
    padding: var(--space-3) 0;
    margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: var(--step-1);
    text-decoration: none;
    &:hover { color: var(--text); }
    &[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
  }
  .tab-count { font-size: var(--step--1); color: var(--muted); }

  .controls { display: grid; gap: var(--space-3); }
  .chip-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
  .chip-label {
    min-width: 3rem;
    color: var(--muted);
    font-family: var(--font-display);
    font-size: var(--step--1);
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
  }
  .chip {
    display: inline-flex;
    align-items: baseline;
    gap: 0.4em;
    padding: 0.3em 0.9em;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    color: var(--text);
    font-size: var(--step--1);
    text-decoration: none;
    &:hover { border-color: var(--accent); color: var(--text); }
    &[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
  }
  .chip-count { color: var(--muted); }

  .game-list { display: grid; gap: var(--space-3); padding: 0; list-style: none; }
  .game-body { display: grid; gap: var(--space-1); min-width: 0; }
  .game-pct { font-family: var(--font-display); font-variant-numeric: tabular-nums; }
  .pending { font-style: italic; }
  .tags { display: flex; flex-wrap: wrap; gap: var(--space-1); }
  .tag {
    padding: 0 0.5em;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    color: var(--muted);
    font-size: 0.75rem;
    line-height: 1.6;
  }

  .game-link {
    color: var(--text);
    text-decoration: none;
    &:hover { color: var(--accent); text-decoration: underline; }
  }

  /* ── Mythic mosaic (Step 43) ── */
  .mosaic {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(88px, 30%), 1fr));
    gap: var(--space-1);
    padding: 0;
    list-style: none;
  }
  .tile {
    display: grid;
    place-items: center;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: var(--radius-sm);
    background: var(--line);
    color: var(--text);
    text-decoration: none;
    & img { display: block; width: 100%; height: 100%; object-fit: cover; }
    &:hover, &:focus-visible { outline: 2px solid var(--mythic); outline-offset: 1px; }
  }
  .tile-name {
    padding: var(--space-2);
    font-size: 0.7rem;
    line-height: 1.25;
    text-align: center;
    overflow-wrap: anywhere;
  }

  /* ── Game page (Step 38) ── */
  .crumb { font-size: var(--step--1); & a { text-decoration: none; } }
  .game-head {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: var(--space-5);
    & h1 { overflow-wrap: anywhere; }
  }
  .game-cover {
    display: block;
    width: 96px;
    height: 96px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--line);
    object-fit: cover;
  }
  .section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-2) var(--space-4);
  }
  .count {
    margin-left: var(--space-1);
    color: var(--muted);
    font-size: var(--step--1);
    font-weight: 600;
  }
  .progress.is-mythic {
    &::-webkit-progress-value { background: var(--mythic); }
    &::-moz-progress-bar { background: var(--mythic); }
  }

  .ach-list { display: grid; gap: var(--space-2); padding: 0; list-style: none; }
  .ach {
    display: grid;
    grid-template-columns: 3rem 1fr;
    align-items: start;
    gap: var(--space-4);
    padding: var(--space-3);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--raised);
    &.is-done { border-left: 3px solid var(--accent); }
  }
  .ach-icon {
    display: block;
    width: 3rem;
    height: 3rem;
    border-radius: var(--radius-sm);
    background: var(--line);
    object-fit: cover;
  }
  /* A locked secret's icon, blurred until its spoiler is opened. */
  .ach-icon.is-hidden { filter: blur(5px) grayscale(1) brightness(0.7); transition: filter 150ms ease; }
  .ach:has(.spoiler[open]) .ach-icon.is-hidden { filter: none; }
  .ach-body { display: grid; gap: var(--space-1); min-width: 0; }
  .ach-name { font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
  .ach-desc { font-size: var(--step--1); }
  .ach-meta { font-size: var(--step--1); color: var(--muted); }
  .rare { color: var(--accent); font-weight: 600; }

  .spoiler {
    font-size: var(--step--1);
    & summary { color: var(--accent); cursor: pointer; width: fit-content; }
    &[open] summary { margin-bottom: var(--space-1); }
  }
  .fold {
    & > summary {
      width: fit-content;
      padding: var(--space-2) var(--space-4);
      border: 1px solid var(--line-strong);
      border-radius: var(--radius);
      cursor: pointer;
      font-weight: 600;
      &:hover { border-color: var(--accent); }
    }
    &[open] > summary { margin-bottom: var(--space-3); }
  }

  @media (max-width: 30rem) {
    .game-head { grid-template-columns: 1fr; }
    .profile-head { grid-template-columns: 1fr; }
    .game-row { grid-template-columns: 3rem 1fr auto; gap: var(--space-3); }
    .game-art { width: 3rem; height: 3rem; }
  }

  /* The fan-site disclaimer on the main page. */
  .disclaimer {
    max-width: 38rem;
    padding-top: var(--space-5);
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: var(--step--1);
  }

  /* The Mythic badge: gold, and the only gold on the page. */
  .badge-mythic {
    display: inline-flex;
    align-items: center;
    gap: 0.45em;
    padding: 0.3em 0.8em;
    border: 1px solid var(--mythic);
    border-radius: 999px;
    background: var(--mythic-soft);
    color: var(--mythic);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.75rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    &::before {
      content: "";
      width: 0.55em;
      height: 0.55em;
      background: currentColor;
      transform: rotate(45deg);
    }
  }

  .progress {
    appearance: none;
    width: 100%;
    height: 0.5rem;
    border: 0;
    border-radius: 999px;
    background: var(--line);
    overflow: hidden;
    &::-webkit-progress-bar { background: var(--line); border-radius: 999px; }
    &::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
    &::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
  }

  .game-row {
    display: grid;
    grid-template-columns: 3.5rem 1fr auto;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-3);
    border-radius: var(--radius);
    background: var(--raised);
    border: 1px solid var(--line);
  }
  .game-art {
    width: 3.5rem;
    height: 3.5rem;
    border-radius: var(--radius-sm);
    background: var(--line);
    object-fit: cover;
  }
  .game-title { font-weight: 600; line-height: 1.3; }
  .game-meta { font-size: var(--step--1); color: var(--muted); }

  .swatch {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    font-size: var(--step--1);
    & .chip {
      height: 4rem;
      border-radius: var(--radius);
      border: 1px solid var(--line-strong);
    }
    &[data-token="ground"] .chip { background: var(--ground); }
    &[data-token="surface"] .chip { background: var(--surface); }
    &[data-token="line"] .chip { background: var(--line); }
    &[data-token="text"] .chip { background: var(--text); }
    &[data-token="muted"] .chip { background: var(--muted); }
    &[data-token="accent"] .chip { background: var(--accent); }
    &[data-token="mythic"] .chip { background: var(--mythic); }
  }
}

/* ── Utilities ───────────────────────────────────────────────────────────── */

@layer utilities {
  .visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap; border: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
