/* ── Design tokens (mirrors the super-math trainer's system) ── */
:root {
  --ink-1:  #18181B;
  --ink-2:  #52525B;
  --ink-3:  #A1A1AA;
  --ink-4:  #D4D4D8;

  --blue:    #1D4ED8;
  --indigo:  #4F46E5;
  --emerald: #059669;
  --rose:    #DC2626;
  --amber:   #D97706;

  --surface: #FAFAF9;
  --card:    #FFFFFF;
  --border:  rgba(0,0,0,0.08);
  --fill:    rgba(0,0,0,0.05);
  --fill-2:  rgba(0,0,0,0.03);

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;

  --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
               "Helvetica Neue", "PingFang SC", Arial, sans-serif;
  background: var(--surface);
  color: var(--ink-1);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.app { max-width: 1080px; margin: 0 auto; padding: 28px 20px 48px; }

/* ── Header ── */
.app-header { text-align: center; padding: 8px 0 2px; }
.app-title { margin: 0; font-size: 32px; font-weight: 700; letter-spacing: -0.5px; color: var(--ink-1); }
.app-subtitle { margin: 6px 0 0; font-size: 14px; color: var(--ink-3); letter-spacing: 0.1px; }

/* ── Segmented control / nav ── */
.segmented-control {
  display: flex; background: rgba(0,0,0,0.06); border-radius: 9px;
  padding: 3px; margin: 20px auto; width: fit-content; min-width: 200px;
}
.seg-btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center;
  padding: 7px 26px; border: none; border-radius: 7px; font-size: 14px; font-weight: 500;
  cursor: pointer; background: transparent; color: var(--ink-2); transition: all 0.18s ease;
  font-family: inherit; text-decoration: none;
}
.seg-btn.active { background: var(--card); color: var(--ink-1); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.12); }

/* ── Card ── */
.card {
  background: var(--card); border-radius: var(--r-xl); padding: 24px 22px;
  box-shadow: var(--shadow-card); border: 1px solid var(--border); transition: box-shadow 0.3s ease;
}
.card.flash-correct { animation: cardFlashGreen 0.55s ease; }
.card.flash-wrong { animation: cardFlashRed 0.55s ease; }
.hidden { display: none !important; }

/* ── Start screen ── */
.start-view { display: flex; flex-direction: column; align-items: center; padding: 52px 20px 48px; }
.start-date { font-size: 14px; color: var(--ink-3); font-weight: 500; margin-bottom: 28px; }
.start-count { font-size: 96px; font-weight: 800; line-height: 1; letter-spacing: -4px; color: var(--ink-1); font-variant-numeric: tabular-nums; }
.start-unit { font-size: 22px; font-weight: 600; color: var(--ink-3); margin-top: 4px; margin-bottom: 44px; }
.btn-start {
  background: var(--ink-1); color: #fff; border: none; border-radius: var(--r-xl);
  padding: 16px 64px; font-size: 17px; font-weight: 600; font-family: inherit; cursor: pointer;
  transition: all 0.15s ease; min-height: 52px;
}
.btn-start:hover { background: #27272A; }
.btn-start:active { transform: scale(0.97); }

/* ── Practice header / progress ── */
.practice-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.progress-label { font-size: 13px; font-weight: 500; color: var(--ink-3); }
.progress-count { font-size: 13px; font-weight: 600; color: var(--indigo); font-variant-numeric: tabular-nums; }
.progress-track { height: 2px; background: var(--ink-4); border-radius: 1px; overflow: hidden; margin-bottom: 18px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--indigo), var(--blue)); border-radius: 1px; transition: width 0.5s cubic-bezier(0.25,1,0.5,1); }

.topic-chip { font-size: 12px; font-weight: 600; color: var(--indigo); background: rgba(79,70,229,0.08); border-radius: 999px; padding: 3px 10px; display: inline-block; margin-bottom: 14px; }

/* ── Countdown timer ── */
.timer-row { display: flex; justify-content: flex-end; margin: -4px 0 14px; }
.timer-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700;
  color: var(--ink-2); background: var(--fill); border-radius: 999px; padding: 4px 12px;
  font-variant-numeric: tabular-nums; transition: color 0.2s ease, background 0.2s ease;
}
.timer-pill::before { content: ""; width: 7px; height: 7px; border-radius: 999px; background: var(--emerald); flex-shrink: 0; }
.timer-pill.warn { color: var(--amber); background: rgba(217,119,6,0.1); }
.timer-pill.warn::before { background: var(--amber); }
.timer-pill.urgent { color: var(--rose); background: rgba(220,38,38,0.1); animation: timerPulse 1s ease-in-out infinite; }
.timer-pill.urgent::before { background: var(--rose); }
@keyframes timerPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* ── Question display ── */
.question-display { font-size: 19px; font-weight: 500; line-height: 1.65; padding: 8px 2px 26px; color: var(--ink-1); }
.question-display u { text-decoration-thickness: 2px; text-underline-offset: 3px; }
.blank-marker { display: inline-block; min-width: 64px; border-bottom: 2px solid var(--ink-3); }

