:root {
  color-scheme: dark;
  --gold: #f0c014;
  --gold-2: #ffe56a;
  --ink: #141000;
  --text: #f4f4f4;
  --muted: #c4c4c4;
  --danger: #ff5d4e;
  --panel: #3a3a3a;
  --panel-2: #2c2c2c;
  --line: #111;
  font-size: clamp(15px, 1.15vw, 20px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(80% 55% at 50% 42%, rgba(130, 96, 12, 0.28), transparent 62%),
    #070705;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
input[type="checkbox"] { accent-color: var(--gold); width: auto; }
button, a { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { opacity: 0.38; cursor: default; }

.page {
  height: 100dvh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  position: relative;
}
.home-link {
  position: absolute;
  z-index: 3;
  top: 8px;
  left: 10px;
  color: rgba(255, 255, 255, 0.72);
  text-decoration: none;
  font-size: 0.85rem;
}
.center { min-height: 0; }
.center.setup {
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 36px 12px 12px;
}

.dialog {
  width: min(1080px, 100%);
  max-height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: linear-gradient(#545454, #3a3a3a);
  border: 1px solid #0a0a0a;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}
.dialog-title {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: linear-gradient(#3e3e3e, #2a2a2a);
  border-bottom: 1px solid #161616;
}
.dialog-title input {
  grid-column: 2;
  width: min(440px, 70vw);
  text-align: center;
  background: transparent;
  border: none;
  color: var(--gold);
  font-weight: 700;
  font-size: 1.2rem;
}
.dialog-title input:focus { outline: 1px solid var(--gold); }
.dialog .dialog-title input { width: min(440px, 70vw); }
.player-main input.pname { width: auto; }
.back-live {
  justify-self: end;
  background: transparent;
  color: var(--gold-2);
  border: 1px solid #6a5a20;
  min-height: 36px;
  padding: 4px 10px;
}
.dialog-body {
  display: grid;
  grid-template-columns: minmax(190px, 240px) minmax(0, 1fr);
  min-height: 0;
}
.clock-list, .settings, .plist, .table-scroll { min-height: 0; }
.clock-list, .settings { overflow: auto; }
.clock-list {
  background: #2a2a2a;
  border-right: 1px solid #161616;
  padding: 8px;
  display: grid;
  align-content: start;
  gap: 6px;
}
.clock-item, .text-btn, .bar button, .pbtns button, .dialog-actions button, .preset-row button {
  background: #242424;
  color: var(--text);
  border: 1px solid #0d0d0d;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.clock-item {
  text-align: left;
  padding: 8px 10px;
  min-height: 44px;
}
.clock-item.sel { background: var(--gold); color: var(--ink); font-weight: 700; }
.clock-item small { display: block; font-weight: 500; opacity: 0.75; }

.settings { padding: 12px 14px 16px; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { min-height: 40px; padding: 6px 12px; background: #2f2f2f; border: 1px solid #111; color: var(--muted); }
.tabs button.on { color: var(--gold); border-color: #8a7020; }

.money-row {
  display: grid;
  grid-template-columns: 8.2rem minmax(0, 1fr) minmax(0, 1fr) minmax(0, 0.7fr);
  gap: 8px;
  align-items: end;
  margin-bottom: 8px;
}
.field { display: grid; gap: 4px; }
.field span, .lbl { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase; }
.check {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  font-size: 1rem;
}
.dialog input:not([type="checkbox"]), .dialog select, .dialog textarea,
.players input, .players select {
  width: 100%;
  background: #222;
  border: 1px solid #0c0c0c;
  padding: 8px;
}
.dialog textarea { min-height: 72px; resize: vertical; }
.row-2 { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.row-2 > * { flex: 1; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 6px 0; }
.err { color: #ffb4ae; font-size: 0.85rem; }

.plist { display: grid; align-content: start; gap: 4px; overflow: auto; }
.player {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  padding: 2px 4px;
  background: rgba(0, 0, 0, 0.22);
}
.player-main { display: flex; align-items: center; gap: 8px; min-width: 0; }
.player-main .pname { flex: 1; min-width: 0; }
.player.sel { outline: 2px solid var(--gold); }
.player.out { opacity: 0.5; }
.player.out .pname { text-decoration: line-through; }
.mark, button.pname {
  background: transparent;
  border: none;
  color: var(--gold);
  min-width: 36px;
  min-height: 40px;
}
button.pname, .pname { font-weight: 650; text-align: left; }
.pmeta { color: var(--gold-2); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.pbtns { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.pbtns button { min-height: 36px; padding: 4px 8px; }

.preset-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.preset-row select { flex: 1; min-width: 160px; background: #222; border: 1px solid #111; padding: 8px; }
.preset-row button, .dialog-actions button, .text-btn { min-height: 40px; padding: 6px 10px; }
.table-scroll { overflow: auto; max-height: min(46dvh, 480px); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 4px; text-align: left; }
th { color: var(--muted); font-size: 0.75rem; font-weight: 600; }
td input { width: 100%; min-width: 0; background: #222; border: 1px solid #111; padding: 6px; }
.break-cell { color: #9ecbff; }
.lv-actions { white-space: nowrap; }
.lv-actions button {
  min-width: 28px;
  min-height: 32px;
  margin: 0 2px;
  padding: 0 6px;
  background: #242424;
  color: #fff;
  border: 1px solid #111;
}
tr.current-lv td { background: rgba(240, 192, 20, 0.16); }
.dialog-actions {
  display: flex;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid #222;
  background: #2f2f2f;
}

.center.live {
  display: grid;
  grid-template-columns: minmax(260px, 30vw) minmax(0, 1fr);
  padding-top: 28px;
}
.players {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  background: rgba(0, 0, 0, 0.35);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}
.players header, .add-row { padding: 8px; }
.players header { font-weight: 700; }
.add-row { display: flex; gap: 6px; }
.add-row input { flex: 1; background: #1b1b1b; border: 1px solid #333; padding: 8px; }
.add-row button, .text-btn.go {
  background: var(--gold);
  color: var(--ink);
  border: none;
  font-weight: 700;
  min-height: 44px;
  padding: 0 12px;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 0;
  padding: 8px 12px 12px;
  user-select: none;
}
.hero-title { margin: 0; color: var(--gold); font-weight: 700; }
.lvl-label { margin: 8px 0 0; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.blinds {
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 0.92;
  font-size: clamp(2.8rem, min(10vw, 16vh), 8.5rem);
}
.ante { margin: 6px 0 0; color: var(--muted); font-size: clamp(1rem, 2vw, 1.6rem); }
.ante:empty { display: none; }
.hero-time, .time-num {
  font-family: Consolas, "Courier New", monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--gold-2);
}
.hero-time {
  margin: 4px 0;
  font-size: clamp(2.6rem, min(8vw, 14vh), 7rem);
  line-height: 1;
}
.next-line { margin: 0; color: var(--muted); }
.metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 28px;
  justify-content: center;
  margin-top: 16px;
}
.metrics div { display: grid; gap: 2px; }
.metrics span { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.metrics b { font-size: clamp(1.05rem, 2vw, 1.7rem); font-variant-numeric: tabular-nums; }
.hero.warn { box-shadow: inset 0 0 80px rgba(255, 70, 50, 0.12); }
.hero.break .blinds { color: #b7d4ff; }
.hero-time.warn, .time-num.warn { color: var(--danger); }
.hero-time.warn { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) {
  .hero-time.warn { animation: none; }
}

.bar {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(#6b6b6b, #2a2a2a);
  border-top: 1px solid #9a9a9a;
  user-select: none;
}
.stat, .time-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #161616;
  border-radius: 8px;
  padding: 4px 6px 4px 10px;
}
.stat b, .time-num { font-size: 1.35rem; min-width: 1.6ch; text-align: center; }
.time-wrap { flex: 1; min-width: min(100%, 220px); }
.time-wrap input[type="range"] { flex: 1; min-width: 70px; accent-color: var(--gold); }
.bar button { min-width: 44px; min-height: 44px; padding: 0 10px; }
.blinds-mini { flex: 1; min-width: 140px; justify-content: center; }
.blinds-mini b { font-size: 1rem; min-width: 0; }
.bar-actions { display: flex; gap: 8px; margin-left: auto; }
.next {
  background: var(--gold);
  color: var(--ink);
  border: none;
  font-weight: 800;
  font-size: 1.8rem;
  min-width: 76px;
  min-height: 56px;
  border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.flash {
  position: absolute;
  left: 12px;
  bottom: calc(100% + 2px);
  margin: 0;
  color: var(--gold-2);
  font-size: 0.9rem;
  text-shadow: 0 1px 2px #000;
}

@media (max-width: 860px) {
  .dialog-body, .center.live { grid-template-columns: 1fr; }
  .clock-list { max-height: 132px; border-right: none; border-bottom: 1px solid #161616; }
  .center.live { grid-template-rows: minmax(0, 1fr) minmax(132px, 34dvh); }
  .hero { order: 1; }
  .players { order: 2; border-right: none; border-top: 1px solid rgba(255, 255, 255, 0.08); }
  .money-row { grid-template-columns: 1fr 1fr; }
  .money-row .field:first-child { grid-column: 1 / -1; }
  .bar-actions { width: 100%; }
  .bar-actions .next { flex: 1; }
}
@media (max-height: 760px) {
  .blinds { font-size: clamp(2.2rem, 12vh, 5rem); }
  .hero-time { font-size: clamp(2rem, 10vh, 4.2rem); }
  .metrics { margin-top: 8px; }
}

@media (max-width: 820px), (orientation: landscape) and (max-height: 520px) {
  .page {
    height: 100svh;
    max-height: 100svh;
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .center.live {
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 0;
    padding-top: 16px;
  }
  .hero {
    justify-content: flex-start;
    padding: 0 8px 4px;
  }
  .hero-title { font-size: 0.9rem; }
  .lvl-label { margin: 0; letter-spacing: 0.06em; font-size: 0.68rem; }
  .blinds { font-size: clamp(1.8rem, 11vw, 2.8rem); }
  .ante { margin: 0; font-size: 0.85rem; }
  .hero-time { margin: 0; font-size: clamp(1.6rem, 9vw, 2.4rem); }
  .next-line { font-size: 0.78rem; }
  .metrics {
    width: 100%;
    margin-top: 4px;
    gap: 2px 6px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  }
  .metrics span { font-size: 0.55rem; letter-spacing: 0; line-height: 1.1; }
  .metrics b { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .players { min-height: 0; }
  .players header, .add-row { padding: 4px 8px; }
  .pbtns button { min-height: 36px; padding: 2px 6px; }

  .bar {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 4px;
    max-height: 34svh;
    overflow: auto;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
  }
  .blinds-mini { display: none; }
  .stat { grid-column: span 2; min-width: 0; padding: 1px 2px 2px; gap: 1px; }
  .stat:nth-child(4), .stat:nth-child(5) { grid-column: span 3; }
  .stat {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 34px;
  }
  .stat .lbl {
    grid-column: 1 / -1;
    font-size: 0.58rem;
    letter-spacing: 0;
    line-height: 1.1;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .stat b { font-size: 1rem; min-width: 0; }
  .bar .stat button { min-width: 34px; min-height: 34px; padding: 0; }
  .time-wrap {
    grid-column: 1 / -1;
    min-width: 0;
    padding: 0 8px;
    gap: 6px;
  }
  .time-wrap .lbl, .time-wrap .time-num { display: none; }
  .time-wrap input[type="range"] { min-width: 0; height: 28px; }
  .bar-actions {
    grid-column: 1 / -1;
    width: auto;
    margin: 0;
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
  }
  .bar-actions button {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    min-height: 40px;
    padding: 0 2px;
    font-size: 0.72rem;
  }
  .bar-actions .next {
    flex: 1.3 1 0;
    grid-column: auto;
    min-width: 0;
    min-height: 40px;
    font-size: 1.25rem;
  }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions button { flex: 1 1 30%; }
  .lv-actions { white-space: normal; display: flex; flex-wrap: wrap; gap: 4px; }
  .lv-actions button { margin: 0; }
}

.felt { display: none; }

@media (min-width: 1180px) and (min-height: 640px) {
  .center.live { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .players { display: none; }
  .felt {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 0;
    padding: 6px 12px 14px;
    background: #050505;
  }
  .felt-title {
    margin: 0;
    text-align: center;
    font-weight: 800;
    font-size: clamp(1.2rem, 2vw, 1.7rem);
  }
  .oval {
    position: relative;
    width: min(92%, 760px);
    height: min(88%, 760px);
    margin: auto;
    border-radius: 50%;
    border: 2px solid rgba(201, 164, 74, 0.9);
    background: radial-gradient(ellipse at 50% 46%, #2c2c2c 0%, #141414 64%, #0a0a0a 100%);
    box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.55);
  }
  .brand, .plaque { pointer-events: none; }
  .brand {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    color: rgba(186, 154, 78, 0.32);
    font-weight: 800;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    font-size: clamp(1rem, 1.6vw, 1.6rem);
  }
  .brand.top { top: 24%; }
  .brand.bot { bottom: 20%; }
  .plaque {
    position: absolute;
    left: 50%;
    top: 48%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 1;
  }
  .brand-mark {
    margin: 0 0 12px;
    color: #c9a44a;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    font-weight: 800;
  }
  .felt-level, .felt-field { margin: 3px 0; font-size: 1.05rem; }
  .dealer {
    position: absolute;
    left: 50%;
    bottom: 7%;
    transform: translateX(-50%);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: radial-gradient(circle at 40% 35%, #ffe56a, #c9a44a 55%, #8a6a12);
    color: #1a1200;
    font-weight: 900;
    box-shadow: 0 0 0 3px #111;
    z-index: 2;
  }
  .seat {
    position: absolute;
    transform: translate(-50%, -50%);
    z-index: 2;
  }
  .seat.empty span {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #161616;
    border: 2px solid #2e2e2e;
    font-weight: 700;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.55);
  }
  .seat-card {
    display: grid;
    justify-items: center;
    width: 128px;
  }
  .avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #2a3344;
    border: 2px solid #0d0d0d;
    font-weight: 800;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.5);
  }
  .seat-meta {
    display: grid;
    justify-items: center;
    margin-top: 4px;
    padding: 2px 8px 3px;
    background: rgba(10, 10, 10, 0.92);
    border-radius: 4px;
  }
  .seat-meta b { font-size: 0.92rem; line-height: 1.15; }
  .stack { color: var(--gold); font-weight: 800; font-size: 0.88rem; }
  .stack small { color: #ddd; font-weight: 650; }
  .seat-time {
    color: #bdbdbd;
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
  }
  .seat-time.warn { color: var(--danger); }
}
