@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@600;700&display=swap');

:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1e4fd1;
  --border: #e5e7eb;
  --shadow: 0 10px 35px rgba(15, 23, 42, 0.08);
  --radius: 12px;
  --brand-accent: #1e3a8a;
  --nav-bg: #ffffff;
  --surface: #f8fafc;
  --surface-soft: #f3f4f6;
  --surface-strong: #eef2ff;
  --table-stripe: #fbfdff;
  --ad-bg: #eef2f7;
  --ad-border: #cbd5e1;
  --tap-btn: #0f172a;
  --tap-btn-text: #ffffff;
  --reaction-idle: #e5e7eb;
  --reaction-wait: #f1f5f9;
}

:root.theme-dark,
body.theme-dark {
  color-scheme: dark;
  --bg: #0b1220;
  --card: #0f172a;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --primary: #60a5fa;
  --primary-dark: #3b82f6;
  --border: #1f2937;
  --shadow: 0 10px 35px rgba(0, 0, 0, 0.55);
  --brand-accent: #bfdbfe;
  --nav-bg: #0f172a;
  --surface: #111827;
  --surface-soft: #0c1628;
  --surface-strong: #15233a;
  --table-stripe: #0d1628;
  --ad-bg: #0d182a;
  --ad-border: #1f2937;
  --tap-btn: #1b2745;
  --tap-btn-text: #e5e7eb;
  --reaction-idle: #111827;
  --reaction-wait: #0c1628;
}

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  width: 100%;
  max-width: 1000px;
  padding: 0 16px;
  margin: 0 auto;
}

.site-header,
.site-footer {
  padding: 20px 0;
}

.site-header .container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.site-nav {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--nav-bg);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
  margin-bottom: 18px;
}

.theme-dark .site-nav {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.nav-links {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: stretch;
}

.nav-link {
  display: block;
  padding: 12px 14px;
  font-weight: 700;
  font-family: 'Space Grotesk', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--muted);
  text-decoration: none;
  border-radius: 10px;
  transition: color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  text-align: center;
}

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

.nav-link.active {
  color: var(--text);
  background: var(--surface-strong);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.12);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: 'Space Grotesk', 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
  padding: 6px 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  line-height: 1.1;
}

.brand-spacebar {
  position: relative;
  display: inline-block;
  font-size: 1.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.brand-spacebar::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: -6px;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.16), rgba(37, 99, 235, 0.38));
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.15);
}

.brand-count {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 7px 12px 6px;
  background: var(--surface-strong);
  color: var(--brand-accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(37, 99, 235, 0.18);
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.12);
}

h1,
h2,
h3,
strong {
  font-family: 'Space Grotesk', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

.tagline,
.site-footer p {
  color: var(--muted);
  margin: 6px 0 0;
}

main {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  align-items: start;
  margin-bottom: 32px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card-head h1 {
  margin: 0 0 10px;
}

.card-head h2 {
  margin: 0 0 6px;
}

.lead {
  margin: 0;
  color: var(--muted);
}

.intro-aux {
  color: var(--muted);
  margin: 10px 0 0;
}

.mode-switch {
  display: inline-flex;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
  margin: 18px 0 10px;
}

.mode-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 700;
  font-family: 'Space Grotesk', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.mode-btn.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 4px 18px rgba(15, 23, 42, 0.12);
}

.mode-section.hidden {
  display: none;
}

.mode-section {
  position: relative;
  --run-progress: 0;
  --progress-fill-size: calc(var(--run-progress, 0) * 100%);
  --progress-remaining-size: calc((1 - var(--run-progress, 0)) * 100%);
  padding: 0;
  background: transparent;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 14px;
}

.mode-surface {
  position: relative;
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

.mode-section.running {
  background: transparent;
  box-shadow: none;
}

.mode-section.running .mode-surface {
  background: rgba(37, 99, 235, 0.03);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.12), 0 6px 20px rgba(37, 99, 235, 0.1);
}

.mode-section.cooldown {
  background: transparent;
  box-shadow: none;
}

.mode-section.cooldown .mode-surface {
  background: linear-gradient(180deg, rgba(107, 114, 128, 0.06), rgba(107, 114, 128, 0.02));
  box-shadow: inset 0 0 0 1px rgba(107, 114, 128, 0.16);
}

.mode-section.progress-enabled.running .progress-surface {
  background: var(--surface);
  background-image: linear-gradient(90deg, rgba(37, 99, 235, 0.12), rgba(37, 99, 235, 0.06));
  background-size: var(--progress-fill-size) 100%;
  background-repeat: no-repeat;
  background-position: left top;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.16), 0 8px 18px rgba(37, 99, 235, 0.08);
  border-color: rgba(37, 99, 235, 0.28);
}

