:root {
  --bg: #000000;
  --panel: #0a0a0a;
  --accent: #e8352a;
  --accent-dim: #6b1815;
  --text: #f5f5f5;
  --text-dim: #9a9a9a;
  --border: #2a2a2a;
  --input-bg: #050505;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
}

/* ===================== SETUP SCREEN ===================== */

#setup-screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 28px clamp(16px, 4vw, 64px);
}

.setup-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.header-icon {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-icon img {
  width: 100%;
  height: 100%;
  display: block;
}

.header-text h1 {
  margin: 0 0 4px 0;
  font-size: 1.7rem;
  font-weight: 800;
}

#timer-summary {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.95rem;
}

.validation-error {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
  margin: 0 0 14px;
}

input.cell-input.input-error {
  border-color: var(--accent);
  background: rgba(232, 53, 42, 0.1);
}

.table-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
}

.table-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--panel);
  text-align: left;
  font-weight: 600;
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  z-index: 1;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  margin-left: 4px;
  padding: 2px;
  vertical-align: middle;
  border-radius: 4px;
}

.link-btn:hover { color: var(--text); }

.link-btn.active {
  color: var(--accent);
}

tbody tr {
  border-bottom: 1px solid var(--border);
}

tbody tr:last-child { border-bottom: none; }

tbody td {
  padding: 12px 14px;
  vertical-align: middle;
}

th.col-gear,
td.gear-cell {
  padding-left: 8px;
  padding-right: 8px;
  text-align: center;
}

.level-num {
  color: var(--text-dim);
  font-weight: 700;
  font-size: 1.05rem;
}

input.cell-input {
  width: 100px;
  background: var(--input-bg);
  border: 1.5px solid rgba(245, 245, 245, 0.45);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 0.95rem;
  text-align: center;
  outline: none;
  transition: border-color 0.15s;
}

input.cell-input:focus {
  border-color: var(--accent);
}

input.cell-input::placeholder {
  color: var(--text-dim);
}

input[type="number"].cell-input::-webkit-outer-spin-button,
input[type="number"].cell-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"].cell-input { -moz-appearance: textfield; }

.duration-input { width: 84px; }

tr.break-row {
  background: rgba(232, 53, 42, 0.04);
}

.break-label-cell {
  color: var(--text-dim);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 8px;
}

.break-label-cell svg {
  color: var(--accent);
  flex-shrink: 0;
}

.gear-btn {
  background: none;
  border: none;
  color: var(--accent);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
}

.gear-btn:hover {
  background: rgba(232, 53, 42, 0.12);
}

.setup-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 22px;
  gap: 12px;
  flex-wrap: wrap;
}

.text-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 6px;
  border-radius: 8px;
}

.text-btn:hover {
  background: rgba(232, 53, 42, 0.1);
}

.text-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Row options popover */
.row-menu {
  position: fixed;
  background: #111;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  min-width: 190px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.6);
  z-index: 50;
}

.row-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 0.92rem;
}

.row-menu button:hover {
  background: rgba(232, 53, 42, 0.14);
}

.row-menu button.danger { color: var(--accent); }
.row-menu hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 6px 2px;
}

/* ===================== TIMER SCREEN ===================== */

#timer-screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 20px clamp(16px, 4vw, 48px) 32px;
}

.timer-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.icon-btn {
  background: none;
  border: 1.5px solid var(--border);
  color: var(--text-dim);
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { color: var(--text); border-color: var(--text-dim); }

.timer-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
}

.timer-level-label {
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: clamp(1rem, 2.4vw, 1.4rem);
}

.timer-clock {
  display: inline-flex;
  font-size: clamp(4.5rem, 16vw, 11rem);
  font-weight: 800;
  line-height: 1;
  margin: 4px 0 12px;
  transition: color 0.2s;
}

.clock-digit,
.clock-colon {
  display: inline-block;
  text-align: center;
}

.clock-digit {
  width: 0.62em;
}

.clock-colon {
  width: 0.32em;
}

.timer-clock.warning {
  color: var(--accent);
}

.timer-blinds {
  display: flex;
  gap: clamp(16px, 4vw, 48px);
  justify-content: center;
  flex-wrap: wrap;
}

.blind-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 90px;
}

.blind-label {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.blind-value {
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.timer-break-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-size: 1.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.timer-next {
  margin-top: 18px;
  color: var(--text-dim);
  font-size: clamp(0.95rem, 1.6vw, 1.15rem);
}

.timer-progress-wrap {
  padding: 0 4px;
  margin-bottom: 22px;
}

.timer-progress-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.timer-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s linear;
}

.timer-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 3vw, 22px);
  flex-wrap: wrap;
}

.ctrl-btn {
  background: none;
  border: 1.5px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  width: 54px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ctrl-btn:hover { border-color: var(--accent); color: var(--accent); }

.ctrl-btn.small {
  width: auto;
  height: 44px;
  border-radius: 22px;
  padding: 0 16px;
  font-weight: 700;
  font-size: 0.9rem;
}

.ctrl-btn.primary {
  width: 72px;
  height: 72px;
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
}

.ctrl-btn.primary:hover {
  color: #000;
  opacity: 0.9;
}

/* ===================== SCROLLBAR ===================== */

.table-scroll::-webkit-scrollbar { width: 10px; }
.table-scroll::-webkit-scrollbar-track { background: transparent; }
.table-scroll::-webkit-scrollbar-thumb {
  background: var(--accent-dim);
  border-radius: 999px;
}
.table-scroll::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ===================== RESPONSIVE ===================== */

@media (max-width: 640px) {
  thead th { padding: 10px 8px; font-size: 0.75rem; }
  tbody td { padding: 8px; }
  input.cell-input { width: 72px; padding: 7px 6px; font-size: 0.85rem; }
  .duration-input { width: 64px; }
  .setup-footer { justify-content: center; }
}

@media (max-width: 480px) {
  .timer-controls { gap: 8px; flex-wrap: nowrap; }

  .ctrl-btn { width: 42px; height: 42px; }
  .ctrl-btn svg { width: 16px; height: 16px; }

  .ctrl-btn.primary { width: 56px; height: 56px; }
  .ctrl-btn.primary svg { width: 22px; height: 22px; }

  .ctrl-btn.small {
    height: 38px;
    padding: 0 10px;
    font-size: 0.78rem;
  }
}
