:root {
  --bg: #0b0d12;
  --panel: #141821;
  --panel-hi: #1a2030;
  --ink: #e6e8ee;
  --muted: #8a93a6;
  --line: #232938;
  --accent: #6ea8ff;
  --good: #4ade80;
  --warn: #facc15;
  --danger: #f87171;
  --opp: #6ea8ff;
  --self: #f59e0b;
  --card-bg: #f7f5ed;       /* warm parchment */
  --card-bg-dim: #d8d5cb;
  --card-ink: #1a1a1a;
  --card-red: #c4202a;
  --card-back: linear-gradient(135deg, #243149 0%, #1a253b 100%);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  user-select: none;
}
body {
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0);
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

main#game {
  flex: 1 1 auto;
  display: grid;
  grid-template-rows: 1fr auto 1fr auto;
  gap: .5rem;
  padding: .5rem;
  min-height: 0;
}

/* ===== Zones (opponent top, player bottom) ===== */
.zone {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5rem .65rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
  min-height: 0;
  overflow: hidden;
}
.opponent-zone { border-top: 2px solid var(--opp); }
.player-zone   { border-bottom: 2px solid var(--self); }

.zone-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: .85rem;
}
.zone-header .player-name { font-weight: 700; }
.zone-header .player-name.opp  { color: var(--opp); }
.zone-header .player-name.self { color: var(--self); }
.zone-header .meta { color: var(--muted); font-size: .8rem; }
.zone-header .meta strong { color: var(--ink); }
.zone-header .score {
  margin-left: auto;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 1.4rem;
  font-weight: 700;
  background: var(--bg);
  padding: .15rem .65rem;
  border-radius: 6px;
  min-width: 2.5rem;
  text-align: center;
  color: var(--accent);
}

/* ===== Card visuals ===== */
.card {
  background: var(--card-bg);
  color: var(--card-ink);
  border-radius: 6px;
  border: 1px solid #b6b3a8;
  width: 56px;
  height: 80px;
  position: relative;
  flex: 0 0 auto;
  font-family: 'Georgia', 'Times New Roman', serif;
  font-weight: 700;
  cursor: default;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .4);
  display: flex;
  align-items: center;
  justify-content: center;
}
.card.red { color: var(--card-red); }
.card.black { color: var(--card-ink); }
.card .card-corner {
  position: absolute;
  font-size: .65rem;
  line-height: 1;
  text-align: center;
  font-weight: 700;
}
.card .card-corner.top    { top: 3px; left: 4px; }
.card .card-corner.bottom { bottom: 3px; right: 4px; transform: rotate(180deg); }
.card .card-center {
  font-size: 1.8rem;
  line-height: 1;
}
.card.face-down {
  background: var(--card-back);
  border-color: #2a3d5e;
  color: transparent;
}
.card.face-down::after {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px dashed rgba(110, 168, 255, .25);
  border-radius: 4px;
}

/* Mini cards for played matches. */
.card.mini {
  width: 32px;
  height: 46px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}
.card.mini .card-corner { font-size: .55rem; }
.card.mini .card-corner.top    { top: 1px; left: 2px; }
.card.mini .card-corner.bottom { bottom: 1px; right: 2px; }
.card.mini .card-center { font-size: 1rem; }

