:root {
  --bg: #0B0F17;
  --surface: #131A26;
  --surface-elevated: #1B2435;
  --border: #26334A;
  --text: #F8FAFC;
  --muted: #94A3B8;
  --emerald: #22C55E;
  --cyan: #38BDF8;
  --amber: #F59E0B;
  --red: #EF4444;
  --violet: #A855F7;
  --radius: 14px;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.stage-open {
  overflow: hidden;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

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

.small {
  font-size: 0.9rem;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 15, 23, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--cyan), var(--emerald));
  color: #061018;
  font-weight: 800;
  font-size: 1.15rem;
  display: grid;
  place-items: center;
}

.brand h1 {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.2;
}

.brand p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.nav-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.nav-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-btn:hover {
  color: var(--text);
  background: var(--surface-elevated);
}

.nav-btn.active {
  color: #061018;
  background: var(--cyan);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--surface-elevated);
}

/* Main Layout */
.app-main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.section-header {
  margin-bottom: 18px;
}

.section-header h2 {
  margin: 0 0 6px;
  font-size: 1.45rem;
}

.section-header p {
  margin: 0;
}

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

.card h3 {
  margin: 0 0 8px;
  font-size: 1.12rem;
}

/* KPI Strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-strip-5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.kpi-card {
  padding: 16px 18px;
  border-top: 3px solid var(--border);
}

.kpi-card.accent-emerald { border-top-color: var(--emerald); }
.kpi-card.accent-cyan { border-top-color: var(--cyan); }
.kpi-card.accent-amber { border-top-color: var(--amber); }
.kpi-card.accent-violet { border-top-color: var(--violet); }

.kpi-label {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
}

/* Today Grid */
.today-grid {
  display: grid;
  grid-template-columns: 1.65fr 1fr;
  gap: 18px;
  align-items: start;
}

