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

:root {
  --bg: #0a0a0f;
  --surface: #14141e;
  --surface2: #1e1e2e;
  --border: #2a2a3e;
  --text: #e4e4ef;
  --text-dim: #8888a0;
  --accent: #6c5ce7;
  --accent2: #a78bfa;
  --accent-glow: rgba(108, 92, 231, 0.3);
  --correct: #00c853;
  --correct-bg: rgba(0, 200, 83, 0.12);
  --wrong: #ff5252;
  --wrong-bg: rgba(255, 82, 82, 0.12);
  --mode-color: #6c5ce7;
  --mode-glow: rgba(108, 92, 231, 0.3);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.container { width: 100%; max-width: 600px; }

.header { text-align: center; margin-bottom: 12px; }
.header h1 {
  font-size: 14px; font-weight: 500; color: var(--text-dim);
  letter-spacing: 2px; text-transform: uppercase;
}



.stats-bar {
  display: flex; justify-content: center; gap: 24px;
  margin-bottom: 24px; font-size: 12px; color: var(--text-dim);
}
.stats-bar .stat { display: flex; align-items: center; gap: 5px; }
.stats-bar .stat-val { color: var(--text); font-weight: 600; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 40px 16px 36px; text-align: center;
  position: relative; overflow: hidden;
}
/* Top accent line removed for minimal UI */

/* Transition envelope for question content */
.card-content {
  transition: opacity 0.08s ease-out;
  opacity: 1;
}
.card-content.dimmed {
  opacity: 0.25;
  pointer-events: none;
}

/* Dimming for the stimulus while drawing characters */
.phrase-stimulus.rendering-dimmed,
#glyph-target.rendering-dimmed {
  opacity: 0.25;
  pointer-events: none;
}
.phrase-stimulus,
#glyph-target {
  transition: opacity 0.15s ease-out;
}