/* Selected hand card — lifted + highlighted. */
.player-hand .card { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.player-hand .card:hover { transform: translateY(-3px); box-shadow: 0 5px 10px rgba(0,0,0,.5); }
.player-hand .card.selected {
  transform: translateY(-10px);
  border: 2px solid var(--good);
  box-shadow: 0 6px 14px rgba(74, 222, 128, .4);
}

/* ===== Hand rows ===== */
.hand-row {
  display: flex;
  gap: .3rem;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding: .2rem .1rem;
  min-height: 90px;
  align-items: flex-end;
}
.player-hand { align-items: flex-start; }

/* ===== Played zone ===== */
.played-row {
  display: flex;
  gap: .55rem;
  overflow-x: auto;
  overflow-y: hidden;
  min-height: 60px;
  align-items: center;
  padding: .15rem .1rem;
}
.played-row .played-empty {
  color: var(--muted);
  font-style: italic;
  font-size: .75rem;
}
.played-match {
  background: rgba(0, 0, 0, .25);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: .15rem .3rem .2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
  flex: 0 0 auto;
}
.played-match .played-tag {
  font-size: .55rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-family: ui-monospace, Menlo, monospace;
}
.played-match .played-row {
  display: flex;
  gap: 2px;
  overflow: visible;
  min-height: 0;
  padding: 0;
}

/* ===== Middle: piles + status ===== */
.middle {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5rem .75rem;
}
.piles {
  display: flex;
  gap: .75rem;
}
.pile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
  min-width: 60px;
}
.pile-label {
  font-size: .65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.pile-label span { color: var(--ink); font-weight: 600; font-family: ui-monospace, Menlo, monospace; }
.pile-slot {
  width: 56px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pile-slot .pile-card { width: 56px; height: 80px; }
.pile-empty {
  width: 56px;
  height: 80px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: .7rem;
  font-style: italic;
}

.status {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  min-width: 0;
}
.status .turn-line { font-weight: 700; font-size: .9rem; }
.status .hint { color: var(--muted); font-size: .75rem; font-style: italic; min-height: 1em; }
.status .log {
  font-family: ui-monospace, Menlo, monospace;
  font-size: .65rem;
  color: var(--muted);
  max-height: 40px;
  overflow-y: auto;
  margin-top: .15rem;
}
.status .log .entry { padding: 0; }
.status .log .entry:last-child { color: var(--ink); }

/* ===== Action bar ===== */
.action-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .4rem .65rem;
  flex-wrap: wrap;
}
.action-bar button {
  background: var(--accent);
  color: var(--bg);
  border: 0;
  border-radius: 5px;
  padding: .45rem .85rem;
  font: inherit;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
}
.action-bar button:disabled {
  background: var(--line);
  color: var(--muted);
  cursor: not-allowed;
}
.action-bar button:not(:disabled):hover { filter: brightness(1.1); }
.action-bar button.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.action-bar button.secondary:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }
.action-bar .leave-btn {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--line);
}
.action-bar .leave-btn:hover { background: var(--danger); color: var(--bg); border-color: var(--danger); }
.action-bar .action-spacer { flex: 1 1 auto; }
.action-bar .action-links {
  display: flex;
  gap: .55rem;
  font-size: .75rem;
}
.action-bar .action-links a {
  color: var(--ink);
  opacity: .85;
  text-decoration: none;
}
.action-bar .action-links a:hover { color: var(--accent); text-decoration: underline; opacity: 1; }
.action-bar .action-links a:visited { color: var(--ink); }

/* ===== Overlays ===== */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 1rem;
  z-index: 100;
}
.overlay.setup-overlay {
  background: var(--bg);
  z-index: 200;
  justify-content: flex-start;
  padding-top: 1.5rem;
  padding-bottom: 1.5rem;
}
.overlay.gameover-overlay { background: rgba(11, 13, 18, .95); z-index: 250; }
/* Hot-seat pass-the-device overlay. Solid background so the previous
   player's hand can't leak through. Below the game-over overlay (250)
   and setup (200) — those should always win. */
.overlay.pass-overlay {
  background: var(--bg);
  z-index: 220;
}
.pass-content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 2rem 2.5rem;
  text-align: center;
  max-width: 420px;
  width: 100%;
}
.pass-content .pass-prompt {
  font-size: .8rem;
  color: var(--muted);
  margin: 0 0 .5rem;
  text-transform: uppercase;
  letter-spacing: .12em;
}
.pass-content .pass-name {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--accent);
  margin: 0 0 .85rem;
  line-height: 1.1;
  word-break: break-word;
}
.pass-content .pass-info {
  color: var(--muted);
  font-family: ui-monospace, Menlo, monospace;
  font-size: .82rem;
  margin: 0 0 1.5rem;
}
.pass-content button {
  background: var(--accent);
  color: var(--bg);
  border: 0;
  border-radius: 6px;
  padding: .65rem 1.75rem;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}
.pass-content button:hover { filter: brightness(1.1); }

.setup-content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.5rem 2rem;
  max-width: 460px;
  width: 100%;
  max-height: calc(100vh - 4rem);
  max-height: calc(100dvh - 4rem);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.setup-content h1 { margin: 0 0 .35rem; font-size: 1.7rem; text-align: center; }