.mode-section[data-progress-kind='timer'].progress-enabled.running .progress-surface {
  background-image: linear-gradient(90deg, rgba(37, 99, 235, 0.16), rgba(37, 99, 235, 0.05));
  background-size: var(--progress-remaining-size) 100%;
  background-position: right top;
}

.mode-section[data-progress-kind='intensity'].progress-enabled.running .progress-surface {
  background-image: linear-gradient(180deg, rgba(37, 99, 235, 0.16), rgba(37, 99, 235, 0.04));
  background-size: 100% var(--progress-fill-size);
  background-position: left bottom;
}

.mode-section[data-progress-kind='steps'].progress-enabled.running .progress-surface {
  background-image: linear-gradient(90deg, rgba(37, 99, 235, 0.16), rgba(37, 99, 235, 0.08));
  background-size: var(--progress-fill-size) 100%;
  background-position: left top;
}

.mode-section.progress-enabled.running .tap-area {
  border-radius: 14px;
  padding: 6px;
  background: var(--surface);
}

.mode-section.running .btn.tap {
  box-shadow: 0 10px 26px rgba(37, 99, 235, 0.18);
}

#doubleTapBtn {
  border: 1px solid transparent;
  box-sizing: border-box;
}

#doubleTapBtn.double-waiting {
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.18);
  border: 1px solid rgba(37, 99, 235, 0.25);
}

#holdTapBtn {
  background: var(--tap-btn);
  color: var(--tap-btn-text);
  border: 1px solid transparent;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.25);
}

.mode-section.hold-active #holdTapBtn {
  background: var(--surface-strong);
  color: var(--text);
  border: 1px solid rgba(37, 99, 235, 0.25);
  animation: holdPulse var(--hold-pulse-duration, 1.35s) ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.25);
}

.mode-section.hold-active .tap-area {
  background: var(--surface);
  border-radius: 14px;
}

@keyframes holdPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.25);
  }
  20% {
    box-shadow: 0 0 0 8px rgba(37, 99, 235, 0.12);
  }
  38% {
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.06);
  }
  58% {
    box-shadow: 0 0 0 11px rgba(37, 99, 235, 0.14);
  }
  78% {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.06);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.18);
  }
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin: 0;
}

.control-label {
  font-weight: 600;
}

select {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 1rem;
}

input[type='number'] {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 1rem;
  width: 140px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.05s ease, box-shadow 0.2s ease, background 0.2s ease;
  font-weight: 600;
  font-family: 'Space Grotesk', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 10px 25px rgba(37, 99, 235, 0.2);
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.ghost {
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.tap {
  width: 100%;
  background: var(--tap-btn);
  color: var(--tap-btn-text);
  padding: 16px;
  font-size: 1.1rem;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.25);
  border: 1px solid transparent;
  box-sizing: border-box;
}

.btn:active {
  transform: translateY(1px);
}

.mode-section .btn.tap.is-pressed,
.mode-section .btn.tap:active {
  transform: translateY(1px) scale(0.985) !important;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.22);
}

.btn.tap:active,
.btn.tap.is-pressed {
  transform: translateY(1px) scale(0.985);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.22);
}

