:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #f8f7f4;
  --ink: #1b1c20;
  --ink-2: #5c5f66;
  --ink-3: #8b8e95;
  --line: #e3e1db;
  --accent: #23634a;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe9;
  --felt: #1f5a43;
  --felt-2: #18493a;
  --warn: #a4521a;
  --danger: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.06), 0 4px 16px rgba(20, 20, 30, 0.06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111316;
    --surface: #1a1d21;
    --surface-2: #20242a;
    --ink: #eceef1;
    --ink-2: #a8adb5;
    --ink-3: #7a8089;
    --line: #2c3138;
    --accent: #4fb089;
    --accent-ink: #0d1f17;
    --accent-soft: #1b3229;
    --felt: #1a4535;
    --felt-2: #13372a;
    --warn: #e09a5f;
    --danger: #f2827a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: 0.8rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); }

.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }

/* ---------- Controls ---------- */

button, .btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 9px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
}
button:hover, .btn:hover { border-color: var(--ink-3); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.07); }
button.ghost { background: transparent; border-color: transparent; color: var(--ink-2); padding: 0.35rem 0.55rem; }
button.ghost:hover { background: var(--surface-2); color: var(--ink); }
button.danger { color: var(--danger); }
button.small, .btn.small { padding: 0.3rem 0.6rem; font-size: 0.85rem; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.55rem 0.7rem;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 6rem; font-family: var(--font); }
label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 0.3rem; }
.field { margin-bottom: 0.9rem; }
.row { display: flex; gap: 0.5rem; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }

.card-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem;
}

.error { color: var(--danger); font-size: 0.9rem; min-height: 1.2em; margin: 0.4rem 0 0; }

.brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 750; letter-spacing: -0.01em; color: var(--ink); text-decoration: none; }
.brand svg { width: 26px; height: 26px; }

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .right { display: flex; align-items: center; gap: 0.4rem; }
.whoami { font-size: 0.9rem; color: var(--ink-2); margin-right: 0.3rem; }
.whoami strong { color: var(--ink); }

/* ---------- Login ---------- */

.center-page { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-box { width: 100%; max-width: 380px; }
.login-box .brand { justify-content: center; font-size: 1.3rem; margin-bottom: 1.2rem; }
.login-box .brand svg { width: 34px; height: 34px; }
.login-box p.intro { text-align: center; margin: 0 0 1.2rem; }
.login-box button[type=submit] { width: 100%; justify-content: center; padding: 0.65rem; }

/* ---------- Lobby ---------- */

.lobby { max-width: 920px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); align-items: start; }
.lobby .card-panel h2 { margin-bottom: 0.9rem; }
.room-list { list-style: none; margin: 0; padding: 0; }
.room-list li + li { border-top: 1px solid var(--line); }
.room-list a { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.75rem 0.25rem; color: var(--ink); text-decoration: none; }
.room-list a:hover .room-name { color: var(--accent); }
.room-name { font-weight: 600; }
.pill { font-size: 0.75rem; font-weight: 650; padding: 0.15rem 0.5rem; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.pill.live { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.notice { background: var(--accent-soft); color: var(--ink); border-radius: 10px; padding: 0.7rem 0.9rem; grid-column: 1 / -1; }
.notice.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); }
.empty { color: var(--ink-3); padding: 0.75rem 0.25rem; }

/* ---------- Room ---------- */

