/* Sam31 - shell, layout and screens. Card visuals live in cards.css. */

:root {
  --felt-1: #0f4436;
  --felt-2: #0a2f26;
  --felt-3: #072019;
  --ink: #f2f6f3;
  --ink-dim: #a8bdb4;
  --ink-faint: #6f8a80;
  --line: rgba(255, 255, 255, 0.12);
  --panel: rgba(6, 26, 21, 0.62);
  --panel-solid: #0b2a22;
  --gold: #e9c46a;
  --gold-deep: #c9a227;
  --red: #e05d4b;
  --green: #56c596;
  --blue: #6bb8e0;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --tap: 44px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  color-scheme: dark;
}

* { box-sizing: border-box; }

/*
 * The browser's own [hidden] rule is only `display: none`, so ANY class that
 * sets a display wins against it and the element stays on screen with its
 * hidden attribute set. That is exactly how the connection spinner ended up
 * spinning away in the corner of a perfectly healthy game. Make it emphatic
 * once here, rather than remembering it at every call site.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
}

body {
  font-family: ui-rounded, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 50% -10%, var(--felt-1) 0%, var(--felt-2) 45%, var(--felt-3) 100%)
    fixed;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }
button { font: inherit; color: inherit; }

/* ---------- generic controls ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 0 18px;
  min-height: var(--tap);
  font-weight: 650;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 120ms ease, transform 80ms ease, border-color 120ms ease;
  touch-action: manipulation;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.13); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.btn--primary {
  background: linear-gradient(180deg, var(--gold) 0%, var(--gold-deep) 100%);
  border-color: transparent;
  color: #2a1e00;
}
.btn--primary:hover:not(:disabled) { filter: brightness(1.06); background: linear-gradient(180deg, var(--gold) 0%, var(--gold-deep) 100%); }

.btn--danger { border-color: rgba(224, 93, 75, 0.5); color: #ffc9c0; }
.btn--danger:hover:not(:disabled) { background: rgba(224, 93, 75, 0.18); }

.btn--ghost { background: transparent; }
.btn--sm { min-height: 34px; padding: 0 12px; font-size: 0.85rem; border-radius: 8px; }
.btn--block { width: 100%; }

input[type="text"], select {
  appearance: none;
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  color: var(--ink);
  font: inherit;
}
input[type="text"]:focus, select:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
input::placeholder { color: var(--ink-faint); }

select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-dim) 50%),
                    linear-gradient(135deg, var(--ink-dim) 50%, transparent 50%);
  background-position: right 18px center, right 13px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 0.8rem; color: var(--ink-dim); font-weight: 600; }
.hint { font-size: 0.8rem; color: var(--ink-faint); line-height: 1.45; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(6px);
}

.row { display: flex; gap: 10px; align-items: center; }
.row--wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack--tight { gap: 8px; }
.spacer { flex: 1; }

/* ---------- home screen ---------- */

.home {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 18px calc(24px + var(--safe-bottom));
  gap: 20px;
}

.home__inner { width: min(560px, 100%); display: flex; flex-direction: column; gap: 18px; }

.brand { text-align: center; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.brand__mark {
  font-size: clamp(2.6rem, 11vw, 3.6rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  background: linear-gradient(180deg, #fff 0%, var(--gold) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand__tag { color: var(--ink-dim); font-size: 0.95rem; }

.tabs { display: flex; gap: 6px; background: rgba(0,0,0,0.25); padding: 5px; border-radius: 11px; }
.tabs button {
  flex: 1; min-height: 38px; border: 0; background: transparent; border-radius: 8px;
  font-weight: 650; color: var(--ink-dim); cursor: pointer;
}
.tabs button[aria-selected="true"] { background: rgba(255,255,255,0.12); color: var(--ink); }

.code-input { text-transform: uppercase; letter-spacing: 0.35em; text-align: center; font-weight: 700; font-size: 1.3rem; }

/* card back picker */
.backs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; }
.backs__item {
  border: 2px solid transparent; background: none; padding: 0; cursor: pointer;
  border-radius: 10px; display: flex; flex-direction: column; align-items: center; gap: 5px;
}
.backs__item .card { width: 100%; height: auto; aspect-ratio: 5 / 7; }
.backs__item[aria-pressed="true"] { border-color: var(--gold); }
.backs__item span { font-size: 0.65rem; color: var(--ink-faint); text-align: center; line-height: 1.2; }
.backs__item[aria-pressed="true"] span { color: var(--gold); }

/* stats strip */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stats div { background: rgba(0,0,0,0.22); border-radius: 10px; padding: 9px 4px; }
.stats b { display: block; font-size: 1.25rem; line-height: 1.1; }
.stats span { font-size: 0.68rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.06em; }

/* leaderboard */
.board { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.board th {
  text-align: right; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--ink-faint); padding: 0 8px 8px; font-weight: 600;
}
.board th:first-child, .board td:first-child { text-align: left; }
.board td { padding: 8px; border-top: 1px solid var(--line); text-align: right; }
.board tr.is-me { color: var(--gold); font-weight: 650; }

/* ---------- lobby ---------- */

.lobby { flex: 1; display: flex; flex-direction: column; padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom)); gap: 14px; align-items: center; }
.lobby__inner { width: min(680px, 100%); display: flex; flex-direction: column; gap: 14px; }

.roomcode {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: linear-gradient(135deg, rgba(233,196,106,0.16), rgba(233,196,106,0.04));
  border: 1px solid rgba(233,196,106,0.35); border-radius: var(--radius); padding: 14px 16px;
}
.roomcode__code { font-size: clamp(2rem, 9vw, 2.6rem); font-weight: 800; letter-spacing: 0.22em; color: var(--gold); line-height: 1; }
.roomcode__label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); }

