/* ============ Lisan design tokens ============ */
:root {
  --bg: #0f1418;
  --card: #161d24;
  --card-2: #1c242d;
  --line: #243039;
  --ink: #e8edf2;
  --ink-2: #9fb0bd;
  --muted: #66788a;
  --accent: #0ca678;        /* validated for dark surface */
  --accent-soft: rgba(12, 166, 120, 0.14);
  --accent-ink: #eafff7;
  --amber: #d97706;
  --amber-soft: rgba(217, 119, 6, 0.15);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.14);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f6f8;
    --card: #ffffff;
    --card-2: #eef1f4;
    --line: #dde3e9;
    --ink: #14202a;
    --ink-2: #45586a;
    --muted: #7a8a99;
    --accent: #059669;      /* validated for light surface */
    --accent-soft: rgba(5, 150, 105, 0.11);
    --accent-ink: #044632;
    --amber: #b45309;
    --amber-soft: rgba(180, 83, 9, 0.12);
    --red: #dc2626;
    --red-soft: rgba(220, 38, 38, 0.1);
    --shadow: 0 3px 12px rgba(20, 32, 42, 0.08);
  }
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Ethiopic", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior-y: contain;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; }
h1, h2, h3 { margin: 0 0 6px; line-height: 1.25; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p { margin: 0 0 10px; }

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 24px);
  min-height: 100vh;
}

.subtle { color: var(--ink-2); font-size: 14px; }
.tiny { color: var(--muted); font-size: 12.5px; }
.amharic { font-size: 14px; color: var(--ink-2); }

/* ============ Tab bar ============ */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 40;
}
.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
  -webkit-tap-highlight-color: transparent;
}
.tabbar a .tab-icon { font-size: 20px; line-height: 1; }
.tabbar a.active { color: var(--accent); font-weight: 600; }

/* ============ Cards, buttons, chips ============ */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card.flat { box-shadow: none; }
.card.accent { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-soft), var(--card)); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--ink);
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.06s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.btn.block { display: flex; width: 100%; }
.btn.small { padding: 7px 12px; font-size: 13.5px; border-radius: 10px; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.btn-row .btn { flex: 1; min-width: 120px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  color: var(--ink-2);
  margin: 0 6px 6px 0;
}
.chip b { color: var(--ink); font-weight: 700; }
.chip.good { border-color: var(--accent); background: var(--accent-soft); }
.chip.warn { border-color: var(--amber); background: var(--amber-soft); }

.badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px;
}

/* ============ Home ============ */
.hero { margin-bottom: 16px; }
.hero .selam { font-size: 14px; color: var(--accent); font-weight: 700; letter-spacing: 0.3px; }

.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.stat-tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-tile .stat-label { font-size: 12.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.stat-tile .stat-value { font-size: 28px; font-weight: 800; line-height: 1.2; color: var(--ink); }
.stat-tile .stat-value small { font-size: 14px; font-weight: 600; color: var(--ink-2); }

.goalbar { height: 6px; border-radius: 3px; background: var(--card-2); margin-top: 8px; overflow: hidden; }
.goalbar > div { height: 100%; border-radius: 3px; background: var(--accent); transition: width 0.4s ease; }

.dots { display: flex; gap: 6px; margin-top: 8px; }
.dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--line);
  background: transparent;
}
.dot.on { background: var(--accent); border-color: var(--accent); }
.dot.today { border-color: var(--ink-2); }

.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  color: var(--ink);
}
.mode-card:active { background: var(--card-2); }
.mode-card .mode-emoji { font-size: 24px; }
.mode-card .mode-name { font-weight: 700; margin-top: 6px; }
.mode-card .mode-desc { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ============ Recording ============ */
.prompt-card { text-align: center; padding: 22px 18px; }
.prompt-cat { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--accent); }
.prompt-text { font-size: 20px; font-weight: 700; margin: 8px 0 4px; line-height: 1.35; }

.rec-area { text-align: center; padding: 14px 0 6px; }
.rec-btn {
  width: 92px; height: 92px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 36px;
  cursor: pointer;
  box-shadow: 0 0 0 8px var(--accent-soft);
  transition: transform 0.1s ease;
}
.rec-btn:active { transform: scale(0.95); }
.rec-btn.recording {
  background: var(--red);
  box-shadow: 0 0 0 8px var(--red-soft);
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 6px var(--red-soft); }
  50% { box-shadow: 0 0 0 16px rgba(239, 68, 68, 0.05); }
  100% { box-shadow: 0 0 0 6px var(--red-soft); }
}
.rec-timer { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 10px; }
.rec-hint { color: var(--muted); font-size: 13px; margin-top: 4px; }

