  *, *::before, *::after { box-sizing: border-box; }
  html { background: #f5f5f7; }
  body {
    margin: 0;
    min-height: 100vh;
    padding: 16px 14px 28px;
    display: flex;
    justify-content: center;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: #1d1d1f;
    background: #f5f5f7;
  }
  .page {
    width: min(100%, 360px);
    text-align: center;
  }
  h1 {
    margin: 10px 0 4px;
    font-size: 26px;
    line-height: 1.15;
    letter-spacing: -0.5px;
  }
  .hook {
    margin: 0 0 8px;
    color: #6e6e73;
    font-size: 15px;
    font-style: italic;
  }
  .instructions {
    margin: 0 0 14px;
    color: #6e6e73;
    font-size: 12px;
    line-height: 1.35;
  }

  .puzzle {
    margin: 0;
  }

  .grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    width: min(100%, 320px);
    aspect-ratio: 1;
    margin: 0 auto;
    padding: 2px;
    gap: 2px;
    overflow: hidden;
    border-radius: 7px;
    background: #1d1d1f;
  }
  .cell {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #ffffff;
  }
  .cell.block {
    background: #1d1d1f;
  }
  .number {
    position: absolute;
    z-index: 3;
    top: 3px;
    left: 4px;
    font-size: 9px;
    line-height: 1;
    font-weight: 700;
    color: #6e6e73;
    pointer-events: none;
  }
  .letter-input {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 7px 0 0;
    border: 0;
    border-radius: 0;
    outline: 0;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    color: #1d1d1f;
    caret-color: #0071e3;
    text-align: center;
    text-transform: uppercase;
    font: 800 clamp(21px, 7vw, 30px)/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  }
  .letter-input:focus {
    background: #a3d2ff;
    box-shadow: inset 0 0 0 3px #0071e3;
  }
  .letter-input:not(:placeholder-shown):valid {
    background: #e7f6e9;
  }
  .letter-input:not(:placeholder-shown):invalid {
    background: #ffe1e1;
    box-shadow: inset 0 0 0 3px #d92d20;
  }
  .solution {
    position: absolute;
    z-index: 2;
    inset: 0;
    display: grid;
    place-items: center;
    padding-top: 7px;
    opacity: 0;
    pointer-events: none;
    color: #1d1d1f;
    font-size: clamp(21px, 7vw, 30px);
    font-weight: 800;
  }


  .solved-banner {
    margin: 14px auto 0;
    padding: 14px 16px;
    width: min(100%, 320px);
    border-radius: 9px;
    background: linear-gradient(135deg, #f0e6ff, #e6f0ff);
  }
  .solved-label {
    display: block;
    margin-bottom: 2px;
    color: #6e6e73;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.4px;
    text-transform: uppercase;
  }
  .agi {
    display: block;
    font-size: 42px;
    line-height: 1.05;
    font-weight: 900;
    letter-spacing: 7px;
    color: #6541c1;
  }
  @keyframes glow {
    0%, 100% { box-shadow: inset 0 0 0 3px rgba(101, 65, 193, .35); }
    50% { box-shadow: inset 0 0 0 5px rgba(59, 130, 246, .65); }
  }

  .clues {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin: 18px auto 0;
    width: min(100%, 340px);
    text-align: left;
  }
  .clue-section h2 {
    margin: 0 0 7px;
    padding: 0 0 5px;
    border-bottom: 1px solid #d2d2d7;
    color: #6e6e73;
    font-size: 12px;
    letter-spacing: 1.25px;
    text-transform: uppercase;
  }
  .clue-list {
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .clue-list li {
    margin: 0 0 7px;
    font-size: 12px;
    line-height: 1.3;
  }
  .clue-num {
    color: #6e6e73;
    font-weight: 800;
  }

  .controls {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 18px auto 0;
    width: min(100%, 340px);
  }
  .button {
    flex: 1 1 0;
    min-width: 0;
    padding: 10px 8px;
    border: 0;
    border-radius: 7px;
    background: #1d1d1f;
    color: #fff;
    text-align: center;
    text-decoration: none;
    font: 700 13px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .button:active {
    transform: scale(.97);
  }
  .hide-label {
    display: none;
  }
  .check-note {
    margin: 9px 0 0;
    color: #6e6e73;
    font-size: 11px;
    line-height: 1.35;
  }
  .check-frame {
    display: none;
    width: 0;
    height: 0;
    border: 0;
  }

  @media (max-width: 390px) {
    body { padding-inline: 12px; }
    h1 { font-size: 24px; }
    .grid { width: min(100%, 300px); }
    .clues { gap: 11px; }
    .clue-list li { font-size: 11.5px; }
    .button { font-size: 12px; }
  }


  /* QA revision: control toggles occur in natural tab order at the control bar. */
  .control-toggle {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }

  /* Entries remain neutral until Check is selected. */
  .letter-input:not(:placeholder-shown):valid,
  .letter-input:not(:placeholder-shown):invalid {
    background: transparent;
    box-shadow: none;
  }
  .puzzle:has(.check-toggle:checked) .letter-input:not(:placeholder-shown):valid {
    background: #e7f6e9;
    box-shadow: inset 0 0 0 3px #277a37;
  }
  .puzzle:has(.check-toggle:checked) .letter-input:not(:placeholder-shown):invalid {
    background: #ffe1e1;
    box-shadow: inset 0 0 0 3px #d92d20;
  }

  /* Fail-safe default: no unsupported selector can create a false solved state. */
  .solved-banner { display: none; }
  .agi-cell { animation: none; }
  .puzzle:valid:has(.check-toggle:checked) .solved-banner { display: block; }
  .puzzle:valid:has(.check-toggle:checked) .agi-cell { animation: glow 1.8s ease-in-out infinite; }

  .puzzle:has(.reveal-toggle:checked) .grid .letter-input {
    color: transparent;
    caret-color: transparent;
    background: #fff4cc;
  }
  .puzzle:has(.reveal-toggle:checked) .grid .solution { opacity: 1; }

  .check-feedback { display: none; }
  .puzzle:has(.check-toggle:checked) .check-feedback { display: block; }
  .puzzle:has(.check-toggle:checked) .check-label { display: none; }
  .uncheck-label { display: none; }
  .puzzle:has(.check-toggle:checked) .uncheck-label { display: inline; }
  .puzzle:has(.reveal-toggle:checked) .show-label { display: none; }
  .puzzle:has(.reveal-toggle:checked) .hide-label { display: inline; }

  .button {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .button:focus-visible,
  .button:has(.control-toggle:focus-visible) {
    outline: 3px solid #0071e3;
    outline-offset: 3px;
  }
  .letter-input:focus-visible {
    outline: 3px solid #0071e3;
    outline-offset: -3px;
    background: #a3d2ff;
  }

  @media (prefers-reduced-motion: reduce) {
    .agi-cell { animation: none !important; }
    .button:active { transform: none; }
  }

  .proof { width: min(100%, 780px); margin: 0 auto; text-align: left; }
  .proof h1 { font-size: 26px; }
  .proof code { overflow-wrap: anywhere; }
  .proof li { margin: .5rem 0; }
  .proof table { width: 100%; border-collapse: collapse; margin: 10px 0 18px; font-size: 13px; }
  .proof th, .proof td { padding: 7px 8px; border: 1px solid #d2d2d7; vertical-align: top; }
  .proof th { background: #ececf0; text-align: left; }
  .proof pre { overflow-x: auto; padding: 12px; border-radius: 7px; background: #ececf0; }
  .proof .status { padding: 10px 12px; border-left: 4px solid #6541c1; background: #f0eaff; }
  @media (max-width: 520px) {
    .proof table { font-size: 11.5px; }
    .proof th, .proof td { padding: 6px; }
  }
