:root {
  color-scheme: dark;
  --bg: #0d1117;
  --panel: #161b22;
  --line: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --good: #3fb950;
  --warn: #d29922;
  --cell: #21262d;
  --vowel: #1f6feb;
  --consonant: #30363d;
  --rare: #9e6a03;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px;
}

#hud {
  display: flex;
  gap: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 20px;
  width: min(480px, 100%);
  justify-content: space-between;
}

.hud-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
}

.hud-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.hud-value {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.hud-preview {
  width: 32px;
  height: 32px;
  line-height: 32px;
  text-align: center;
  background: var(--cell);
  border-radius: 6px;
  margin-top: 2px;
}

#stage {
  position: relative;
}

#boards-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

#board,
#opponent-board {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: block;
}

/* The board is a gesture surface: slide to steer, tap to drop. Without this
   the browser claims the drag for scrolling and the letter never moves.
   `none` rather than `pan-y` because a vertical flick is a legitimate
   gesture here too, not a request to scroll the page. */
#board {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#opponent-board {
  opacity: 0.92;
}

#opponent-hud {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 14px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
}

#opponent-name {
  font-weight: 600;
  color: var(--text);
}

#opponent-score-block {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.opponent-score-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

#opponent-score {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 18px;
  color: var(--accent);
  min-width: 28px;
  text-align: right;
}

/* --- In-game ladder sidebar: compact standings shown beside the board
   during any match so the stakes stay visible while playing. --- */
#league-sidebar {
  width: 185px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  align-self: flex-start;
}

#league-sidebar-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 2px;
}

/* The ladder lists every player rather than a top-N cut, so it gets its own
   scroll rather than growing the page past the board. */
#league-sidebar-count {
  font-size: 11px;
  color: var(--accent);
  margin-bottom: 8px;
}

#league-sidebar-body {
  max-height: 60vh;
  overflow-y: auto;
}

/* A player who is online gets more than a 7px dot -- playtesters reported
   they couldn't tell who was around at all. */
.ladder-row.is-online-row .ladder-name { color: var(--text); }
.ladder-row:not(.is-online-row) .ladder-name { color: var(--muted); }

.ladder-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
  padding: 3px 5px;
  border-radius: 4px;
}

.ladder-row.row-you {
  background: rgba(88, 166, 255, 0.15);
  font-weight: 600;
}

.ladder-rank {
  color: var(--muted);
  width: 16px;
  flex-shrink: 0;
}

.ladder-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ladder-rating {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.ladder-empty {
  font-size: 12px;
  color: var(--muted);
}

/* On-screen pause/exit for practice matches: touch players have no Esc key.
   Sits over the board's top-right corner; hidden in ranked play, where
   leaving mid-match is a forfeit by spec. */
#match-exit {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 5;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(22, 27, 34, 0.85);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#match-exit:hover { color: var(--text); border-color: var(--muted); }

#combo-callout {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 2px 12px rgba(88, 166, 255, 0.6);
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease, transform 120ms ease;
  text-align: center;
  white-space: nowrap;
}

#combo-callout.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#combo-callout .notice {
  font-size: 15px;
  font-weight: 500;
  color: var(--warn);
  text-shadow: none;
}

#combo-callout .bonus {
  display: block;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  margin-top: 2px;
}

.hidden { display: none !important; }

/* --- End-of-match word list (playtest request) ---
   Collapsed by default so result screens stay compact; the summary line
   still names the best word so there's a reason to open it. */
.word-log {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--cell);
}

.word-log summary {
  cursor: pointer;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text);
  list-style-position: inside;
}

.word-log-rows {
  max-height: 200px;
  overflow-y: auto;
  padding: 0 12px 8px;
}

