  /* castlefall game surface.
     theme.css owns the page chrome (body, headings, links, the measure). This
     file owns only the game itself, so its selectors are scoped under .game —
     with the two fixed bars as the exception, since they must sit outside the
     app container to be position:fixed.
     Tokens here are prefixed --cf- so they cannot collide with theme.css's;
     --rule in particular means a border shorthand there and a colour here. */
  .game, .wordbar, .timer-bar {
    --cf-ink:   #000000;
    --cf-muted: #6B6B6B;
    --cf-link:  #0019FF;
    --cf-rule:  #DDDDDD;
    --cf-sans:  -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --cf-mono:  ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  }

  /* The word bar is position:fixed over the page; keep it off the last control. */
  body { padding-bottom: 7rem; }


  .game h1 { font-size: 1.4rem; font-weight: 400; line-height: 1.25; margin: 0 0 0.5rem; }
  .game h2 { font-size: 1em; font-weight: 400; margin: 2.5rem 0 0.75rem;
             padding-bottom: 0.3rem; border-bottom: 1px solid var(--cf-rule); }
  .game .lede { margin: 0 0 2.5rem; color: var(--cf-muted); font-size: 0.9em; }

  /* ---- game surface: sans, and never smaller than 16px on inputs, or iOS
     Safari zooms the viewport on focus and never zooms back ---- */

  .game { font-family: var(--cf-sans); letter-spacing: 0; font-size: 1rem; }

  .game button, .game input, .game select {
    font-family: var(--cf-sans);
    font-size: 1rem;
    letter-spacing: 0;
  }

  .game button {
    min-height: 44px;
    padding: 0.6rem 1.1rem;
    border: 1px solid var(--cf-ink);
    border-radius: 0;
    background: #FFFFFF;
    color: var(--cf-ink);
    cursor: pointer;
  }
  .game button:hover { background: var(--cf-ink); color: #FFFFFF; }
  .game button:focus-visible { outline: 2px solid var(--cf-link); outline-offset: 2px; }
  .game button[disabled], .game button[disabled]:hover {
    cursor: not-allowed;
    background: #FFFFFF;
    color: #AAAAAA;
    border-color: #DDDDDD;
  }
  .game button.primary { background: var(--cf-ink); color: #FFFFFF; }
  .game button.primary:hover { background: var(--cf-link); border-color: var(--cf-link); }
  .game button.primary[disabled], .game button.primary[disabled]:hover {
    background: #FFFFFF;
    color: #AAAAAA;
    border-color: #DDDDDD;
  }

  .game input[type="text"], .game input[type="number"], .game select {
    min-height: 44px;
    padding: 0.5rem 0.6rem;
    border: 1px solid #BBBBBB;
    border-radius: 0;
    background: #FFFFFF;
    color: var(--cf-ink);
  }
  .game input:focus-visible, .game select:focus-visible {
    outline: 2px solid var(--cf-link);
    outline-offset: -1px;
  }

  /* ---- join gate ---- */

  .join { margin-bottom: 2rem; }
  .join-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
  }
  .control { display: flex; flex-direction: column; gap: 0.25rem; flex: 0 1 14rem; max-width: 14rem; }
  .control span { font-size: 0.8rem; color: var(--cf-muted); }
  .control input { width: 100%; }
  .join-note { margin: 1rem 0 0; font-size: 0.8rem; color: var(--cf-muted); }

  /* ---- status bar ---- */

  .statusbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 0.75rem;
  }
  .statusbar .whoami { flex: 1 1 12rem; }
  .statusbar .whoami strong { font-weight: 600; }

  /* ---- declare result (statusbar) ---- */

  .declare {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    flex: 1 1 100%;
    margin-top: 0.25rem;
  }
  .declare[hidden] { display: none; }
  .declare input { flex: 1 1 12rem; min-width: 0; }
  .declare button { min-height: 40px; padding: 0.4rem 0.9rem; font-size: 0.9rem; }

  /* Connection banner. Hidden while healthy; only speaks up when it isn't. */
  .conn {
    padding: 0.6rem 0.8rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    border: 1px solid #DDBBBB;
    background: #FFF5F5;
    color: #AA0000;
  }
  .conn[hidden] { display: none; }

  /* ---- grids: auto-fill, so a narrow phone collapses to one column and
     nothing ever scrolls sideways ---- */

  .grid {
    display: grid;
    gap: 0.4rem;
    grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  }
  .grid.players { grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr)); }

  .player {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 2rem;
    padding: 0.15rem 0;
  }
  .player .who { overflow-wrap: anywhere; }
  .player.disconnected .who { color: var(--cf-muted); font-style: italic; }
  .player button.kick {
    min-height: 32px;
    padding: 0.15rem 0.5rem;
    font-size: 0.75rem;
    border-color: #CCCCCC;
    color: var(--cf-muted);
    flex: none;
  }
  .player button.kick:hover { background: #AA0000; border-color: #AA0000; color: #FFFFFF; }
  .count { color: var(--cf-muted); font-size: 0.85em; }

  /* ---- new round form ---- */

  .newround {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
    margin: 1.5rem 0 0;
    font-size: 0.95rem;
  }
  .newround input.wordcount { width: 4.5rem; text-align: center; }
  .newround select { flex: 1 1 12rem; min-width: 0; }

  /* ---- rounds ---- */

  .round {
    border: 1px solid var(--cf-ink);
    padding: 0.9rem 1rem 1rem;
    margin-bottom: 1rem;
  }
  .round.spoiled { border-color: #CCCCCC; background: #FAFAFA; }
  .round h3 {
    font-family: var(--cf-sans);
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0;
    margin: 0 0 0.6rem;
  }
  .round h3 .round-stats { font-weight: 400; color: var(--cf-muted); }
  .round h4 {
    font-family: var(--cf-sans);
    font-size: 0.8rem;
    font-weight: 400;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--cf-muted);
    margin: 1rem 0 0.5rem;
  }
  .round .word { overflow-wrap: anywhere; }
  /* your own word, and anyone revealed to have shared it */
  .round .same { font-weight: 700; }
  .round .same::before { content: "\2022\00a0"; }
  .round .myword {
    margin-top: 1rem;
    padding-top: 0.8rem;
    border-top: 1px solid var(--cf-rule);
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
  }
  .round .myword strong { font-size: 1.15rem; }

  /* ---- round result row (appears once teams are revealed) ---- */

  .round .result {
    margin-top: 1rem;
    padding-top: 0.8rem;
    border-top: 1px solid var(--cf-rule);
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
  }
  .round .result.scored { font-weight: 600; }
  .round .result button { min-height: 36px; padding: 0.4rem 0.8rem; font-size: 0.85rem; }

  /* ---- log ---- */

  .logwrap {
    margin-top: 0.5rem;
    height: clamp(9rem, 28vh, 16rem);
    overflow-y: auto;
    border: 1px solid var(--cf-rule);
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
  }
  table.log { width: 100%; border-spacing: 0; table-layout: fixed; }
  table.log td { padding: 0.1rem 0.4rem 0.1rem 0; vertical-align: top; }
  table.log td.at { width: 5.5rem; font-family: var(--cf-mono); color: var(--cf-muted); font-size: 0.9em; }
  table.log td.what { overflow-wrap: anywhere; }
  table.log tr.roundstart td.what { font-weight: 700; }
  table.log tr.roundstartpast td.what { font-weight: 700; color: var(--cf-muted); }
  table.log tr.error td.what { color: #AA0000; font-weight: 600; }
  table.log tr.setting td.what, table.log tr.connect td.what { color: var(--cf-muted); }
  table.log tr.timer td.what { color: #FFFFFF; font-weight: 600; }
  table.log tr.result td.what { font-weight: 700; }

  .chatform {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
  }
  .chatform input { flex: 1 1 auto; min-width: 0; }

  /* ---- settings ---- */

  .settings { margin-top: 2rem; font-size: 0.9rem; }
  .settings summary { cursor: pointer; color: var(--cf-link); }
  .settings summary:hover { text-decoration: underline; }
  .settings .row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
    margin-top: 0.8rem;
  }
  .settings label { display: inline-flex; align-items: center; gap: 0.4rem; }
  .settings input[type="checkbox"] { width: 1.1rem; height: 1.1rem; }
  .settings .hint { color: var(--cf-muted); font-size: 0.85em; margin: 0.5rem 0 0; }

  /* ---- sticky word bar: the one thing you look at while holding the phone
     at a table, so it stays reachable without scrolling past the grid ---- */

  .wordbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    display: flex;
    gap: 0.8rem;
    align-items: center;
    padding: 0.7rem clamp(1.5rem, 5vw, 3.5rem);
    padding-bottom: max(0.7rem, env(safe-area-inset-bottom));
    background: #FFFFFF;
    border-top: 1px solid var(--cf-ink);
    font-family: var(--cf-sans);
    letter-spacing: 0;
  }
  .wordbar[hidden] { display: none; }
  .wordbar .label { font-size: 0.8rem; color: var(--cf-muted); flex: none; }
  .wordbar .value { font-size: 1.3rem; font-weight: 700; overflow-wrap: anywhere; }
  .wordbar button { flex: none; margin-left: auto; }

  /* ---- timer overlay: a fixed bar across the top while a timer runs ---- */

  .timer-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.6rem clamp(1.5rem, 5vw, 3.5rem);
    padding-top: max(0.6rem, env(safe-area-inset-top));
    background-color: hsl(120, 100%, 30%);
    color: #FFFFFF;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
  }
  .timer-bar[hidden] { display: none; }
  .timer-bar .label { font-size: 0.8rem; opacity: 0.9; }
  .timer-bar .value {
    font-size: 1.4rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1;
  }

  /* ---- leaderboard: right-side panel on wide screens, stacked below on
     phones ---- */

  .leaderboard { margin-top: 2.5rem;
                 border: var(--panel-border); border-radius: var(--radius);
                 background: var(--panel-bg); padding: 6px 7px; }
  .leaderboard h2 { margin-top: 0; }
  .leaderboard ol {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: lboard;
  }
  .leaderboard li {
    counter-increment: lboard;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--cf-rule);
  }
  .leaderboard li::before {
    content: counter(lboard) ".";
    flex: none;
    color: var(--cf-muted);
    font-family: var(--cf-mono);
    font-size: 0.85em;
  }
  .leaderboard .who { overflow-wrap: anywhere; }
  .leaderboard .wins { flex: none; color: var(--cf-muted); font-variant-numeric: tabular-nums; }
  .leaderboard li.me { font-weight: 700; }
  .leaderboard li.gone .who { color: var(--cf-muted); font-style: italic; }

  @media (min-width: 60rem) {
    #app {
      display: grid;
      grid-template-columns: minmax(0, 1fr) 14rem;
      column-gap: 2rem;
      align-items: start;
    }
    #app[hidden] { display: none; }
    .app-main { min-width: 0; }
    .leaderboard { margin-top: 0; position: sticky; top: 1rem; min-width: 0; }
  }

  /* ---- footer ---- */

  .back { margin-top: 3rem; font-size: 0.8em; }
  .credit { margin-top: 1rem; font-size: 0.75em; color: var(--cf-muted); }
  .credit a { color: var(--cf-muted); }

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