.seats { display: flex; flex-direction: column; gap: 8px; }
.seatrow {
  display: flex; align-items: center; gap: 11px;
  background: rgba(0,0,0,0.22); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 12px; min-height: 52px;
}
.seatrow__avatar {
  width: 34px; height: 34px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 0.9rem;
  background: rgba(255,255,255,0.1);
}
.seatrow__avatar.is-bot { background: rgba(107,184,224,0.2); color: var(--blue); }
.seatrow__name { font-weight: 650; }
.seatrow__meta { font-size: 0.74rem; color: var(--ink-faint); }

.tag {
  font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700;
  padding: 2px 7px; border-radius: 999px; background: rgba(255,255,255,0.1); color: var(--ink-dim);
}
.tag--host { background: rgba(233,196,106,0.2); color: var(--gold); }
.tag--bot { background: rgba(107,184,224,0.18); color: var(--blue); }
.tag--you { background: rgba(86,197,150,0.18); color: var(--green); }
.tag--off { background: rgba(224,93,75,0.18); color: var(--red); }

.rules { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.rules .field > label { display: flex; justify-content: space-between; gap: 8px; }

/* ---------- table ---------- */

.table {
  flex: 1;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 10px;
  padding: calc(8px + var(--safe-top)) 10px calc(8px + var(--safe-bottom));
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  min-height: 100dvh;
}

.topbar { display: flex; align-items: center; gap: 10px; }
.topbar__code { font-weight: 800; letter-spacing: 0.16em; color: var(--gold); font-size: 0.95rem; }
.topbar__round { font-size: 0.75rem; color: var(--ink-faint); }

.opponents { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.opponents::-webkit-scrollbar { display: none; }

.opp {
  flex: 1 1 0; min-width: 108px;
  background: rgba(0,0,0,0.24); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 9px;
  display: flex; flex-direction: column; gap: 6px;
  transition: border-color 160ms ease, background 160ms ease;
}
.opp.is-turn { border-color: var(--gold); background: rgba(233,196,106,0.1); }
.opp.is-out { opacity: 0.4; }
.opp__top { display: flex; align-items: center; gap: 6px; min-width: 0; }
.opp__name { font-weight: 650; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opp__cards { display: flex; gap: 3px; }
.opp__cards .card { width: 22px; height: 31px; border-radius: 3px; }
.opp__bottom { display: flex; align-items: center; justify-content: space-between; gap: 6px; }

.lives { display: flex; gap: 3px; align-items: center; }
.life { width: 9px; height: 9px; border-radius: 50%; background: var(--green); }
.life.is-spent { background: rgba(255,255,255,0.15); }
.lives__bus { font-size: 0.62rem; color: var(--red); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }

.middle {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 6px 0; min-height: 0;
}

.banner {
  text-align: center; font-weight: 650; font-size: 0.95rem; min-height: 1.4em;
  color: var(--ink-dim);
}
.banner.is-you { color: var(--gold); }
.banner strong { color: var(--ink); }

.piles { display: flex; gap: clamp(16px, 6vw, 44px); align-items: flex-start; justify-content: center; }
.pile { display: flex; flex-direction: column; align-items: center; gap: 7px; }
.pile__label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint); }
.pile__slot { position: relative; }
.pile__count {
  position: absolute; bottom: -7px; right: -7px;
  background: var(--panel-solid); border: 1px solid var(--line); color: var(--ink-dim);
  border-radius: 999px; min-width: 22px; height: 22px; padding: 0 5px;
  display: grid; place-items: center; font-size: 0.68rem; font-weight: 700;
}
.pile__empty {
  width: var(--card-w); height: var(--card-h);
  border: 2px dashed rgba(255,255,255,0.16); border-radius: var(--card-radius);
  display: grid; place-items: center; color: var(--ink-faint); font-size: 0.7rem;
}

.myarea { display: flex; flex-direction: column; gap: 10px; align-items: center; }

.myhead { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.score {
  display: inline-flex; align-items: baseline; gap: 6px;
  background: rgba(0,0,0,0.3); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 14px;
}
.score b { font-size: 1.5rem; line-height: 1; font-variant-numeric: tabular-nums; }
.score span { font-size: 0.7rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.06em; }
.score.is-hot b { color: var(--gold); }
.score.is-blitz { border-color: var(--gold); box-shadow: 0 0 18px rgba(233,196,106,0.35); }

.myhand { display: flex; gap: clamp(6px, 2vw, 12px); justify-content: center; align-items: flex-end; min-height: var(--card-h); }

.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.actions .btn { min-width: 120px; }

.log {
  border-top: 1px solid var(--line); padding-top: 8px;
  font-size: 0.76rem; color: var(--ink-faint); line-height: 1.5;
  max-height: 4.5em; overflow-y: auto; scrollbar-width: thin;
}
.log p:last-child { color: var(--ink-dim); }

/* ---------- overlays ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(3, 14, 11, 0.82);
  backdrop-filter: blur(7px);
  display: flex; align-items: center; justify-content: center;
  padding: calc(16px + var(--safe-top)) 14px calc(16px + var(--safe-bottom));
  overflow-y: auto;
  animation: fade 180ms ease;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  width: min(560px, 100%);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
  max-height: 100%;
}
.sheet__title { text-align: center; font-size: 1.3rem; }
.sheet__sub { text-align: center; color: var(--ink-dim); font-size: 0.9rem; }
.sheet__scroll { overflow-y: auto; display: flex; flex-direction: column; gap: 9px; }

.reveal-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.04); border: 1px solid transparent;
}
.reveal-row.is-low { border-color: rgba(224,93,75,0.5); background: rgba(224,93,75,0.1); }
.reveal-row.is-top { border-color: rgba(233,196,106,0.5); background: rgba(233,196,106,0.09); }
.reveal-row__name { font-weight: 650; font-size: 0.9rem; }
.reveal-row__cards { display: flex; gap: 3px; }
.reveal-row__cards .card { width: 34px; height: 48px; font-size: 8px; --card-radius: 4px; }
.reveal-row__score { font-size: 1.15rem; font-weight: 750; font-variant-numeric: tabular-nums; margin-left: auto; }
.reveal-row__cost { font-size: 0.72rem; color: var(--red); font-weight: 700; }

.winner { text-align: center; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.winner__crown { font-size: 3rem; line-height: 1; }
.winner__name { font-size: 1.7rem; font-weight: 800; color: var(--gold); }

/* Between-hands countdown under the revealed hands. */
.countdown { display: flex; flex-direction: column; gap: 9px; }

.countdown__track {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.countdown__fill {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold));
  /* Matches the 200ms repaint interval, so the bar slides instead of stepping. */
  transition: width 200ms linear;
}

.countdown__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
}
.countdown__text {
  font-size: 0.82rem;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}