.live-transcript {
  min-height: 64px;
  background: var(--card-2);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--line);
  padding: 12px;
  font-size: 15px;
  color: var(--ink-2);
  text-align: left;
  margin-top: 14px;
}
.live-transcript .interim { color: var(--muted); font-style: italic; }

/* ============ Feedback ============ */
.score-ring {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 58px; height: 58px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
  flex: none;
}
.feedback-head { display: flex; gap: 14px; align-items: center; margin-bottom: 10px; }
.fix-item {
  border-left: 3px solid var(--amber);
  background: var(--card-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 14.5px;
}
.fix-item .you { color: var(--red); text-decoration: line-through; text-decoration-thickness: 1px; }
.fix-item .better { color: var(--accent); font-weight: 700; }
.fix-item .why { color: var(--ink-2); font-size: 13px; margin-top: 3px; }
.steal { background: var(--accent-soft); border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 6px; font-weight: 600; font-size: 14.5px; }
.natural-version { background: var(--card-2); border-radius: var(--radius-sm); padding: 12px; font-size: 15px; font-style: italic; }

ul.tips-list { margin: 6px 0 0; padding-left: 20px; }
ul.tips-list li { margin-bottom: 6px; font-size: 14.5px; color: var(--ink-2); }

/* ============ Shadowing ============ */
.shadow-sentence { font-size: 20px; font-weight: 700; line-height: 1.45; margin: 10px 0; }
.shadow-sentence .w.hit { color: var(--accent); }
.shadow-sentence .w.miss { color: var(--red); border-bottom: 2px dotted var(--red); }
.score-big { font-size: 34px; font-weight: 800; }

/* ============ Chat / Talk ============ */
.chat-box { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.45;
}
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.bubble.ai { align-self: flex-start; background: var(--card-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble .correction {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(255, 255, 255, 0.4);
  font-size: 13px;
  opacity: 0.95;
}
.talk-controls {
  position: sticky;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 8px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  box-shadow: var(--shadow);
}
.talk-controls input {
  flex: 1;
  min-width: 0;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
}
.mic-round {
  width: 46px; height: 46px; flex: none;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}
.mic-round.listening { background: var(--red); animation: pulse 1.4s infinite; }

/* ============ Charts (single-series, validated green) ============ */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 110px; padding-top: 18px; }
.bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.bar {
  width: 100%;
  max-width: 26px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;   /* rounded data end, anchored baseline */
  min-height: 3px;
}
.bar-label { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; max-width: 100%; }
.bar-value { font-size: 11px; font-weight: 700; color: var(--ink-2); }
.baseline { border-top: 1px solid var(--line); }

/* ============ Lists ============ */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; font-size: 15px; }
.list-item .sub { font-size: 12.5px; color: var(--muted); }
.list-emoji { font-size: 22px; flex: none; }

/* ============ Forms ============ */
label.field { display: block; margin-bottom: 14px; }
label.field .lab { display: block; font-size: 13.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

/* ============ Misc ============ */
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mt { margin-top: 14px; }
.mb0 { margin-bottom: 0; }
.hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }

.notice { background: var(--amber-soft); border: 1px solid var(--amber); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13.5px; color: var(--ink); }
.notice.error { background: var(--red-soft); border-color: var(--red); }

.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 18px);
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--bg);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 60;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--ink-2); }

@media (min-width: 640px) {
  .screen { padding-top: 28px; }
}

/* ============ Forced light theme (Settings → Theme) ============ */
:root[data-theme="light"] {
  --bg: #f4f6f8;
  --card: #ffffff;
  --card-2: #eef1f4;
  --line: #dde3e9;
  --ink: #14202a;
  --ink-2: #45586a;
  --muted: #7a8a99;
  --accent: #059669;
  --accent-soft: rgba(5, 150, 105, 0.11);
  --accent-ink: #044632;
  --amber: #b45309;
  --amber-soft: rgba(180, 83, 9, 0.12);
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.1);
  --shadow: 0 3px 12px rgba(20, 32, 42, 0.08);
}

/* ============ v4 components ============ */

/* Tappable toast (e.g. "tap to reload") */
.toast.tappable { pointer-events: auto; cursor: pointer; text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; }

/* Live microphone level while recording */
.level-meter {
  height: 6px; width: 60%; max-width: 220px; margin: 10px auto 0;
  background: var(--card-2); border-radius: 3px; overflow: hidden;
}
.level-meter > div {
  height: 100%; width: 100%; background: var(--accent); border-radius: 3px;
  transform-origin: left center; transform: scaleX(0.03); transition: transform 0.08s linear;
}

