:root {
  --felt: #07140f;
  --felt-2: #0c1f18;
  --rail: #12261e;
  --gold: #d4af37;
  --gold-2: #f0d78c;
  --cream: #f4ead0;
  --red: #c0392b;
  --green: #2ecc71;
  --muted: #8aa396;
  --card: #10261d;
  --line: rgba(212, 175, 55, 0.18);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --tab-h: calc(72px + var(--safe-bot));
  --top-h: calc(72px + var(--safe-top));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; min-height: 100%; background: var(--felt); color: var(--cream); font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif; }
body { overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

#app { min-height: 100dvh; background:
  radial-gradient(1200px 500px at 50% -80px, rgba(46, 120, 82, 0.28), transparent 60%),
  linear-gradient(180deg, #08150f 0%, #07140f 40%, #05110c 100%); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(10px + var(--safe-top)) 16px 12px;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(180deg, rgba(7,20,15,.96), rgba(7,20,15,.78));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: .4px; color: var(--gold-2); }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.chip-mark {
  width: 36px; height: 36px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f4ead0, #d4af37 45%, #8a6a16);
  box-shadow: 0 0 0 3px #10261d, 0 0 0 5px rgba(212,175,55,.5);
}

.top-actions { display: flex; align-items: center; gap: 8px; }
.sync-dot { width: 10px; height: 10px; border-radius: 50%; background: #8aa396; box-shadow: 0 0 0 3px rgba(138,163,150,.2); }
.sync-dot.online { background: #2ecc71; box-shadow: 0 0 0 3px rgba(46,204,113,.25); }
.sync-dot.offline { background: #c0392b; }
.sync-dot.local { background: #d4af37; }
.login-gate {
  position: fixed; inset: 0; z-index: 90; background: #07140f;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-gate[hidden] { display: none !important; pointer-events: none !important; }
.login-card { width: 100%; max-width: 420px; }
.login-card h2 { color: var(--gold-2); margin: 0 0 8px; }
body.role-player .admin-only, body.role-player .fab { display: none !important; }
body.role-player .tabbar { grid-template-columns: repeat(6, 1fr); }
.icon-btn, .btn {
  min-height: 44px; border: 1px solid var(--line); background: var(--card);
  color: var(--cream); border-radius: 14px; padding: 0 14px;
}
.icon-btn { width: 44px; padding: 0; display: grid; place-items: center; }
.btn { font-weight: 700; letter-spacing: .3px; }
.btn.primary { background: linear-gradient(180deg, #d4af37, #b89020); color: #1a1406; border: none; }
.btn.danger { background: #3a1614; color: #ffb4ab; border-color: rgba(192,57,43,.4); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-row.three { grid-template-columns: 1fr 1fr 1fr; }
.clock-controls-title { margin: 16px 0 8px; }
.clock-controls { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; width: 100%; }
.clock-controls .btn {
  min-height: 56px; width: 100%; font-size: 18px; font-weight: 800; letter-spacing: .8px;
  touch-action: manipulation;
}
.clock-minutes-row {
  display: grid; grid-template-columns: minmax(72px, 1fr) auto minmax(110px, 1.2fr);
  align-items: center; gap: 8px; width: 100%;
}
.clock-minutes-input {
  min-height: 56px; width: 100%; text-align: center; font-size: 22px; font-weight: 800;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 0 10px;
}
.clock-minutes-label { color: var(--muted); font-weight: 700; letter-spacing: .3px; }
.clock-minutes-row #tmApply, .clock-minutes-row #presentApply { min-height: 56px; width: 100%; }
.clock-adjust-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%;
}
.clock-adjust-grid .adj-time {
  min-height: 56px; font-size: 16px; font-weight: 800; letter-spacing: .4px;
  touch-action: manipulation;
}
.clock-status { font-size: 18px; font-weight: 800; color: var(--gold); margin-bottom: 8px; }
.clock-status.running { color: #7dffb3; }
.clock-status.paused { color: #ffcc66; }
.clock-status.finished { color: #ff6b6b; }
.clock-adjust {
  display: grid; grid-template-columns: 72px minmax(0, 1fr) 72px;
  align-items: center; gap: 8px; margin: 10px 0 8px; width: 100%;
}
.clock-adjust .adj-btn {
  width: 72px; min-width: 72px; min-height: 72px; font-size: 40px; font-weight: 800; line-height: 1;
  border-radius: 18px; padding: 0; touch-action: manipulation;
}
.clock-adjust .adj-btn:disabled { opacity: .35; }
.clock-adjust .timer { font-size: clamp(40px, 12vw, 68px); letter-spacing: 1px; min-width: 0; }
.clock-admin-entry { margin-top: 16px; }
.clock-admin-entry .btn { min-height: 56px; font-size: 16px; font-weight: 800; }

.view { padding: 14px 14px calc(var(--tab-h) + 18px); max-width: 720px; margin: 0 auto; }

.card {
  background: linear-gradient(180deg, rgba(22,48,37,.9), rgba(16,38,29,.92));
  border: 1px solid var(--line); border-radius: 18px; padding: 14px; margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 8px; font-size: 15px; color: var(--gold); }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.kpi { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi .card { margin: 0; }
.kpi .num { font-size: 26px; font-weight: 800; color: var(--gold-2); }
.kpi .lbl { font-size: 12px; color: var(--muted); }

.search {
  width: 100%; min-height: 46px; border-radius: 14px; border: 1px solid var(--line);
  background: #0b1b15; padding: 0 14px; margin-bottom: 12px;
}
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 10px; padding: 12px;
  background: rgba(8,22,17,.7); border: 1px solid var(--line); border-radius: 16px;
}
.item .meta { flex: 1; min-width: 0; }
.item .meta strong { display: block; font-size: 15px; }
.item .meta span { font-size: 12px; color: var(--muted); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: #1c3a2d; color: var(--gold-2); font-weight: 800; flex-shrink: 0;
}
.tag { font-size: 11px; padding: 4px 8px; border-radius: 999px; font-weight: 700; }
.tag.ok { background: rgba(46,204,113,.15); color: #7dffa9; }
.tag.warn { background: rgba(212,175,55,.15); color: var(--gold-2); }
.tag.bad { background: rgba(192,57,43,.18); color: #ffb4ab; }
.tag.live { background: rgba(46,204,113,.2); color: #7dffa9; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--tab-h) + 12px); z-index: 15;
  width: 58px; height: 58px; border-radius: 50%; border: none;
  background: linear-gradient(180deg, #d4af37, #b89020); color: #1a1406;
  font-size: 32px; line-height: 1; box-shadow: 0 10px 24px rgba(0,0,0,.4);
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: var(--tab-h); padding: 6px 4px var(--safe-bot);
  display: grid; grid-template-columns: repeat(8, 1fr);
  background: rgba(8, 20, 15, .96); border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.tab {
  background: none; border: none; color: var(--muted); display: flex; flex-direction: column;
  align-items: center; gap: 2px; font-size: 10px; min-height: 52px;
}
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.tab.active { color: var(--gold-2); }

.form { display: flex; flex-direction: column; gap: 10px; }
label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; min-height: 46px; border-radius: 12px; border: 1px solid var(--line);
  background: #0b1b15; padding: 0 12px; color-scheme: dark;
}
.tab span { text-align: center; line-height: 1.15; max-width: 100%; font-size: 9px; }
button, .tab { touch-action: manipulation; }
textarea { min-height: 90px; padding: 12px; resize: vertical; }

.timer-wrap { text-align: center; padding: 8px 0 4px; }
.timer {
  font-variant-numeric: tabular-nums; font-size: 64px; font-weight: 800; letter-spacing: 2px;
  color: var(--gold-2); text-shadow: 0 0 24px rgba(212,175,55,.25);
}
.timer.warn { color: #ffcc66; }
.timer.danger { color: #ff6b6b; animation: pulse 1s infinite; }
.timer.final10 { color: #ff3b3b; animation: pulse .5s infinite; font-size: 72px; }
@keyframes pulse { 50% { opacity: .55; transform: scale(1.02); } }
.round-info { font-size: 14px; color: var(--muted); margin-top: 4px; }
.blinds { font-size: 28px; font-weight: 800; color: var(--cream); margin: 6px 0 12px; }
.structure { display: flex; flex-direction: column; gap: 6px; }
.structure .lvl {
  display: grid; grid-template-columns: 48px 1fr 70px; gap: 8px; align-items: center;
  padding: 8px 10px; border-radius: 12px; background: rgba(0,0,0,.18);
}
.structure .lvl.current { outline: 1px solid var(--gold); background: rgba(212,175,55,.1); }

.modal-root {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-root[hidden] { display: none !important; pointer-events: none !important; }
.sheet {
  width: 100%; max-width: 720px; background: #0d1c16; border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0; padding: 16px 16px calc(18px + var(--safe-bot));
  max-height: 90dvh; overflow: auto;
}
.sheet h2 { margin: 0 0 12px; font-size: 18px; color: var(--gold-2); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 16px); transform: translateX(-50%);
  background: #1c3a2d; color: var(--cream); padding: 10px 16px; border-radius: 16px; z-index: 220;
  border: 1px solid var(--line); white-space: normal; max-width: 92vw; font-size: 13px; line-height: 1.35;
}
.toast.toast-error { background: #3a1515; border-color: #ff6b6b; color: #ffd6d6; }
.cloud-error {
  background: #3a1515; border: 1px solid #ff6b6b; color: #ffd6d6;
  border-radius: 12px; padding: 10px 12px; margin: 0 0 12px; font-size: 12px; line-height: 1.4;
  word-break: break-word;
}
.toast[hidden] { display: none !important; }
.alert-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(80,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  pointer-events: none; padding: 16px;
}
.alert-overlay[hidden] { display: none !important; }
.alert-box {
  pointer-events: auto; position: relative; z-index: 201;
  background: #1a0d0d; border: 2px solid #ff6b6b; border-radius: 20px; padding: 24px;
  text-align: center; width: min(420px, 100%);
}
.alert-box p { font-size: 22px; font-weight: 800; margin: 0 0 8px; }
.alert-box #alertSub { font-size: 16px; color: #ffcc66; }
.alert-box #alertBlinds { font-size: 22px; margin: 8px 0 16px; }
.alert-box button {
  min-height: 52px; width: 100%; border: none; border-radius: 14px;
  background: #d4af37; color: #1a1406; font-weight: 800;
  pointer-events: auto; touch-action: manipulation; -webkit-tap-highlight-color: rgba(212,175,55,.35);
}
.alert-box #alertClock {
  display: block; margin: 16px 0 12px; min-height: 72px; position: relative; z-index: 202;
  background: linear-gradient(180deg, #d4af37, #b89020); color: #1a1406;
  border: 3px solid #f0d78c; font-size: 22px; letter-spacing: 2px;
}
.alert-box #alertNext[hidden] { display: none !important; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.champion-banner {
  background: linear-gradient(135deg, rgba(212,175,55,.2), rgba(16,38,29,.9));
  border: 1px solid var(--gold); text-align: center; padding: 18px;
}
.champion-banner .crown { font-size: 28px; color: var(--gold); }
.check { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.check input { width: 22px; height: 22px; min-height: 22px; }
.small-actions { display: flex; gap: 6px; }
.small-actions button { min-height: 36px; padding: 0 10px; font-size: 12px; }
.year-row { display: flex; gap: 8px; margin-bottom: 12px; }
.year-row select { flex: 1; }
.bar { height: 8px; background: #0b1b15; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #d4af37, #f0d78c); }
.bar > i.out { background: linear-gradient(90deg, #c0392b, #ff8a7a); }
.kpi.three { grid-template-columns: 1fr 1fr 1fr; }
.kpi .num.pos { color: #7dffa9; }
.kpi .num.neg { color: #ffb4ab; }
.seg { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.seg button { min-height: 40px; border-radius: 12px; border: 1px solid var(--line); background: #0b1b15; }
.seg button.active { background: linear-gradient(180deg, #d4af37, #b89020); color: #1a1406; border: none; font-weight: 800; }
.amt.in { color: #7dffa9; font-weight: 800; }
.amt.out { color: #ffb4ab; font-weight: 800; }
.present-stage {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  width: 100%; height: 100%; height: 100dvh; min-height: -webkit-fill-available;
  z-index: 9999;
  background: #05110c;
  flex-direction: column; align-items: center; justify-content: center;
  padding: calc(8px + var(--safe-top)) 12px calc(12px + var(--safe-bot));
}
.present-stage.is-on,
body.clock-present #presentStage {
  display: flex !important;
}
body.clock-present { overflow: hidden; }
body.clock-present #app,
body.clock-present #toast,
body.clock-present #modalRoot,
body.clock-present #alertOverlay,
body.clock-present #loginGate {
  display: none !important;
}
.present-exit {
  position: absolute; top: calc(8px + var(--safe-top)); right: 12px;
  width: 40px; height: 40px; min-height: 40px; padding: 0;
  border: 1px solid rgba(212,175,55,.28); border-radius: 12px;
  background: rgba(16,38,29,.72); color: var(--gold-2);
  display: grid; place-items: center; z-index: 2;
}
.present-time {
  font-variant-numeric: tabular-nums; font-weight: 800; letter-spacing: 0.06em;
  color: var(--gold-2); text-shadow: 0 0 48px rgba(212,175,55,.35);
  font-size: clamp(80px, 32vmin, 42vw);
  line-height: 0.9; text-align: center;
  flex: 1; display: flex; align-items: center; justify-content: center;
  width: 100%;
}
.present-time.warn { color: #ffcc66; }
.present-time.danger { color: #fff4f0; text-shadow: 0 0 40px rgba(255,40,40,.55); }
.present-time.final10 { color: #fff4f0; }
.present-reset {
  margin-top: 0; min-height: 44px; min-width: 132px; font-size: 14px;
  opacity: .72; z-index: 2;
}
.present-controls {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px;
  width: min(96vw, 720px); z-index: 2; padding: 8px 0 4px;
}
.present-controls .btn {
  min-height: 48px; font-size: 14px; font-weight: 800; letter-spacing: .4px;
  touch-action: manipulation; margin: 0;
}
.present-controls .adj-time { min-height: 48px; }
.present-minutes-row { grid-column: 1 / -1; }
.present-audio-hint {
  position: absolute; bottom: calc(72px + var(--safe-bot));
  margin: 0; padding: 8px 14px; border-radius: 999px;
  background: rgba(16,38,29,.78); color: var(--gold-2); font-size: 13px;
  z-index: 2;
}
.present-audio-hint[hidden] { display: none !important; }
.present-stage.is-flash {
  animation: presentFlash .55s ease-in-out infinite;
}
.present-stage.is-done {
  background: #140808;
  animation: none;
}
@keyframes presentFlash {
  0%, 100% { background: #05110c; }
  50% { background: #9a1212; }
}
@media (orientation: landscape) {
  .present-time { font-size: clamp(96px, 42vmin, 52vw); letter-spacing: 0.08em; }
  .present-reset { min-height: 40px; }
  .present-controls { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .present-controls .btn { min-height: 44px; font-size: 13px; }
}
@media (min-width: 720px) {
  .tabbar { left: 50%; transform: translateX(-50%); width: 720px; border-radius: 18px 18px 0 0; }
  .view { padding-top: 18px; }
  .timer { font-size: 84px; }
  .clock-adjust .timer { font-size: 68px; }
}