.word-log-row span:last-child {
  color: var(--warn);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* --- Hover tooltips: any element with data-tip shows it on hover.
   Default position is above the element; add data-tip-down for elements
   near the top of the screen (HUD, table headers). Hover-only by design --
   the playtest is keyboard/desktop-first. --- */
[data-tip] {
  position: relative;
}

[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  background: #1c2128;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: normal;
  text-transform: none;
  padding: 8px 11px;
  border-radius: 8px;
  width: max-content;
  max-width: 250px;
  white-space: normal;
  text-align: left;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  z-index: 60;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 120ms ease;
}

[data-tip]:hover::after {
  opacity: 1;
  visibility: visible;
}

[data-tip][data-tip-down]::after {
  bottom: auto;
  top: calc(100% + 7px);
}

/* On touch devices there is no hover, so these tooltips can never be read --
   and because each one is laid out at `width: max-content` even while hidden,
   they widened the page past the viewport and made the whole thing scroll
   sideways on a phone (375px viewport, 463px scroll width). Dropping the
   pseudo-element on hover-less pointers fixes the scroll and costs nothing. */
@media (hover: none) {
  [data-tip]::after { content: none; }
}

/* --- Mode cards on the home screen: each play mode is a full-width button
   with a visible one-line explanation so nobody has to guess (or hover) to
   learn that Live needs both players online while Find Match doesn't. --- */
.mode-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

.mode-card {
  text-align: left;
  background: var(--cell);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  width: 100%;
}

.mode-card:hover {
  border-color: var(--accent);
}

.mode-title {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(88, 166, 255, 0.15);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.mode-badge.live {
  background: rgba(63, 185, 80, 0.15);
  color: var(--good);
}

.mode-badge.practice {
  background: rgba(139, 148, 158, 0.15);
  color: var(--muted);
}

.mode-desc {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.5;
}

/* --- Compact mode cards (native shell home menu) ---
   Headings only so every mode fits on one phone screen; the info icon
   toggles the same description the web shows inline. Rendered only when
   client/main.js is running inside the Capacitor shell. --- */
.mode-card.compact { padding: 12px 14px; }

.mode-card.compact .mode-desc { margin-top: 8px; }

.mode-info {
  margin-left: auto;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  font-style: italic;
  font-family: Georgia, serif;
}

/* --- Online presence --- */
.online-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
  flex-shrink: 0;
  margin-right: 6px;
  vertical-align: middle;
}

.online-dot.is-online {
  background: var(--good);
  box-shadow: 0 0 5px rgba(63, 185, 80, 0.8);
}

/* Spelled-out presence. The dot alone was not readable -- see the Status
   column on the leaderboard and the summary line above it. */
.online-word {
  font-size: 11px;
  color: var(--muted);
}

.online-word.is-online {
  color: var(--good);
  font-weight: 600;
}

#league-table .col-status { white-space: nowrap; }

.online-summary {
  margin: 0 0 10px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--good);
  border-radius: 8px;
  background: var(--cell);
  font-size: 13px;
  line-height: 1.5;
}

.online-summary.none {
  border-left-color: var(--muted);
  color: var(--muted);
}

.mode-live-status {
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.mode-live-status.online { color: var(--text); }
.mode-live-status.offline { color: var(--warn); }

#overlay {
  position: absolute;
  inset: 0;
  background: rgba(13, 17, 23, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}

#overlay-panel {
  text-align: center;
  padding: 24px;
  max-width: 360px;
  /* The menu grew past what fits on a laptop screen -- scroll inside the
     panel rather than spilling over the HUD and the controls footer. */
  max-height: 100%;
  overflow-y: auto;
}

#overlay-panel h1 {
  margin: 0 0 4px;
  font-size: 26px;
}

#overlay-subtitle {
  color: var(--muted);
  margin: 0 0 16px;
}

#overlay-body {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 20px;
  line-height: 1.6;
  text-align: left;
}

#overlay-body .stat-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 4px 0;
}

#overlay-body .stat-row span:first-child {
  flex-shrink: 0;
}

#overlay-body .stat-row span:last-child {
  text-align: right;
}

#overlay-button {
  background: var(--accent);
  color: #0d1117;
  border: none;
  border-radius: 8px;
  padding: 10px 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

#overlay-button:hover { filter: brightness(1.1); }

#countdown-display {
  font-size: 64px;
  font-weight: 700;
  text-align: center;
  color: var(--accent);
  margin: 16px 0;
}

#username-input {
  width: 100%;
  background: var(--cell);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 15px;
}

