/*
  Reading the styles? Respect. No framework, no build, no !important crimes (almost).
  The cascade layers are declared up front so the priority order is honest. Mind the glow.
*/
@layer reset, tokens, base, layout, components, vignettes, chrome, motion;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; }
  button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
  ol { margin: 0; padding: 0; list-style: none; }
  pre { margin: 0; }
  [hidden] { display: none !important; }
  :focus-visible { outline: 2px solid var(--c-blue); outline-offset: 3px; border-radius: 6px; }
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }
}

@layer tokens {
  :root {
    --c-amber: #d9a441;
    --c-orange: #cf6a44;
    --c-blue: #4d9fe6;
    --c-green: #46b58a;
    --c-ink: #05070d;

    --c-text: rgba(255, 255, 255, 0.92);
    --c-muted: rgba(255, 255, 255, 0.45);
    --c-faint: rgba(255, 255, 255, 0.26);
    --c-line: rgba(255, 255, 255, 0.12);
    --c-fill: rgba(255, 255, 255, 0.05);

    --font-display: 'Space Grotesk', sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', monospace;

    --card-max: 820px;
    --radius: 22px;
    --radius-sm: 10px;
    --ease: cubic-bezier(0.2, 0.9, 0.2, 1);
  }
}

@layer base {
  html, body { min-height: 100%; }

  body {
    margin: 0;
    overflow-x: hidden;
    font-family: var(--font-mono);
    color: var(--c-text);
    background: var(--c-ink) radial-gradient(120% 120% at 30% 20%, #11233f 0%, #07090f 55%, #03040a 100%) fixed no-repeat;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
  }
}

@layer layout {
  .backdrop {
    position: fixed;
    inset: 0;
    z-index: 0;
    display: block;
    width: 100%;
    height: 100%;
  }

  .stage {
    position: relative;
    z-index: 1;
    min-height: 100svh;
    display: grid;
    place-items: center;
    padding: clamp(16px, 4vw, 24px);
    padding-bottom: clamp(52px, 9vw, 64px);
  }
}

@layer components {
  .card {
    position: relative;
    flex: 0 1 auto;
    width: min(var(--card-max), 92vw);
    min-width: 0;
    padding: clamp(28px, 5vw, 52px) clamp(24px, 5vw, 60px) clamp(22px, 4vw, 40px);
    border-radius: var(--radius);
    text-align: center;
    background: rgba(10, 14, 24, 0.34);
    border: 1px solid var(--c-line);
    box-shadow:
      0 30px 80px -30px rgba(0, 0, 0, 0.8),
      0 0 70px -22px rgba(90, 160, 224, 0.4),
      inset 0 1px 0 rgba(255, 255, 255, 0.08);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    backdrop-filter: blur(14px) saturate(140%);
    animation: card-in 1.1s var(--ease) both;
  }

  /* engineered detail: fine corner ticks just inside the card edges */
  .card::after {
    content: '';
    position: absolute;
    inset: 12px;
    pointer-events: none;
    background:
      linear-gradient(var(--c-faint), var(--c-faint)) left top / 12px 1px no-repeat,
      linear-gradient(var(--c-faint), var(--c-faint)) left top / 1px 12px no-repeat,
      linear-gradient(var(--c-faint), var(--c-faint)) right top / 12px 1px no-repeat,
      linear-gradient(var(--c-faint), var(--c-faint)) right top / 1px 12px no-repeat,
      linear-gradient(var(--c-faint), var(--c-faint)) left bottom / 12px 1px no-repeat,
      linear-gradient(var(--c-faint), var(--c-faint)) left bottom / 1px 12px no-repeat,
      linear-gradient(var(--c-faint), var(--c-faint)) right bottom / 12px 1px no-repeat,
      linear-gradient(var(--c-faint), var(--c-faint)) right bottom / 1px 12px no-repeat;
  }

  .card-sig {
    position: absolute;
    right: 18px;
    bottom: 16px;
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.04em;
    color: var(--c-faint);
  }

  .wordmark {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.6rem, 6.4vw, 3.3rem);
    letter-spacing: clamp(0.02em, 0.8vw, 0.1em);
    line-height: 1.08;
    white-space: nowrap;
    background: linear-gradient(105deg, #eaf2ff 0%, #9fc2ec 55%, #5aa0e0 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 2px 22px rgba(90, 160, 224, 0.28));
  }

  .tagline {
    margin: 8px 0 0;
    font-size: clamp(0.62rem, 1.6vw, 0.78rem);
    letter-spacing: 0.42em;
    text-transform: uppercase;
    color: var(--c-muted);
  }

  .quote {
    margin: clamp(22px, 4vw, 32px) 0 0;
  }

  .quote__text {
    margin: 0 auto;
    max-width: 56ch;
    font-size: clamp(0.86rem, 2.4vw, 1.08rem);
    line-height: 1.6;
    color: var(--c-text);
  }

  .scramble__glyph {
    color: var(--c-blue);
    opacity: 0.75;
  }

  .caret {
    display: inline-block;
    width: 0.55ch;
    height: 1.05em;
    margin-left: 0.1em;
    transform: translateY(0.16em);
    background: var(--c-blue);
    box-shadow: 0 0 10px var(--c-blue);
    animation: blink 1.05s steps(1) infinite;
  }

  .quote__author {
    margin: 14px 0 0;
    font-size: clamp(0.66rem, 1.8vw, 0.8rem);
    letter-spacing: 0.04em;
    color: var(--c-muted);
    transition: opacity 0.4s ease;
  }

  .quote__author::before {
    content: '// ';
    color: var(--c-faint);
  }

  .deck {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(10px, 2vw, 22px);
    width: 100%;
  }

  .navbtn {
    flex: none;
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(10, 14, 24, 0.34);
    border: 1px solid var(--c-line);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    backdrop-filter: blur(14px) saturate(140%);
    color: var(--c-muted);
    font-size: 1rem;
    line-height: 1;
    transition: color 0.25s ease, border-color 0.25s ease, transform 0.2s ease;
  }

  .navbtn:hover { color: var(--c-amber); border-color: rgba(77, 159, 230, 0.5); transform: scale(1.07); }
  .navbtn:active { transform: scale(0.95); }

  .pager {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 9px;
    margin-top: clamp(20px, 3.5vw, 30px);
  }

  .pager__count {
    font-size: 0.7rem;
    letter-spacing: 0.16em;
    color: var(--c-faint);
    font-variant-numeric: tabular-nums;
  }

  .pager__track {
    width: clamp(120px, 45%, 220px);
    height: 3px;
    border-radius: 999px;
    background: var(--c-fill);
    overflow: hidden;
  }

  .pager__fill {
    display: block;
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, #5aa0e0, var(--c-blue));
    transition: width 0.5s var(--ease);
  }

  @media (max-width: 560px) {
    .deck { display: block; }
    /* leave a gutter on each side so the fixed carets never overlap the card */
    .card {
      width: calc(100vw - 100px);
      max-width: none;
      margin-inline: auto;
      /* extra room at the foot so the corner signature clears the centered pager */
      padding-bottom: 42px;
    }
    .card-sig { bottom: 13px; right: 14px; }
    .navbtn {
      position: fixed;
      top: 50%;
      transform: translateY(-50%);
      width: 40px;
      height: 40px;
      z-index: 3;
    }
    .navbtn--prev { left: 6px; }
    .navbtn--next { right: 6px; }
    .navbtn:hover { transform: translateY(-50%) scale(1.07); }
    .navbtn:active { transform: translateY(-50%) scale(0.94); }
  }
}

@layer vignettes {
  .vignette {
    display: grid;
    place-items: center;
    margin-top: clamp(18px, 3vw, 26px);
    min-height: 132px;
  }

  .vignette[hidden] { display: none; }

  .vig {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    width: 100%;
    min-width: 0;
    max-width: 460px;
    animation: vig-in 0.5s var(--ease) both;
  }

  .vig-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
  }

  .vig-row--spread {
    justify-content: space-between;
    width: 100%;
  }

  .vig-btn {
    padding: 8px 16px;
    border: 1px solid var(--c-line);
    border-radius: 999px;
    background: var(--c-fill);
    font-size: 0.78rem;
    letter-spacing: 0.03em;
    color: var(--c-text);
    transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease, transform 0.15s ease;
  }

  .vig-btn:hover:not(:disabled) {
    border-color: var(--c-blue);
    transform: translateY(-1px);
  }

  .vig-btn:active:not(:disabled) { transform: translateY(0); }

  .vig-btn:disabled {
    opacity: 0.5;
    cursor: default;
  }

  .vig-btn.is-active {
    color: var(--c-ink);
    background: var(--c-amber);
    border-color: var(--c-amber);
    font-weight: 500;
  }

  .vig-seg {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 100%;
    padding: 4px;
    border: 1px solid var(--c-line);
    border-radius: var(--radius-sm);
    background: var(--c-fill);
  }

  .vig-seg__opt {
    padding: 6px 18px;
    border-radius: 999px;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    color: var(--c-muted);
    transition: color 0.2s ease, background 0.2s ease;
  }

  .vig-seg__opt.is-active {
    color: var(--c-ink);
    background: var(--c-amber);
    font-weight: 500;
  }

  .vig-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    counter-reset: hard;
    font-size: 0.92rem;
    text-align: left;
  }

  .vig-list__item {
    counter-increment: hard;
    padding-left: 1.8em;
    position: relative;
    color: var(--c-text);
    animation: vig-in 0.35s var(--ease) both;
  }

  .vig-list__item::before {
    content: counter(hard) '.';
    position: absolute;
    left: 0;
    color: var(--c-amber);
  }

  .vig-list__item:nth-child(n + 3) { color: var(--c-muted); }

  .vig-code {
    width: 100%;
    min-width: 0;
    padding: 14px 16px;
    border: 1px solid var(--c-line);
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.35);
    font-size: 0.78rem;
    line-height: 1.6;
    text-align: left;
    white-space: pre;
    overflow-x: auto;
    color: var(--c-text);
    transition: opacity 0.35s ease, transform 0.35s ease, filter 0.35s ease;
  }

  .vig-code .tok-key { color: var(--c-blue); }
  .vig-code .tok-fn { color: var(--c-amber); }
  .vig-code .tok-str { color: var(--c-green); }
  .vig-code .tok-dim { color: var(--c-muted); }
  .vig-code .tok-bug { color: var(--c-orange); text-decoration: wavy underline var(--c-orange); text-underline-offset: 3px; }

  .vig-code.is-removed {
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
    filter: blur(2px);
  }

  .vig-talk {
    width: 100%;
    padding: 14px 16px;
    border: 1px dashed var(--c-line);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    line-height: 1.6;
    font-style: italic;
    text-align: left;
    color: var(--c-muted);
  }

  .vig-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.74rem;
    letter-spacing: 0.04em;
    border: 1px solid currentColor;
    transition: color 0.3s ease;
  }

  .vig-tag.is-bad { color: var(--c-orange); }
  .vig-tag.is-good { color: var(--c-green); }

  .vig-meter {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 12px;
    width: 100%;
    font-size: 0.74rem;
    color: var(--c-muted);
  }

  .vig-meter__track {
    height: 8px;
    border-radius: 999px;
    background: var(--c-fill);
    overflow: hidden;
  }

  .vig-meter__fill {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--c-green);
    transition: width 0.4s var(--ease), background 0.4s ease;
  }

  .vig-readout {
    margin: 0;
    font-size: 0.78rem;
    color: var(--c-muted);
    min-height: 1.4em;
    transition: color 0.3s ease;
  }

  .vig-readout.is-bad { color: var(--c-orange); }
  .vig-readout.is-good { color: var(--c-green); }

  .vig-canvas {
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 104px;
    padding: 16px;
    border: 1px solid var(--c-line);
    border-radius: var(--radius-sm);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(0, 0, 0, 0.2));
  }

  .vig-slider {
    width: 100%;
  }

  .vig-slider input[type="range"] {
    width: 100%;
    accent-color: var(--c-blue);
    cursor: ew-resize;
  }

  .vig-form {
    display: flex;
    gap: 8px;
    width: 100%;
  }

  .vig-input {
    flex: 1;
    min-width: 0;
    padding: 9px 14px;
    border: 1px solid var(--c-line);
    border-radius: 999px;
    background: var(--c-fill);
    font: inherit;
    font-size: 0.8rem;
    color: var(--c-text);
  }

  .vig-input::placeholder { color: var(--c-faint); }
  .vig-input:focus-visible { border-color: var(--c-blue); outline: none; }
  .vig-input {
    -webkit-user-select: text;
    user-select: text;
  }

  @media (pointer: coarse) {
    .vig-btn,
    .vig-seg__opt {
      padding-top: 11px;
      padding-bottom: 11px;
    }
    .vig-input {
      padding-top: 11px;
      padding-bottom: 11px;
      font-size: 16px;
    }
    .navbtn {
      padding: 8px 6px;
    }
  }

  /* simplicity parts */
  .vig-part {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    background: linear-gradient(135deg, var(--c-blue), var(--c-amber));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 2px 6px -2px rgba(0, 0, 0, 0.5);
    animation: vig-in 0.3s var(--ease) both;
  }

  .vig-canvas.is-unstable .vig-part { animation: wobble 0.5s ease-in-out infinite; }
  .vig-canvas.is-critical .vig-part { animation: wobble 0.22s ease-in-out infinite; }

  .vig-canvas.is-toppled .vig-part {
    animation: topple 0.7s var(--ease) forwards;
  }
  .vig-canvas.is-toppled .vig-part:nth-child(even) { --topple-spin: -55deg; }
  .vig-canvas.is-toppled .vig-part:nth-child(3n) { animation-delay: 0.06s; }
  .vig-canvas.is-toppled .vig-part:nth-child(3n + 1) { animation-delay: 0.12s; }

  .vig-game {
    position: relative;
    width: 100%;
    min-width: 0;
    aspect-ratio: 16 / 7;
    border: 1px solid var(--c-line);
    border-radius: var(--radius-sm);
    background: linear-gradient(180deg, #1d3c63 0%, #0a1626 100%);
    overflow: hidden;
    touch-action: manipulation;
  }

  .vig-game canvas {
    display: block;
    width: 100%;
    height: 100%;
  }

  .vig-bits {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .vig-bit {
    width: 34px;
    height: 38px;
    border: 1px solid var(--c-line);
    border-radius: var(--radius-sm);
    background: var(--c-fill);
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
    color: var(--c-muted);
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  }

  .vig-bit.is-on {
    color: var(--c-ink);
    background: var(--c-amber);
    border-color: var(--c-amber);
    font-weight: 600;
  }

  .vig-cells {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .vig-cell {
    min-width: 36px;
    height: 38px;
    padding: 0 8px;
    border: 1px solid var(--c-line);
    border-radius: var(--radius-sm);
    background: var(--c-fill);
    font-size: 0.82rem;
    font-variant-numeric: tabular-nums;
    color: var(--c-text);
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  }

  .vig-cell.is-hit { border-color: var(--c-green); color: var(--c-green); }
  .vig-cell.is-miss { border-color: var(--c-orange); color: var(--c-orange); }

  .vig-pass { color: var(--c-green); }
  .vig-fail { color: var(--c-orange); }

  .vig-face {
    font-size: 2.4rem;
    line-height: 1;
    transition: transform 0.2s ease;
  }

  .vig-lines {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    align-items: flex-start;
    font-size: 0.82rem;
    text-align: left;
  }

  .vig-line {
    display: flex;
    gap: 0.55em;
    align-items: baseline;
  }
}

@layer chrome {
  .yearmark,
  .throwback {
    position: fixed;
    bottom: 16px;
    z-index: 2;
    font-size: 0.74rem;
    letter-spacing: 0.12em;
  }

  .yearmark {
    left: 20px;
    color: rgba(255, 193, 18, 0.55);
  }

  .throwback {
    right: 20px;
    color: var(--c-faint);
    text-decoration: none;
    transition: color 0.35s ease;
  }

  .throwback:hover { color: var(--c-amber); }

  .gh {
    position: fixed;
    left: 50%;
    bottom: 13px;
    z-index: 2;
    display: inline-flex;
    transform: translateX(-50%);
    color: var(--c-faint);
    transition: color 0.35s ease, transform 0.35s ease;
  }

  .gh:hover {
    color: var(--c-amber);
    transform: translateX(-50%) translateY(-2px);
  }

  .gh svg { display: block; }
}

@layer motion {
  @keyframes card-in {
    from { opacity: 0; transform: translateY(18px) scale(0.985); }
    to { opacity: 1; transform: none; }
  }

  @keyframes vig-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
  }

  @keyframes spin { to { transform: rotate(360deg); } }
  @keyframes blink { 50% { opacity: 0; } }

  @keyframes topple {
    to {
      transform: translateY(64px) rotate(var(--topple-spin, 52deg));
      opacity: 0;
    }
  }

  @keyframes wobble {
    0%, 100% { transform: translate(0, 0) rotate(0); }
    25% { transform: translate(1px, -1px) rotate(2deg); }
    75% { transform: translate(-1px, 1px) rotate(-2deg); }
  }

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.001ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.001ms !important;
    }
  }
}