/* Mode badge */
.mode-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1.5px; padding: 4px 14px; border-radius: 100px;
  margin-bottom: 20px; transition: all 0.3s;
  color: var(--mode-color); background: rgba(108, 92, 231, 0.1);
  border: 1px solid rgba(108, 92, 231, 0.2);
}
.mode-badge.reading { color: #6c5ce7; background: rgba(108, 92, 231, 0.1); border-color: rgba(108, 92, 231, 0.2); }
.mode-badge.phrase  { color: #e17055; background: rgba(225, 112, 85, 0.1); border-color: rgba(225, 112, 85, 0.2); }
.mode-badge.visual  { color: #a78bfa; background: rgba(167, 139, 250, 0.1); border-color: rgba(167, 139, 250, 0.2); }
.mode-badge.aural   { color: #6dd5fa; background: rgba(109, 213, 250, 0.1); border-color: rgba(109, 213, 250, 0.2); }
.mode-badge.comprehension { color: #2dd4bf; background: rgba(45, 212, 191, 0.1); border-color: rgba(45, 212, 191, 0.2); }

/* Phrase mode: stimulus display */
.phrase-stimulus {
  display: flex; align-items: center; justify-content: center;
  gap: 4px; flex-wrap: wrap;
  margin: 24px 0 20px; line-height: 1.5;
}
/* VN words are multi-syllable space-form units — a real word gap (flex drops the
   inter-element whitespace; 4px runs them together). zh keeps the tight 4px. */
body.lang-vi .phrase-stimulus { gap: 0.5em; }
.phrase-word {
  display: inline-flex; align-items: center;
}
/* Plain text rendering (high C words) */
.phrase-word-text {
  font-size: 36px;
  letter-spacing: 0.04em;
  color: var(--text);
}
/* Decomposed glyph inside a phrase word */
.phrase-word .glyph-decomposed {
  margin-bottom: 0;
}
.phrase-word .glyph-decomposed svg {
  width: 36px; height: 36px;
}
/* Target word highlighted in phrase stimulus */
.phrase-target-highlight {
  background: rgba(225, 112, 85, 0.12);
  border: 1px solid rgba(225, 112, 85, 0.50);
  border-radius: 6px;
  padding: 4px 8px;
  box-shadow: 0 0 12px rgba(225, 112, 85, 0.18);
  margin: 0 -4px;
}
/* Base style for aural characters — no transitions, we control via classes */
.aural-char {
  border-radius: 4px;
}
/* Active highlight: background glow only, foreground colors preserved */
.char-highlight {
  background: var(--mode-glow) !important;
  box-shadow: 0 0 14px var(--mode-glow);
  animation: charAttack 150ms ease-out forwards;
}
@keyframes charAttack {
  from { background: transparent; box-shadow: 0 0 0 transparent; }
  to   { background: var(--mode-glow); box-shadow: 0 0 14px var(--mode-glow); }
}
/* Decay: fades out after highlight is removed */
.char-decay {
  animation: charDecay 200ms ease-in forwards;
}
@keyframes charDecay {
  from { background: var(--mode-glow); box-shadow: 0 0 14px var(--mode-glow); }
  to   { background: transparent; box-shadow: 0 0 0 transparent; }
}
/* Target word indicator after phrase: · 在 */
.phrase-target-indicator {
  color: #fff; white-space: nowrap;
}
/* Contextual word meaning in choices: · at */
.tw-gloss {
  color: inherit;
}
.choice-arrow {
  color: var(--text-dim);
  margin: 0 2px;
}
/* Phrase choice: sentence gloss on second line */
.sentence-line {
  display: block;
  margin-top: 3px;
  margin-left: 34px;
  font-size: 13px;
  opacity: 0.85;
}
.sentence-prefix {
  color: var(--text-dim);
}
/* Phrase choices use 15px main text */
.phrase-choice-text {
  font-size: 15px;
}
.kanji-bracket {
  color: var(--text-dim);
  margin-left: 2px;
  margin-right: 2px;
  font-size: 0.95em;
  opacity: 0.50;
}
.kanji-text {
  font-family: 'Noto Serif SC', serif;
  color: #fff;
  font-weight: 600;
  font-size: 0.95em;
  opacity: 0.75;
}

/* Reading mode: glyph */
.glyph {
  font-family: 'Noto Serif SC', serif; font-size: 88px; font-weight: 400;
  line-height: 1.2; margin-bottom: 8px; min-height: 106px;
  background: linear-gradient(135deg, #fff 0%, #c4b5fd 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text; filter: drop-shadow(0 0 40px var(--mode-glow));
}
/* Reserve space for async SVG decomposition rendering.
   136px covers: 88px SVG + 8px margin + legend (~38px when C < 0.375) */
#glyph-target {
  min-height: 136px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}

/* Decomposed glyph container */
.glyph-decomposed {
  display: flex; align-items: center; justify-content: center;
  gap: 4px; margin-bottom: 8px;
  filter: drop-shadow(0 0 40px var(--mode-glow));
}
.glyph-decomposed svg {
  width: 88px; height: 88px;
  transition: opacity 0.08s;
}
.glyph-decomposed svg.char-dimmed {
  opacity: 0.45;
}

/* VN morpheme-breakdown scaffold (syllable → Hán → gloss, dimmed by competence) */
.morpheme-breakdown { gap: 18px; flex-wrap: wrap; }
.morpheme-cell {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 2px; transition: opacity 0.08s;
}
.morpheme-cell.char-dimmed { opacity: 0.4; }
.morpheme-syl { font-size: 2.1rem; font-weight: 600; color: var(--text); line-height: 1.05; }
.morpheme-han { font-size: 1.05rem; color: var(--muted, #8a8a8a); font-family: 'Noto Serif SC', serif; }
.morpheme-gloss { font-size: 0.78rem; color: var(--muted, #8a8a8a); max-width: 96px; line-height: 1.15; }

/* Component legend */
.comp-legend {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; flex-wrap: wrap;
  font-size: 12px; color: var(--text-dim);
  margin-bottom: 16px; margin-top: 4px;
}
.comp-legend-item {
  display: inline-flex; align-items: center; gap: 4px;
}
.comp-legend-dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
}
.comp-legend-char {
  font-family: 'Noto Serif SC', serif; font-size: 14px; font-weight: 500;
  color: var(--text);
}
.comp-legend-role {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  opacity: 0.7;
}

/* Visual mode: meaning prompt */
.meaning {
  font-size: 26px; font-weight: 700; margin-bottom: 6px;
  background: linear-gradient(135deg, #fff 0%, #a78bfa 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.prompt-label {
  font-size: 12px; color: var(--text-dim); margin-bottom: 24px;
  text-transform: uppercase; letter-spacing: 1.5px;
}

/* Comprehension mode: English gloss prompt + Chinese sentence options (inverted shape) */
.comp-prompt {
  font-size: 26px; font-weight: 700; margin-bottom: 6px; line-height: 1.35;
  background: linear-gradient(135deg, #fff 0%, #5eead4 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.comp-sentence {
  font-family: 'Noto Serif SC', serif;
  font-size: 24px; font-weight: 500; letter-spacing: 0.04em;
  vertical-align: middle;
}

/* Aural mode: floating play button */
.play-bar {
  position: fixed;
  bottom: 120px;
  right: 48px;
  z-index: 999;
  display: none; /* shown only in aural mode */
}
.play-bar.visible { display: flex; align-items: center; justify-content: center; }
.play-bar-btn {
  width: 104px;
  height: 52px; border-radius: 26px;
  border: 1px solid rgba(109, 213, 250, 0.4);
  background: rgba(109, 213, 250, 0.15);
  color: #6dd5fa; cursor: pointer;
  transition: all 0.2s;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  font-family: 'Inter', sans-serif; font-weight: 500;
  -webkit-tap-highlight-color: transparent;
  opacity: 0.8;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.play-bar-btn:active {
  transform: scale(0.95);
  background: rgba(109, 213, 250, 0.25);
}
@media (hover: hover) and (pointer: fine) {
  .play-bar-btn:hover {
    opacity: 1;
    background: rgba(109, 213, 250, 0.25);
    border-color: rgba(109, 213, 250, 0.6);
    box-shadow: 0 0 20px rgba(109, 213, 250, 0.2);
  }
}
.play-bar-btn.playing {
  border-color: rgba(109, 213, 250, 0.6);
  background: rgba(109, 213, 250, 0.25);
  opacity: 1;
  animation: playBarPulse 1s ease-in-out infinite alternate;
}
@keyframes playBarPulse {
  from { box-shadow: 0 0 12px rgba(109, 213, 250, 0.2); }
  to   { box-shadow: 0 0 28px rgba(109, 213, 250, 0.4); }
}
.play-bar-icon {
  font-size: 18px; line-height: 1;
  font-family: 'Inter', sans-serif;
  color: inherit; 
  display: inline-block;
  transition: transform 0.2s;
}
.play-bar-label {
  display: block; 
  font-size: 11px; 
  letter-spacing: 1px; 
  text-transform: uppercase;
}

/* Aural mode: option Chinese character styling */
.aural-opt-word {
    font-family: 'Noto Serif SC', serif;
    font-size: 20px;
    font-weight: 600;
    margin-right: 8px;
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
}
.aural-opt-word .glyph-decomposed {
    display: inline-flex;
    vertical-align: middle;
}
.aural-opt-word .glyph-decomposed svg {
    width: 24px;
    height: 24px;
}
.aural-opt-word .glyph-decomposed .fallback-text {
    font-size: 24px;
}
#glyph-target .glyph-decomposed .fallback-text {
    font-size: 88px;
}
.aural-opt-gloss {
    font-size: 14px;
    color: var(--text);
    opacity: 0.9;
}

.rank-badge {
  display: inline-block; font-size: 11px; color: var(--text-dim);
  background: var(--surface2); padding: 3px 10px; border-radius: 100px;
  margin-bottom: 24px;
}

/* Text options (reading + aural) */
.options { display: flex; flex-direction: column; gap: 10px; }
.option-btn {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 8px; color: var(--text);
  font-family: 'Inter', sans-serif; font-size: 16px; font-weight: 500;
  cursor: pointer; transition: all 0.2s; text-align: left;
  position: relative; overflow: hidden;
}
@media (hover: hover) and (pointer: fine) {
  .option-btn:hover:not(.disabled) {
    border-color: var(--mode-color); background: rgba(108, 92, 231, 0.08);
    transform: translateX(4px);
  }
}
.option-btn .key {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 6px;
  background: rgba(255,255,255,0.06); font-size: 13px; font-weight: 600;
  margin-right: 8px; color: var(--text-dim);
  position: relative;
}
.option-btn.correct-choice { border-color: var(--correct); background: var(--correct-bg); }
.option-btn.wrong-choice   { border-color: var(--wrong); background: var(--wrong-bg); }
.option-btn.reveal-correct { border-color: var(--correct); background: var(--correct-bg); opacity: 0.7; }
.option-btn.disabled       { cursor: default; opacity: 0.5; }

/* Visual options (SVG cards in 2x2 grid) */
.options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.option-card {
  background: var(--surface2); border: 2px solid var(--border);
  border-radius: 14px; padding: 16px 12px; cursor: pointer;
  transition: all 0.2s; position: relative;
  display: flex; flex-direction: column; align-items: center; min-height: 120px;
}
@media (hover: hover) and (pointer: fine) {
  .option-card:hover:not(.disabled) {
    border-color: var(--accent2); background: rgba(167, 139, 250, 0.06);
    transform: translateY(-2px); box-shadow: 0 4px 20px rgba(167, 139, 250, 0.15);
  }
}
.option-card .key-label {
  position: absolute; top: 8px; left: 10px; font-size: 11px; font-weight: 600;
  color: var(--text-dim); background: rgba(255,255,255,0.05);
  width: 22px; height: 22px; display: flex; align-items: center;
  justify-content: center; border-radius: 5px;
}
.option-card.correct-choice { border-color: var(--correct); background: var(--correct-bg); }
.option-card.wrong-choice   { border-color: var(--wrong); background: var(--wrong-bg); }
.option-card.reveal-correct { border-color: var(--correct); background: var(--correct-bg); opacity: 0.7; }
.option-card.disabled       { cursor: default; opacity: 0.4; }

.char-svg-container {
  display: flex; align-items: center; justify-content: center; gap: 4px; flex: 1;
}
.char-svg-container svg { width: 72px; height: 72px; }
.char-svg-container svg path { fill: var(--text); stroke: none; }

/* Struck-out previous wrong choices — only the word text is red; box looks normal */
.option-btn.struck {
  cursor: default; pointer-events: none;
}
.option-btn.struck .struck-text { color: var(--wrong); }
.struck-orig-sentence {
  display: block; color: rgba(255,255,255,0.35);
  margin-top: 2px; margin-left: 34px; font-style: italic;
}
/* Diagonal slash through the key badge only */
.option-btn.struck .key::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 141%; height: 2px;
  background: var(--wrong);
  border-radius: 1px;
  transform: translate(-50%, -50%) rotate(45deg);
  opacity: 0.85;
}
.option-card.struck {
  cursor: default; pointer-events: none;
}
.option-card.struck .char-svg-container svg path {
  fill: var(--wrong);
}

.loading {
  text-align: center; color: var(--text-dim); font-size: 16px; padding: 80px 0;
}
.loading .spinner {
  display: inline-block; width: 24px; height: 24px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite; margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: fadeIn 0.35s ease-out; }
/* Initial load only — after first question, transitions use .card-content opacity */
.card-content.initial-load { animation: fadeIn 0.35s ease-out; }

/* ─── Debug Panel ────────────────────────────────────── */
.debug-panel {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.6;
  transition: all 0.3s;
}
.debug-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; cursor: pointer;
  background: var(--surface); border: none; color: var(--text-dim);
  font-family: 'Inter', sans-serif; font-size: 12px;
  width: 100%; text-align: left; transition: all 0.2s;
  letter-spacing: 1px; text-transform: uppercase; font-weight: 600;
}
@media (hover: hover) and (pointer: fine) {
  .debug-toggle:hover { color: var(--text); background: var(--surface2); }
}
.debug-toggle .chevron {
  transition: transform 0.3s; font-size: 10px;
}
.debug-toggle .chevron.open { transform: rotate(180deg); }
.debug-toggle .shortcut {
  font-size: 10px; opacity: 0.5; font-weight: 400;
  background: rgba(255,255,255,0.06); padding: 2px 6px;
  border-radius: 4px; margin-left: 8px;
}
.debug-body {
  max-height: 0; overflow: hidden; transition: max-height 0.4s ease-out;
}
.debug-body.open {
  max-height: 4000px; overflow-y: auto;
}
.debug-section {
  border-top: 1px solid var(--border); padding: 14px 18px;
}
.debug-section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.5px; color: var(--accent); margin-bottom: 10px;
  display: flex; align-items: center; gap: 6px;
}
.debug-section-title .icon { font-style: normal; }
.debug-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px;
}
.debug-grid.three-col {
  grid-template-columns: 1fr 1fr 1fr;
}
.debug-item {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 2px 0;
}
.debug-key {
  color: var(--text-dim); font-size: 11px;
}
.debug-val {
  color: var(--text); font-weight: 600; font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
}
.debug-val.highlight { color: var(--accent); }
.debug-val.correct-color { color: var(--correct); }
.debug-val.warn-color { color: #ffa726; }

/* Modality probability bar */
.modality-bar {
  display: flex; height: 6px; border-radius: 3px; overflow: hidden;
  margin: 8px 0 4px; background: var(--surface2);
}
.modality-bar .seg {
  height: 100%; transition: width 0.3s;
}
.modality-bar .seg.reading { background: #6c5ce7; }
.modality-bar .seg.visual { background: #a78bfa; }
.modality-bar .seg.aural { background: #6dd5fa; }

/* Character competence bars */
.char-bar-row {
  display: flex; align-items: center; gap: 8px; margin: 4px 0;
}
.char-bar-label {
  font-family: 'Noto Serif SC', serif; font-size: 16px;
  font-weight: 400; min-width: 24px; text-align: center;
}
.char-bar-track {
  flex: 1; height: 8px; background: var(--surface2); border-radius: 4px;
  overflow: hidden; position: relative;
}
.char-bar-fill {
  height: 100%; border-radius: 4px; transition: width 0.5s ease-out;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}
.char-bar-fill.aural {
  background: linear-gradient(90deg, #2193b0, #6dd5fa);
}
.char-bar-value {
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 10px;
  color: var(--text-dim); min-width: 36px; text-align: right;
}

/* Top candidates table */
.candidates-table {
  width: 100%; border-collapse: collapse; font-size: 11px;
}
.candidates-table th {
  text-align: left; padding: 4px 6px; color: var(--text-dim);
  font-weight: 500; border-bottom: 1px solid var(--border);
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
}
.candidates-table td {
  padding: 4px 6px; border-bottom: 1px solid rgba(42, 42, 62, 0.4);
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.candidates-table tr.is-target {
  background: rgba(108, 92, 231, 0.1);
}
.candidates-table tr.is-target td:first-child {
  color: var(--accent); font-weight: 700;
}
.candidates-table .glyph-col {
  font-family: 'Noto Sans SC', sans-serif; font-size: 14px; font-weight: 700;
}

/* Pool stats mini cards */
.pool-cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 8px;
}
.pool-card {
  background: var(--surface2); border-radius: 8px; padding: 10px;
  text-align: center;
}
.pool-card .pc-val {
  font-size: 20px; font-weight: 700; color: var(--text);
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.pool-card .pc-label {
  font-size: 9px; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 0.5px; margin-top: 2px;
}

/* ─── Flag Defect Button ────────────────────────────────────── */
@keyframes flagFadeIn {
  0% { opacity: 0; }
  88.24% { opacity: 0.75; } /* 15s / 17s */
  100% { opacity: 0.25; } /* 17s / 17s */
}

.flag-btn {
  position: fixed;
  bottom: 16px;
  left: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0; /* Starts completely invisible */
  z-index: 1000;
  transition: transform 0.2s, background 0.2s, border-color 0.2s, color 0.2s, opacity 0.2s;
}

.flag-btn.question-active {
  /* Invisible for 5s, brightens to 0.75 over 15s, then drops to 0.25 over 2s */
  animation: flagFadeIn 17s linear 5s forwards;
}

/* In fullscreen mode, keep the unflagged button invisible but clickable */
body.fullscreen .flag-btn:not(.flagged) {
  opacity: 0 !important;
  animation: none !important;
}

@media (hover: hover) and (pointer: fine) {
  .flag-btn:hover {
    opacity: 1 !important; /* Override animation when hovered */
    background: var(--wrong-bg);
    border-color: var(--wrong);
    color: var(--wrong);
  }
}
.flag-btn:active {
  transform: scale(0.9);
}
.flag-btn.flagged {
  color: var(--correct);
  border-color: var(--correct);
  background: var(--correct-bg);
  opacity: 1 !important;
}
/* Hide system status when not in fullscreen */
body:not(.fullscreen) #sys-clock,
body:not(.fullscreen) #sys-battery {
  display: none !important;
}