#username-input:focus,
#passphrase-input:focus {
  outline: none;
  border-color: var(--accent);
}

#passphrase-input {
  width: 100%;
  background: var(--cell);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 15px;
  margin-top: 8px;
}

.auth-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.auth-tab {
  flex: 1;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.auth-tab.active {
  background: var(--cell);
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

.auth-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: left;
}

.auth-error {
  margin-top: 10px;
  color: #f85149;
  font-size: 13px;
}

.mode-card.subtle .mode-title { color: var(--muted); font-weight: 500; }

/* Destructive actions (Delete Account): visibly different from everything
   else on the menu so it can't be mistaken for a routine item. */
.mode-card.danger { border-color: rgba(248, 81, 73, 0.5); }
.mode-card.danger .mode-title { color: #f85149; }
.mode-card.danger:hover { border-color: #f85149; }

#delete-confirm-input {
  width: 100%;
  background: var(--cell);
  border: 1px solid #f85149;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 15px;
  margin: 8px 0;
}

#delete-confirm-input:focus { outline: none; border-color: #ff7b72; }

#feedback-input {
  width: 100%;
  background: var(--cell);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  resize: vertical;
}

#feedback-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* --- Pending / match history ---
   A player who finishes an async match sees nothing until their opponent
   plays. These surfaces make that effort visible in the meantime. */
.pending-banner {
  margin-top: 12px;
  background: var(--cell);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: left;
}

.pending-score {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}

.pending-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.5;
}

/* Turn nudge: we hold no contact details, so the message is copied and the
   player sends it through whatever channel they already use. */
.nudge-row {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.nudge-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 7px;
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #0d1117;
  cursor: pointer;
}

.nudge-btn.copied {
  background: var(--good);
  border-color: var(--good);
}

.nudge-hint {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

.nudge-fallback {
  width: 100%;
  margin-top: 6px;
  min-height: 68px;
  font: inherit;
  font-size: 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px;
  resize: vertical;
}

.awaiting-badge {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(88, 166, 255, 0.18);
  color: var(--accent);
  white-space: nowrap;
}

.hist-list {
  margin-top: 14px;
  max-height: 46vh;
  overflow-y: auto;
  text-align: left;
}

.hist-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--cell);
}

.hist-row.win { border-left-color: var(--good); }
.hist-row.loss { border-left-color: #f85149; }
.hist-row.draw { border-left-color: var(--muted); }
.hist-row.pending { border-left-color: var(--accent); }
.hist-row.yourturn { border-left-color: var(--warn); }
.hist-row.voided { border-left-color: var(--line); opacity: 0.65; }

.hist-main { display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; }
.hist-result { font-weight: 600; font-size: 13px; }
.hist-vs { font-size: 12px; color: var(--muted); }

.hist-tag {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 4px;
}

.hist-side { display: flex; align-items: baseline; gap: 8px; justify-self: end; }
.hist-score { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }
.hist-delta { font-size: 12px; font-variant-numeric: tabular-nums; }
.hist-delta.win { color: var(--good); }
.hist-delta.loss { color: #f85149; }
.hist-delta.draw { color: var(--muted); }
.hist-pending-note { font-size: 11px; color: var(--muted); font-style: italic; }
.hist-when { grid-column: 1 / -1; font-size: 11px; color: var(--muted); }

/* --- Open challenges ---
   A challenge is a match with nobody on the other side yet: the poster has
   played their three minutes and left the seed for whoever turns up. --- */
.challenge-list { text-align: left; }

.challenge-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--cell);
}

.challenge-row.is-yours { border-left-color: var(--warn); }