.seg-label {
  display: inline-block; font-size: 10px; font-weight: 700; color: var(--indigo);
  vertical-align: super; margin-left: 1px;
}
.seg-underline { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }

/* ── Options (multiple choice) ── */
.option-list { display: flex; flex-direction: column; gap: 10px; }
.option-btn {
  display: flex; align-items: flex-start; gap: 12px; text-align: left;
  background: var(--fill); border: 1.5px solid transparent; border-radius: var(--r-md);
  padding: 13px 16px; font-size: 15px; font-family: inherit; color: var(--ink-1);
  cursor: pointer; transition: all 0.15s ease; width: 100%;
}
.option-btn:hover { background: rgba(0,0,0,0.07); }
.option-btn:active { transform: scale(0.99); }
.option-letter {
  flex-shrink: 0; width: 24px; height: 24px; border-radius: 999px; background: var(--card);
  border: 1.5px solid var(--ink-4); display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--ink-2);
}
.option-text { flex: 1; padding-top: 2px; }

.option-btn.picked { border-color: rgba(79,70,229,0.45); background: rgba(79,70,229,0.07); }
.option-btn.picked .option-letter { background: var(--indigo); border-color: var(--indigo); color: #fff; }

.option-btn.correct { border-color: rgba(5,150,105,0.5); background: rgba(5,150,105,0.09); }
.option-btn.correct .option-letter { background: var(--emerald); border-color: var(--emerald); color: #fff; }
.option-btn.wrong { border-color: rgba(220,38,38,0.5); background: rgba(220,38,38,0.08); }
.option-btn.wrong .option-letter { background: var(--rose); border-color: var(--rose); color: #fff; }
.option-btn:disabled { cursor: default; }

/* ── Feedback / explanation ── */
.feedback-panel { margin-top: 18px; padding: 16px 16px 18px; border-radius: var(--r-lg); background: var(--fill-2); border: 1px solid var(--border); }
.feedback-line { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.feedback-ok { color: var(--emerald); }
.feedback-wrong { color: var(--rose); }
.explanation { font-size: 14px; line-height: 1.65; color: var(--ink-2); }
.penalty-note { margin-top: 10px; font-size: 12px; color: var(--rose); font-weight: 600; }

.btn-next {
  display: block; width: 100%; margin-top: 14px; background: var(--ink-1); color: #fff;
  border: none; border-radius: var(--r-md); padding: 13px 0; font-size: 15px; font-weight: 700;
  font-family: inherit; cursor: pointer;
}
.btn-next:active { transform: scale(0.98); }

/* ── Completed: wrong-answer review ── */
.review-item { text-align: left; padding: 18px 0; border-top: 1px solid var(--border); }
.review-item:first-child { border-top: none; }

/* ── Completed ── */
.completed-view { text-align: center; padding: 48px 16px; }
.completed-icon { font-size: 52px; margin-bottom: 16px; line-height: 1; }
.completed-title { font-size: 24px; font-weight: 700; margin: 0 0 8px; letter-spacing: -0.5px; }
.completed-stats { font-size: 15px; color: var(--ink-2); margin: 0 0 6px; }
.completed-note { font-size: 13px; color: var(--ink-3); margin: 0 0 28px; }
.btn-secondary {
  background: var(--fill); color: var(--ink-1); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 11px 26px; font-size: 14px; font-weight: 600; font-family: inherit; cursor: pointer;
  transition: all 0.15s ease; min-height: 40px;
}
.btn-secondary:hover { background: rgba(0,0,0,0.08); }
.btn-secondary:active { transform: scale(0.97); }

/* ── Stats layout ── */
.stats-grid-top { display: grid; grid-template-columns: 210px 1fr; gap: 12px; margin-bottom: 12px; }
.ability-card { background: var(--card); border-radius: var(--r-xl); padding: 22px 18px; box-shadow: var(--shadow-card); border: 1px solid var(--border); }
.ability-ovr { text-align: center; padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.ovr-number { font-size: 66px; font-weight: 800; letter-spacing: -3px; line-height: 1; color: var(--indigo); font-variant-numeric: tabular-nums; }
.ovr-label { font-size: 10px; font-weight: 600; letter-spacing: 1.5px; color: var(--ink-3); text-transform: uppercase; margin-top: 5px; }

.topic-panel { background: var(--card); border-radius: var(--r-xl); padding: 18px 16px; box-shadow: var(--shadow-card); border: 1px solid var(--border); }
.panel-header { font-size: 11px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 12px; }
.topic-items { display: flex; flex-direction: column; max-height: 220px; overflow-y: auto; }
.topic-item { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--fill); font-size: 13px; gap: 10px; }
.topic-item:last-child { border-bottom: none; }
.topic-item-left { font-weight: 600; color: var(--ink-1); white-space: nowrap; }
.topic-item-bar { flex: 1; height: 4px; background: var(--fill); border-radius: 2px; overflow: hidden; }
.topic-item-bar-fill { height: 100%; border-radius: 2px; background: var(--indigo); }

.rating-chip { display: inline-flex; align-items: center; border-radius: 4px; padding: 1px 7px; font-size: 11px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip-hi { color: #059669; background: rgba(5,150,105,0.09); }
.chip-mid { color: var(--ink-2); background: var(--fill); }
.chip-lo { color: #DC2626; background: rgba(220,38,38,0.08); }

.stats-layout { display: grid; grid-template-columns: minmax(250px, 33%) 1fr; gap: 12px; }
.stats-panel { background: var(--card); border-radius: var(--r-xl); padding: 16px; box-shadow: var(--shadow-card); border: 1px solid var(--border); display: flex; flex-direction: column; }

.day-list { display: flex; flex-direction: column; flex: 1; min-height: 0; max-height: 540px; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.day-card { display: block; background: transparent; border: none; border-radius: var(--r-lg); padding: 10px 12px; cursor: pointer; transition: background 0.15s ease; text-align: left; width: 100%; font-family: inherit; border-bottom: 1px solid var(--fill); }
.day-card:last-child { border-bottom: none; }
.day-card:hover { background: var(--fill); }
.active-day-card { background: rgba(79,70,229,0.07) !important; border-radius: var(--r-lg); }
.day-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3px; }
.day-card-date { font-size: 13px; font-weight: 600; color: var(--ink-1); font-variant-numeric: tabular-nums; }
.day-card-overview { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-3); }

.detail-panel { display: flex; flex-direction: column; height: 100%; }
.detail-summary { padding-bottom: 12px; margin-bottom: 4px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.detail-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.detail-meta-count { font-size: 12px; color: var(--ink-2); font-weight: 500; }
.detail-acc-bar { height: 3px; background: var(--fill); border-radius: 2px; overflow: hidden; }
.detail-acc-fill { height: 100%; border-radius: 2px; background: var(--indigo); transition: width 0.6s cubic-bezier(0.25,1,0.5,1); }

.question-list { flex: 1; max-height: 490px; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.question-item { padding: 10px 4px; border-bottom: 1px solid var(--fill); font-size: 13px; }
.question-item:last-child { border-bottom: none; }
.q-item-top { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.q-index { font-size: 11px; color: var(--ink-3); min-width: 20px; font-variant-numeric: tabular-nums; }
.q-topic { font-size: 11px; color: var(--ink-3); font-weight: 600; }
.q-mark { margin-left: auto; font-size: 12px; font-weight: 700; }
.q-mark.ok { color: var(--emerald); }
.q-mark.no { color: var(--rose); }
.q-stem { color: var(--ink-2); font-size: 13px; line-height: 1.5; }
.q-empty { text-align: center; padding: 32px 0; font-size: 13px; color: var(--ink-3); }

.ok-text { color: var(--emerald); font-weight: 600; }
.error-text { color: var(--rose); font-weight: 600; }

@keyframes cardFlashGreen { 0% { box-shadow: 0 0 0 2px rgba(5,150,105,0.45), var(--shadow-card); } 100% { box-shadow: var(--shadow-card); } }
@keyframes cardFlashRed { 0% { box-shadow: 0 0 0 2px rgba(220,38,38,0.45), var(--shadow-card); } 100% { box-shadow: var(--shadow-card); } }

@media (min-width: 768px) {
  .app { padding: 36px 32px 64px; }
  .app-title { font-size: 36px; }
  #practiceView { max-width: 640px; margin: 0 auto; }
  .card { padding: 30px 28px; }
  .question-display { font-size: 21px; }
}

@media (max-width: 767px) {
  .stats-grid-top { grid-template-columns: 1fr; }
  .stats-layout { grid-template-columns: 1fr; }
  .day-list { max-height: 240px; }
  .ability-card { display: grid; grid-template-columns: 110px 1fr; gap: 20px; align-items: center; }
  .ability-ovr { border-bottom: none; border-right: 1px solid var(--border); padding-bottom: 0; margin-bottom: 0; padding-right: 20px; }
  .ovr-number { font-size: 52px; }
}

@media (max-width: 480px) {
  .ability-card { grid-template-columns: 1fr; }
  .ability-ovr { border-right: none; border-bottom: 1px solid var(--border); padding-right: 0; padding-bottom: 14px; margin-bottom: 14px; }
}
