/* ==========================================================================
   Tieng Viet Tone Markers - light/dark themes, red shades, outlined yellow
   ========================================================================== */

/* ---------- Theme variables ---------- */
body[data-theme="light"] {
  --bg: #ffffff;
  --bg-alt: #fdf4f4;
  --panel: #ffffff;
  --panel-border: #d32f2f;
  --red: #c62828;
  --red-deep: #8e0000;
  --red-bright: #e53935;
  --red-soft: #fdecea;
  --text: #2a1111;
  --text-dim: #8a6363;
  --yellow: #ffd400;
  --outline-color: #000000;
  --outline-shadows:
    2px 0 0 var(--outline-color), -2px 0 0 var(--outline-color),
    0 2px 0 var(--outline-color), 0 -2px 0 var(--outline-color),
    1.4px 1.4px 0 var(--outline-color), -1.4px 1.4px 0 var(--outline-color),
    1.4px -1.4px 0 var(--outline-color), -1.4px -1.4px 0 var(--outline-color);
  --outline-shadows-sm:
    1.2px 0 0 var(--outline-color), -1.2px 0 0 var(--outline-color),
    0 1.2px 0 var(--outline-color), 0 -1.2px 0 var(--outline-color);
  --bar-track: #f3d6d6;
  --track-off: #d9c9c9;
  --good: #1b5e20;
  --good-bright: #43a047;
  --bad: #b00020;
  --shadow: rgba(142, 0, 0, 0.22);
}

body[data-theme="dark"] {
  --bg: #0a0a0a;
  --bg-alt: #140d0d;
  --panel: #180e0e;
  --panel-border: #8e1c1c;
  --red: #ef5350;
  --red-deep: #b71c1c;
  --red-bright: #ff6f6a;
  --red-soft: #2a1414;
  --text: #f3e9e9;
  --text-dim: #c59b9b;
  --yellow: #ffe100;
  /* dark mode: yellow text needs no outline on black */
  --outline-color: transparent;
  --outline-shadows: none;
  --outline-shadows-sm: none;
  --bar-track: #3a1a1a;
  --track-off: #4a3030;
  --good: #81c784;
  --good-bright: #66bb6a;
  --bad: #ff8a80;
  --shadow: rgba(0, 0, 0, 0.6);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  transition: background 0.25s ease, color 0.25s ease;
}

.app {
  max-width: 880px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Outlined yellow text ---------- */
.outlined {
  color: var(--yellow);
  text-shadow: var(--outline-shadows);
  font-weight: 800;
}

.outlined-sm {
  color: var(--yellow);
  text-shadow: var(--outline-shadows-sm);
  font-weight: 700;
}

/* ---------- Header ---------- */
.app-header { text-align: center; }

.app-title {
  font-size: clamp(2rem, 6vw, 3.1rem);
  margin: 8px 0 4px;
  letter-spacing: 0.02em;
}

.app-tagline {
  margin: 0;
  color: var(--red);
  font-weight: 600;
  font-size: clamp(0.9rem, 2.5vw, 1.05rem);

  a {
    color: var(--text-dim);
  }
}

/* ---------- Screens ---------- */
.screen { display: none; }

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  animation: fadeUp 0.3s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.instruction {
  margin: 0;
  color: var(--text-dim);
  font-weight: 600;
  text-align: center;
}

.instruction small { font-weight: 500; opacity: 0.85; }

/* ---------- Rules card (menu screen only) ---------- */
.rules {
  width: 100%;
  max-width: 560px;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 18px;
  padding: 14px 22px 16px;
  box-shadow: 0 6px 18px var(--shadow);
}

.rules-title {
  margin: 0 0 10px;
  font-size: 1.1rem;
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: center;
}

.rules-list {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.92rem;
  line-height: 1.45;

  rli::marker { color: var(--red); font-weight: 800; }

  strong { color: var(--red); }

  table { 
    width: 100%; 
  }
  table td {
    border: 1px dashed;
    padding: 4px 10px;
  }
}


.rules-note {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--text-dim);
  text-align: center;
}

/* ---------- Session score ---------- */
.session-bar {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 6px 18px;
  border: 2px solid var(--red);
  border-radius: 999px;
  background: var(--red-soft);
}

.session-label {
  font-weight: 700;
  color: var(--red);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
}

.session-score { font-size: 1.3rem; min-width: 1.5em; text-align: center; }

.results-session {
  font-size: 1.05rem;
  font-weight: 600;
}

/* ---------- Tone legend (menu) ---------- */
.tone-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.tone-mini {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 72px;
  padding: 8px 10px;
  border: 2px solid var(--red);
  border-radius: 12px;
  background: var(--red-soft);
}

.tone-mini-glyph {
  font-size: 1.6rem;
  line-height: 1.1;
  color: var(--yellow);
  text-shadow: var(--outline-shadows-sm);
  font-weight: 700;
}

.tone-mini-name { font-size: 0.78rem; font-weight: 700; color: var(--red); }
.tone-mini-ex   { font-size: 0.72rem; color: var(--text-dim); }

