/* Nesso — original dark strategy-game visual identity */

:root {
  --bg-deep: #0e1218;
  --bg-panel: #171d27;
  --bg-elevated: #1f2734;
  --bg-hover: #283244;
  --border: #2e3a4d;
  --text: #e8eef7;
  --text-muted: #9aa8bc;
  --accent: #3db8a0;
  --accent-strong: #2a9b86;
  --danger: #d45d6a;
  --warning: #d4a04a;
  --focus: #7ec8ff;
  --tile-face: #243041;
  --tile-shadow: rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;

  --color-crimson: #e23d4d;
  --color-amber: #f08a24;
  --color-gold: #e6c34a;
  --color-emerald: #2fbf7a;
  --color-azure: #3b9ef0;
  --color-violet: #9b6bdb;

  --cell: 56px;
  --touch: 44px;
}

html.high-contrast {
  --bg-deep: #000;
  --bg-panel: #111;
  --text: #fff;
  --text-muted: #ddd;
  --border: #888;
  --accent: #5dffd0;
}

html[data-tile-size="small"] { --cell: 48px; }
html[data-tile-size="large"] { --cell: 72px; }

*,
*::before,
*::after { box-sizing: border-box; }

html {
  height: -webkit-fill-available;
}

html, body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(ellipse at 20% 0%, rgba(61, 184, 160, 0.08), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(59, 158, 240, 0.06), transparent 45%),
    linear-gradient(180deg, #121821 0%, var(--bg-deep) 40%, #0b0f14 100%);
  background-attachment: fixed;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

.nesso-app {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.btn-back {
  width: var(--touch);
  min-width: var(--touch);
  padding: 0;
  font-size: 1.35rem;
  line-height: 1;
  border-radius: 12px;
  flex-shrink: 0;
}

.game-top {
  gap: 0.5rem 0.75rem;
}

.game-top .brand {
  font-size: 1.05rem;
}

body {
  background-image:
    linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px),
    radial-gradient(ellipse at 20% 0%, rgba(61, 184, 160, 0.08), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(59, 158, 240, 0.06), transparent 45%),
    linear-gradient(180deg, #121821 0%, var(--bg-deep) 40%, #0b0f14 100%);
  background-size: 32px 32px, 32px 32px, auto, auto, auto;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.brand {
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text);
}

.brand-hero {
  font-size: clamp(2.5rem, 6vw, 4rem);
  margin: 0 0 0.25rem;
  background: linear-gradient(120deg, #e8eef7, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.screen {
  min-height: 100vh;
  display: none;
  flex-direction: column;
}

.screen.is-active,
.screen:not([hidden]).is-active {
  display: flex;
}

.screen[hidden] { display: none !important; }

.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.75rem 1.25rem;
  background: rgba(23, 29, 39, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.top-actions {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.panel {
  width: min(720px, calc(100% - 2rem));
  margin: 1.5rem auto;
  padding: 1.5rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.panel.narrow { width: min(480px, calc(100% - 2rem)); }
.panel.wide { width: min(1100px, calc(100% - 2rem)); }

.lede { color: var(--text-muted); line-height: 1.5; }
.muted { color: var(--text-muted); }
.error { color: var(--danger); min-height: 1.25rem; }

.hero {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem 1rem;
  min-height: min(70vh, 560px);
}

.hero-content {
  width: min(720px, 100%);
  text-align: left;
}

.hero-content h1 {
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 650;
  margin: 0.25rem 0 0.75rem;
  max-width: 18ch;
  line-height: 1.2;
}

.feature-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  padding: 0 1.25rem 2rem;
  width: min(1000px, 100%);
  margin: 0 auto;
}

.feature-card,
.profile-card,
.stat-card,
.podium-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.feature-card h2,
.profile-card h3 { margin: 0 0 0.35rem; font-size: 1.05rem; }
.feature-card p { margin: 0; color: var(--text-muted); font-size: 0.95rem; }

.card-grid, .stats-grid, .podium {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.85rem;
  margin: 1rem 0;
}

.stat-card h3 {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}
.stat-card p {
  margin: 0.35rem 0 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn:hover:not(:disabled) { background: var(--bg-hover); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent-strong);
  border-color: transparent;
  color: #041512;
}
.btn-primary:hover:not(:disabled) { background: var(--accent); }

.btn-ghost {
  background: transparent;
}

.btn-danger {
  background: rgba(212, 93, 106, 0.15);
  border-color: var(--danger);
  color: #ffb4bc;
}

.btn-small {
  min-height: 36px;
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.icon-btn { width: var(--touch); padding: 0; font-size: 1.15rem; }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.75rem 0;
}

.field input,
.field select,
.fieldset input {
  min-height: var(--touch);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-deep);
  color: var(--text);
  font: inherit;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: var(--touch);
  margin: 0.35rem 0;
}

.fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin: 1rem 0;
}

/* Game layout */
.screen-game {
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

.game-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr minmax(200px, 280px);
  gap: 0;
  min-height: 0;
  overflow: hidden;
}

.side-panel {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 0.85rem;
  overflow: auto;
}

.right-panel { border-right: none; border-left: 1px solid var(--border); }

.side-panel h2, .side-panel h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.board-area {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #0a0e14;
}

.board-viewport {
  flex: 1;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  position: relative;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

.board-viewport:active { cursor: grabbing; }

.board-transform {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
  touch-action: none;
}

.board-layer {
  position: relative;
  touch-action: none;
}

.board-cell {
  position: absolute;
  display: grid;
  place-items: center;
  border-radius: 12px;
  padding: 0;
  margin: 0;
  border: 1px dashed transparent;
  background: transparent;
  color: inherit;
}

.board-cell.is-legal {
  border-color: rgba(61, 184, 160, 0.45);
  background: rgba(61, 184, 160, 0.08);
  cursor: pointer;
}

.board-cell.is-legal:hover,
.board-cell.is-focused {
  background: rgba(61, 184, 160, 0.2);
  border-color: var(--accent);
}

.board-cell.is-pending {
  outline: 2px dashed var(--warning);
  outline-offset: -2px;
  opacity: 0.95;
}

.board-cell.is-qwirkle-highlight,
.board-cell.is-nesso-highlight {
  box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(61, 184, 160, 0.35);
  z-index: 2;
}

html.hide-grid .board-cell.is-legal {
  border-style: solid;
}

.board-controls {
  position: relative;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  align-items: center;
  padding: 0.45rem 0.6rem;
  background: rgba(23, 29, 39, 0.96);
  border-top: 1px solid var(--border);
  pointer-events: auto;
  touch-action: manipulation;
}

.board-ctrl-btn {
  min-width: 52px;
  min-height: var(--touch);
  font-size: 1.05rem;
  font-weight: 700;
  flex: 1 1 auto;
  max-width: 120px;
}

.rack-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  padding-bottom: max(0.65rem, env(safe-area-inset-bottom));
  background: rgba(23, 29, 39, 0.96);
  border-top: 1px solid var(--border);
}

/* Online lobby */
.online-panel { width: min(720px, calc(100% - 2rem)); }
.online-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.online-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.online-card h3 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.code-input {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-weight: 700;
  font-size: 1.2rem;
}
.lobby-code {
  font-family: var(--mono);
  letter-spacing: 0.18em;
  color: var(--accent);
}
.lobby-players {
  list-style: none;
  margin: 1rem 0;
  padding: 0;
}
.lobby-player {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0.85rem;
  margin-bottom: 0.45rem;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  min-height: var(--touch);
  align-items: center;
}
.lobby-player.is-ready {
  outline: 2px solid var(--accent);
}
.lobby-hint {
  margin: 0.75rem 0 0;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  background: rgba(61, 184, 160, 0.12);
  border: 1px solid rgba(61, 184, 160, 0.35);
  color: var(--text);
  font-weight: 600;
}
.lobby-hint[hidden] {
  display: none !important;
}
.online-config-hint {
  margin-top: 1rem;
}
.online-config-hint code {
  font-family: var(--mono);
  font-size: 0.85em;
}

.rack {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  min-height: calc(var(--cell) + 8px);
  flex: 1;
}

.rack-slot.is-on-board {
  flex: 0 0 auto;
  border-radius: 12px;
  border: 2px dashed rgba(154, 168, 188, 0.45);
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(255, 255, 255, 0.03),
      rgba(255, 255, 255, 0.03) 4px,
      transparent 4px,
      transparent 8px
    );
  box-sizing: border-box;
  pointer-events: none;
}

.rack.is-hidden { visibility: hidden; min-height: calc(var(--cell) + 8px); }

.rack.is-waiting {
  opacity: 0.92;
}

.rack.is-waiting .tile {
  cursor: default;
}

.rack-wait-note {
  margin: 0 0 0.35rem;
  width: 100%;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
}

.rack-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

/* Tiles */
.tile {
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 14px;
}

.tile .tile-svg,
.board-cell .tile-svg {
  display: block;
  filter: drop-shadow(0 4px 6px var(--tile-shadow));
}

.tile-face {
  fill: var(--tile-face);
  stroke: #3a4a60;
  stroke-width: 2;
}

.tile.is-selected {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 14px;
}

.tile.is-dragging { opacity: 0.55; }

.tile-color-crimson { color: var(--color-crimson); }
.tile-color-amber { color: var(--color-amber); }
.tile-color-gold { color: var(--color-gold); }
.tile-color-emerald { color: var(--color-emerald); }
.tile-color-azure { color: var(--color-azure); }
.tile-color-violet { color: var(--color-violet); }

html.colorblind .tile,
html.colorblind .board-cell {
  /* pattern overlays come from SVG */
}

html.colorblind .tile[data-color="crimson"] .tile-face { stroke: #ff8a95; stroke-dasharray: 4 2; }
html.colorblind .tile[data-color="amber"] .tile-face { stroke: #ffc078; stroke-dasharray: 1 3; }
html.colorblind .tile[data-color="gold"] .tile-face { stroke: #ffe08a; stroke-dasharray: 6 2; }
html.colorblind .tile[data-color="emerald"] .tile-face { stroke: #7dffb8; stroke-dasharray: 2 2; }
html.colorblind .tile[data-color="azure"] .tile-face { stroke: #9accff; stroke-dasharray: 3 1; }
html.colorblind .tile[data-color="violet"] .tile-face { stroke: #d2b0ff; stroke-dasharray: 5 3; }

.scoreboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.scoreboard-head h2 {
  margin: 0;
}

.scoreboard-close {
  display: none;
  min-height: 36px;
  min-width: 36px;
  padding: 0.35rem 0.65rem;
}

.mobile-history-block {
  display: none;
}

.board-score-preview {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: rgba(23, 29, 39, 0.96);
}

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.player-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.5rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.35rem;
  background: var(--bg-elevated);
}

.player-row.is-current {
  outline: 2px solid var(--accent);
}

.player-name { font-weight: 700; display: block; }
.player-type { font-size: 0.75rem; color: var(--text-muted); }
.player-score { font-size: 1.25rem; font-weight: 800; }

.bag-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0.55rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.bag-line-label {
  min-width: 0;
}

.bag-line #bag-count,
.bag-line strong {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.score-breakdown {
  list-style: none;
  margin: 0;
  padding: 0;
}

.score-breakdown li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.score-total { font-size: 1.05rem; }
.invalid-msg { color: var(--danger); }

.turn-history-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.opening-hint {
  margin: 0;
  padding: 0.4rem 0.75rem;
  background: rgba(212, 160, 74, 0.15);
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.nesso-banner,
.qwirkle-banner {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  min-width: min(280px, 80vw);
  padding: 0.85rem 1.35rem 0.95rem;
  background: linear-gradient(160deg, rgba(31, 39, 52, 0.96), rgba(14, 18, 24, 0.96));
  border: 2px solid var(--accent);
  border-radius: 18px;
  font-weight: 800;
  letter-spacing: 0.06em;
  pointer-events: none;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  align-items: center;
}

/* display:flex must not override the HTML hidden attribute */
.nesso-banner[hidden],
.qwirkle-banner[hidden] {
  display: none !important;
}

.nesso-banner-eyebrow {
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.nesso-banner-title {
  font-size: 1.35rem;
  letter-spacing: 0.12em;
}

.nesso-banner-links {
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
}

.score-chip {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  background: var(--accent);
  color: #041512;
  font-weight: 800;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
}

.nesso-particle,
.qwirkle-particle {
  position: fixed;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 184, 160, 0.25);
  pointer-events: none;
  z-index: 101;
}

.nesso-ring {
  position: fixed;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid rgba(61, 184, 160, 0.55);
  pointer-events: none;
  z-index: 100;
}

.privacy-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #0a0e14;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.privacy-overlay[hidden] { display: none !important; }

.privacy-card {
  text-align: center;
  max-width: 420px;
}

.tutorial-panel {
  position: fixed;
  left: 1rem;
  bottom: calc(var(--cell) + 5rem);
  z-index: 30;
  width: min(360px, calc(100% - 2rem));
  background: var(--bg-panel);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: 0 12px 30px rgba(0,0,0,0.4);
}

.thinking {
  margin-top: 0.75rem;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  background: rgba(61, 184, 160, 0.12);
  color: var(--accent);
  font-weight: 600;
}

.toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  max-width: min(480px, calc(100% - 2rem));
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.65);
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal[hidden] { display: none !important; }

.modal-panel {
  width: min(560px, 100%);
  max-height: min(80vh, 700px);
  overflow: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.code-block {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.85rem;
  background: var(--bg-deep);
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  overflow: auto;
}

.table-scroll { overflow: auto; }
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.history-table th, .history-table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.rules-panel h3 { margin-top: 1.4rem; }
.diagram-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}
.mini-board {
  display: grid;
  grid-template-columns: repeat(7, 40px);
  grid-template-rows: repeat(7, 40px);
  gap: 2px;
  background: var(--bg-deep);
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  min-height: 120px;
}
.mini-tile { display: grid; place-items: center; }

.shake { animation: shake 0.35s linear; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.save-status {
  font-size: 0.8rem;
  color: var(--accent);
}

.turn-banner {
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: rgba(61, 184, 160, 0.15);
}

.profile-card.is-active {
  outline: 2px solid var(--accent);
}

/* Mobile / iPhone Safari & Chrome */
@media (max-width: 900px) {
  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  /* Always-visible compact score strip (chess.com-style) */
  .left-panel {
    position: relative;
    z-index: 5;
    max-height: none;
    transform: none;
    visibility: visible;
    pointer-events: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    padding: 0.4rem 0.55rem 0.45rem;
    overflow: visible;
    background: rgba(23, 29, 39, 0.98);
  }

  .left-panel .scoreboard-head,
  .left-panel .mobile-history-block {
    display: none;
  }

  /* Always show remaining tile count under the score chips */
  .left-panel .bag-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0.4rem 0 0;
    padding: 0.3rem 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    font-size: 0.8rem;
  }

  .left-panel .bag-line #bag-count,
  .left-panel .bag-line strong {
    font-size: 1rem;
    color: var(--accent);
  }

  .left-panel .thinking {
    margin-top: 0.25rem;
    font-size: 0.8rem;
  }

  .players-panel .player-list {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 0.4rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .players-panel .player-list::-webkit-scrollbar {
    display: none;
  }

  .players-panel .player-row {
    flex: 1 1 0;
    min-width: 4.75rem;
    margin: 0;
    padding: 0.35rem 0.45rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.15rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
  }

  .players-panel .player-row.is-current {
    border-color: var(--accent);
    background: rgba(61, 184, 160, 0.12);
  }

  .players-panel .player-main {
    min-width: 0;
  }

  .players-panel .player-name {
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .players-panel .player-type {
    display: none;
  }

  .players-panel .player-stats {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.35rem;
  }

  .players-panel .player-score {
    font-size: 1.15rem;
    line-height: 1;
  }

  .players-panel .player-qwirkles {
    font-size: 0.7rem;
    color: var(--text-muted);
  }

  /* Details sheet: full scoreboard + history over the board */
  .left-panel.is-open {
    position: fixed;
    z-index: 45;
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    max-height: min(70dvh, 520px);
    overflow: auto;
    border-top: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 0.75rem 0.85rem;
    padding-bottom: max(0.85rem, env(safe-area-inset-bottom));
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
  }

  .left-panel.is-open .scoreboard-head {
    display: flex;
  }

  .left-panel.is-open .mobile-history-block {
    display: block;
  }

  .left-panel.is-open .bag-line {
    margin-top: 0.65rem;
  }

  .left-panel.is-open .scoreboard-close {
    display: inline-flex;
  }

  .left-panel.is-open .players-panel .player-list {
    flex-direction: column;
    overflow: visible;
  }

  .left-panel.is-open .players-panel .player-row {
    flex-direction: row;
    align-items: center;
    min-width: 0;
  }

  .left-panel.is-open .players-panel .player-type {
    display: block;
  }

  .board-controls {
    position: relative;
    bottom: auto;
    right: auto;
    justify-content: stretch;
    padding: 0.35rem 0.5rem;
    gap: 0.35rem;
  }

  .board-ctrl-btn {
    max-width: none;
    flex: 1 1 22%;
    min-height: 40px;
    font-size: 0.95rem;
  }

  .board-area {
    min-height: 0;
  }

  .board-viewport {
    min-height: 140px;
  }

  .board-score-preview {
    padding: 0.35rem 0.65rem;
    font-size: 0.9rem;
    max-height: 5.5rem;
    overflow: auto;
  }

  .board-score-preview .score-breakdown {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.75rem;
  }

  .board-score-preview .score-breakdown li {
    margin: 0;
  }

  .board-score-preview .score-total {
    margin: 0.2rem 0 0;
  }

  .right-panel {
    display: none;
  }

  .game-top {
    padding: 0.45rem 0.65rem;
    padding-top: max(0.45rem, env(safe-area-inset-top));
    gap: 0.35rem 0.5rem;
  }

  .game-top .brand {
    font-size: 0.95rem;
  }

  .game-top .turn-banner {
    order: 3;
    width: 100%;
    font-size: 0.85rem;
    padding: 0.2rem 0.55rem;
  }

  .game-top .top-actions {
    margin-left: auto;
    gap: 0.25rem;
  }

  .game-top .top-actions .btn {
    min-height: 40px;
    min-width: 40px;
    padding: 0.35rem 0.55rem;
    font-size: 0.85rem;
  }

  .game-top .save-status {
    font-size: 0.75rem;
  }

  .rack-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
    padding: 0.45rem 0.55rem;
    padding-bottom: max(0.45rem, env(safe-area-inset-bottom));
  }

  .rack {
    justify-content: center;
  }

  .rack-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
  }

  .rack-actions .btn {
    width: 100%;
    min-height: 42px;
    font-size: 0.88rem;
    padding: 0.4rem 0.5rem;
  }

  .rack-actions .btn-primary {
    grid-column: 1 / -1;
  }

  .board-viewport {
    /* Reduce accidental page scroll while panning on iOS */
    touch-action: none;
    overscroll-behavior: contain;
  }

  .hero-content h1 {
    max-width: none;
  }

  .btn-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .btn-row .btn {
    width: 100%;
  }

  body { overflow-x: hidden; }
}

@supports (-webkit-touch-callout: none) {
  /* iOS Safari: prefer dynamic viewport for the game shell */
  .screen-game {
    height: -webkit-fill-available;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .qwirkle-particle,
  .nesso-particle,
  .nesso-ring { display: none; }
}

html[data-animation-level="off"] .qwirkle-particle,
html[data-animation-level="reduced"] .qwirkle-particle,
html[data-animation-level="off"] .nesso-particle,
html[data-animation-level="reduced"] .nesso-particle,
html[data-animation-level="off"] .nesso-ring,
html[data-animation-level="reduced"] .nesso-ring {
  display: none;
}

@media (max-width: 900px) {
  .hide-on-narrow { display: none !important; }
}