.setup-content .tag {
  color: var(--muted);
  margin: 0 0 1rem;
  font-size: .85rem;
  text-align: center;
}

/* Mode tabs (vs AI / Hot-seat). Pattern lifted from Card Battle's setup. */
.setup-content .mode-tabs {
  display: flex;
  gap: .25rem;
  margin: .25rem 0 1rem;
  border-bottom: 1px solid var(--line);
}
.setup-content .mode-tab {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  padding: .5rem .75rem;
  font: inherit;
  font-size: .9rem;
  cursor: pointer;
  transition: color .12s, border-color .12s;
}
.setup-content .mode-tab:hover { color: var(--ink); }
.setup-content .mode-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.setup-content .mode-panel { padding-top: .25rem; }

.setup-content .hotseat-tag {
  color: var(--muted);
  font-size: .8rem;
  margin: .25rem 0 1rem;
  text-align: center;
  font-style: italic;
}
.setup-content label.p1 > span { color: var(--self); }
.setup-content label.p2 > span { color: var(--opp); }
.setup-content label { display: block; margin: .65rem 0; }
.setup-content label > span { color: var(--muted); font-size: .85rem; display: block; margin-bottom: .25rem; }
.setup-content input[type=text],
.setup-content select {
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .55rem .65rem;
  font: inherit;
  font-size: 1rem;
}
.setup-content select { cursor: pointer; }
.setup-content input:focus,
.setup-content select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}
.setup-content .ai-level-desc {
  margin: -.35rem 0 .75rem;
  font-size: .75rem;
  color: var(--muted);
  font-style: italic;
  line-height: 1.35;
}
.setup-content .actions {
  display: flex;
  gap: .75rem;
  justify-content: center;
  margin-top: 1rem;
}
.setup-content .actions button {
  background: var(--accent);
  color: var(--bg);
  border: 0;
  border-radius: 6px;
  padding: .65rem 1.5rem;
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}
.setup-content .actions button:hover { filter: brightness(1.1); }
.setup-version-line {
  margin-top: 1.25rem;
  text-align: center;
  font-size: .7rem;
  color: var(--muted);
  font-family: ui-monospace, Menlo, monospace;
}
.setup-version-line a { color: var(--ink); text-decoration: none; opacity: .85; }
.setup-version-line a:hover { color: var(--accent); text-decoration: underline; opacity: 1; }
.setup-version-line a:visited { color: var(--ink); }

.gameover-content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.75rem 2rem;
  max-width: 460px;
  text-align: center;
}
.gameover-content h1 { margin: 0 0 .75rem; font-size: 1.7rem; }
.gameover-tally {
  font-family: ui-monospace, Menlo, monospace;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.6;
  margin: .75rem 0;
}
.gameover-tally strong { color: var(--accent); }
.gameover-content .actions {
  display: flex;
  gap: .75rem;
  justify-content: center;
  margin-top: 1rem;
}
.gameover-content button {
  background: var(--accent);
  color: var(--bg);
  border: 0;
  border-radius: 6px;
  padding: .55rem 1.25rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.gameover-content button.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

/* ===== Phone / portrait scaling ===== */
@media (max-width: 500px) {
  main#game { padding: .35rem; gap: .35rem; }
  .zone { padding: .35rem .5rem; }
  .zone-header .player-name { font-size: .75rem; }
  .zone-header .meta { font-size: .7rem; }
  .zone-header .score { font-size: 1.1rem; padding: .1rem .45rem; min-width: 2rem; }
  .card { width: 44px; height: 64px; }
  .card .card-center { font-size: 1.4rem; }
  .card .card-corner { font-size: .55rem; }
  .card.mini { width: 28px; height: 40px; }
  .card.mini .card-center { font-size: .85rem; }
  .pile-slot { width: 44px; height: 64px; }
  .pile-slot .pile-card { width: 44px; height: 64px; }
  .pile-empty { width: 44px; height: 64px; font-size: .6rem; }
  .hand-row { min-height: 74px; }
  .played-row { min-height: 50px; }
  .action-bar { padding: .35rem .5rem; gap: .35rem; }
  .action-bar button { padding: .35rem .65rem; font-size: .72rem; }
  .action-bar .action-links { font-size: .65rem; gap: .4rem; }
  .status .turn-line { font-size: .8rem; }
  .status .hint { font-size: .7rem; }
}