.hero-card h2 {
  margin: 10px 0 6px;
  font-size: 1.4rem;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.pill-accent { background: rgba(56, 189, 248, 0.16); color: var(--cyan); }
.pill-success { background: rgba(34, 197, 94, 0.16); color: var(--emerald); }
.pill-warn { background: rgba(245, 158, 11, 0.18); color: var(--amber); }
.pill-tier { background: var(--surface-elevated); color: var(--text); border: 1px solid var(--border); }

.circuit-steps {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0 20px;
}

.circuit-step {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.circuit-step.done {
  border-color: rgba(34, 197, 94, 0.5);
  background: rgba(34, 197, 94, 0.08);
}

.step-index {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
}

.circuit-step.done .step-index {
  background: var(--emerald);
  color: #05140B;
  border-color: var(--emerald);
}

.step-name {
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.3;
}

.step-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-lg {
  padding: 13px 22px;
  font-size: 1rem;
}

.btn-primary {
  background: var(--cyan);
  color: #061018;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-secondary {
  background: var(--surface-elevated);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: #233046;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.4);
  color: #FCA5A5;
}

.warmup-list {
  margin: 12px 0 16px;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 0.9rem;
}

.habit-check-inline,
.habit-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.9rem;
}

.habit-check-inline input,
.habit-item input {
  margin-top: 3px;
  accent-color: var(--emerald);
  width: 16px;
  height: 16px;
}

.energy-bar {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.energy-label {
  font-size: 0.88rem;
  color: var(--muted);
}

.energy-pills,
.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill-btn {
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.pill-btn.active {
  background: var(--cyan);
  border-color: var(--cyan);
  color: #061018;
}

/* Drills Grid */
.drills-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.drill-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.drill-card-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.drill-icon {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 12px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 1.35rem;
}

.drill-card-head h3 {
  margin-bottom: 4px;
}

.drill-card-head p {
  margin: 0;
}

.drill-stats-mini {
  display: flex;
  gap: 24px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-elevated);
}

.drill-stats-mini > div {
  display: flex;
  flex-direction: column;
}

.mini-lbl {
  font-size: 0.75rem;
  color: var(--muted);
}

.drill-controls {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

.select-input {
  background: var(--surface-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.88rem;
}

.drill-card-actions {
  display: flex;
  gap: 10px;
  margin-top: auto;
}

/* Progress Charts & Tables */
.chart-card {
  margin-bottom: 18px;
}

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

.chart-host {
  position: relative;
  min-height: 240px;
}

.trend-svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-dot {
  cursor: pointer;
  transition: r 0.12s ease;
}

.chart-dot:hover {
  r: 7;
}

.chart-tooltip {
  position: absolute;
  top: 8px;
  transform: translateX(-50%);
  background: #070A10;
  border: 1px solid var(--cyan);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.8rem;
  pointer-events: none;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.tip-date {
  font-weight: 700;
  color: var(--cyan);
  margin-bottom: 2px;
}

.chart-empty {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 44px 20px;
  text-align: center;
}

.chart-empty-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.chart-empty-desc {
  color: var(--muted);
  font-size: 0.9rem;
}

.progress-two-col {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
}

.drill-bars {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}

.drill-bar-row {
  display: grid;
  grid-template-columns: 190px 1fr 115px;
  align-items: center;
  gap: 12px;
}

.drill-bar-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
}

.drill-bar-track {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-elevated);
  overflow: hidden;
}

.drill-bar-fill {
  height: 100%;
  border-radius: 999px;
}

.drill-bar-stats {
  text-align: right;
  font-size: 0.84rem;
  color: var(--muted);
}

.data-tools-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 10px;
}

.runs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.runs-table th,
.runs-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.runs-table th {
  color: var(--muted);
  font-weight: 600;
}

/* Plan & Science */
.plan-grid {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 18px;
  margin-bottom: 18px;
}

.habit-list,
.weeks-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.week-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.week-card.active-week {
  border-color: var(--emerald);
  background: rgba(34, 197, 94, 0.08);
}

.week-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.week-card p {
  margin: 0;
}

.science-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 12px;
}

.science-item {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.science-item h4 {
  margin: 0 0 6px;
  font-size: 0.96rem;
}

.science-item p {
  margin: 0;
}

/* Full-Focus Drill Overlay */
.stage-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: 18px 24px 24px;
}

.stage-topbar {
  max-width: 920px;
  width: 100%;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stage-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stage-title-group h2 {
  margin: 0;
  font-size: 1.15rem;
}

.stage-progress-bar {
  max-width: 920px;
  width: 100%;
  margin: 0 auto 10px;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-elevated);
  overflow: hidden;
}

.stage-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--cyan);
  transition: width 0.2s ease;
}

.stage-rule-banner {
  max-width: 920px;
  width: 100%;
  margin: 0 auto 14px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.92rem;
  text-align: center;
}

.drill-stage {
  max-width: 920px;
  width: 100%;
  flex: 1;
  min-height: 360px;
  margin: 0 auto;
  border-radius: 18px;
  border: 2px solid var(--border);
  background: var(--surface);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  user-select: none;
  touch-action: manipulation;
  cursor: pointer;
  overflow: hidden;
}

.drill-stage.state-waiting {
  background: #1B1A12;
  border-color: rgba(245, 158, 11, 0.45);
}

.drill-stage.drill-audio-rt.state-waiting,
.drill-stage.drill-audio-rt.state-active {
  background: #161326;
  border-color: rgba(168, 85, 247, 0.45);
}

.drill-stage.drill-choice-rt.state-waiting,
.drill-stage.drill-spatial-peripheral.state-waiting,
.drill-stage.drill-spatial-peripheral.state-active,
.drill-stage.drill-go-nogo.state-waiting {
  background: var(--surface);
  border-color: var(--border);
}

.drill-stage.state-go {
  background: var(--emerald);
  border-color: #86EFAC;
  color: #041309;
}

.drill-stage.state-feedback-ok {
  background: rgba(34, 197, 94, 0.14);
  border-color: var(--emerald);
}

.drill-stage.state-feedback-bad {
  background: rgba(239, 68, 68, 0.16);
  border-color: var(--red);
}

.stage-center-msg {
  text-align: center;
  padding: 20px;
}