.challenge-main { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.challenge-name { font-weight: 600; font-size: 14px; }
.challenge-rating { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.challenge-tag {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 4px;
}

.challenge-when { grid-column: 1; font-size: 11px; color: var(--muted); }

/* The score you're chasing. Shown up front on purpose -- an open challenge
   is a target to beat, not a blind race. */
.challenge-target {
  grid-column: 1;
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 3px;
}

.challenge-target-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.challenge-target-score {
  font-size: 19px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.challenge-target-pending { font-size: 13px; color: var(--muted); font-style: italic; }

/* HUD target block, shown only while chasing a posted score. */
#hud-target-block.target-beaten .hud-value { color: var(--good); }
#hud-target-block.target-beaten .hud-label { color: var(--good); }

.challenge-btn {
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  cursor: pointer;
  white-space: nowrap;
}

.challenge-btn:hover { background: var(--accent); color: #0d1117; }

.challenge-na { font-size: 11px; color: var(--muted); white-space: nowrap; }

#league-table .col-action { text-align: right; }

.challenge-accept,
.challenge-cancel {
  grid-column: 2;
  grid-row: 1 / span 2;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
}

.challenge-accept {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #0d1117;
}

.challenge-cancel {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}

.challenge-cancel:hover { color: var(--text); border-color: var(--muted); }

.challenge-empty,
.challenge-section-label {
  font-size: 12px;
  color: var(--muted);
  padding: 10px 2px;
}

.challenge-section-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 10px;
  margin-top: 6px;
}

.challenge-notice {
  margin-bottom: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(210, 153, 34, 0.12);
  border: 1px solid var(--warn);
  color: var(--text);
  font-size: 13px;
}

/* --- Unlimited Play records ---
   Two boards side by side from the same runs: longest survival and highest
   score rank differently, which is the reason for showing both. --- */
.record-boards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  text-align: left;
}

.record-board-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}

.record-row {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 2px 8px;
  align-items: baseline;
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
}

.record-row.row-you {
  background: rgba(88, 166, 255, 0.10);
  border-radius: 5px;
}

.record-rank {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.record-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}

.record-primary {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  justify-self: end;
}

.record-secondary {
  grid-column: 2 / -1;
  font-size: 10px;
  color: var(--muted);
}

@media (max-width: 640px) {
  .record-boards { grid-template-columns: 1fr; }
}

/* --- How to Play --- */
/* Wider than the default overlay panel: this is the one screen with real
   reading on it, and a 360px column made it scroll far more than it should. */
#overlay-panel.wide {
  max-width: 560px;
  width: min(560px, 92vw);
}

.howto {
  text-align: left;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 6px;
}

.howto-section {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.howto-section:last-child { border-bottom: none; }

.howto h3 {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.howto p {
  margin: 0 0 6px;
  font-size: 13px;
  line-height: 1.55;
}

.howto ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.6;
}

.howto li { margin-bottom: 3px; }

.howto-note {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

.howto-scores {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.howto-scores span {
  flex: 1;
  background: var(--cell);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 4px;
  text-align: center;
  font-size: 12px;
}

.howto-scores b {
  display: block;
  color: var(--accent);
  font-size: 15px;
}

.howto-scores small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  margin-top: 1px;
}

.howto-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12px;
  color: var(--muted);
}

.howto kbd {
  background: var(--cell);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 11px;
  color: var(--text);
}

#league-modal {
  position: absolute;
  inset: 0;
  background: rgba(13, 17, 23, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  z-index: 10;
}

#league-panel {
  width: min(560px, 92%);
  max-height: 90%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
}

#league-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

#league-header h2 { margin: 0; font-size: 18px; }

#league-close-button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}

#league-close-button:hover { color: var(--text); }

#league-table-wrap {
  margin-top: 10px;
  overflow-y: auto;
  overflow-x: auto;
}

#league-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

#league-table th {
  position: sticky;
  top: 0;
  background: var(--panel);
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}

#league-table td {
  padding: 5px 8px;
  border-bottom: 1px solid rgba(48, 54, 61, 0.5);
  white-space: nowrap;
}

#league-table tr.row-you { background: rgba(88, 166, 255, 0.15); font-weight: 600; }

#controls-help {
  display: flex;
  gap: 16px;
  color: var(--muted);
  font-size: 12px;
}

/* --- Touch controls (phones/tablets) ---
   Shown only on touch devices; the keyboard remains the desktop path. Sized
   for thumbs and marked touch-action:none so dragging a control never
   scrolls or zooms the page mid-match. */
#touch-controls {
  display: flex;
  gap: 8px;
  width: min(480px, 100%);
  margin-top: 4px;
}

