/* =========================================================================
   Poker Tournament Timer — themes + layout
   Themes are driven entirely by CSS custom properties on [data-theme] so the
   host can switch them live for every viewer.
   ========================================================================= */

:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---- Theme: Classic Felt (default) ---- */
[data-theme="classic-felt"] {
  --bg: radial-gradient(ellipse at top, #1b5e3a 0%, #0e3a23 70%, #082617 100%);
  --bg-solid: #0e3a23;
  --fg: #f3f7f2;
  --muted: #bcd6c5;
  --accent: #f5c542;
  --accent-fg: #20140a;
  --panel: rgba(0, 0, 0, 0.28);
  --panel-border: rgba(245, 197, 66, 0.35);
  --break: #4aa3ff;
  --danger: #e05656;
  --clock-glow: rgba(245, 197, 66, 0.35);
}

/* ---- Theme: Dark Neon ---- */
[data-theme="dark-neon"] {
  --bg: radial-gradient(ellipse at top, #16012b 0%, #0a0118 70%, #04000c 100%);
  --bg-solid: #0a0118;
  --fg: #f4f0ff;
  --muted: #a99fd0;
  --accent: #00e5ff;
  --accent-fg: #001417;
  --panel: rgba(255, 255, 255, 0.05);
  --panel-border: rgba(0, 229, 255, 0.4);
  --break: #ff4fd8;
  --danger: #ff5470;
  --clock-glow: rgba(0, 229, 255, 0.45);
}

/* ---- Theme: Light Minimal ---- */
[data-theme="light-minimal"] {
  --bg: #f4f6f8;
  --bg-solid: #f4f6f8;
  --fg: #1d2430;
  --muted: #5b6675;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --panel: #ffffff;
  --panel-border: #d8dee6;
  --break: #0ea5e9;
  --danger: #dc2626;
  --clock-glow: rgba(37, 99, 235, 0.15);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  background-attachment: fixed;
}

/* =========================  VIEWER  ===================================== */

body.viewer {
  display: flex;
  min-height: 100vh;
  overflow: hidden;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* "safe": stay centered when content fits, but anchor to the top (don't clip
     the logo off the top) when the column is taller than the viewport. */
  justify-content: safe center;
  text-align: center;
  padding: 3vh 4vw;
  gap: 2.2vh;
  position: relative;
  width: 100%;
  min-height: 100vh;
  overflow-y: auto;
}

.topbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1vh;
}

.logo {
  max-height: 14vh;
  max-width: 60vw;
  object-fit: contain;
}

.tournament-name {
  margin: 0;
  font-size: clamp(1.2rem, 4vw, 2.6rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--fg);
}

.clock-area { display: flex; flex-direction: column; align-items: center; gap: 1vh; }

.phase {
  font-size: clamp(1rem, 3.5vw, 2.2rem);
  font-weight: 700;
  letter-spacing: 0.25em;
  color: var(--accent);
  text-transform: uppercase;
}

.clock {
  font-size: clamp(4rem, 22vw, 18rem);
  font-weight: 800;
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  text-shadow: 0 0 40px var(--clock-glow);
}

.blinds {
  display: flex;
  align-items: baseline;
  gap: 0.6em;
  font-size: clamp(1.2rem, 5vw, 3.2rem);
}
.blinds-label { font-size: 0.4em; color: var(--muted); text-transform: uppercase; letter-spacing: 0.2em; }
.blinds-value { font-weight: 700; }

.ante {
  font-size: clamp(0.9rem, 3vw, 1.6rem);
  color: var(--muted);
  letter-spacing: 0.08em;
}

.nextup {
  display: flex;
  gap: 0.6em;
  align-items: baseline;
  font-size: clamp(0.85rem, 2.6vw, 1.4rem);
  color: var(--muted);
}
.nextup-label { text-transform: uppercase; letter-spacing: 0.2em; font-size: 0.8em; }
.nextup-value { color: var(--fg); font-weight: 600; }

.info-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5vw;
  width: min(240px, 90vw);
  margin-top: 1vh;
}
.info-cell {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 1.4vh 1vw;
  display: flex;
  flex-direction: column;
  gap: 0.3em;
}
.info-num { font-size: clamp(1.1rem, 3.4vw, 2.2rem); font-weight: 700; font-variant-numeric: tabular-nums; }
.info-cap { font-size: clamp(0.6rem, 1.6vw, 0.85rem); color: var(--muted); text-transform: uppercase; letter-spacing: 0.15em; }

/* Site (frontpage) logo beneath the info panel. */
.site-brand { margin-top: 1.5vh; display: flex; justify-content: center; }
.site-brand[hidden] { display: none; }
.site-brand-logo { max-height: 9vh; max-width: 42vw; object-fit: contain; opacity: 0.9; }
body.viewer.is-break .site-brand { display: none; }

