*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: #0a0a0a;
  color: #e8e8e8;
  font-family: 'Courier New', Courier, monospace;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.container {
  width: 100%;
  max-width: 480px;
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
}

/* ===== Mode toggle ===== */
.mode-toggle {
  display: flex;
  background: #111;
  border-radius: 100px;
  padding: 3px;
}

.mode-btn {
  border: none;
  background: transparent;
  color: #444;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 8px 14px;
  border-radius: 100px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.mode-btn.active {
  background: #1e1e1e;
  color: #e8e8e8;
}

.mode-btn:hover:not(.active) {
  color: #666;
}

/* ===== Timer section ===== */
#timerSection {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

/* ===== Display area ===== */
.display-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.progress-bar {
  width: 100%;
  height: 2px;
  background: #1a1a1a;
  border-radius: 1px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 100%;
  background: #6bffb8;
  border-radius: 1px;
  transition: width 0.1s linear, background 0.6s ease;
}

.progress-fill.warning { background: #ffb347; }
.progress-fill.danger  { background: #ff6b6b; }

.timer-display {
  font-size: clamp(64px, 18vw, 96px);
  font-weight: 200;
  letter-spacing: 0.04em;
  color: #ffffff;
  line-height: 1;
  user-select: none;
  transition: color 0.4s ease;
}

.timer-display.warn    { color: #ffb347; }
.timer-display.danger  { color: #ff6b6b; }

.timer-display.expired {
  color: #ff6b6b;
  animation: flash 0.6s ease-in-out infinite;
}

@keyframes flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

/* ===== Section label ===== */
.section-label {
  font-size: 10px;
  letter-spacing: 0.2em;
  color: #aaa;
  text-transform: uppercase;
  margin-bottom: 0;
}

/* ===== Countdown config ===== */
.cd-config {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.preset-btn {
  border: 1px solid #1e1e1e;
  background: transparent;
  color: #666;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.05em;
  padding: 7px 16px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.2;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.preset-btn small {
  font-size: 10px;
  color: #aaa;
  letter-spacing: 0.08em;
  transition: color 0.15s;
}

.preset-btn:hover { border-color: #333; color: #aaa; }
.preset-btn:hover small { color: #555; }

.preset-btn.selected {
  border-color: #6bffb8;
  color: #6bffb8;
  background: rgba(107, 255, 184, 0.06);
}

.preset-btn.selected small { color: #4dcc96; }

.time-builder {
  display: flex;
  gap: 8px;
  align-items: center;
}

.add-btns {
  display: flex;
  gap: 6px;
  flex: 1;
}

.add-btn {
  flex: 1;
  border: 1px solid #1e1e1e;
  background: transparent;
  color: #666;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.05em;
  padding: 7px 0;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.add-btn:hover:not(:disabled) { border-color: #6bffb8; color: #6bffb8; }
.add-btn:disabled { opacity: 0.3; cursor: default; }

.time-clear-btn {
  border: 1px solid #1e1e1e;
  background: transparent;
  color: #444;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.1em;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.time-clear-btn:hover:not(:disabled) { border-color: #ff6b6b; color: #ff6b6b; }
.time-clear-btn:disabled { opacity: 0.3; cursor: default; }

/* ===== Topic area ===== */
.topic-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.topic-select {
  width: 100%;
  background: #0a0a0a;
  border: 1px solid #1e1e1e;
  color: #666;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.05em;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s, color 0.15s;
}

.topic-select:focus { border-color: #333; color: #aaa; }
.topic-select option, .topic-select optgroup { background: #111; }

/* ===== Controls ===== */
.controls-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.controls {
  display: flex;
  gap: 20px;
  align-items: center;
}

.kbd-hints {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0;
  background: #111;
  border: 1px solid #222;
  border-radius: 10px;
  overflow: hidden;
  width: 100%;
  max-width: 340px;
}

.kbd-hint-row {
  display: contents;
}

.kbd-hint-row:not(:last-child) .kbd-combo,
.kbd-hint-row:not(:last-child) .kbd-desc {
  border-bottom: 1px solid #1c1c1c;
}

.kbd-combo {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 9px 14px;
  background: #161616;
  border-right: 1px solid #1c1c1c;
  justify-content: flex-end;
  min-width: 110px;
}

.kbd-desc {
  display: flex;
  align-items: center;
  padding: 9px 14px;
  font-size: 11px;
  color: #aaa;
  letter-spacing: 0.05em;
}

.kbd-sep {
  font-size: 10px;
  color: #444;
  margin: 0 1px;
}

kbd {
  background: #222;
  border: 1px solid #3a3a3a;
  border-bottom: 2px solid #3a3a3a;
  border-radius: 4px;
  padding: 2px 7px;
  font-family: inherit;
  font-size: 10px;
  color: #e0e0e0;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.btn {
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
  user-select: none;
}

.btn-lap, .btn-reset {
  width: 72px;
  height: 72px;
  background: #1e1e1e;
  color: #888;
}

.btn-lap:not(:disabled):hover,
.btn-reset:hover { background: #2a2a2a; color: #ccc; }

.btn-lap:disabled { opacity: 0.3; cursor: default; }

.btn-start {
  width: 88px;
  height: 88px;
  background: #1e1e1e;
  color: #e8e8e8;
  font-size: 14px;
}

.btn-start:hover:not(:disabled) { background: #2a2a2a; }
.btn-start:disabled { opacity: 0.3; cursor: default; }
.btn-start.running { color: #ff6b6b; }

/* ===== Question tracker ===== */
.q-tracker {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: #888;
}

.q-sep { color: #aaa; }
#qCount { color: #e8e8e8; }

/* ===== Lap table ===== */
.laps { width: 100%; }

.hidden { display: none; }

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

thead th {
  font-size: 11px;
  letter-spacing: 0.15em;
  color: #444;
  text-transform: uppercase;
  padding-bottom: 12px;
  border-bottom: 1px solid #1e1e1e;
  text-align: right;
}

thead th:first-child { text-align: left; }

tbody tr {
  border-bottom: 1px solid #111;
  transition: background 0.1s;
}

tbody tr:hover { background: #111; }

tbody td {
  padding: 10px 0;
  font-size: 15px;
  text-align: right;
  color: #888;
  letter-spacing: 0.05em;
}

tbody td:first-child {
  text-align: left;
  color: #444;
  font-size: 12px;
}

tbody td.lap-time { color: #e8e8e8; }
tbody tr.slowest td.lap-time { color: #ff6b6b; }
tbody tr.fastest td.lap-time { color: #6bffb8; }

/* ===== Score buttons (○/✗) ===== */
.score-cell {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  padding: 6px 0;
}

.result-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid #666;
  background: transparent;
  font-size: 12px;
  color: #ccc;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  padding: 0;
  line-height: 1;
}

.result-btn:hover { border-color: #999; color: #fff; }

.result-btn.correct.active {
  border-color: #6bffb8;
  background: rgba(107, 255, 184, 0.12);
  color: #6bffb8;
}

.result-btn.incorrect.active {
  border-color: #ff6b6b;
  background: rgba(255, 107, 107, 0.12);
  color: #ff6b6b;
}

/* ===== Save button ===== */
.save-btn {
  margin-top: 16px;
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  color: #666;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.save-btn:hover { border-color: #6bffb8; color: #6bffb8; }
.save-btn:disabled { opacity: 0.5; cursor: default; }

/* ===== Stats section ===== */
#statsSection {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.stats-heading {
  font-size: 11px;
  letter-spacing: 0.2em;
  color: #444;
  text-transform: uppercase;
  text-align: center;
}

.stats-empty {
  text-align: center;
  color: #444;
  font-size: 13px;
  line-height: 1.8;
}

.stats-hint {
  text-align: center;
  color: #aaa;
  font-size: 11px;
  letter-spacing: 0.05em;
}

#statsSection table {
  width: 100%;
  border-collapse: collapse;
}

#statsSection thead th {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: #aaa;
  text-transform: uppercase;
  padding-bottom: 10px;
  border-bottom: 1px solid #333;
  text-align: right;
}

#statsSection thead th:first-child { text-align: left; }

#statsSection tbody td {
  padding: 10px 0;
  text-align: right;
  font-size: 13px;
  color: #ccc;
}

#statsSection tbody td:first-child {
  text-align: left;
  color: #888;
  font-size: 12px;
  letter-spacing: 0.03em;
}

.stat-pct { font-size: 14px; font-weight: 400; }

tr.good .stat-pct { color: #6bffb8; }
tr.ok  .stat-pct  { color: #ffb347; }
tr.bad .stat-pct  { color: #ff6b6b; }

.stat-bar-cell {
  width: 60px;
  padding-left: 12px;
}

.stat-bar-fill {
  height: 3px;
  border-radius: 2px;
  background: #6bffb8;
  min-width: 2px;
}

tr.ok  .stat-bar-fill { background: #ffb347; }
tr.bad .stat-bar-fill { background: #ff6b6b; }

.clear-btn {
  align-self: center;
  padding: 6px 16px;
  background: transparent;
  border: 1px solid #555;
  border-radius: 6px;
  color: #ccc;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.clear-btn:hover { border-color: #ff6b6b; color: #ff6b6b; }

/* ===== Undo bar ===== */
.undo-bar {
  display: flex;
  justify-content: center;
}

.undo-btn {
  background: transparent;
  border: 1px solid #333;
  border-radius: 6px;
  color: #888;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.1em;
  padding: 6px 16px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.undo-btn:hover { border-color: #aaa; color: #e8e8e8; }

/* ===== Responsive ===== */
@media (max-width: 400px) {
  .container {
    padding: 24px 16px;
  }

  .mode-btn {
    padding: 7px 10px;
  }
}