/* ---------- Settings panel ---------- */
.panel {
  width: 100%;
  max-width: 540px;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 18px;
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 6px 18px var(--shadow);
}

.panel-title {
  margin: 0;
  font-size: 1.15rem;
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: center;
}

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

.setting.row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setting-label { font-weight: 700; }

.setting-value {
  color: var(--red);
  font-variant-numeric: tabular-nums;
}

.setting-note { font-weight: 500; color: var(--text-dim); font-size: 0.85em; }

/* Skill buttons */
.skill-group { display: flex; gap: 8px; }

.skill-btn {
  flex: 1;
  padding: 10px 6px;
  border: 2px solid var(--red);
  border-radius: 12px;
  background: transparent;
  color: var(--red);
  font-size: 1.15rem;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.skill-sub { display: block; font-size: 0.68rem; font-weight: 600; opacity: 0.85; }

.skill-btn:hover { transform: translateY(-2px); }

.skill-btn.active {
  background: linear-gradient(150deg, var(--red-bright), var(--red-deep));
  border-color: var(--red-deep);
  color: #ffffff;
}

.skill-btn.active .skill-sub { color: #ffffff; }

/* Slider */
input[type="range"] {
  width: 100%;
  accent-color: var(--red);
  cursor: pointer;
  height: 28px;
}

.slider-ends {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: -4px;
}

/* Toggle */
.toggle {
  position: relative;
  width: 62px;
  height: 34px;
  border-radius: 999px;
  border: 2px solid var(--red);
  background: var(--track-off);
  cursor: pointer;
  padding: 0;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.toggle-knob {
  position: absolute;
  top: 2px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  transition: left 0.2s ease;
}

.toggle.on { background: linear-gradient(150deg, var(--red-bright), var(--red-deep)); }
.toggle.on .toggle-knob { left: 31px; }

/* Theme button */
.theme-btn {
  padding: 8px 16px;
  border: 2px solid var(--red);
  border-radius: 12px;
  background: transparent;
  color: var(--red);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.theme-btn:hover { transform: translateY(-2px); background: var(--red-soft); }

/* ---------- Buttons ---------- */
.btn-primary {
  border: 3px solid var(--red-deep);
  border-radius: 16px;
  padding: 14px 34px;
  font-size: 1.25rem;
  font-family: inherit;
  cursor: pointer;
  background: linear-gradient(150deg, var(--red-bright), var(--red-deep));
  box-shadow: 0 5px 0 var(--red-deep), 0 8px 16px var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn-primary:hover { transform: translateY(-2px); }

.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--red-deep);
}

.btn-big { font-size: 1.3rem; padding: 15px 40px; }

.btn-secondary {
  padding: 10px 22px;
  border: 2px solid var(--red);
  border-radius: 12px;
  background: transparent;
  color: var(--red);
  font-weight: 700;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.btn-secondary:hover { transform: translateY(-2px); background: var(--red-soft); }

/* ---------- Progress bars ---------- */
.progress {
  width: 100%;
  max-width: 640px;
  height: 12px;
  background: var(--bar-track);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--red);
}

.progress-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--red-bright), var(--red-deep));
  border-radius: 999px;
}

/* ---------- Preparation screen ---------- */
.prep-count-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.prep-count { font-size: 3rem; line-height: 1; min-width: 2.2em; text-align: center; }

.prep-progress { max-width: 420px; }

.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  width: 100%;
}