.viewer-controls {
  position: absolute;
  bottom: 2vh;
  left: 2vw;
  display: flex;
  gap: 0.5rem;
}
.corner-btn {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--fg);
  border-radius: 999px;
  padding: 0.5em 1em;
  font-size: 0.85rem;
  cursor: pointer;
}
.corner-btn:hover { border-color: var(--accent); }
.corner-btn.on { border-color: var(--accent); color: var(--accent); }

/* ----- Scoreboard (right rail) ----- */
.scoreboard {
  width: clamp(220px, 22vw, 340px);
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 1.2vh;
  padding: 2.4vh 1.2vw;
  overflow: hidden;
}
.sb-head { display: flex; align-items: center; justify-content: space-between; }
.sb-title {
  font-size: clamp(0.85rem, 1.5vw, 1.15rem);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--muted);
}
.sb-count {
  background: var(--bg-solid);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 0.1em 0.65em;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.sb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  overflow-y: auto;
  flex: 1;
}
.sb-empty { color: var(--muted); font-size: 0.9rem; padding: 0.6em 0.2em; }
.sb-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55em 0.7em;
  background: var(--bg-solid);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
}
.sb-rank { width: 1.6em; text-align: right; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.sb-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-chips { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.sb-row.me { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.sb-row.pending .sb-chips { color: var(--muted); font-weight: 600; }
.sb-update { align-self: stretch; }

/* ----- Modal (after-round chip entry) ----- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5vh 5vw;
}
.modal-overlay[hidden] { display: none; }
.modal { width: min(420px, 100%); }
.modal-actions { display: flex; gap: 0.6rem; justify-content: flex-end; }

.admin-link {
  position: absolute;
  bottom: 2vh;
  right: 2vw;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
}
.admin-link:hover { color: var(--accent); }

/* Break + final-seconds states */
body.viewer.is-break .phase { color: var(--break); }
body.viewer.is-break .clock { text-shadow: 0 0 40px var(--break); }
body.viewer.final-seconds .clock { color: var(--danger); animation: pulse 1s infinite; }

/* ----- Break layout: countdown on top, scoreboard below ----- */
body.viewer.is-break { flex-direction: column; overflow-y: auto; }
body.viewer.is-break .stage { min-height: auto; }
body.viewer.is-break .blinds,
body.viewer.is-break .nextup,
body.viewer.is-break .info-panel { display: none; }
body.viewer.is-break .scoreboard {
  align-self: center;
  width: min(900px, 94vw);
  max-height: 48vh;
  margin-bottom: 3vh;
  border-left: none;
  border-top: 1px solid var(--panel-border);
  border-radius: 16px;
}
/* Final minutes of the break: scoreboard out, "return to your tables" in. */
body.viewer.break-ending .scoreboard { display: none; }
.return-msg {
  display: none;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 32vh;
  padding: 4vh 6vw 6vh;
  font-size: clamp(1.6rem, 6vw, 4.5rem);
  font-weight: 800;
  letter-spacing: 0.03em;
  color: var(--break);
}
body.viewer.break-ending .return-msg { display: flex; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* Screen flash on level transition */
body.flash-level { animation: flashbg 1.2s ease-out; }
@keyframes flashbg {
  0% { background-color: var(--accent); }
  100% { background-color: transparent; }
}

/* =========================  ADMIN  ====================================== */

body.admin { background: var(--bg-solid); min-height: 100vh; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card { width: min(380px, 100%); text-align: center; display: flex; flex-direction: column; gap: 0.9rem; }

.admin-layout {
  max-width: 1340px;
  margin: 0 auto;
  padding: 1.2rem;
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 340px;
  gap: 1.2rem;
  align-items: start;
}
.admin-main { display: flex; flex-direction: column; gap: 1.2rem; min-width: 0; }
.admin-side { display: flex; flex-direction: column; gap: 1.2rem; position: sticky; top: 1.2rem; }
.admin-menu { display: flex; flex-direction: column; gap: 0.6rem; position: sticky; top: 1.2rem; }
.admin-menu .menu-title { margin: 0 0 0.1rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.15em; color: var(--muted); }
.admin-menu .btn { width: 100%; text-align: center; }
.admin-header { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; }

/* ----- Host player overview ----- */
.admin-players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; max-height: 70vh; overflow-y: auto; }
.ap-empty { color: var(--muted); font-size: 0.9rem; }
.ap-row { display: grid; grid-template-columns: minmax(0, 1fr) 6em auto auto; align-items: center; gap: 0.4rem; }
.ap-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 0.9rem; }
.ap-chips { width: 100%; text-align: right; color: var(--fg); }

@media (max-width: 1040px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-menu, .admin-side { position: static; }
  .admin-menu { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .admin-menu .menu-title { width: 100%; }
  .admin-menu .btn { width: auto; }
}
.admin-header h1 { margin: 0; font-size: 1.4rem; }
.header-actions { display: flex; gap: 0.5rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 1.2rem;
}
.card h2 { margin: 0 0 0.9rem; font-size: 1.05rem; }

.muted { color: var(--muted); font-size: 0.85rem; }
.error { color: var(--danger); font-size: 0.9rem; }

/* Buttons */
.btn {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 0.6em 1em;
  font-size: 0.95rem;
  cursor: pointer;
  transition: filter 0.15s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 700; }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-small { padding: 0.3em 0.6em; font-size: 0.85rem; }

input, select {
  background: var(--bg-solid);
  color: var(--fg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.5em 0.7em;
  font-size: 0.95rem;
  font-family: inherit;
}
input[type="checkbox"] { width: auto; }

/* Live preview block */
.preview { text-align: center; margin-bottom: 1rem; }
.pv-phase { color: var(--accent); letter-spacing: 0.2em; font-weight: 700; }
.pv-clock { font-size: clamp(3rem, 14vw, 6rem); font-weight: 800; font-variant-numeric: tabular-nums; }
.pv-blinds { font-size: 1.3rem; }
.pv-status { color: var(--muted); margin-top: 0.3rem; }
.pv-status.running { color: var(--accent); }

.controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; }

.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.8rem; align-items: end; }
.grid-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.grid-form label input, .grid-form label select { color: var(--fg); }
.grid-form .check { flex-direction: row; align-items: center; gap: 0.5rem; }

/* Structure editor */
.structure-bar { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.structure-bar select { flex: 1; min-width: 160px; }

.levels-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.levels-table th, .levels-table td { padding: 0.35rem 0.4rem; text-align: center; }
.levels-table th { color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--panel-border); }
.levels-table input[type="number"] { width: 5.5em; text-align: center; }
.levels-table tr.break-row { background: color-mix(in srgb, var(--break) 14%, transparent); }
.levels-table .pos { color: var(--muted); }

.structure-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.9rem; align-items: center; }
.structure-actions input { flex: 1; min-width: 150px; }

.logo-actions { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.9rem; }
.logo-preview-wrap { margin-top: 0.8rem; }
.logo-preview { max-height: 80px; max-width: 240px; object-fit: contain; background: #fff2; border-radius: 8px; padding: 4px; }

/* =========================  HOME / JOIN / SHARE  ======================== */

body.centered {
  background: var(--bg-solid);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
}

/* Home: centered content column with a Features grid below the forms. */
body.home {
  background: var(--bg-solid);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.6rem;
  padding: 1.2rem;
}
.features-section { width: min(1100px, 100%); }
.features-heading {
  text-align: center;
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--muted);
}
.feature-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.8rem;
}
.feature-item {
  padding: 0.9em 0.9em;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
}
.feature-item h3 { margin: 0 0 0.3rem; font-size: 0.9rem; font-weight: 700; line-height: 1.3; }
.feature-item p { margin: 0; font-size: 0.78rem; color: var(--muted); line-height: 1.45; }

@media (max-width: 1000px) { .feature-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px)  { .feature-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px)  { .feature-grid { grid-template-columns: 1fr; } }

.home-wrap {
  width: min(480px, 100%);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.home-title { text-align: center; margin: 0.4rem 0 0.2rem; font-size: 1.6rem; }

.card.narrow { width: min(480px, 100%); }
.center-text { text-align: center; }
.small { font-size: 0.78rem; }

.stack-form { display: flex; flex-direction: column; gap: 0.7rem; }
.stack-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.stack-form input { color: var(--fg); }

.inline-form { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: end; margin-top: 1rem; }
.inline-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); flex: 1; min-width: 180px; }
.inline-form input { color: var(--fg); }