.room-title { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.room-title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 1.1rem; }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); flex: none; }
.conn-dot.on { background: #2fb36b; box-shadow: 0 0 0 3px color-mix(in srgb, #2fb36b 25%, transparent); }

.room { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.25rem; padding: 1.25rem; max-width: 1280px; margin: 0 auto; align-items: start; }
.room-main { display: grid; gap: 1rem; min-width: 0; }

.current-ticket { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.current-ticket .label { margin-bottom: 0.35rem; }
.current-ticket .title { font-size: 1.25rem; font-weight: 700; word-break: break-word; }
.current-ticket .title a { color: inherit; text-decoration-color: var(--ink-3); text-underline-offset: 3px; }

.table {
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-2) 100%);
  border-radius: 22px;
  padding: 1.5rem 1.25rem 1.25rem;
  color: #f2f6f3;
  box-shadow: inset 0 0 0 6px rgba(0, 0, 0, 0.12), var(--shadow);
}
.seats { display: flex; flex-wrap: wrap; justify-content: center; gap: 1.1rem 1rem; min-height: 120px; }
.seat { display: flex; flex-direction: column; align-items: center; gap: 0.45rem; width: 100px; }
.seat .name { font-size: 0.82rem; font-weight: 600; text-align: center; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat.offline { opacity: 0.45; }
.seat .badge { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: #f6d77a; height: 0.9rem; }

.pcard {
  width: 52px;
  height: 74px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 750;
  font-size: 1.2rem;
  border: 2px dashed rgba(255, 255, 255, 0.28);
  color: transparent;
  transition: transform 0.25s;
}
.pcard.down {
  border: 2px solid #f2f6f3;
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.16) 0 4px, transparent 4px 9px),
    #2f8a63;
}
.pcard.up { border: 2px solid #ffffff; background: #ffffff; color: #1b1c20; animation: flip 0.35s ease-out; }
.pcard.up.none { background: rgba(255, 255, 255, 0.12); color: rgba(255, 255, 255, 0.6); border-style: dashed; font-size: 0.9rem; }
@keyframes flip { from { transform: rotateY(90deg); } to { transform: rotateY(0); } }

.table-status { text-align: center; margin-top: 1.1rem; font-size: 0.92rem; color: rgba(242, 246, 243, 0.85); }
.watchers { text-align: center; margin-top: 0.4rem; font-size: 0.8rem; color: rgba(242, 246, 243, 0.65); }
.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; margin-top: 0.9rem; }
.table button { border-color: rgba(255, 255, 255, 0.25); background: rgba(255, 255, 255, 0.1); color: #fff; }
.table button:hover { background: rgba(255, 255, 255, 0.18); border-color: rgba(255, 255, 255, 0.45); }
.table button.primary { background: #f2f6f3; color: #17402f; border-color: #f2f6f3; }
.table button.primary:hover { filter: none; background: #ffffff; }

.results { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1.25rem; align-items: center; }
.results .big { text-align: center; padding-right: 1.25rem; border-right: 1px solid var(--line); }
.results .big .num { font-size: 2.2rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1; }
.results .big .lbl { font-size: 0.8rem; color: var(--ink-2); margin-top: 0.3rem; }
.consensus { display: inline-block; margin-top: 0.5rem; font-size: 0.75rem; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 0.15rem 0.5rem; border-radius: 99px; }
.dist { display: grid; gap: 0.35rem; }
.dist-row { display: grid; grid-template-columns: 2.6rem minmax(0, 1fr) auto; gap: 0.6rem; align-items: center; font-size: 0.9rem; }
.dist-row .v { font-weight: 750; text-align: right; }
.dist-row .bar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.dist-row .bar span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.dist-row .who { color: var(--ink-2); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 14rem; }

.estimate-picker { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.estimate-picker .chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.5rem 0 0.7rem; }
.chip { padding: 0.3rem 0.65rem; border-radius: 8px; font-weight: 700; min-width: 2.4rem; justify-content: center; }
.chip.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.estimate-picker .row input { max-width: 8rem; }

.hand { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.55rem; padding: 0.25rem 0; }
.hand button.card {
  width: 58px;
  height: 84px;
  border-radius: 10px;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 800;
  border: 2px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}
.hand button.card:hover:not(:disabled) { transform: translateY(-4px); border-color: var(--accent); }
.hand button.card.selected { transform: translateY(-10px); background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.hand-hint { text-align: center; margin-top: 0.6rem; }

.sidebar { display: grid; gap: 1rem; position: sticky; top: 72px; max-height: calc(100vh - 92px); }
.sidebar .card-panel { display: flex; flex-direction: column; min-height: 0; }
.tickets-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.6rem; gap: 0.5rem; }
.ticket-list { position: relative; list-style: none; padding: 0; margin: 0 -0.4rem; overflow-y: auto; min-height: 0; max-height: 46vh; }
.ticket { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.4rem; border-radius: 8px; }
.ticket + .ticket { margin-top: 2px; }
.ticket.clickable { cursor: pointer; }
.ticket.clickable:hover { background: var(--surface-2); }
.ticket.current { background: var(--accent-soft); }
.ticket .idx { width: 1.4rem; text-align: right; color: var(--ink-3); font-size: 0.8rem; font-variant-numeric: tabular-nums; flex: none; }
.ticket .t { flex: 1; min-width: 0; font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket.done .t { color: var(--ink-2); }
.ticket .est { font-weight: 750; font-size: 0.8rem; padding: 0.1rem 0.45rem; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); flex: none; }
.ticket.done .est { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.ticket .rm { visibility: hidden; padding: 0.1rem 0.35rem; }
.ticket:hover .rm, .ticket .rm:focus { visibility: visible; }
.ticket a.ext { color: var(--ink-3); flex: none; display: inline-flex; }
.ticket a.ext:hover { color: var(--accent); }
.ticket a.ext svg { width: 14px; height: 14px; }

.add-form { margin-top: 0.9rem; padding-top: 0.9rem; border-top: 1px solid var(--line); display: grid; gap: 0.5rem; }
.add-form .switch { justify-self: start; }
.sidebar-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 0.6rem; }

.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.15rem; }
.people li { display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0; font-size: 0.92rem; }
.people .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; }
.people .dot.on { background: #2fb36b; }
.people .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people .tag { font-size: 0.7rem; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em; }

.toggle { white-space: nowrap; display: inline-flex; align-items: center; gap: 0.45rem; font-weight: 500; font-size: 0.88rem; color: var(--ink-2); cursor: pointer; margin: 0; }
.toggle input { width: auto; accent-color: var(--accent); }

.toast { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 0.6rem 1rem; border-radius: 10px; font-size: 0.9rem; box-shadow: var(--shadow); z-index: 50; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.toast.show { opacity: 1; }

.short { display: none; }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 85%, transparent); z-index: 40; text-align: center; padding: 1.5rem; }

@media (max-width: 900px) {
  .room { grid-template-columns: 1fr; padding: 0.9rem; }
  .sidebar { position: static; max-height: none; }
  .ticket-list { max-height: none; }
  .lobby { grid-template-columns: 1fr; }
  .ticket .rm { visibility: visible; }
}

@media (max-width: 560px) {
  .topbar { padding: 0.6rem 0.8rem; }
  .whoami { display: none; }
  .hand button.card { width: 48px; height: 70px; font-size: 1.05rem; }
  .seat { width: 78px; }
  .long { display: none; }
  .short { display: inline; }
  .results { grid-template-columns: 1fr; }
  .results .big { border-right: none; border-bottom: 1px solid var(--line); padding: 0 0 1rem; }
  .current-ticket { flex-direction: column; }
}
