:root {
  /* Default Dark Theme (inspired by reference screenshots) */
  --bg-outer: #0d0c12;
  --bg-app: #171520;
  --bg-card: #1f1c2b;
  --bg-control: #242132;
  --border-card: #312d44;
  --border-control: #38334d;
  --text-main: #f5f4f8;
  --text-muted: #9b96b0;
  --accent-solid: #ff8e53;
  --accent-grad: linear-gradient(90deg, #ffae42 0%, #ff7b54 100%);
  --accent-text: #171520;
  --danger: #ff6b6b;
  --success: #4cd97b;
  --scale: 1;
}

/* Light Theme */
body[data-resolved-theme="light"] {
  --bg-outer: #e5e1da;
  --bg-app: #f6f4ef;
  --bg-card: #ffffff;
  --bg-control: #f0ede6;
  --border-card: #e2ddd3;
  --border-control: #d5cfc3;
  --text-main: #221f2b;
  --text-muted: #6e697d;
  --accent-solid: #f47b3e;
  --accent-grad: linear-gradient(90deg, #ffa438 0%, #f46c45 100%);
  --accent-text: #171520;
  --danger: #d94343;
  --success: #2f9e56;
}

/* High Contrast Theme (for low vision accessibility) */
body[data-resolved-theme="contrast"] {
  --bg-outer: #000000;
  --bg-app: #000000;
  --bg-card: #0c0c0c;
  --bg-control: #161616;
  --border-card: #ffffff;
  --border-control: #ffffff;
  --text-main: #ffffff;
  --text-muted: #ffe600;
  --accent-solid: #ffe600;
  --accent-grad: linear-gradient(90deg, #ffe600 0%, #ffbb00 100%);
  --accent-text: #000000;
  --danger: #ff5555;
  --success: #00ff88;
}

/* 6 Font Size Steps */
body[data-font-step="1"] { --scale: 0.88; }
body[data-font-step="2"] { --scale: 1.00; }
body[data-font-step="3"] { --scale: 1.14; }
body[data-font-step="4"] { --scale: 1.28; }
body[data-font-step="5"] { --scale: 1.44; }
body[data-font-step="6"] { --scale: 1.62; }

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-outer);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Mobile-proportioned shell so eyes never jump across wide screens */
.app-shell {
  width: 100%;
  max-width: 412px;
  height: 100dvh;
  max-height: 880px;
  background-color: var(--bg-app);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}

@media (min-width: 450px) {
  .app-shell {
    height: 94dvh;
    border-radius: 30px;
    border: 1px solid var(--border-card);
  }
}

.screen {
  flex: 1;
  display: none;
  flex-direction: column;
  padding: 16px 20px 22px;
  overflow-y: auto;
  overflow-x: hidden;
}

.screen.active {
  display: flex;
}

.hidden {
  display: none !important;
}

/* ==========================================
   SCREEN 1: HOME
   ========================================== */
.home-top-bar {
  display: flex;
  justify-content: flex-end;
  min-height: 34px;
}

.gear-btn, .icon-close-btn {
  background: transparent;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  opacity: 0.9;
  transition: background 0.15s, transform 0.15s;
}

.gear-btn:hover, .icon-close-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.hero-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-top: -6px;
  margin-bottom: 16px;
}

.hero-icon {
  width: 68px;
  height: 68px;
  border-radius: 18px;
  box-shadow: 0 8px 22px rgba(255, 126, 84, 0.28);
  margin-bottom: 12px;
}

.hero-title {
  font-size: calc(1.55rem * var(--scale));
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.hero-subtitle {
  color: var(--text-muted);
  font-size: calc(0.88rem * var(--scale));
  line-height: 1.4;
  max-width: 280px;
}

/* 3 Stat Boxes */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat-box {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 16px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.stat-num {
  font-size: calc(1.45rem * var(--scale));
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
}

.stat-lbl {
  font-size: calc(0.74rem * var(--scale));
  color: var(--text-muted);
  text-align: center;
}

/* Chart Card */
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 18px;
  padding: 14px 14px 10px;
  flex: 1;
  min-height: 185px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin-bottom: 16px;
}

.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.chart-mode-btn {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: calc(0.86rem * var(--scale));
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 4px;
  border-radius: 6px;
}

.chart-mode-chevron {
  font-size: 0.78rem;
  color: var(--accent-solid);
  opacity: 0.85;
}

.config-summary-badge {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: calc(0.76rem * var(--scale));
  cursor: pointer;
  text-align: right;
}

.config-summary-badge:hover {
  color: var(--text-main);
}

.chart-svg-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  width: 100%;
}

#historyChart {
  width: 100%;
  height: 155px;
  display: block;
}