.countdown__row .btn { margin-left: auto; }

@media (prefers-reduced-motion: reduce) {
  .countdown__fill { transition: none; }
}

/* ---------- toast + connection ---------- */

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + var(--safe-bottom)); z-index: 60;
  background: #2a1010; border: 1px solid rgba(224,93,75,0.6); color: #ffd9d3;
  padding: 11px 16px; border-radius: 11px; font-size: 0.88rem; font-weight: 600;
  box-shadow: var(--shadow); max-width: min(420px, calc(100vw - 28px)); text-align: center;
  animation: rise 200ms ease;
}
.toast.is-info { background: #0d2b24; border-color: rgba(86,197,150,0.5); color: #cdf3e3; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }

.connection {
  position: fixed; top: calc(10px + var(--safe-top)); left: 50%; transform: translateX(-50%);
  z-index: 70; display: flex; align-items: center; gap: 9px;
  background: #3a2a08; border: 1px solid rgba(233,196,106,0.5); color: #ffe9b8;
  padding: 8px 14px; border-radius: 999px; font-size: 0.82rem; font-weight: 600;
}
.spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25); border-top-color: var(--gold);
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- phones ---------- */

@media (max-width: 620px) {
  .backs { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .backs__item span { font-size: 0.55rem; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .panel { padding: 14px; }
  .actions .btn { flex: 1; min-width: 0; padding: 0 10px; }
  .opp { min-width: 96px; padding: 7px; }
  .table { gap: 8px; }
  .reveal-row__cards .card { width: 28px; height: 40px; }
}

@media (max-width: 380px) {
  .opp__cards .card { width: 18px; height: 26px; }
}

/* Short landscape phones: give the hand as much room as possible. */
@media (max-height: 520px) and (orientation: landscape) {
  .log { display: none; }
  .pile__label { display: none; }
  .middle { gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
