/* Dibs: plain, phone-first styles. Colors are tokens so a redesign only touches this file. */
:root {
  --bg: #f4f4f1;
  --panel: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --line: #d6d6cf;
  --accent: #1f6f4a;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --card: #ffffff;
  --card-back: #2d4f8a;
  --red: #c0262d;
  --black: #1d1d1b;
  --felt: #e6efe8;
  --focus: #f0b400;
  --radius: 10px;
  --tap: 44px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161716;
    --panel: #212321;
    --text: #ececea;
    --muted: #9a9b96;
    --line: #3a3c39;
    --accent: #3fa877;
    --accent-text: #0b0c0b;
    --danger: #ef6b62;
    --card: #f7f7f4;
    --card-back: #3b62a8;
    --felt: #1c2a21;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
body.center { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; }
h1, h2, h3 { line-height: 1.2; }
a { color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--accent); border-radius: var(--radius);
  background: var(--accent); color: var(--accent-text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.secondary { background: transparent; color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 10px; font-size: 14px; }
.btn.big { width: 100%; min-height: 56px; font-size: 18px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.landing { width: min(320px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 16px; text-align: center; }
.logo { font-size: 56px; font-weight: 800; letter-spacing: -2px; margin: 0 0 24px; }

/* Forms and plain pages */
.page { width: min(560px, 100%); margin: 0 auto; padding: 16px; }
.home { display: inline-block; font-weight: 800; font-size: 22px; text-decoration: none; color: var(--text); margin-bottom: 8px; }
.form, .stack { display: flex; flex-direction: column; gap: 14px; }
.form label, .field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.form small, .field small, .small:not(.btn) { font-weight: 400; color: var(--muted); font-size: 13px; }
input, select {
  font: inherit; min-height: var(--tap); padding: 0 12px; width: 100%;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text);
}
input[type=checkbox], input[type=radio] { width: 22px; min-height: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--accent); }
input.code { text-transform: uppercase; letter-spacing: 4px; font-size: 22px; font-weight: 700; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
legend { font-weight: 600; padding: 0 4px; }
label.check, .form label.check { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; }
details summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; font-weight: 600; }
details[open] > *:not(summary) { margin-bottom: 14px; }
.error { color: var(--danger); font-weight: 600; }
.muted { color: var(--muted); }
.center-text { text-align: center; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 2px; }
.wrap { overflow-wrap: anywhere; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > .field { flex: 1; min-width: 120px; }
.grow { flex: 1; min-width: 0; }

/* App shell */
body.app { padding-bottom: env(safe-area-inset-bottom); }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.code-chip { border: 1px solid var(--line); background: transparent; color: var(--text); border-radius: 999px; min-height: 36px; padding: 0 12px; font: inherit; cursor: pointer; }
.code-chip strong { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 1px; }
.top-info { flex: 1; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn { font-size: 13px; color: var(--danger); }
.conn.online { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.conn.connecting { color: var(--muted); }

.lobby { width: min(560px, 100%); margin: 0 auto; padding: 12px 16px 32px; display: flex; flex-direction: column; gap: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.panel h1, .panel h2 { margin: 0 0 6px; }
.panel h2 { font-size: 18px; }
.seats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 8px 0; }
.seat {
  min-height: 64px; border: 1px dashed var(--line); border-radius: var(--radius); background: transparent; color: var(--muted);
  font: inherit; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; padding: 6px;
}
.seat.taken { border-style: solid; color: var(--text); background: var(--felt); }
.seat.mine { border-color: var(--accent); border-width: 2px; }
.seat-n { font-size: 12px; color: var(--muted); }
.team-tag { font-size: 12px; padding: 2px 6px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); }
.players { list-style: none; padding: 0; margin: 0 0 10px; }
.players li { display: flex; align-items: center; gap: 8px; min-height: var(--tap); border-bottom: 1px solid var(--line); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.on { background: var(--accent); }
.dot.off { background: transparent; border: 2px solid var(--muted); }
.ready { font-size: 12px; color: var(--accent); font-weight: 600; }

/* Bottom sheet and toast */
.noscroll { overflow: hidden; }
.sheet-wrap { position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: min(560px, 100%); max-height: 88vh; max-height: 88dvh; overflow-y: auto; background: var(--panel);
  border-radius: 16px 16px 0 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 18px; overflow-wrap: anywhere; }
.sheet .btn { width: 100%; }
.sheet .sheet-head .btn { width: auto; flex: none; }
.sheet .row .btn { width: auto; flex: 1; }
#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: var(--radius); background: var(--text); color: var(--bg);
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 30;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }
.log { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.log li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Table */
.table { width: min(720px, 100%); margin: 0 auto; padding: 8px 12px 76px; display: flex; flex-direction: column; gap: 10px; }
.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); }
.banner.attention { border-color: var(--focus); border-width: 2px; }
.strip { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.strip-p { display: flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-size: 14px; max-width: 100%; }
.strip-p.me { border-color: var(--accent); }
.strip-p.turn { box-shadow: 0 0 0 2px var(--focus); }
.strip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 9em; }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; border-radius: 10px; font-size: 12px; font-weight: 700; padding: 0 5px; }
.badge.dealer { background: var(--text); color: var(--bg); }
.badge.turn { background: var(--focus); color: #000; }
.felt { background: var(--felt); border-radius: var(--radius); padding: 10px; display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; }
.felt .container.k-stack:not(.spread) { flex: 0 0 auto; }
.felt .container.k-grid, .felt .container .row-cards { flex: 1 1 100%; }
.others { display: flex; flex-direction: column; gap: 6px; }
.other { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.other-name { font-weight: 700; display: flex; gap: 6px; align-items: center; min-width: 5em; }
.mine { background: var(--panel); border: 2px solid var(--accent); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.container { min-width: 0; }
.c-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.c-label { background: none; border: none; padding: 4px 0; min-height: 32px; font: inherit; font-weight: 600; color: var(--text); cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.count { color: var(--muted); font-weight: 400; font-size: 14px; }
.pile { position: relative; width: max-content; }
.depth { position: absolute; inset: 3px -3px -3px 3px; border-radius: 7px; border: 1px solid var(--line); background: var(--card-back); z-index: -1; }
.row-cards { display: flex; flex-wrap: wrap; gap: 6px; }
.row-cards.compact { gap: 2px; }
.grid { display: grid; grid-template-columns: repeat(var(--cols), max-content); gap: 6px; }

.card {
  width: 52px; height: 74px; border-radius: 7px; border: 1px solid #8a8a84; background: var(--card); color: var(--black);
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font: 700 18px/1 system-ui, sans-serif; padding: 0; cursor: pointer; position: relative; flex: none;
}
.card.small { width: 26px; height: 37px; font-size: 11px; border-radius: 4px; }
.card .suit { font-size: 20px; }
.card.small .suit { font-size: 11px; }
.card.red { color: var(--red); }
.card.back { background: repeating-linear-gradient(45deg, var(--card-back) 0 6px, #ffffff33 6px 8px); border-color: var(--card-back); }
.card.empty { background: transparent; border: 2px dashed var(--line); }
.card.private { border: 2px dashed var(--accent); }
.card.private::after { content: "only you"; position: absolute; bottom: 2px; font-size: 8px; font-weight: 600; color: var(--accent); }
.card.small.private::after { content: none; }
.card.selected { outline: 3px solid var(--focus); }
.card.c-red { color: #fff; background: #c0262d; }
.card.c-yellow { color: #1d1d1b; background: #e9c400; }
.card.c-green { color: #fff; background: #1f8a4a; }
.card.c-blue { color: #fff; background: #1f5fb3; }
.card.c-wild { color: #fff; background: conic-gradient(#c0262d 0 25%, #e9c400 0 50%, #1f8a4a 0 75%, #1f5fb3 0); }
.card.c-red .suit, .card.c-blue .suit, .card.c-green .suit, .card.c-yellow .suit, .card.c-wild .suit { font-size: 11px; }
.hand .card { width: 56px; height: 80px; }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line);
}
.actionbar .btn { flex: none; }
input[type=range] { padding: 0; min-height: var(--tap); }
.hand .card.private::after { content: none; }
.other .card { width: 36px; height: 51px; font-size: 13px; border-radius: 5px; }
.other .card .suit { font-size: 13px; }
.other .card.private::after { content: none; }
.other .grid { gap: 4px; }
.scores { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; font: inherit; color: var(--text); cursor: pointer; min-height: var(--tap); text-align: left; }
.score-chip { padding: 2px 8px; border-radius: 6px; background: var(--bg); }
.score-chip.lead { background: var(--focus); color: #000; }
.score-list { list-style: none; padding: 0; margin: 0; }
.score-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: var(--tap); border-bottom: 1px solid var(--line); padding: 4px 0; }
.score-n { font-size: 22px; min-width: 2.5ch; text-align: right; }
.sheet .score-row .btn { width: auto; min-width: 44px; }
.log li { display: flex; gap: 8px; align-items: center; }
.sheet .log .btn { width: auto; }
.win { font-weight: 700; color: var(--accent); font-size: 18px; }
.guide { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; }
.guide p { margin: 0; }
.guide-status { font-weight: 600; }
.guide-hint { color: var(--muted); font-size: 14px; }
.guide-steps { display: flex; flex-wrap: wrap; gap: 6px; }

/* Compact rows for the other players, and banners that stay in view */
.banners { position: sticky; top: 53px; z-index: 3; display: flex; flex-direction: column; gap: 6px; }
.other { padding: 4px 10px; gap: 4px 12px; }
.other .container { display: flex; align-items: center; gap: 6px; }
.other .c-head { margin: 0; }
.other .c-label { font-weight: 400; font-size: 14px; min-height: 28px; }
.other .card.small { width: 20px; height: 29px; border-radius: 3px; font-size: 9px; }
.other .card.small .suit { font-size: 9px; }
.other .row-cards.compact { gap: 1px; }

/* Narrow phones (320-360px): a five-card board and 8 cards in a hand still fit */
@media (max-width: 360px) {
  .table { padding-left: 8px; padding-right: 8px; }
  .felt { padding: 8px; }
  .card { width: 44px; height: 63px; font-size: 16px; }
  .hand .card { width: 46px; height: 66px; }
  .card .suit { font-size: 17px; }
}
.other .card.small.face { width: 30px; height: 42px; font-size: 12px; }
.other .card.small.face .suit { font-size: 12px; }
