:root {
  --bg: #0e0f12;
  --surface: #1a1c21;
  --surface-2: #24272e;
  --border: #33363e;
  --text: #f2f3f5;
  --muted: #9aa0ab;
  --accent: #e5484d;
  --accent-text: #fff;
  --round: #3dd68c;
  --rest: #4ea8ff;
  --getready: #f5c84c;
  --warn: #ff8b3d;
  --danger: #ff6369;
  --radius: 14px;
  --tap: 60px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

main {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
}

h2 { font-size: 1.15rem; margin: 28px 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
h3 { font-size: 1rem; margin: 24px 0 10px; color: var(--muted); }
.view > h2:first-child, .view > .msg:first-child + h2 { margin-top: 4px; }

/* ---------- banner ---------- */
.banner {
  background: #4a2a00;
  color: #ffd9a8;
  border-bottom: 1px solid #7a4a10;
  padding: 12px 16px;
  font-size: .95rem;
}
.banner p { margin: 0; }
.banner p + p { margin-top: 6px; }

/* ---------- buttons ---------- */
.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-danger { background: transparent; color: var(--danger); border-color: #5a2a2c; }
.btn-block { width: 100%; margin-top: 12px; }
.btn-huge { min-height: 84px; font-size: 1.5rem; }

/* ---------- timer ---------- */
.view[data-view="timer"] { text-align: center; padding-top: 8px; }

.phase {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
body[data-phase="round"] .phase { color: var(--round); }
body[data-phase="rest"] .phase { color: var(--rest); }
body[data-phase="getready"] .phase { color: var(--getready); }

.clock {
  font-size: clamp(5.5rem, 30vw, 11rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  margin: 8px 0 4px;
}
.clock.warn { color: var(--warn); }

.round-info, .source-info { color: var(--muted); font-size: .95rem; }

.combo {
  margin: 28px 0 20px;
  min-height: 150px;
  padding: 18px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.combo-numbers {
  font-size: clamp(3rem, 16vw, 5.5rem);
  font-weight: 800;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.combo-names { color: var(--muted); font-size: 1.15rem; margin-top: 6px; }

/* Drill buttons take the combo box's place before and after a session. */
.drill-chips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 20px 0 12px;
}
.chip {
  min-height: 56px;
  padding: 4px 10px;
  font-size: 1rem;
  line-height: 1.2;
}
.chip[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
body[data-phase="idle"] .combo,
body[data-phase="done"] .combo { display: none; }
body:not([data-phase="idle"]):not([data-phase="done"]) .drill-chips { display: none; }

/* Like a phone timer: Reset small on the left, the main play/pause button on the right. */
.controls {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 12px;
  margin-top: 20px;
}
.btn-icon { display: flex; align-items: center; justify-content: center; gap: 10px; }
.btn-icon .icon { width: 30px; height: 30px; fill: currentColor; flex: none; }
#btn-reset { font-size: 1.15rem; }
#btn-reset .icon { width: 24px; height: 24px; }

/* ---------- forms ---------- */
.field { display: block; margin: 14px 0; }
.field > span, .field-label { display: flex; justify-content: space-between; color: var(--muted); margin-bottom: 6px; font-size: .95rem; }
.field-label { margin-top: 16px; }

select, input[type="text"] {
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input[type="range"] { width: 100%; height: 44px; accent-color: var(--accent); }
input[type="range"]:disabled { opacity: .35; }

.row { display: flex; gap: 10px; margin: 10px 0; }
.row > * { flex: 1; }
.row > input { flex: 2; }

/* ---------- settings: grouped list rows ---------- */
.settings .group-title {
  margin: 22px 4px 8px;
  font-size: .85rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
}
.settings .group-title:first-of-type { margin-top: 4px; }

.group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.row-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 6px 14px;
  background: none;
  border: 0;
  color: var(--text);
  font: inherit;
  text-align: left;
}
.row-item + .row-item { border-top: 1px solid var(--border); }
.row-item.col { flex-direction: column; align-items: stretch; gap: 0; padding-top: 10px; }
.row-head { display: flex; justify-content: space-between; align-items: center; }
.row-head output { color: var(--muted); font-variant-numeric: tabular-nums; }
.row-label { display: flex; flex-direction: column; }
.row-label small { color: var(--muted); font-size: .8rem; }
.row-action { justify-content: center; color: var(--accent); font-weight: 600; cursor: pointer; }
.row-action:active { background: var(--surface-2); }

.row-select {
  width: auto;
  max-width: 58%;
  min-height: 40px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--surface-2);
  text-overflow: ellipsis;
}

/* Compact −/value/+ */
.stepper { display: flex; align-items: center; gap: 4px; flex: none; }
.step {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
.step:active { background: var(--border); }
.stepper-value { min-width: 3.4em; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

/* On/off switch built from a checkbox */
.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 50px;
  height: 30px;
  margin: 0;
  border-radius: 15px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #c9ccd3;
  transition: transform .15s;
}
.switch:checked { background: var(--accent); border-color: var(--accent); }
.switch:checked::after { transform: translateX(20px); background: #fff; }
.switch:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* Compact two-option control */
.seg { display: inline-flex; flex: none; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 7px;
  color: var(--muted);
  font-weight: 600;
  font-size: .95rem;
  cursor: pointer;
}
.seg input:checked + span { background: var(--bg); color: var(--text); box-shadow: 0 0 0 1px var(--border); }
.seg input:focus-visible + span { outline: 2px solid var(--text); }

.msg { min-height: 1.4em; color: var(--muted); margin: 6px 0; }
.msg.error { color: var(--danger); }

/* ---------- combo builder ---------- */
.builder-display {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 2rem;
  font-weight: 800;
}
.builder-display.empty { color: var(--muted); font-size: 1rem; font-weight: 400; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
.key { min-height: 76px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px; }
.key-num { font-size: 1.8rem; line-height: 1; }
.key-name { font-size: .8rem; font-weight: 400; color: var(--muted); margin-top: 4px; }

.combo-list { list-style: none; padding: 0; margin: 0; }
.combo-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 4px 4px 4px 14px;
  border-bottom: 1px solid var(--border);
}
.combo-list .c-num { font-weight: 700; font-size: 1.2rem; min-width: 5.5em; }
.combo-list .c-names { flex: 1; color: var(--muted); font-size: .9rem; }
.combo-list .remove { min-height: 48px; width: 48px; padding: 0; color: var(--danger); }
.combo-list .empty { color: var(--muted); border: 0; padding-left: 0; }

/* ---------- tabs ---------- */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  min-height: 68px;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--text); box-shadow: inset 0 3px 0 var(--accent); }
