:root {
  --bg: #0b1220;
  --bg-elev: #121a2b;
  --bg-card: #172235;
  --text: #e8eefc;
  --muted: #8b9bb8;
  --primary: #5b8cff;
  --primary-press: #3f73ef;
  --accent: #4fd1c5;
  --danger: #ff6b8a;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

html.light {
  --bg: #f4f7fc;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --text: #152033;
  --muted: #66768f;
  --primary: #3b6ef5;
  --primary-press: #2d5ad4;
  --accent: #0f9f93;
  --danger: #e5486a;
  --border: rgba(15, 30, 60, 0.08);
  --shadow: 0 8px 24px rgba(30, 50, 90, 0.08);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  user-select: none;
}

#app {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  background: var(--bg);
}

.screen {
  display: none;
  height: 100%;
  flex-direction: column;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  overflow: hidden;
}

.screen.active {
  display: flex;
}

/* Home */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

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

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #5b8cff, #4fd1c5);
  color: white;
  font-size: 22px;
  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.5px;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 12px;
  font-size: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.icon-btn.placeholder {
  visibility: hidden;
}

.tip-card {
  background: linear-gradient(135deg, rgba(91, 140, 255, 0.15), rgba(79, 209, 197, 0.1));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 20px;
}

.tip-card strong {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
}

.tip-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.section-title {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--muted);
  font-weight: 600;
}

.mode-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}

.mode-card {
  display: flex;
  gap: 14px;
  align-items: center;
  text-align: left;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.mode-card:active {
  transform: scale(0.98);
}

.mode-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 22px;
  flex-shrink: 0;
  background: rgba(91, 140, 255, 0.12);
}

.mode-card h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.mode-card p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* Train */
.train-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.train-title-wrap {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.train-title-wrap h2 {
  margin: 0;
  font-size: 17px;
}

.train-sub {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 10px;
}

#progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.2s linear;
}

.stage {
  flex: 1;
  position: relative;
  border-radius: calc(var(--radius) + 4px);
  background:
    radial-gradient(circle at 50% 40%, rgba(91, 140, 255, 0.08), transparent 55%),
    var(--bg-elev);
  border: 1px solid var(--border);
  overflow: hidden;
  min-height: 240px;
}

.train-footer {
  padding-top: 14px;
}

.timer-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

#phase-label {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}

#timer-text {
  font-variant-numeric: tabular-nums;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.instruction {
  margin: 0 0 14px;
  min-height: 40px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
}

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

.btn {
  border: none;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn.primary {
  background: var(--primary);
  color: white;
}

.btn.primary:active {
  background: var(--primary-press);
}

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

.btn.block {
  width: 100%;
}

/* Settings */
.settings-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
}

.setting-item select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
}

.setting-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

.settings-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  padding: 0 4px;
}

/* Modal */
.modal {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 20;
  backdrop-filter: blur(4px);
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 320px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 22px 22px;
  text-align: center;
  box-shadow: var(--shadow);
}

.modal-emoji {
  font-size: 36px;
  margin-bottom: 8px;
}

.modal-card h3 {
  margin: 0 0 8px;
  font-size: 20px;
}

.modal-card p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

/* ===== Training visuals ===== */
.target {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 0 rgba(91, 140, 255, 0.35);
  transition: left 0.35s ease, top 0.35s ease, width 0.35s ease, height 0.35s ease,
    background 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  will-change: left, top, width, height;
}

.target.pulse {
  animation: pulse 0.9s ease-out;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(91, 140, 255, 0.45); }
  100% { box-shadow: 0 0 0 28px rgba(91, 140, 255, 0); }
}

.target.near {
  background: radial-gradient(circle at 35% 30%, #fff 0 12%, var(--accent) 13% 100%);
}

.target.far {
  background: radial-gradient(circle at 35% 30%, #fff 0 10%, var(--primary) 11% 100%);
}

.target.track {
  background: radial-gradient(circle at 35% 30%, #fff 0 14%, #ff8a5b 15% 100%);
}

.target.saccade {
  background: radial-gradient(circle at 35% 30%, #fff 0 12%, #c084fc 13% 100%);
}

.target.blink-hint {
  background: radial-gradient(circle at 35% 30%, #fff 0 12%, #fbbf24 13% 100%);
}

/* Near-far dual dots */
.nf-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 10%;
}

.nf-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  opacity: 0.25;
  transition: transform 0.35s ease, opacity 0.35s ease, box-shadow 0.35s ease;
  background: radial-gradient(circle at 35% 30%, #fff 0 14%, var(--primary) 15% 100%);
}

.nf-dot.active {
  opacity: 1;
  transform: scale(1.55);
  box-shadow: 0 0 24px rgba(91, 140, 255, 0.55);
}

.nf-dot.near {
  background: radial-gradient(circle at 35% 30%, #fff 0 14%, var(--accent) 15% 100%);
}

/* Figure 8 trail */
.fig8-path {
  position: absolute;
  inset: 12%;
  border: 1.5px dashed rgba(139, 155, 184, 0.25);
  border-radius: 50%;
  pointer-events: none;
}

/* Palm rest */
.palm-stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
}

.palm-circle {
  width: min(58vw, 220px);
  height: min(58vw, 220px);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(20, 24, 36, 0.95), #05070d 70%);
  border: 2px solid rgba(255, 255, 255, 0.06);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.6);
}

html.light .palm-circle {
  background: radial-gradient(circle, #2a3144, #121722 70%);
  color: #c5cddd;
}

/* Focus ladder */
.ladder {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
}

.ladder-ring {
  border-radius: 50%;
  border: 2px solid rgba(139, 155, 184, 0.25);
  display: grid;
  place-items: center;
  transition: border-color 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}

.ladder-ring.active {
  border-color: var(--accent);
  box-shadow: 0 0 18px rgba(79, 209, 197, 0.35);
  transform: scale(1.06);
}

.ladder-core {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
}

/* Convergence bars */
.conv-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.conv-bar {
  width: 10px;
  height: 42%;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--primary), var(--accent));
  transition: transform 0.5s ease, opacity 0.3s ease;
  box-shadow: 0 0 16px rgba(91, 140, 255, 0.3);
}

/* Blink overlay */
.blink-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.72);
  color: white;
  font-size: 42px;
  font-weight: 700;
  letter-spacing: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.blink-overlay.show {
  opacity: 1;
}

/* Countdown big number */
.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 72px;
  font-weight: 800;
  color: var(--text);
  opacity: 0.9;
}

@media (min-height: 740px) {
  .stage {
    min-height: 320px;
  }
}