.stage-main-label {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.stage-feedback-value {
  font-size: 2.3rem;
  font-weight: 800;
}

.stage-subhint {
  margin-top: 10px;
  font-size: 0.92rem;
  color: var(--muted);
}

.drill-stage.state-go .stage-subhint {
  color: #062812;
}

/* Choice RT Lanes */
.choice-grid {
  width: min(560px, 90%);
  display: grid;
  gap: 14px;
}

.choice-grid.choices-2 {
  grid-template-columns: repeat(2, 1fr);
}

.choice-grid.choices-4 {
  grid-template-columns: repeat(3, 1fr);
  grid-template-areas:
    ". up ."
    "left down right";
}

.choice-grid.choices-4 [data-dir="up"] { grid-area: up; }
.choice-grid.choices-4 [data-dir="left"] { grid-area: left; }
.choice-grid.choices-4 [data-dir="down"] { grid-area: down; }
.choice-grid.choices-4 [data-dir="right"] { grid-area: right; }

.choice-lane {
  border: 2px solid var(--border);
  background: var(--surface-elevated);
  color: var(--muted);
  border-radius: 14px;
  padding: 26px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.choice-lane-active {
  background: var(--cyan);
  border-color: #E0F2FE;
  color: #04121D;
  transform: scale(1.03);
}

.choice-arrow {
  font-size: 2rem;
  font-weight: 800;
}

.choice-label {
  font-size: 0.85rem;
  font-weight: 700;
}

/* Go / No-Go */
.gonogo-shape {
  width: 112px;
  height: 112px;
  margin: 0 auto 10px;
}

.gonogo-circle {
  border-radius: 999px;
  background: var(--emerald);
  box-shadow: 0 0 28px rgba(34, 197, 94, 0.35);
}

.gonogo-square {
  border-radius: 16px;
  background: var(--red);
  box-shadow: 0 0 28px rgba(239, 68, 68, 0.35);
}

.stroop-word {
  font-size: 3.4rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

/* Spatial */
.spatial-fixation {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.6rem;
  color: rgba(148, 163, 184, 0.45);
  pointer-events: none;
}

.drill-spatial-peripheral .stage-subhint {
  position: absolute;
  bottom: 14px;
  pointer-events: none;
}

.spatial-target,
.spatial-decoy {
  position: absolute;
  border-radius: 999px;
  cursor: pointer;
  padding: 0;
}

.spatial-target {
  background: var(--cyan);
  border: 2px solid #BAE6FD;
  box-shadow: 0 0 22px rgba(56, 189, 248, 0.45);
}

.spatial-decoy {
  background: transparent;
  border: 4px solid var(--amber);
}

/* Audio */
.audio-pulse-ring {
  width: 84px;
  height: 84px;
  margin: 0 auto 14px;
  border-radius: 999px;
  border: 2px solid var(--violet);
  background: rgba(168, 85, 247, 0.14);
  display: grid;
  place-items: center;
  font-size: 2rem;
  color: var(--violet);
}

.stage-audio-reveal {
  font-size: 1rem;
  font-weight: 700;
  color: var(--violet);
  margin-bottom: 6px;
}

/* Post Drill Card */
.stage-post-panel {
  max-width: 620px;
  width: 100%;
  margin: auto;
}

.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.post-card h2 {
  margin: 10px 0 8px;
}

.post-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(115px, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.mini-stat {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mini-stat span {
  font-size: 0.78rem;
  color: var(--muted);
}

.mini-stat strong {
  font-size: 1.25rem;
}

.post-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

/* Modal & Toast */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.65);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-card {
  max-width: 440px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

.modal-card h3 {
  margin-top: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 80;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success { border-color: var(--emerald); }
.toast.error { border-color: var(--red); }

@media (max-width: 900px) {
  .kpi-strip,
  .kpi-strip-5,
  .today-grid,
  .drills-grid,
  .progress-two-col,
  .plan-grid,
  .science-grid {
    grid-template-columns: 1fr;
  }

  .circuit-steps {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .drill-bar-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .drill-bar-stats {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
