  :root{
    --paper:#ECE9DF;
    --grid:#DDD9CC;
    --ink:#2B2A26;
    --pencil:#8B887E;
    --pencil-dark:#5A5750;
    --yellow:#F2D14B;
    --green:#A8C77F;
    --red:#C0503C;
    --tile:#FAF8F1;
  }
  *{box-sizing:border-box;margin:0;padding:0;}
  body{
    font-family:"Courier New",Courier,monospace;
    background:var(--paper);
    background-image:
      linear-gradient(var(--grid) 1px, transparent 1px),
      linear-gradient(90deg, var(--grid) 1px, transparent 1px);
    background-size:22px 22px;
    color:var(--ink);
    display:flex;justify-content:center;
    padding:16px 10px 60px;
  }
  .sheet{width:100%;max-width:430px;}

  /* flex-end, not baseline: baseline would line the title up with the small
     "misses" label and leave the count hanging below it. Explicit line-height:1
     on both sides makes the box bottoms sit on the text baselines, so the title
     and the count share one line. */
  header{display:flex;justify-content:space-between;align-items:flex-end;border-bottom:2px solid var(--ink);padding-bottom:8px;margin-bottom:6px;}
  h1{font-size:24px;letter-spacing:6px;font-weight:bold;line-height:1;}
  /* A life bar: one segment per miss you're allowed, depleting from the RIGHT so
     the remaining run always reads left-to-right. Segments flex, so the bar
     fills its box at any width instead of relying on fixed token sizes. */
  .misses{
    border:2px solid var(--ink);background:var(--tile);
    box-shadow:3px 3px 0 var(--ink);
    padding:8px 10px 9px;margin-top:14px;
  }
  .misses-label{
    font-size:11px;letter-spacing:1px;text-transform:uppercase;font-weight:bold;
    color:var(--pencil-dark);text-align:center;margin-bottom:6px;
  }
  .misses-bar{display:flex;gap:2px;}
  .misses-bar i{
    flex:1 1 0;height:16px;display:block;
    border:1.5px solid var(--ink);background:var(--tile);
  }
  .misses-bar i.spent{
    border-color:var(--red);
    background-image:linear-gradient(45deg,
      transparent 38%, var(--red) 38%, var(--red) 62%, transparent 62%);
  }
  .misses-bar i.just{animation:strike .36s;}
  @keyframes strike{0%{transform:scale(1.5) rotate(-8deg);}100%{transform:scale(1);}}
  .misses.danger{border-color:var(--red);box-shadow:3px 3px 0 var(--red);}
  .misses.danger .misses-label{color:var(--red);animation:missPulse 1.2s infinite;}
  .misses.danger .misses-bar i:not(.spent){border-color:var(--red);}
  @keyframes missPulse{50%{opacity:.45;}}

  .tagline{font-size:12px;color:var(--pencil-dark);margin-bottom:8px;}
  .tagline a{color:var(--ink);cursor:pointer;text-decoration:underline;}

  .theme{
    text-align:center;font-size:13px;letter-spacing:3px;font-weight:bold;
    border:2px solid var(--ink);background:var(--yellow);
    box-shadow:3px 3px 0 var(--ink);
    padding:8px;margin:10px 0 4px;transform:rotate(-.5deg);
  }
  .theme small{display:block;font-size:9px;letter-spacing:2px;font-weight:normal;color:var(--ink);opacity:.6;}

  .slot.revealed{background:var(--paper);color:var(--red);border-style:dashed;border-color:var(--red);box-shadow:none;}

  #rules{display:none;border:1px dashed var(--pencil);padding:10px;font-size:12px;line-height:1.55;margin-bottom:12px;background:var(--tile);}
  #rules.open{display:block;}
  #rules li{margin-left:16px;margin-bottom:4px;}
  .chip{display:inline-block;padding:0 4px;border:1px solid var(--ink);font-weight:bold;}
  .chip.g{background:var(--green);}
  .chip.y{background:var(--yellow);}

  .words{display:flex;flex-direction:column;gap:10px;margin-top:8px;}
  .word-block{transition:opacity .18s;}
  .word-block.dimmed{opacity:.3;}
  .word-block.flagged .word-row{position:relative;}
  .word-block.flagged .word-row::before{
    content:"\25B8";color:var(--ink);font-size:16px;font-weight:bold;
    /* vertically centred against the tiles, so it holds at both slot sizes */
    position:absolute;left:-13px;top:50%;transform:translateY(-50%);
  }
  .row-chips{display:flex;gap:4px;justify-content:center;align-items:center;margin-top:4px;min-height:24px;}
  .chips-label{font-size:10px;letter-spacing:1px;color:var(--pencil);text-transform:uppercase;margin-right:2px;}
  /* Shrink-wrapped so the flagged-row arrow can anchor to the tiles themselves.
     A full-width row would measure the arrow's offset from the sheet edge, which
     pushed it tens of px away from the words and off-screen on a phone. */
  .word-row{display:flex;gap:5px;align-items:center;justify-content:center;width:fit-content;margin:0 auto;}
  .chip-tile{
    width:24px;height:24px;display:flex;align-items:center;justify-content:center;
    font-size:12px;font-weight:bold;background:var(--paper);color:var(--pencil);
    border:1.5px dashed var(--pencil);cursor:pointer;
  }
  .chip-tile:nth-child(odd){transform:rotate(3deg);}
  .chip-tile:nth-child(even){transform:rotate(-3deg);}
  .chip-tile:hover,.chip-tile:focus{outline:none;color:var(--ink);border-color:var(--ink);}
  .chip-tile.inspecting{background:var(--yellow);color:var(--ink);border-style:solid;border-color:var(--ink);outline:2px solid var(--red);}
  .slot{
    width:44px;height:50px;background:var(--tile);
    border:2px solid var(--ink);
    display:flex;align-items:center;justify-content:center;
    font-size:22px;font-weight:bold;
    box-shadow:2px 2px 0 var(--ink);
    position:relative;cursor:default;
  }
  .word-block:nth-child(odd) .slot:nth-child(odd){transform:rotate(-1deg);}
  .word-block:nth-child(odd) .slot:nth-child(even){transform:rotate(1deg);}
  .word-block:nth-child(even) .slot:nth-child(odd){transform:rotate(1deg);}
  .word-block:nth-child(even) .slot:nth-child(even){transform:rotate(-1deg);}
  .slot.open.targetable{cursor:pointer;border-style:dashed;border-color:var(--pencil);box-shadow:2px 2px 0 var(--pencil);}
  .slot.open.targetable:hover,.slot.open.targetable:focus{background:var(--yellow);outline:none;}
  .slot.filled{background:var(--green);}
  .slot.missed{cursor:not-allowed;}
  .slot .x{color:var(--red);font-size:18px;font-weight:bold;}
  .slot.pop{animation:pop .3s;}
  @keyframes pop{0%{transform:scale(1.2);}100%{transform:scale(1);}}

  .table{margin-top:16px;border:2px solid var(--ink);background:var(--tile);box-shadow:4px 4px 0 var(--ink);padding:14px;text-align:center;position:relative;}
  .hand{display:flex;gap:12px;justify-content:center;margin-bottom:8px;}

  /* Three columns, each a draw pile with its current card sitting on top. The
     pile behind the card is what used to be a single deck off to the left. */
  .col{position:relative;width:58px;height:66px;}
  .stack{position:absolute;inset:0;}
  .stack i{
    position:absolute;left:0;top:0;width:58px;height:66px;display:block;
    background:var(--tile);border:2px solid var(--ink);
  }
  .stack i:nth-child(1){transform:translate(3px,3px) rotate(1deg);}
  .stack i:nth-child(2){transform:translate(5px,5px) rotate(-1deg);}
  .stack i:nth-child(3){transform:translate(7px,7px) rotate(1.5deg);}
  .stack i:nth-child(4){transform:translate(9px,9px) rotate(-.5deg);}
  .hand-tile{
    width:58px;height:66px;font-size:30px;font-weight:bold;
    display:flex;align-items:center;justify-content:center;
    border:2px solid var(--ink);background:var(--yellow);
    box-shadow:3px 3px 0 var(--ink);cursor:pointer;
  }
  .hand-tile{position:relative;z-index:1;}
  .col:nth-child(1) .hand-tile{transform:rotate(-2deg);}
  .col:nth-child(2) .hand-tile{transform:rotate(1deg);}
  .col:nth-child(3) .hand-tile{transform:rotate(-1deg);}
  .hand-tile:hover,.hand-tile:focus{outline:none;filter:brightness(1.05);}
  .hand-tile.selected{outline:3px solid var(--red);transform:translateY(-4px) rotate(0deg);}

  /* face-down: the back of a card, no letter */
  .hand-tile.down{
    background:var(--tile);
    background-image:repeating-linear-gradient(45deg,
      var(--grid) 0 4px, transparent 4px 8px);
  }
  /* an exhausted pile retires — nothing left to draw in this column */
  .hand-tile.gone{
    background:transparent;border-style:dashed;border-color:var(--pencil);
    box-shadow:none;cursor:default;
  }

  .hand-tile.drawn{animation:drawn .312s;}
  @keyframes drawn{0%{transform:translateY(-9px) rotate(0);opacity:.2;}100%{opacity:1;}}
  /* flip = horizontal squash; the face has already swapped in the DOM, so the
     card compresses to nothing and opens out again showing the letter */
  .hand-tile.flipping{animation:flipCard .312s ease-in-out;}
  @keyframes flipCard{0%{transform:scaleX(-1);}50%{transform:scaleX(.05);}100%{transform:scaleX(1);}}
  button{
    font-family:inherit;font-size:14px;font-weight:bold;letter-spacing:1px;
    background:var(--tile);border:2px solid var(--ink);color:var(--ink);
    padding:10px 18px;cursor:pointer;box-shadow:3px 3px 0 var(--ink);
  }
  button:hover{background:var(--yellow);}
  button:active{transform:translate(2px,2px);box-shadow:1px 1px 0 var(--ink);}
  button:focus-visible{outline:3px solid var(--red);outline-offset:2px;}
  button.quiet{font-weight:normal;font-size:12px;box-shadow:none;border-style:dashed;border-color:var(--pencil-dark);color:var(--pencil-dark);padding:8px 14px;}
  .btnrow{display:flex;gap:10px;justify-content:center;flex-wrap:wrap;}

  #status{
    margin-top:10px;padding-top:10px;font-size:12px;line-height:1.4;
    min-height:34px;display:flex;align-items:center;justify-content:center;
    border-top:1px dashed var(--green);color:var(--ink);
  }
  #status.idle{border-top-color:var(--pencil);color:var(--pencil);}
  #status.mid{border-top-color:var(--yellow);}
  #status.bad{border-top-color:var(--red);color:var(--red);}

  #winbox{display:none;margin-top:20px;border:3px double var(--ink);background:var(--tile);padding:20px;text-align:center;}
  #winbox.open{display:block;}
  #winbox h2{font-size:20px;letter-spacing:3px;margin-bottom:8px;}
  #winbox .score{font-size:40px;font-weight:bold;}
  #winbox p{font-size:12px;color:var(--pencil);margin:8px 0 14px;}

  .shake{animation:shake .36s;}
  @keyframes shake{0%,100%{transform:translateX(0);}25%{transform:translateX(-6px);}75%{transform:translateX(6px);}}

  /* ---- motion --------------------------------------------------------- */
  /* Travelling tiles live on this overlay because render() rebuilds the board
     on every action; nothing animating can survive on the tiles themselves. */
  #fly{position:fixed;inset:0;pointer-events:none;z-index:50;}
  .ghost{
    position:fixed;display:flex;align-items:center;justify-content:center;
    font-weight:bold;transition:transform .252s cubic-bezier(.3,.8,.4,1),opacity .252s ease-out;
    will-change:transform,opacity;
  }
  .ghost.hit{
    background:var(--yellow);border:2px solid var(--ink);
    box-shadow:3px 3px 0 var(--ink);font-size:30px;
  }
  /* A rejected card lifts clear of its column, then drops back down and sinks
     into the pile. The pile sits directly under the card, so a straight flight
     would travel no distance — the arc is what makes it read. */
  .ghost.tuck{
    background:var(--yellow);border:2px solid var(--ink);
    box-shadow:3px 3px 0 var(--ink);font-size:30px;
    transition:none;
    animation:tuck .624s cubic-bezier(.35,0,.55,1) forwards;
  }
  @keyframes tuck{
    0%  {transform:translate(0,0) rotate(0) scale(1);opacity:1;}
    42% {transform:translate(var(--lift-x,10px),-34px) rotate(-12deg) scale(1.04);opacity:1;}
    72% {transform:translate(var(--tuck-x,2px),0) rotate(-4deg) scale(.95);opacity:.95;}
    100%{transform:translate(var(--tuck-x,2px),var(--tuck-y,11px)) rotate(3deg) scale(.8);opacity:0;}
  }
  .stack.taking{animation:stackTake .408s;}
  @keyframes stackTake{40%{transform:translateY(3px) scale(1.03);}}
  /* the slot stays blank until the flying tile lands in it */
  .slot.landing{color:transparent;}
  /* transient miss mark: the persistent ✗ only shows while its letter is active */
  .ghost.stamp-x{
    color:var(--red);font-size:26px;
    animation:stampX .744s ease-out forwards;
  }
  @keyframes stampX{
    0%{transform:scale(1.9) rotate(-14deg);opacity:0;}
    22%{transform:scale(1) rotate(-8deg);opacity:1;}
    70%{opacity:1;}
    100%{opacity:0;}
  }
  .slot.nope{animation:nope .384s;}
  @keyframes nope{0%,100%{transform:translateX(0);}30%{transform:translateX(-4px);}65%{transform:translateX(4px);}}

  .slot.dealt-in{animation:dealtIn .408s backwards;}
  @keyframes dealtIn{0%{opacity:0;transform:translateY(-10px) scale(.9);}100%{opacity:1;}}

  .slot.settle{animation:settle .48s backwards;}
  @keyframes settle{
    0%{transform:translateY(-5px);}
    45%{transform:translateY(2px);}
    100%{transform:translateY(0);}
  }

  #endTitle.stamp{animation:stampIn .504s cubic-bezier(.2,1.5,.4,1);}
  @keyframes stampIn{
    0%{transform:scale(1.7) rotate(-7deg);opacity:0;}
    55%{opacity:1;}
    100%{transform:scale(1) rotate(0);opacity:1;}
  }

  .hand-tile.nudge{animation:breathe 2.28s ease-in-out infinite;}
  @keyframes breathe{50%{transform:translateY(-3px);}}

  /* ---- stats ---------------------------------------------------------- */
  #stats:not(:empty){
    border-top:1px dashed var(--pencil);margin:14px 0 4px;padding-top:12px;
  }
  .stat-row{display:flex;justify-content:center;gap:18px;flex-wrap:wrap;}
  .stat{display:flex;flex-direction:column;align-items:center;min-width:52px;}
  .stat b{font-size:22px;line-height:1;}
  .stat span{font-size:9px;letter-spacing:1px;text-transform:uppercase;color:var(--pencil-dark);margin-top:3px;}
  .dist{margin-top:12px;display:flex;flex-direction:column;gap:3px;}
  .dist-row{display:flex;align-items:center;gap:6px;font-size:10px;}
  .dist-label{width:38px;flex:none;text-align:right;color:var(--pencil-dark);letter-spacing:1px;}
  /* the bar is a % of this track, not of the row — the label is outside it */
  .dist-track{flex:1;min-width:0;display:flex;}
  .dist-bar{
    background:var(--grid);border:1px solid var(--ink);color:var(--ink);
    font-size:9px;font-weight:bold;text-align:right;padding:1px 4px;min-height:14px;
  }
  .dist-bar.mine{background:var(--green);}

  footer{margin-top:30px;font-size:10px;color:var(--pencil-dark);text-align:center;line-height:1.6;}
  /* keeps "(~25 minutes to go)" from breaking mid-phrase on a narrow screen */
  .countdown{white-space:nowrap;}

  @media (prefers-reduced-motion: reduce){
    *{animation:none !important;transition:none !important;}
  }
  @media (max-width:380px){
    .slot{width:38px;height:44px;font-size:19px;}
    .word-block.flagged .word-row::before{left:-11px;font-size:14px;}
    /* smaller hand makes room for the deck at 320px, and buys back a little
       height on exactly the phones that need it */
    .hand{gap:10px;}
    .hand-tile{width:50px;height:58px;font-size:26px;}
    /* segments flex, so only the chrome needs trimming on small screens */
    .misses{padding:7px 8px 8px;}
    .misses-bar{gap:1.5px;}
    .misses-bar i{height:14px;}
    .col{width:50px;height:58px;}
    .stack i{width:50px;height:58px;}
  }
