  :root { --bg: #12131c; --fg: #e9eaf4; --muted: #8b8fa8; --line: #2a2d42; --card: #1b1d2c; --key: #272a40; --accent: #f5b13d; --accent-ink: #1b1405; --bad: #ff6b81; --win: #4fcf8b; --win-ink: #062614; }
  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  html, body { height: 100%; }
  body { margin: 0; background: var(--bg); color: var(--fg); font-family: "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
    display: flex; flex-direction: column; align-items: center; }
  header { width: 100%; text-align: center; padding: 16px 0 12px; }
  h1 { margin: 0; font-size: 34px; font-weight: 800; letter-spacing: .02em; }
  h1 .grad { background: linear-gradient(90deg, #ffb347, #ff6f91); -webkit-background-clip: text; background-clip: text; color: transparent; }
  .sub { color: var(--muted); font-size: 14px; margin-top: 4px; letter-spacing: .12em; text-transform: uppercase; }
  .hidden { display: none !important; }

  #game { flex: 1; width: 100%; max-width: 500px; display: flex; flex-direction: column; align-items: center; min-height: 0; }
  #board { scrollbar-color: var(--key) transparent; scrollbar-width: thin; flex: 1; overflow-y: auto; width: 100%; padding: 14px 0 12px; display: flex; flex-direction: column; align-items: center; gap: 7px; }
  .row { display: flex; gap: 7px; }
  .tile { --s: min(60px, 14vw); width: var(--s); height: var(--s); border: 2px solid transparent; border-radius: 12px; background: var(--card);
    display: grid; place-items: center; font-size: calc(var(--s) * .52); font-weight: 800; text-transform: uppercase; color: var(--fg); }
  .row.start .tile { background: var(--key); }
  .row.done .tile.match { background: var(--accent); color: var(--accent-ink); }
  .row.typing .tile { border-color: var(--line); background: transparent; }
  .row.typing .tile.filled { border-color: var(--muted); }
  .row.target .tile { background: transparent; border: 2px dashed var(--accent); color: var(--accent); opacity: .85; }
  .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .16em; margin-top: 12px; }
  .label:first-child { margin-top: 0; }
  .row.shake { animation: shake .35s; }
  @keyframes shake { 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }
  .empty { color: var(--muted); text-align: center; padding: 60px 24px; font-size: 18px; }

  #toast { position: fixed; top: 96px; left: 50%; transform: translateX(-50%); background: var(--fg); color: #12131c; font-weight: 700;
    padding: 10px 16px; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 20; white-space: nowrap; }
  #toast.show { opacity: 1; }

  #kb { width: 100%; max-width: 500px; padding: 0 8px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
  .krow { display: flex; gap: 6px; justify-content: center; width: 100%; }
  .key { flex: 0 1 43px; height: 54px; border: 0; border-radius: 12px; background: var(--key); color: var(--fg); font-weight: 700; font-size: 15px;
    font-family: inherit; text-transform: uppercase; cursor: pointer; padding: 0; }
  .key.wide { flex-basis: 65px; font-size: 12px; letter-spacing: .04em; }
  .key:active { background: #353955; }
  footer { display: flex; gap: 8px; justify-content: center; padding: 16px 8px 20px; flex-wrap: wrap; }
  footer button { background: var(--card); border: 0; border-radius: 999px; padding: 8px 14px; color: var(--muted); font-size: 13px; font-family: inherit; cursor: pointer; }
  footer button:hover { color: var(--fg); }

  #modal { position: fixed; inset: 0; background: rgba(8,9,14,.8); display: grid; place-items: center; z-index: 10; padding: 16px; overflow-y: auto; }
  #modal .box { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 30px 22px 22px; text-align: left; width: 100%; max-width: 400px; margin: auto; }
  #modal h2 { margin: 0 0 12px; font-size: 22px; text-align: center; }
  #modal p { margin: 8px 0; line-height: 1.45; color: #c4c6da; }
  #modal .x { position: absolute; top: 12px; right: 14px; width: 30px; height: 30px; border-radius: 50%; background: var(--key); border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
  .kicker { text-align: center; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .2em; text-transform: uppercase; }
  .big { text-align: center; font-size: 30px; font-weight: 800; text-transform: uppercase; margin: 6px 0 16px; letter-spacing: .03em; }
  .big em { font-style: normal; color: var(--accent); margin: 0 6px; }
  .score { display: flex; gap: 10px; margin-bottom: 14px; }
  .score div { flex: 1; background: var(--bg); border-radius: 14px; padding: 10px; text-align: center; }
  .score b { display: block; font-size: 28px; } .score span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
  .copy { display: block; width: 100%; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px; padding: 12px; font-weight: 800; font-size: 15px; font-family: inherit; cursor: pointer; margin-bottom: 8px; }
  .sec { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; margin: 18px 0 8px; }
  .stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .stats div { background: var(--bg); border-radius: 14px; padding: 10px 4px; text-align: center; }
  .stats b { display: block; font-size: 24px; } .stats span { font-size: 10px; color: var(--muted); line-height: 1.2; display: block; }
  .dist { display: flex; flex-direction: column; gap: 4px; }
  .br { display: flex; align-items: center; gap: 8px; }
  .br i { width: 18px; text-align: right; font-style: normal; font-size: 12px; color: var(--muted); }
  .track { flex: 1; height: 16px; }
  .fill { background: var(--key); color: var(--fg); height: 100%; min-width: 22px; border-radius: 999px; font-size: 11px; font-weight: 700; padding-left: 8px; line-height: 16px; }
  .fill.hl { background: var(--accent); color: var(--accent-ink); }
  .next { margin-top: 18px; text-align: center; font-size: 13px; color: var(--muted); } .next b { display: block; font-size: 22px; color: var(--fg); letter-spacing: .06em; }
  .path { letter-spacing: .08em; text-transform: uppercase; font-weight: 700; line-height: 1.7; text-align: center; }
  .retry { margin-top: 14px; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px; padding: 10px 20px; font-weight: 800; font-family: inherit; cursor: pointer; }


  footer .pill { background: var(--card); border-radius: 999px; padding: 8px 14px; color: var(--muted); font-size: 13px; text-decoration: none; }
  footer .pill:hover { color: var(--fg); }

  /* ads: kept well away from the keyboard so nobody taps one by accident */
  .adbar { flex: none; width: 100%; max-width: 728px; padding: 6px 8px 14px; text-align: center; }
  .adlabel { font-size: 10px; color: var(--muted); letter-spacing: .16em; text-transform: uppercase; margin-bottom: 4px; }
  .adslot { min-height: 50px; overflow: hidden; }
  .adslot.ph { display: grid; place-items: center; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); font-size: 12px; min-height: 90px; }
  .rail { position: fixed; top: 150px; width: 160px; text-align: center; display: none; }
  .rail .adslot { min-height: 600px; }
  .rail.rail-l { left: calc(50% - 250px - 190px); }
  .rail.rail-r { right: calc(50% - 250px - 190px); }
  @media (min-width: 1100px) { .rail:not(.hidden) { display: block; } }

  /* No double-tap zoom or text selection while playing. Pinch-zoom still works for accessibility. */
  html, body, * { touch-action: manipulation; }
  .key, .tile, .row, .label, header, footer button, footer .pill, #kb, #board { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

  /* The finished word turns green. */
  .row.solved .tile, .row.solved .tile.match { background: var(--win); border-color: var(--win); color: var(--win-ink); animation: pop .5s ease backwards; }
  .row.solved .tile:nth-child(2) { animation-delay: .08s; }
  .row.solved .tile:nth-child(3) { animation-delay: .16s; }
  .row.solved .tile:nth-child(4) { animation-delay: .24s; }
  .row.solved .tile:nth-child(5) { animation-delay: .32s; }
  .row.solved .tile:nth-child(6) { animation-delay: .40s; }
  @keyframes pop { 0% { transform: scale(.7); opacity: .4; } 60% { transform: scale(1.14); } 100% { transform: scale(1); opacity: 1; } }
  @media (prefers-reduced-motion: reduce) { .row.solved .tile { animation: none; } }