/* Bottom Actions on Home */
.home-bottom-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: auto;
}

.install-pill-btn {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-control);
  border-radius: 12px;
  padding: 10px 22px;
  font-size: calc(0.85rem * var(--scale));
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.install-pill-btn:active {
  transform: scale(0.97);
}

.start-gradient-btn {
  width: 100%;
  background: var(--accent-grad);
  color: var(--accent-text);
  border: none;
  border-radius: 16px;
  padding: 16px 24px;
  font-size: calc(1.15rem * var(--scale));
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(255, 132, 75, 0.25);
  transition: transform 0.1s, filter 0.15s;
}

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

/* ==========================================
   SCREEN 2: GAME (ERGONOMIC THUMB LAYOUT)
   ========================================== */
.game-top-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.timer-bar-track {
  width: 100%;
  height: 7px;
  background: var(--bg-control);
  border-radius: 99px;
  overflow: hidden;
}

.timer-bar-fill {
  height: 100%;
  width: 100%;
  background: var(--accent-grad);
  border-radius: 99px;
  transition: width 0.15s linear;
}

.game-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.timer-text {
  font-size: calc(1rem * var(--scale));
  font-weight: 700;
  color: var(--text-muted);
}

.live-score-pill {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  color: var(--accent-solid);
  font-weight: 800;
  font-size: calc(0.95rem * var(--scale));
  padding: 4px 12px;
  border-radius: 99px;
}

/* Breath overlay */
.breath-overlay {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
}

.breath-circle {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: var(--accent-grad);
  opacity: 0.85;
  animation: breathePulse 3s ease-in-out infinite;
}

@keyframes breathePulse {
  0%, 100% { transform: scale(0.75); opacity: 0.5; }
  50% { transform: scale(1.25); opacity: 0.95; }
}

.breath-text {
  font-size: calc(1.2rem * var(--scale));
  font-weight: 700;
  color: var(--text-main);
}

/* Ergonomic stage: keeps math task right above thumb buttons */
.game-ergonomic-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 16px;
  padding-bottom: 6px;
}

body[data-hand="right"] .game-ergonomic-stage {
  align-items: flex-end;
}

body[data-hand="left"] .game-ergonomic-stage {
  align-items: flex-start;
}

.problem-card {
  background: var(--bg-card);
  border: 2px solid var(--border-card);
  border-radius: 20px;
  padding: 18px 24px;
  min-width: 74%;
  text-align: center;
  transition: border-color 0.14s, transform 0.12s;
}

.problem-card.flash-correct {
  border-color: var(--success);
}

.problem-card.flash-wrong {
  border-color: var(--danger);
  animation: gentleShake 0.24s ease-in-out;
}

@keyframes gentleShake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-6px); }
  70% { transform: translateX(6px); }
}

.problem-hint {
  font-size: calc(0.76rem * var(--scale));
  color: var(--text-muted);
  margin-bottom: 4px;
}

.problem-expression {
  font-size: calc(2.2rem * var(--scale));
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.15;
}

.answers-column {
  display: flex;
  flex-direction: column;
  gap: 11px;
  width: 74%;
}

/* When large font steps are selected, expand width to 100% so big digits fit comfortably */
body[data-font-step="5"] .problem-card,
body[data-font-step="6"] .problem-card,
body[data-font-step="5"] .answers-column,
body[data-font-step="6"] .answers-column {
  width: 100%;
}

.answer-btn {
  background: var(--bg-card);
  color: var(--text-main);
  border: 2px solid var(--border-control);
  border-radius: 16px;
  padding: calc(14px * var(--scale)) 18px;
  font-size: calc(1.55rem * var(--scale));
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.08s, background 0.12s, border-color 0.12s;
}

.answer-btn:active {
  transform: scale(0.96);
  border-color: var(--accent-solid);
  background: var(--bg-control);
}

