* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: radial-gradient(circle at top, #171826 0%, #0a0a10 60%);
  color: #eee;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
}
#app { max-width: 640px; margin: 0 auto; min-height: 100vh; padding: 16px 16px 90px; position: relative; }

.screen { display: none; }
.screen.active { display: block; }

/* ---------- Hero / gamification header ---------- */
.hero {
  background: linear-gradient(135deg, #1c1d33 0%, #262042 100%);
  border: 1px solid #3a3760;
  border-radius: 16px;
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: 0 4px 24px rgba(90, 70, 200, 0.15);
}
.hero-top { display: flex; align-items: center; gap: 12px; }
.level-badge {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 48px; height: 48px; border-radius: 50%;
  background: linear-gradient(135deg, #7c5cff, #ff6b9d);
  flex-shrink: 0;
  box-shadow: 0 0 14px rgba(124, 92, 255, 0.5);
}
.level-num { font-weight: 800; font-size: 1.1rem; line-height: 1; color: #fff; }
.level-label { font-size: 0.55rem; color: #fff; opacity: 0.85; letter-spacing: 0.05em; }
.hero-mid { flex: 1; }
.xp-bar-track { background: #14141f; border-radius: 8px; height: 10px; overflow: hidden; border: 1px solid #333; }
.xp-bar-fill { height: 100%; background: linear-gradient(90deg, #7c5cff, #ff6b9d); transition: width 0.4s ease; }
.xp-text { font-size: 0.7rem; color: #aaa; margin-top: 4px; }
.streak-chip {
  display: flex; align-items: center; gap: 4px;
  background: #2a1810; border: 1px solid #5a3a20; border-radius: 20px;
  padding: 6px 12px; font-weight: 700; font-size: 0.95rem; color: #ffb35c; flex-shrink: 0;
}
.hero-stats { display: flex; justify-content: space-around; margin-top: 12px; }
.hero-stat { display: flex; flex-direction: column; align-items: center; }
.hero-stat b { font-size: 1.1rem; color: #fff; }
.hero-stat span { font-size: 0.65rem; color: #999; text-transform: uppercase; letter-spacing: 0.04em; }

h1 { font-size: 1.6rem; margin-bottom: 4px; }
.sub { color: #999; margin-top: 0; margin-bottom: 14px; font-size: 0.85rem; }

.duration-row { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; flex-wrap: wrap; }
.duration-label { color: #999; font-size: 0.8rem; }
.duration-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.duration-chip {
  background: #1c1c1c; color: #ccc; border: 1px solid #333; border-radius: 999px;
  padding: 5px 12px; font-size: 0.8rem; cursor: pointer;
}
.duration-chip.active { background: #3a6df0; color: #fff; border-color: #3a6df0; font-weight: 600; }

.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode-btn {
  border: 1px solid #333; border-radius: 14px;
  padding: 18px 12px; color: #fff; display: flex; flex-direction: column;
  gap: 6px; cursor: pointer; text-align: left; position: relative; overflow: hidden;
}
.mode-c1 { background: linear-gradient(145deg, #1e1430, #2c1a3f); border-color: #5a3a80; }
.mode-c2 { background: linear-gradient(145deg, #14202f, #1a3244); border-color: #2a5a80; }
.mode-c3 { background: linear-gradient(145deg, #142a1e, #1a3e28); border-color: #2a7a4a; }
.mode-c4 { background: linear-gradient(145deg, #2a1e14, #3e2c1a); border-color: #a06a2a; }
.mode-btn:active { filter: brightness(1.3); }
.mode-icon { font-size: 1.6rem; }
.mode-name { font-weight: 700; font-size: 0.95rem; }
.mode-desc { font-size: 0.72rem; color: #bbb; }

/* Quick tools (Brock string / pencil push-ups) */
.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.tool-btn {
  border: 1px solid #333; border-radius: 14px; background: linear-gradient(145deg, #1a1a1a, #262626);
  padding: 14px 12px; color: #fff; display: flex; flex-direction: column;
  gap: 4px; cursor: pointer; text-align: left;
}
.tool-btn:active { filter: brightness(1.3); }
.tool-body { padding: 16px; display: flex; flex-direction: column; gap: 16px; align-items: center; }
.tool-instructions { font-size: 0.95rem; line-height: 1.5; color: #ddd; max-width: 480px; }
.tool-timer-display { font-size: 3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tool-controls { display: flex; gap: 12px; }
.tool-btn-primary, .tool-btn-secondary {
  padding: 12px 20px; border-radius: 10px; border: none; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.tool-btn-primary { background: #3a6df0; color: #fff; }
.tool-btn-secondary { background: #2a3a2a; color: #8f8; border: 1px solid #3a5a3a; }
.tool-note { font-size: 0.75rem; color: #888; text-align: center; max-width: 420px; }

/* ---------- Daily checklist ---------- */
.checklist-body { padding: 4px 0 16px; }
.checklist-progress { font-size: 1.1rem; font-weight: 700; margin: 8px 0 4px; color: #fff; }
.checklist-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.checklist-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  background: #1c1d2e; border: 1px solid #34344a; border-radius: 12px;
  padding: 12px 14px; color: #eee; font-family: inherit;
  cursor: pointer;
}
.checklist-row.auto { cursor: default; opacity: 0.9; }
.checklist-row.done { background: #16281c; border-color: #2c5a3a; }
.checklist-check { font-size: 1.3rem; flex-shrink: 0; }
.checklist-text { display: flex; flex-direction: column; gap: 2px; }
.checklist-label { font-weight: 600; font-size: 0.98rem; }
.checklist-desc { font-size: 0.75rem; color: #999; }
.checklist-row.done .checklist-desc { color: #7ac98a; }

/* Bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-width: 640px; margin: 0 auto;
  display: flex; background: #14141f; border-top: 1px solid #2a2a3a;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 10;
}
.nav-btn {
  flex: 1; background: none; border: none; color: #888;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; font-size: 1.1rem;
}
.nav-btn span { font-size: 0.62rem; }
.nav-btn.active { color: #a78bfa; }

.config-status { font-size: 0.75rem; color: #666; margin-top: 10px; }

.task-topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px; font-size: 0.85rem;
}
.task-topbar button {
  background: #2a1a1a; border: 1px solid #5a2a2a; color: #f88;
  padding: 8px 12px; border-radius: 8px; font-size: 0.8rem;
}
.task-topbar > span:first-of-type, .task-topbar b { color: #eee; }

.stats-bar {
  display: flex; justify-content: space-between; font-size: 0.8rem;
  color: #aaa; margin-bottom: 10px; background: #16161d; padding: 8px 12px;
  border-radius: 8px; flex-wrap: wrap; gap: 4px;
}
.stats-bar b { color: #fff; }
.xp-live { color: #a78bfa; font-weight: 600; }

.stage {
  background: #000; border-radius: 12px; display: flex;
  align-items: center; justify-content: center; overflow: hidden;
  margin-bottom: 14px; border: 1px solid #222; position: relative;
}
#canvas { width: 100%; height: auto; max-height: 60vh; touch-action: none; }

/* ---------- Game HUD ---------- */
.hud-bar {
  display: flex; justify-content: center; align-items: center;
  margin-bottom: 8px; gap: 8px;
}
.hud-chip {
  background: #16161d; border: 1px solid #2a2a3a; border-radius: 20px;
  padding: 6px 14px; font-size: 0.95rem; font-weight: 700; color: #fff;
  text-align: center; transition: transform 0.15s ease;
}
#hud-score { color: #ffd76b; }
#hud-combo { color: #ff8a5b; }
#hud-combo-wrap.pulse { transform: scale(1.2); }
#hud-lives { font-size: 1rem; letter-spacing: 2px; }
#hud-lives.shake { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.game-hint { font-size: 0.78rem; color: #999; text-align: center; padding: 6px 4px; }
#canvas.game-canvas { cursor: crosshair; }

.timer-ring-track {
  height: 6px; background: #1c1c26; border-radius: 4px; overflow: hidden; margin-bottom: 10px;
}
.timer-ring-track.hidden { display: none; }
.timer-ring-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #7c5cff, #ff6b9d);
  transform-origin: left; transition: width 0.05s linear;
}
.timer-ring-fill.urgent { background: linear-gradient(90deg, #ff6b6b, #ffb36b); }

.combo-popup {
  position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) scale(0.7);
  font-size: 1.6rem; font-weight: 800; color: #ffd76b; opacity: 0;
  pointer-events: none; text-shadow: 0 0 12px rgba(255, 215, 107, 0.7);
  transition: none;
}
.combo-popup.show {
  animation: comboPop 0.7s ease-out forwards;
}
@keyframes comboPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1.3); }
}

.game-over-overlay {
  position: absolute; inset: 0; background: rgba(10, 10, 16, 0.92);
  display: flex; align-items: center; justify-content: center; z-index: 5;
}
.game-over-overlay.hidden { display: none; }
.go-title { font-size: 1.4rem; font-weight: 800; text-align: center; margin-bottom: 6px; color: #ff8a5b; }
.go-sub { font-size: 0.8rem; color: #aaa; text-align: center; margin-bottom: 14px; padding: 0 20px; }
.game-over-box { text-align: center; }
.game-over-box button {
  display: block; width: 200px; margin: 0 auto 8px; padding: 12px; border-radius: 10px;
  border: none; font-size: 0.9rem; font-weight: 700;
}
#btn-continue-after-go { background: linear-gradient(135deg, #7c5cff, #ff6b9d); color: #fff; }
#btn-end-after-go { background: #232330; color: #ddd; }

#response-area { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 14px; }
.resp-btn {
  background: #1a1a22; border: 1px solid #444; color: #fff;
  padding: 14px 18px; border-radius: 10px; font-size: 1.1rem; min-width: 54px;
}
.resp-btn:active { background: #333; }
.resp-btn.key-pressed { background: #7c5cff; border-color: #7c5cff; transition: background 0.15s; }
/* Letter Rescue (crowding) answer options: big, high-contrast, easy to read at a glance */
.resp-btn-letter { font-size: 2rem; font-weight: 700; min-width: 64px; padding: 10px 20px; }

.safety-row { text-align: center; }
#btn-diplopia {
  background: #3a1a1a; border: 1px solid #5a2a2a; color: #f99;
  padding: 10px 16px; border-radius: 10px; font-size: 0.8rem; width: 100%;
}

.end-celebrate { font-size: 3rem; text-align: center; margin-bottom: -6px; }
#screen-end h2 { margin-top: 0; text-align: center; }
#end-summary { background: #16161d; padding: 12px; border-radius: 10px; margin-bottom: 12px; font-size: 0.9rem; line-height: 1.6; }
#end-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; justify-content: center; }
.badge-pill {
  background: linear-gradient(135deg, #7c5cff33, #ff6b9d33); border: 1px solid #7c5cff88;
  color: #d9c9ff; padding: 6px 10px; border-radius: 20px; font-size: 0.72rem; font-weight: 600;
}
.comfort-label { display: block; margin-bottom: 10px; font-size: 0.85rem; }
.comfort-label select { margin-left: 8px; padding: 6px; border-radius: 6px; background: #222; color: #fff; border: 1px solid #444; }
#session-notes {
  width: 100%; min-height: 70px; background: #16161d; color: #eee;
  border: 1px solid #333; border-radius: 8px; padding: 8px; margin-bottom: 12px;
  font-family: inherit;
}
#screen-end button, #screen-history button, #screen-settings button { width: 100%; padding: 14px; margin-bottom: 8px; border-radius: 10px; border: none; font-size: 0.95rem; }
#btn-save-session { background: linear-gradient(135deg, #2a7a4a, #1e5c38); color: #fff; font-weight: 700; }
#btn-home { background: #232330; color: #ddd; }

#history-list .hist-row {
  background: #16161d; padding: 10px 12px; border-radius: 8px; margin-bottom: 8px; font-size: 0.8rem;
  border-left: 3px solid #7c5cff;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.hist-row-main { flex: 1; }
.btn-hist-delete {
  background: transparent; border: 1px solid #4a2a2a; color: #ff8a8a; border-radius: 6px;
  padding: 6px 10px; font-size: 0.9rem; cursor: pointer; flex-shrink: 0;
}
.btn-hist-delete:active { background: #3a1a1a; }
.btn-danger-outline {
  background: transparent; border: 1px solid #6a2a2a; color: #ff8a8a; border-radius: 8px;
  padding: 8px 12px; font-size: 0.8rem; margin: 10px 0; width: 100%; cursor: pointer;
}
.btn-danger-outline:active { background: #2a1414; }
.flash { animation: flash 0.3s; }
@keyframes flash { 0% { background: #3a1a1a55; } 100% { background: transparent; } }

/* Progress screen */
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chart-card { background: #14141f; border: 1px solid #2a2a3a; border-radius: 12px; padding: 12px; margin-bottom: 14px; }
.chart-title { font-size: 0.8rem; color: #aaa; margin-bottom: 8px; font-weight: 600; }

/* Settings screen */
.settings-card { background: #14141f; border: 1px solid #2a2a3a; border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.settings-title { font-weight: 700; margin-bottom: 6px; }
.settings-desc { font-size: 0.78rem; color: #999; margin-top: 0; margin-bottom: 10px; line-height: 1.4; }
.settings-label { display: block; font-size: 0.75rem; color: #ccc; margin-bottom: 10px; }
.settings-label input {
  display: block; width: 100%; margin-top: 4px; padding: 10px;
  background: #1a1a22; border: 1px solid #444; border-radius: 8px; color: #fff; font-size: 0.85rem;
}
.radio-row { display: flex; flex-direction: column; gap: 8px; }
.radio-row label { font-size: 0.82rem; color: #ddd; display: flex; align-items: center; gap: 8px; }
.stepper-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid #232330;
}
.stepper-row:last-child { border-bottom: none; }
.stepper-label { font-size: 0.78rem; color: #ccc; flex: 1; line-height: 1.3; }
.stepper-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.stepper-value { min-width: 42px; text-align: center; font-weight: 700; font-size: 0.9rem; color: #fff; }
.stepper-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid #444; background: #232330;
  color: #fff; font-size: 1.1rem; font-weight: 700; cursor: pointer; line-height: 1;
}
.stepper-btn:active { background: #7c5cff; }
.stepper-group-title { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: #7c5cff; margin: 14px 0 2px; font-weight: 700; }
.stepper-group-title:first-child { margin-top: 0; }
#btn-sb-save { background: linear-gradient(135deg, #7c5cff, #5c3fd9); color: #fff; font-weight: 700; }
#btn-sb-sync-now { background: #232330; color: #ddd; }
.settings-status { font-size: 0.75rem; color: #888; margin-top: 6px; }
.upload-label {
  display: block; text-align: center; background: #232330; border: 1px solid #444;
  color: #ddd; padding: 12px; border-radius: 10px; font-size: 0.85rem; cursor: pointer; margin-bottom: 8px;
}
.danger-btn { background: #3a1a1a; border: 1px solid #5a2a2a; color: #f99; }