.share-row { margin-bottom: 0.9rem; }
.share-row > label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.3rem; }
.copy-line { display: flex; gap: 0.5rem; }
.copy-line input { flex: 1; color: var(--fg); font-family: ui-monospace, monospace; font-size: 0.85rem; }

.setup-steps { margin: 0.5rem 0 1rem; padding-left: 1.2rem; line-height: 1.6; }
.setup-steps li { margin-bottom: 0.3rem; }

.site-admin-link {
  position: fixed;
  top: 0.8rem;
  right: 1rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 0.35em 0.9em;
  background: var(--panel);
}
.site-admin-link:hover { color: var(--accent); border-color: var(--accent); }

.site-logo { max-height: 96px; max-width: 80%; object-fit: contain; }
.home-logo { display: block; margin: 0 auto 0.6rem; max-height: clamp(140px, 32vw, 260px); max-width: 100%; }
.home-tagline { text-align: center; color: var(--muted); margin: -0.4rem 0 0.4rem; }

.game-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.game-actions { display: flex; gap: 0.5rem; }

.code-badge {
  display: inline-block;
  font-family: ui-monospace, monospace;
  font-size: 1.4rem;
  letter-spacing: 0.2em;
  font-weight: 700;
  color: var(--accent);
  background: var(--bg-solid);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 0.4rem 0.9rem;
}

@media (max-width: 820px) {
  body.viewer { flex-direction: column; overflow: auto; height: auto; min-height: 100vh; }
  .scoreboard {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--panel-border);
    max-height: 45vh;
  }
}

@media (max-width: 520px) {
  .controls { grid-template-columns: repeat(2, 1fr); }
}