/* ==========================================
   SCREEN 3: RESULT
   ========================================== */
.result-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
}

.record-badge {
  background: var(--accent-grad);
  color: var(--accent-text);
  font-weight: 800;
  padding: 7px 16px;
  border-radius: 99px;
  font-size: calc(0.88rem * var(--scale));
}

.result-title {
  font-size: calc(1.35rem * var(--scale));
  font-weight: 800;
}

.score-ring {
  width: 156px;
  height: 156px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 4px solid var(--accent-solid);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  box-shadow: 0 10px 28px rgba(255, 142, 83, 0.18);
}

.score-big {
  font-size: calc(2.7rem * var(--scale));
  font-weight: 800;
  color: var(--accent-solid);
  line-height: 1;
}

.score-sub {
  font-size: calc(0.75rem * var(--scale));
  color: var(--text-muted);
  margin-top: 6px;
}

.result-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-label {
  font-size: calc(0.76rem * var(--scale));
  color: var(--text-muted);
}

.metric-val {
  font-size: calc(1.15rem * var(--scale));
  font-weight: 800;
}

.neuro-note {
  font-size: calc(0.8rem * var(--scale));
  color: var(--text-muted);
  line-height: 1.45;
  max-width: 320px;
}

.result-bottom-actions {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 12px;
  margin-top: auto;
}

.secondary-action-btn {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-control);
  border-radius: 16px;
  padding: 15px;
  font-size: calc(1rem * var(--scale));
  font-weight: 700;
  cursor: pointer;
}

/* ==========================================
   SETTINGS MODAL (Matches Screenshots)
   ========================================== */
.settings-modal {
  position: absolute;
  inset: 0;
  background: var(--bg-app);
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
}

.settings-header h2 {
  font-size: 1.35rem;
  font-weight: 800;
}

.settings-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 6px 18px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.setting-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 16px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.card-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-main);
}

.card-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.custom-select {
  width: 100%;
  background: var(--bg-control);
  color: var(--text-main);
  border: 1px solid var(--border-control);
  border-radius: 11px;
  padding: 11px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
}

/* Option Buttons inside Setting Cards */
.option-btn {
  background: var(--bg-control);
  color: var(--text-main);
  border: 1px solid var(--border-control);
  border-radius: 11px;
  padding: 11px 10px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.option-btn.active {
  background: var(--accent-solid);
  color: var(--accent-text);
  border-color: var(--accent-solid);
}

/* 6 Font Step Buttons + Live Preview */
.font-steps-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
}

.font-step-btn {
  height: 46px;
  padding: 0;
}

.font-preview-box {
  text-align: center;
  padding: 10px 0 4px;
  font-weight: 800;
  font-size: calc(1.75rem * var(--scale));
  color: var(--text-main);
  letter-spacing: 0.02em;
}

.grid-2x2, .grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.op-btn {
  font-size: 1.35rem;
  height: 48px;
}

.stack-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* iOS Style Switches */
.switches-card {
  gap: 14px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.switch-label {
  font-size: 0.92rem;
  font-weight: 700;
}

.ios-switch {
  appearance: none;
  -webkit-appearance: none;
  width: 48px;
  height: 28px;
  background: var(--bg-control);
  border: 1px solid var(--border-control);
  border-radius: 99px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.ios-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.2s cubic-bezier(0.2, 0.85, 0.32, 1.2);
}

.ios-switch:checked {
  background: var(--accent-solid);
  border-color: var(--accent-solid);
}

.ios-switch:checked::after {
  transform: translateX(20px);
}

/* Data Card Buttons */
.data-btns-row {
  margin-top: 2px;
}

.outline-btn {
  background: var(--bg-control);
  color: var(--text-main);
  border: 1px solid var(--border-control);
  border-radius: 11px;
  padding: 11px 10px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
}

.outline-btn:active {
  opacity: 0.8;
}

.danger-btn {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 11px;
  padding: 11px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 2px;
}

.danger-btn:active {
  background: rgba(255, 107, 107, 0.12);
}

.settings-footer {
  text-align: left;
  padding: 4px 4px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-footer p {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.version-tag {
  align-self: center;
  font-size: 0.76rem;
  color: var(--text-muted);
  opacity: 0.8;
}
