/* Double Solitaire -- one calm dark table, seat colours for "whose card".
   Spacing: 4px base; panels never closer than 12px; tap targets >= 44px. */
:root {
  --bg: #14213a;
  --bg2: #0f1a2f;
  --panel: rgba(255, 255, 255, 0.055);
  --panel-line: rgba(255, 255, 255, 0.13);
  --text: #eef2f8;
  --muted: #a9b6cc;
  --accent: #fde047;      /* action / selection yellow */
  --accent-text: #0f172a;
  --good: #34d399;
  --bad: #fb7185;
  --red: #d32f3a;
  --black: #1b2233;
  --s0: #3b82f6;          /* seat colours: blue, pink, green, violet */
  --s1: #ec4899;
  --s2: #10b981;
  --s3: #a855f7;
  --radius: 14px;
  --gut: 12px;
  --cw: 48px;
  --ch: 67px;
  --gap: 6px;
  color-scheme: dark;
}
@media (min-width: 600px) { :root { --gut: 20px; } }
@media (min-width: 1100px) { :root { --gut: 28px; } }

* { box-sizing: border-box; }
html { background: var(--bg2); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; touch-action: manipulation; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(140% 900px at 50% 0%, #1d3057 0%, var(--bg) 55%, var(--bg2) 100%) no-repeat, var(--bg2);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
}
main {
  padding: calc(env(safe-area-inset-top, 0px) + 14px) calc(env(safe-area-inset-right, 0px) + var(--gut))
           calc(env(safe-area-inset-bottom, 0px) + 28px) calc(env(safe-area-inset-left, 0px) + var(--gut));
  max-width: 1500px;
  margin: 0 auto;
}
.boot, .noscript { text-align: center; color: var(--muted); padding: 3rem 1rem; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }

/* ---- buttons and fields ---------------------------------------------- */
button, .btn {
  font: inherit;
  font-weight: 650;
  font-size: 1.0625rem;
  min-height: 48px;
  padding: 0 1.25rem;
  border-radius: 12px;
  border: 1px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.09);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-align: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
button:hover { background: rgba(255, 255, 255, 0.14); }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
button.primary:hover { background: #fef08a; }
button.primary:disabled { background: rgba(255, 255, 255, 0.09); color: var(--muted); border-color: var(--panel-line); opacity: 1; }
button.big { min-height: 60px; font-size: 1.25rem; padding: 0 1.75rem; border-radius: 14px; }
button.wide { width: 100%; }
button.small { min-height: 44px; font-size: 0.95rem; padding: 0 0.9rem; }
button.on { background: rgba(253, 224, 71, 0.18); border-color: var(--accent); }

label.field { display: grid; gap: 0.5rem; font-weight: 600; }
label.field span.hint { font-weight: 400; color: var(--muted); font-size: 0.9rem; }
input[type=text] {
  font: inherit;
  font-size: 1.25rem;
  min-height: 56px;
  padding: 0 1rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  width: 100%;
}
input.code { text-transform: uppercase; letter-spacing: 0.3em; text-align: center; font-weight: 700; }
.seg { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.seg button { flex: 1 1 8rem; }

/* ---- welcome / join / lobby panels ---------------------------------- */
.narrow { max-width: 560px; margin: 0 auto; display: grid; gap: 1.5rem; }
.brand { text-align: center; display: grid; gap: 0.5rem; padding-top: 0.75rem; }
.brand h1 { font-size: clamp(1.9rem, 6vw, 2.6rem); letter-spacing: -0.01em; }
.brand p { color: var(--muted); font-size: 1.05rem; }
.brand .suits { font-size: 1.4rem; letter-spacing: 0.35em; color: var(--muted); }
.brand .suits .r { color: #f87171; }
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: grid;
  gap: 1.25rem;
}
.panel h2 { font-size: 1.25rem; text-align: center; }
.panel .lead { text-align: center; color: var(--muted); }
.panel.hl { border-color: rgba(253, 224, 71, 0.55); background: rgba(253, 224, 71, 0.07); }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 auto; }
.center { text-align: center; }
.err { color: var(--bad); text-align: center; font-weight: 600; }
.muted { color: var(--muted); }
.footer-note { text-align: center; color: var(--muted); font-size: 0.9rem; }

.who { display: grid; gap: 0.75rem; }
.who-row {
  display: flex; align-items: center; gap: 0.75rem;
  min-height: 52px; padding: 0.5rem 0.75rem;
  border-radius: 12px; background: rgba(0, 0, 0, 0.18);
}
.who-row .nm { flex: 1 1 auto; font-weight: 650; font-size: 1.1rem; }
.who-row .tag { color: var(--muted); font-size: 0.9rem; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 auto; background: var(--seat); }
.dot.off { opacity: 0.35; }

.share { display: grid; gap: 1.25rem; justify-items: center; }
.share .code-big { font-size: 2.4rem; font-weight: 800; letter-spacing: 0.25em; padding-left: 0.25em; line-height: 1; }
.share .link { font-size: 1.05rem; color: var(--muted); word-break: break-all; text-align: center; }
.share .btns { display: flex; gap: 0.75rem; flex-wrap: wrap; justify-content: center; width: 100%; }
.share .btns button { flex: 1 1 11rem; }
.qr { background: #fff; padding: 14px; border-radius: 12px; line-height: 0; }
.qr svg { width: min(240px, 62vw); height: auto; display: block; }
.qr-cap { color: var(--muted); text-align: center; font-size: 0.95rem; }

/* ---- game ------------------------------------------------------------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 0.75rem; margin-bottom: 14px;
}
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 0.45rem;
  min-height: 36px; padding: 0 0.75rem; border-radius: 999px;
  background: rgba(0, 0, 0, 0.22); border: 1px solid var(--panel-line);
  font-weight: 650; font-size: 0.95rem; white-space: nowrap;
}
.chip .n { color: var(--accent); font-variant-numeric: tabular-nums; }
.chip.me { border-color: var(--seat); }
.chip.room { color: var(--muted); font-weight: 600; letter-spacing: 0.05em; }
.topbar .actions { display: flex; gap: 0.5rem; margin-left: auto; }
@media (max-width: 599px) {
  .topbar { flex-wrap: nowrap; align-items: flex-start; }
  .chip.room { display: none; }
  .chip { min-height: 34px; padding: 0 0.6rem; font-size: 0.9rem; gap: 0.35rem; }
  .chip .dot { width: 11px; height: 11px; }
}

.game { display: grid; gap: 14px; }
.game.side { grid-template-columns: minmax(0, 1fr) var(--sidew); align-items: start; }
.game .mainc, .game .sidec { display: grid; gap: 14px; min-width: 0; align-content: start; }

.area {
  position: relative;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  padding: 10px;
}
.area.mine { border-top: 4px solid var(--seat); }
.area.opp { border-left: 4px solid var(--seat); padding: 8px 10px 10px; }
.area.found { background: rgba(0, 0, 0, 0.16); }
.area.found .area-h { justify-content: center; text-align: center; }
.area-h {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  font-size: 0.9rem; color: var(--muted); margin-bottom: 8px; min-height: 24px;
}
.area-h b { color: var(--text); font-size: 1rem; }
.area-h .nm { display: inline-flex; align-items: center; gap: 0.45rem; min-width: 0; }
.area-h .nm b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.opp-toggle {
  width: 100%; min-height: 44px; padding: 0 0.25rem; background: none; border: 0;
  display: flex; justify-content: space-between; font-size: 0.95rem; font-weight: 500; color: var(--muted);
}
.opp-toggle:hover { background: none; }
.opp-toggle .chev { font-size: 0.8rem; }
.opp-toggle .nm { display: inline-flex; align-items: center; gap: 0.45rem; min-width: 0; }
.opp-toggle .nm b { color: var(--text); }
.opp-sum { display: inline-flex; align-items: center; gap: 0.5rem; }

.found-grid { display: grid; gap: var(--fgap); justify-content: center; }
.slot {
  width: var(--fw); height: var(--fh); border-radius: 7px;
  border: 2px dashed rgba(255, 255, 255, 0.2);
  display: flex; align-items: center; justify-content: center;
  color: rgba(255, 255, 255, 0.25); font-weight: 700; font-size: calc(var(--fw) * 0.34);
  position: relative;
}
.slot > .card { position: absolute; inset: -2px; width: var(--fw); height: var(--fh); }

.row-top { display: flex; gap: var(--gap); align-items: stretch; }
.pile { width: var(--cw); height: var(--ch); position: relative; flex: 0 0 auto; }
.pile.stock { cursor: pointer; }
.pile .empty {
  position: absolute; inset: 0; border-radius: 7px; border: 2px dashed rgba(255, 255, 255, 0.25);
  display: flex; align-items: center; justify-content: center; font-size: calc(var(--cw) * 0.45); color: var(--muted);
}
.pile .count {
  position: absolute; left: 50%; bottom: -2px; transform: translate(-50%, 50%);
  background: #0b1325; border: 1px solid var(--panel-line); border-radius: 999px;
  padding: 0 0.45rem; font-size: 0.75rem; line-height: 1.5; color: var(--muted); white-space: nowrap;
}
.waste { position: relative; height: var(--ch); flex: 0 0 auto; }
.status-box {
  margin-left: auto; display: grid; gap: 0.5rem; justify-items: end; align-content: center;
  text-align: right; min-width: 0; flex: 1 1 auto;
}
.status-box .big-n { font-size: 1.05rem; font-weight: 700; }
.status-box .big-n span { color: var(--accent); }
.stuck-note { font-size: 0.85rem; color: var(--muted); }

.tab { display: grid; grid-template-columns: repeat(7, var(--cw)); gap: var(--gap); margin-top: 18px; justify-content: space-between; }
.col { position: relative; min-height: var(--ch); border-radius: 7px; }
.col.empty-col::before {
  content: "K"; position: absolute; left: 0; top: 0; width: var(--cw); height: var(--ch);
  border: 2px dashed rgba(255, 255, 255, 0.2); border-radius: 7px; box-sizing: border-box;
  display: flex; align-items: center; justify-content: center; color: rgba(255, 255, 255, 0.25);
  font-weight: 700; font-size: calc(var(--cw) * 0.36);
}
.col > .card { position: absolute; left: 0; }

/* ---- cards ------------------------------------------------------------------- */
.card {
  width: var(--cw); height: var(--ch); border-radius: 7px;
  background: #fbfbf8; color: var(--black);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  position: relative; overflow: hidden;
  font-weight: 700; user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.card.red { color: var(--red); }
.card .cr {
  position: absolute; left: 7%; top: 3%; font-size: calc(var(--cw) * 0.33); line-height: 1.05;
  letter-spacing: -0.04em; white-space: nowrap;
}
.card .cc {
  position: absolute; left: 0; right: 0; bottom: 14%; text-align: center;
  font-size: calc(var(--cw) * 0.5); line-height: 1;
}
.card::after { /* owner band */
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: max(4px, calc(var(--ch) * 0.07));
  background: var(--seat);
}
.card.back {
  background-color: var(--seat);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), inset 0 0 0 2px rgba(255, 255, 255, 0.85), inset 0 0 0 4px var(--seat);
}
.card.back::after { display: none; }
.card.back.p0 { background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.28) 0 3px, transparent 3px 8px); }
.card.back.p1 { background-image: radial-gradient(rgba(255,255,255,.4) 1.6px, transparent 2px); background-size: 8px 8px; }
.card.back.p2 { background-image: linear-gradient(90deg, rgba(255,255,255,.25) 50%, transparent 50%), linear-gradient(rgba(255,255,255,.25) 50%, transparent 50%); background-size: 10px 10px; }
.card.back.p3 { background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.25) 0 2px, transparent 2px 7px), repeating-linear-gradient(-45deg, rgba(255,255,255,.25) 0 2px, transparent 2px 7px); }
.card.sel { box-shadow: 0 0 0 3px var(--accent), 0 6px 14px rgba(0, 0, 0, 0.5); transform: translateY(-3px); z-index: 50; }
.card.shake { animation: shake 0.38s ease; }
@keyframes shake { 20% { transform: translateX(-5px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }
.card.fresh { animation: pop 0.5s ease; }
@keyframes pop { 0% { transform: scale(1.12); box-shadow: 0 0 0 3px #fff; } 100% { transform: none; } }
.can-drop { box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.9); border-radius: 7px; }
.slot.can-drop { border-color: var(--good); border-style: solid; }

.mini .card .cr { font-size: calc(var(--cw) * 0.36); left: 6%; top: 2%; }
.mini.tiny .card .cc { display: none; }
.area.found .card .cr { font-size: calc(var(--fw) * 0.34); }
.mini .card { border-radius: 4px; }
.mini .col.empty-col::before { content: ""; border-width: 1px; border-radius: 4px; }
.mini .tab { margin-top: 0; }
.mini .card.back { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.8); }
.opp-meta { display: flex; gap: 0.75rem; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.opp-meta .pile .count { font-size: 0.7rem; }

/* ---- overlays, toast, connection -------------------------------------------- */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(6, 12, 26, 0.72);
  display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  overflow-y: auto;
}
.overlay .panel { width: min(520px, 100%); background: #1a2945; max-height: 100%; overflow-y: auto; }
.results { display: grid; gap: 0.75rem; }
.results .who-row .n { font-size: 1.3rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.results .crown { font-size: 1.2rem; }
.over-bar {
  display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; justify-content: center;
  padding: 0.75rem; margin-bottom: 14px; border-radius: var(--radius);
  background: rgba(253, 224, 71, 0.1); border: 1px solid rgba(253, 224, 71, 0.45);
  text-align: center;
}
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  transform: translateX(-50%); z-index: 300;
  max-width: min(92vw, 460px); width: max-content;
  padding: 0.85rem 1.25rem; border-radius: 12px;
  background: #0b1325; border: 1px solid var(--panel-line); color: var(--text);
  font-weight: 650; text-align: center; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
}
.toast.race { border-color: var(--bad); }
.conn {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 10px); left: 50%; transform: translateX(-50%);
  z-index: 300; padding: 0.5rem 1rem; border-radius: 999px;
  background: #9f1239; color: #fff; font-weight: 650; font-size: 0.95rem;
}
@media (prefers-reduced-motion: reduce) { .card, .card.sel { transition: none; } .card.shake, .card.fresh { animation: none; } }