.status {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin: 0;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.metric .label,
.metric .value,
.metric .count {
  font-family: 'Space Grotesk', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

.metric .label {
  display: block;
  color: var(--muted);
  font-size: 0.95rem;
}

.metric .value {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  margin-top: 6px;
  line-height: 1.2;
}

.metric .count {
  font-size: 2rem;
}

.tap-area {
  margin: 0;
  text-align: center;
  padding: 6px;
  border-radius: 14px;
}

.tap-hint {
  color: var(--muted);
  margin: 8px 0 0;
  font-size: 0.95rem;
}

.result {
  font-weight: 600;
  margin: 12px 0 0;
}

.mode-surface .result {
  margin: 0;
}

.reaction-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  margin: 10px 0 12px;
}

.reaction-signal {
  height: 120px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--text);
  background: var(--reaction-idle);
  transition: background 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

.reaction-signal.waiting {
  background: var(--reaction-wait);
  color: var(--muted);
}

.reaction-signal.ready {
  background: #22c55e;
  color: #0b1c10;
  box-shadow: 0 10px 30px rgba(34, 197, 94, 0.3);
  transition: none;
}

.reaction-signal.early {
  background: #fecdd3;
  color: #7f1d1d;
  box-shadow: 0 10px 30px rgba(248, 113, 113, 0.25);
}

.reaction-instruction {
  margin: 12px 0 0;
  font-weight: 600;
}

.rhythm-visual {
  text-align: center;
  margin: 14px 0 10px;
}

.rhythm-beat {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  margin: 0 auto 8px;
  background: var(--surface-strong);
  border: 10px solid var(--primary);
  box-shadow: inset 0 0 0 8px rgba(37, 99, 235, 0.08);
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.rhythm-beat.active {
  background: var(--primary);
  border-color: var(--primary-dark);
  transform: scale(1.08);
  box-shadow: 0 14px 32px rgba(37, 99, 235, 0.35);
}

.mode-section + .mode-section {
  margin-top: 24px;
}

.recent-results {
  margin-top: 22px;
}

.mode-section > .recent-results {
  padding: 0 8px;
  margin: 0;
}

.mode-section.running .recent-results,
.mode-section.cooldown .recent-results {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

.results-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.muted {
  color: var(--muted);
  margin: 0;
}

.table {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table.cols-2 .table-row {
  grid-template-columns: repeat(2, 1fr);
}

.table.cols-3 .table-row {
  grid-template-columns: repeat(3, 1fr);
}

.table-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 10px 12px;
}

.table-head {
  background: var(--surface);
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}

.table-row span {
  font-size: 0.98rem;
}

.table-body-row:nth-child(odd) {
  background: var(--table-stripe);
}

.ad {
  position: sticky;
  top: 20px;
}

.ad-box {
  height: 200px;
  background: var(--ad-bg);
  border: 1px dashed var(--ad-border);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.faq .faq-item + .faq-item {
  margin-top: 16px;
}

.faq h3 {
  margin-bottom: 6px;
}

.faq ul {
  list-style: none;
  padding-left: 0;
  margin: 10px 0;
}

.faq li {
  position: relative;
  padding-left: 28px;
  margin: 8px 0;
}

.faq li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.85em;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: transparent;
  border: 2px solid rgba(37, 99, 235, 0.28);
  box-shadow: none;
  transform: translateY(-50%);
}

.faq li::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 0.85em;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: none;
  transform: translateY(-50%);
}

.theme-toggle {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-weight: 700;
  font-family: 'Space Grotesk', 'Segoe UI', system-ui, -apple-system, sans-serif;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
  transition: background 0.2s ease, transform 0.05s ease, box-shadow 0.2s ease;
}

.theme-toggle:hover {
  background: var(--surface-soft);
}

.theme-toggle:active {
  transform: translateY(1px);
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.18);
}

.theme-toggle-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.16);
}

@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
  }

  .ad {
    position: static;
  }

  .nav-links {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .nav-links {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .btn,
  select {
    width: 100%;
  }

  .metric .value {
    font-size: 1.8rem;
  }

  .metric .count {
    font-size: 2.2rem;
  }

  .table-row {
    grid-template-columns: 1.2fr 1fr 1fr 1fr;
  }

  .theme-toggle {
    top: 10px;
    right: 10px;
    padding: 9px 12px;
  }
}