.word-card {
  background: var(--red-soft);
  border: 2px solid var(--red);
  border-radius: 14px;
  padding: 14px 8px 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: popIn 0.35s ease backwards;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

.word-marked { font-size: 1.55rem; }

.word-meaning { font-size: 0.82rem; color: var(--text-dim); font-weight: 600; }

.word-tones { font-size: 0.72rem; color: var(--red); font-weight: 700; }

/* ---------- Quiz screen ---------- */
.quiz-top {
  width: 100%;
  max-width: 640px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-weight: 700;
  color: var(--text-dim);
  font-size: 0.95rem;
}

.word-countdown {
  color: var(--red);
  min-width: 3.6em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.quiz-word {
  font-size: clamp(3.2rem, 11vw, 5.6rem);
  line-height: 1.15;
  letter-spacing: 0.06em;
  text-align: center;
  margin-top: 6px;
}

/* Slow pulsating pink highlight on letters missing their tone mark */
.missing-tone {
  border-radius: 0.14em;
  padding: 0 0.06em;
  background-color: rgba(255, 170, 200, 0.3); /* static fallback if animation is disabled */
  animation: tonePulse 2s ease-in-out infinite both;
}

@keyframes tonePulse {
  0%, 100% { background-color: rgba(255, 170, 200, 0.25); }
  50%      { background-color: rgba(255, 105, 180, 0.65); }
}

/* Marker buttons: nine squares, shades of red */
.tone-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.tone-btn {
  position: relative;
  width: min(86px, 15vw);
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  border: 3px solid transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-family: inherit;
  padding: 4px;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.tone-btn:nth-child(1) { background: linear-gradient(160deg, #d32f2f, #8e0000); box-shadow: 0 4px 10px var(--shadow); }
.tone-btn:nth-child(2) { background: linear-gradient(160deg, #e53935, #b71c1c); box-shadow: 0 4px 10px var(--shadow); }
.tone-btn:nth-child(3) { background: linear-gradient(160deg, #c62828, #7f0000); box-shadow: 0 4px 10px var(--shadow); }
.tone-btn:nth-child(4) { background: linear-gradient(160deg, #ef5350, #b71c1c); box-shadow: 0 4px 10px var(--shadow); }
.tone-btn:nth-child(5) { background: linear-gradient(160deg, #b71c1c, #660000); box-shadow: 0 4px 10px var(--shadow); }
.tone-btn:nth-child(6) { background: linear-gradient(160deg, #c62828, #8e0000); box-shadow: 0 4px 10px var(--shadow); }
.tone-btn:nth-child(7) { background: linear-gradient(160deg, #d84343, #931111); box-shadow: 0 4px 10px var(--shadow); }
.tone-btn:nth-child(8) { background: linear-gradient(160deg, #a31515, #6d0000); box-shadow: 0 4px 10px var(--shadow); }
.tone-btn:nth-child(9) { background: linear-gradient(160deg, #e05252, #a02020); box-shadow: 0 4px 10px var(--shadow); }

.tone-btn:hover { transform: translateY(-3px); }

.tone-glyph {
  font-size: clamp(1.6rem, 5vw, 2.3rem);
  line-height: 1.15;
  color: var(--yellow);
  text-shadow: var(--outline-shadows);
  font-weight: 700;
}

.tone-name {
  font-size: 0.72rem;
  color: var(--yellow);
  text-shadow: var(--outline-shadows-sm);
  font-weight: 700;
}

.tone-example { font-size: 0.62rem; color: var(--yellow); opacity: 0.85; text-shadow: var(--outline-shadows-sm); }

.tone-btn.selected {
  border-color: var(--yellow);
  transform: scale(1.07);
  box-shadow: 0 0 0 4px rgba(255, 212, 0, 0.45);
}

.tone-btn.correct {
  background: linear-gradient(160deg, var(--good-bright), #1b5e20);
  border-color: var(--good);
}

.tone-btn.wrong {
  background: linear-gradient(160deg, #6d6d6d, #3a3a3a);
  border-color: #111;
  animation: shake 0.4s ease;
}

.tone-btn.missed {
  border: 3px dashed var(--yellow);
  animation: pulse 0.8s ease infinite;
}

.tone-btn.dim { opacity: 0.3; }

.tone-btn.correct::after,
.tone-btn.wrong::after {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.tone-btn.correct::after { content: "\2713"; background: #1b5e20; }
.tone-btn.wrong::after   { content: "\2715"; background: #b00020; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 212, 0, 0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(255, 212, 0, 0.15); }
}

/* Chips (current picks) */
.chips-label { font-size: 0.85rem; }

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  width: 100%;
  align-items: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 2px solid var(--red);
  border-radius: 999px;
  background: var(--red-soft);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.chip:hover { transform: scale(1.06); }

.chip-glyph {
  font-size: 1.15rem;
  color: var(--red);
  font-weight: 700;
}

.chip-x { color: var(--text-dim); font-weight: 500; }

.chips-empty { color: var(--text-dim); opacity: 0.6; font-weight: 600; }

/* Feedback */
.feedback {
  min-height: 3.6em;
  text-align: center;
  font-size: 1.1rem;
  line-height: 1.5;
}

.feedback strong { font-size: 1.25rem; }

.feedback.good strong { color: var(--good); }
.feedback.part strong { color: var(--red); }
.feedback.bad strong  { color: var(--bad); }

.reveal {
  display: block;
  margin-top: 4px;
  font-size: 0.92rem;
  color: var(--text-dim);
}

.reveal-word { color: var(--red); font-size: 1.05rem; }

/* ---------- Results screen ---------- */
.results-summary {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.results-score { display: flex; align-items: baseline; gap: 8px; }

.results-num { font-size: 4rem; line-height: 1; }

.results-denom { font-size: 1.8rem; color: var(--text-dim); font-weight: 700; }

.results-pct { color: var(--red); font-weight: 700; font-size: 1.05rem; }

.recap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
  width: 100%;
  max-width: 720px;
  margin-top: 10px;
}

.recap-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  border-left: 5px solid var(--text-dim);
  background: var(--bg-alt);
  font-size: 0.9rem;
}

.recap-item.ok   { border-left-color: var(--good); }
.recap-item.part { border-left-color: var(--yellow); }
.recap-item.miss { border-left-color: var(--bad); }

.recap-word { font-weight: 800; color: var(--red); font-size: 1.02rem; }

.recap-meaning { color: var(--text-dim); font-size: 0.78rem; }

.recap-tones { font-size: 0.78rem; color: var(--text-dim); }

.recap-pts { font-weight: 800; }

.recap-item.ok   .recap-pts { color: var(--good); }
.recap-item.part .recap-pts { color: var(--red); }
.recap-item.miss .recap-pts { color: var(--bad); }

.results-buttons { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }

/* ---------- Focus & motion ---------- */
:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
}