#touch-controls button {
  flex: 1;
  min-height: 62px;
  background: var(--cell);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#touch-controls button.pressed {
  background: var(--accent);
  color: #0d1117;
  border-color: var(--accent);
}

#touch-hard {
  font-size: 14px;
  letter-spacing: 0.06em;
}

/* --- Responsive: make the board fit a phone screen ---
   The canvas has a fixed 480x840 internal resolution; these rules scale it
   visually while preserving the 4:7 aspect, leaving room for the HUD and the
   touch controls. */
#board,
#opponent-board {
  width: min(480px, 100%);
  aspect-ratio: 4 / 7;
  height: auto;
}

@media (max-width: 760px), (max-height: 780px) {
  #app { padding: 8px; gap: 8px; }

  /* The ladder is nice-to-have context; the board is not. Reclaim its width. */
  #league-sidebar { display: none !important; }

  #controls-help { display: none; }

  #hud { padding: 6px 12px; gap: 10px; }
  .hud-value { font-size: 17px; }
  .hud-label { font-size: 10px; }

  #boards-row { gap: 6px; width: 100%; justify-content: center; }

  #board,
  #opponent-board {
    width: auto;
    height: min(56vh, calc(100vw * 1.75));
    max-width: 100%;
  }

  /* Two boards side by side must each fit half the screen. */
  #opponent-board-col:not(.hidden) ~ #my-board-col #board,
  #boards-row:has(#opponent-board-col:not(.hidden)) #board,
  #boards-row:has(#opponent-board-col:not(.hidden)) #opponent-board {
    height: min(48vh, calc(50vw * 1.75));
  }

  #opponent-hud { padding: 4px 8px; font-size: 11px; margin-bottom: 4px; }
  #opponent-score { font-size: 15px; }

  #overlay-panel { padding: 16px; }
  .howto { max-height: 52vh; }

  /* --- Native app shell (Capacitor iOS), phone-sized screens only ---
     Scoped under body.native-app (set in client/main.js from IS_NATIVE_APP)
     so the website's layout is untouched. The shell has no browser chrome:
     the 56vh Safari budget above wastes the bottom third of the screen.
     Board height = screen minus HUD, touch controls, gaps and safe areas,
     still capped by the 4:7 aspect ratio. */
  body.native-app #board,
  body.native-app #opponent-board {
    height: min(
      calc(100dvh - 170px - env(safe-area-inset-top) - env(safe-area-inset-bottom)),
      calc(100vw * 1.75)
    );
  }

  /* Two boards side by side (live match) must each fit half the width. */
  body.native-app #boards-row:has(#opponent-board-col:not(.hidden)) #board,
  body.native-app #boards-row:has(#opponent-board-col:not(.hidden)) #opponent-board {
    height: min(
      calc(100dvh - 170px - env(safe-area-inset-top) - env(safe-area-inset-bottom)),
      calc(50vw * 1.75)
    );
  }
}

/* --- Native app shell: menus use the whole screen ---
   #overlay is scoped to the board area (#stage) on the web, which clips a
   long menu on tall phones (17 Pro Max: the Settings card fell off the
   bottom). In the shell the overlay covers the full viewport instead; the
   backdrop already dims what's behind it, and safe-area padding keeps the
   panel clear of the Dynamic Island and home indicator. */
body.native-app #overlay {
  position: fixed;
  border-radius: 0;
  padding-top: calc(env(safe-area-inset-top) + 8px);
  padding-bottom: calc(env(safe-area-inset-bottom) + 8px);
}

body.native-app #league-modal {
  position: fixed;
  border-radius: 0;
  padding-top: calc(env(safe-area-inset-top) + 8px);
  padding-bottom: calc(env(safe-area-inset-bottom) + 8px);
}

/* --- Native app shell: safe areas ---
   With viewport-fit=cover the webview extends under the Dynamic Island and
   the home indicator; pad the app container clear of both. env() is 0
   everywhere else, but scope to the shell anyway so the website never moves. */
body.native-app #app {
  padding-top: calc(8px + env(safe-area-inset-top));
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  padding-left: calc(8px + env(safe-area-inset-left));
  padding-right: calc(8px + env(safe-area-inset-right));
}
