:root {
  --bg: #1a3d28;
  --accent: #e8c84a;
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.55);
  --divider: rgba(255, 255, 255, 0.18);
  --panel-border: rgba(255, 255, 255, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
}

body.modal-open { overflow: hidden; }

/* ---- App shell: full viewport, 16:9 optimized ---- */
.app {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

/* ---- Top bar ---- */
.top-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 16vh;
  min-height: 32px;
  max-height: 80px;
  padding: 0 20px;
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.event-title {
  color: var(--accent);
  font-size: clamp(36px, 6vh, 60px);
  font-weight: bold;
  letter-spacing: 0.06em;
}

/* ---- 3-column main layout (fills remaining height) ---- */
.main-layout {
  display: grid;
  grid-template-columns: minmax(0, 22fr) minmax(0, 56fr) minmax(0, 22fr);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ---- Left: Prize Pool ---- */
.prize-panel {
  padding: 2.5vh 2vw 2vh;
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-heading {
  color: var(--accent);
  font-size: clamp(18px, 2.8vh, 32px);
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 1.5vh;
}

.prize-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.8vh;
  margin-bottom: 2vh;
}

.prize-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.place {
  color: var(--muted);
  font-size: clamp(22px, 3.8vh, 46px);
  font-weight: bold;
  letter-spacing: 0.04em;
  min-width: 3ch;
}

.prize-val {
  color: var(--text);
  font-size: clamp(22px, 3.8vh, 46px);
  font-weight: 400;
  text-align: right;
}

/* ---- Center: Timer ---- */
.timer-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  padding: 1.2vh 3vw 1.2vh;
  overflow: hidden;
  min-width: 0;
}

.level-kicker {
  color: var(--accent);
  font-size: clamp(26px, 4.8vh, 60px);
  font-weight: bold;
  margin-bottom: 0.5vh;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

/* Timer: sized to use ~25-27% of 94vh main area */
.time {
  font-size: clamp(84px, 26vh, 240px);
  font-weight: 900;
  line-height: 1;
  color: var(--text);
  letter-spacing: 0.04em;
  margin-bottom: 0.5vh;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.time.is-warning {
  color: #ff8f8f;
}

.time.is-critical {
  color: #ff5d5d;
  animation: timer-blink 1s steps(1, end) infinite;
}

@keyframes timer-blink {
  0%, 49.999% {
    opacity: 1;
  }
  50%, 100% {
    opacity: 0;
  }
}

.info-divider {
  width: 100%;
  height: 1px;
  background: var(--divider);
  margin: 0.45vh 0;
  flex-shrink: 0;
}

.time-progress {
  width: 100%;
  height: 8px;
  margin: 0.45vh 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
  flex-shrink: 0;
}

.time-progress-bar {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.12s linear;
}

.time-progress-bar.is-warning {
  background: linear-gradient(90deg, #ff7878, #ff9b9b);
}

.info-section {
  width: 100%;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.info-label {
  color: var(--accent);
  font-size: clamp(24px, 3.5vh, 44px);
  font-weight: bold;
  margin-bottom: 0.35vh;
}

.info-val {
  font-size: clamp(48px, 9vh, 110px);
  font-weight: bold;
  text-align: center;
  line-height: 1.05;
}

/* ---- Timer controls (center panel bottom) ---- */
.timer-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 2.5vw;
  margin-top: 0;
  padding-top: 0.8vh;
  flex-shrink: 0;
}

.ctrl-btn {
  width: clamp(36px, 5.5vh, 54px);
  height: clamp(36px, 5.5vh, 54px);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: clamp(18px, 2.9vh, 30px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
  line-height: 1;
}

.ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.45);
}

.ctrl-btn:disabled {
  opacity: 0.28;
  cursor: not-allowed;
}

.ctrl-btn-play {
  width: clamp(58px, 8.2vh, 82px);
  height: clamp(58px, 8.2vh, 82px);
  font-size: clamp(24px, 3.6vh, 38px);
  background: var(--bg);
  border-color: var(--accent);
  color: #ffffff;
}

.ctrl-btn-play:hover {
  background: var(--bg);
  border-color: var(--accent);
  filter: brightness(1.12);
}

/* ---- Right: Stats ---- */
.stats-panel {
  padding: 2.5vh 2vw 2vh;
  border-left: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 3vh;
  overflow: hidden;
}

.stat-label {
  color: var(--accent);
  font-size: clamp(18px, 2.8vh, 32px);
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.4vh;
}

.stat-val {
  font-size: clamp(34px, 7.2vh, 92px);
  font-weight: bold;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

/* ---- Corner: Settings only ---- */
.corner-controls {
  position: fixed;
  bottom: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 100;
}

.corner-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.corner-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 6px;
  border: none;
  background: #4a8fc4;
  color: #ffffff;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
  transition: opacity 0.15s;
  user-select: none;
  line-height: 1;
}

.corner-btn:hover { opacity: 1; }
.corner-btn-player { background: #2ea44f; }
.corner-btn-elim { background: #c93a3a; }
.corner-btn-settings { font-size: 17px; }

/* ---- Settings Overlay ---- */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  padding: 28px 18px;
  display: grid;
  place-items: center;
  background: rgba(2, 10, 6, 0.75);
  backdrop-filter: blur(8px);
}

.settings-overlay[hidden] { display: none; }

.settings-dialog {
  width: min(920px, 100%);
  max-height: calc(100vh - 56px);
  overflow: auto;
  border-radius: 22px;
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--bg);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.55);
  color: var(--text);
}

.settings-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 12px;
}

.settings-topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-topbar h1 {
  margin: 0;
  font-size: 22px;
  color: var(--accent);
}

.settings-panel { display: grid; gap: 18px; }

.settings-card {
  padding: 18px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.settings-card h2 {
  margin: 0 0 14px;
  font-size: 15px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.settings-list { display: grid; gap: 10px; }

.prize-editor-list {
  display: grid;
  gap: 8px;
}

.prize-editor-row {
  display: grid;
  grid-template-columns: minmax(90px, 120px) minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.prize-editor-place,
.prize-editor-value {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-size: 15px;
}

.prize-editor-place:focus,
.prize-editor-value:focus {
  outline: none;
  border-color: rgba(232, 200, 74, 0.5);
  box-shadow: 0 0 0 3px rgba(232, 200, 74, 0.1);
}

.prize-remove-btn {
  white-space: nowrap;
}

.settings-row,
.settings-volume {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.settings-row span,
.settings-volume span {
  color: var(--text);
  font-size: 15px;
}

.settings-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.settings-number-row input[type="number"],
.settings-text-row input[type="text"] {
  width: 320px;
  max-width: 55%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-size: 15px;
}

.settings-number-row input[type="number"]:focus,
.settings-text-row input[type="text"]:focus {
  outline: none;
  border-color: rgba(232, 200, 74, 0.5);
  box-shadow: 0 0 0 3px rgba(232, 200, 74, 0.1);
}

.settings-volume input[type="range"] {
  width: min(200px, 50vw);
  cursor: pointer;
}

.levels-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.levels-head h2 { margin-bottom: 0; }

.levels-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.levels-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.level-edit {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.level-edit input {
  width: 100%;
  min-width: 0;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 14px;
}

.level-edit input::placeholder { color: rgba(255, 255, 255, 0.35); }

.level-edit input:focus {
  outline: none;
  border-color: rgba(232, 200, 74, 0.4);
  box-shadow: 0 0 0 3px rgba(232, 200, 74, 0.1);
}

.level-actions-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.levels-list {
  display: grid;
  gap: 8px;
  max-height: 460px;
  overflow: auto;
  padding-right: 4px;
}

.level-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.level-row.is-break {
  border-color: rgba(232, 200, 74, 0.25);
  background: rgba(232, 200, 74, 0.04);
}

.level-row-info strong {
  display: block;
  margin-bottom: 2px;
  font-size: 14px;
  color: var(--accent);
}

.level-row-info span,
.level-row .meta { color: var(--muted); font-size: 13px; }

.level-row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Buttons */
.btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  color: var(--text);
  font: inherit;
  user-select: none;
  border-radius: 999px;
  padding: 7px 13px;
  background: rgba(255, 255, 255, 0.07);
  font-size: 13px;
  transition: background 0.15s;
}

.btn:hover { background: rgba(255, 255, 255, 0.12); }

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(232, 200, 74, 0.3);
}

.btn-primary {
  background: var(--accent);
  color: #1a2a10;
  border-color: transparent;
  font-weight: bold;
}

.btn-primary:hover { background: #f0d460; }
.btn-secondary { border-color: rgba(255, 255, 255, 0.12); }

.file-input {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.07);
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: background 0.15s;
}

.file-input:hover { background: rgba(255, 255, 255, 0.12); }

.file-input input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.template-select {
  min-width: 170px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.template-select:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(232, 200, 74, 0.3);
}

.template-select option {
  color: var(--text);
  background: var(--bg);
}

.app.flash { outline: 3px solid rgba(232, 200, 74, 0.3); }

/* ---- Responsive: non-16:9 screens ---- */
@media (max-width: 800px) {
  .top-bar {
    height: 12vh;
    max-height: 64px;
    padding: 0 12px;
  }

  .event-title {
    width: 100%;
    font-size: clamp(24px, 8vw, 34px);
    line-height: 1.1;
    letter-spacing: 0.03em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .main-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    align-content: start;
    overflow-y: auto;
  }

  .prize-panel {
    display: none;
  }

  .timer-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
    gap: 0.6vh 3vw;
    padding: 1vh 4vw 0.8vh;
  }

  .timer-panel > .level-kicker,
  .timer-panel > .time,
  .timer-panel > .time-progress,
  .timer-panel > .info-section-blinds,
  .timer-panel > .timer-controls {
    grid-column: 1 / -1;
  }

  .timer-panel > .level-kicker,
  .timer-panel > .time {
    text-align: center;
  }

  .timer-panel > .info-divider {
    display: none;
  }

  .timer-panel > .info-section-ante {
    grid-column: 1;
  }

  .timer-panel > .info-section-next {
    grid-column: 2;
  }

  .timer-panel .info-section {
    min-height: 0;
  }

  .timer-panel .info-section-ante,
  .timer-panel .info-section-next {
    justify-content: flex-start;
  }

  .timer-panel .info-section-ante .info-label,
  .timer-panel .info-section-next .info-label {
    font-size: clamp(14px, 3.3vw, 18px);
    margin-bottom: 0.25vh;
  }

  .timer-panel .info-section-ante .info-val,
  .timer-panel .info-section-next .info-val {
    font-size: clamp(24px, 6.2vw, 34px);
    line-height: 1.05;
  }

  .timer-controls {
    padding-top: 0.25vh;
    gap: 4vw;
  }

  .ctrl-btn {
    width: clamp(34px, 9.5vw, 44px);
    height: clamp(34px, 9.5vw, 44px);
    font-size: clamp(16px, 4.3vw, 22px);
  }

  .ctrl-btn-play {
    width: clamp(52px, 12.8vw, 64px);
    height: clamp(52px, 12.8vw, 64px);
    font-size: clamp(22px, 5.1vw, 28px);
  }

  .stats-panel {
    border-left: none;
    border-top: 1px solid var(--panel-border);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px 14px;
    padding: 8px 12px 10px;
  }

  .stat-group {
    min-width: 0;
    flex: 1 1 44%;
  }

  .stat-label {
    font-size: clamp(13px, 3.7vw, 17px);
    margin-bottom: 0.15vh;
    letter-spacing: 0.08em;
  }

  .stat-val {
    font-size: clamp(24px, 9.2vw, 42px);
    line-height: 1.02;
  }

  .time { font-size: clamp(50px, 16vw, 96px); }
  .level-edit { grid-template-columns: repeat(3, 1fr); }
  .settings-overlay { padding: 0; }
  .settings-dialog {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    padding: 16px;
  }
}