/* Structure frame under a prompt */
.frame-list { text-align: left; margin: 10px auto 0; padding-left: 22px; max-width: 420px; font-size: 14px; color: var(--ink-2); }
.frame-list li { margin-bottom: 4px; }

/* Workout ring on Home */
.ring {
  --p: 0;
  width: 54px; height: 54px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--card-2) 0);
  display: grid; place-items: center;
}
.ring > span {
  width: 42px; height: 42px; border-radius: 50%; background: var(--card);
  display: grid; place-items: center; font-size: 12.5px; font-weight: 800; color: var(--ink);
}
.workout-step .step-check {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 13px; font-weight: 800;
  background: var(--card-2); color: var(--muted); border: 1px solid var(--line);
}
.workout-step.done .step-check { background: var(--accent); color: #fff; border-color: var(--accent); }
.workout-step.done .title { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }

/* Pronunciation Lab */
.pair-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.pair { display: inline-flex; align-items: center; gap: 6px; }
.pair-choice { font-size: 20px; padding: 16px 12px; }
.pair-choice:disabled { opacity: 0.7; }

/* "Say line": a sentence with hear / say / save controls (Bridge, rescue) */
.say-line { padding: 10px 0; border-bottom: 1px solid var(--line); }
.say-line:last-of-type { border-bottom: none; }
.say-line .say-text { font-size: 15.5px; font-weight: 600; margin-bottom: 6px; }
.say-line.big .say-text { font-size: 20px; font-weight: 700; color: var(--accent); line-height: 1.35; }
.say-line .say-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.rescue { border-color: var(--amber); margin-top: 8px; }

/* Toggle rows in Settings */
.toggle { display: flex; gap: 12px; align-items: flex-start; margin-top: 14px; cursor: pointer; }
.toggle input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex: none; }

/* Stressed words in shadowing */
.shadow-sentence .stress { color: var(--accent); }

/* Achievements */
.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.badge-tile {
  text-align: center; padding: 10px 6px; border-radius: var(--radius-sm);
  background: var(--card-2); border: 1px solid var(--line); opacity: 0.45;
}
.badge-tile.on { opacity: 1; border-color: var(--accent); background: var(--accent-soft); }
.badge-tile .badge-emoji { font-size: 24px; filter: grayscale(1); }
.badge-tile.on .badge-emoji { filter: none; }
.badge-tile .badge-name { font-size: 12px; font-weight: 700; margin-top: 4px; }
.badge-tile .badge-desc { font-size: 10.5px; color: var(--muted); line-height: 1.3; }

/* Steal rows with a save button */
.steal.spread { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* Textareas share the input look, plus resize */
textarea { resize: vertical; min-height: 72px; line-height: 1.45; }

/* ============ v5 components ============ */

/* Retell keyword chips */
.kw-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.kw { font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--card-2); color: var(--ink-2); }
.kw.hit { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.kw.miss { border-color: var(--red); color: var(--red); text-decoration: line-through; text-decoration-thickness: 1px; }

/* 12-week practice heatmap: 7 rows (Mon–Sun) × 12 columns */
.heatmap { display: grid; grid-template-rows: repeat(7, 12px); grid-auto-flow: column; grid-auto-columns: 12px; gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heatmap .hm { width: 12px; height: 12px; border-radius: 3px; background: var(--card-2); border: 1px solid var(--line); }
.heatmap .hm.l1 { background: color-mix(in srgb, var(--accent) 35%, var(--card-2)); border-color: transparent; }
.heatmap .hm.l2 { background: color-mix(in srgb, var(--accent) 60%, var(--card-2)); border-color: transparent; }
.heatmap .hm.l3 { background: var(--accent); border-color: transparent; }
.heatmap .hm.today { outline: 2px solid var(--ink-2); outline-offset: -1px; }
.heatmap .hm.future { opacity: 0.25; }

/* Range: markers used / unused */
.marker-row { display: flex; flex-wrap: wrap; gap: 6px; }
.marker { font-size: 12.5px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--card-2); color: var(--ink-2); display: inline-flex; gap: 6px; align-items: center; }
.marker.on { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.marker button { border: none; background: none; color: var(--accent); font-weight: 800; cursor: pointer; padding: 0 2px; font: inherit; }

/* Streak freezes on the stat tile */
.freeze { font-size: 12.5px; color: var(--ink-2); margin-top: 6px; }

@media (prefers-reduced-motion: reduce) {
  .rec-btn.recording, .mic-round.listening { animation: none; }
  .spinner { animation-duration: 1.6s; }
  .goalbar > div, .level-meter > div { transition: none; }
}
