/* Vorbim — palette drawn from Moldovan woven carpets: indigo, saffron, wine, linen */
:root {
  --bg: #f6f2ea;
  --surface: #fffdf9;
  --surface-2: #efe9dd;
  --ink: #1d2233;
  --ink-2: #4a5068;
  --ink-3: #7b7f92;
  --line: #e2dbcc;
  --indigo: #1f3a7a;
  --indigo-2: #2f53a8;
  --indigo-soft: #e3e9f7;
  --saffron: #e0a526;
  --saffron-soft: #fbefd2;
  --wine: #8e1f33;
  --wine-soft: #f6e1e4;
  --green: #2f7a4f;
  --green-soft: #def0e5;
  --red: #b3372f;
  --red-soft: #f8e0dd;
  --shadow: 0 1px 2px rgba(29, 34, 51, .06), 0 6px 20px rgba(29, 34, 51, .06);
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141c; --surface: #1a1d28; --surface-2: #232736; --ink: #eceaf2; --ink-2: #b9bccb; --ink-3: #8a8ea2;
    --line: #2e3345; --indigo: #8fa8ec; --indigo-2: #a9bdf2; --indigo-soft: #222c4a; --saffron: #f0bd4f; --saffron-soft: #3a301a;
    --wine: #ef8a9b; --wine-soft: #3b1f27; --green: #6fcf97; --green-soft: #173527; --red: #f08a80; --red-soft: #3d1f1d;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12141c; --surface: #1a1d28; --surface-2: #232736; --ink: #eceaf2; --ink-2: #b9bccb; --ink-3: #8a8ea2;
  --line: #2e3345; --indigo: #8fa8ec; --indigo-2: #a9bdf2; --indigo-soft: #222c4a; --saffron: #f0bd4f; --saffron-soft: #3a301a;
  --wine: #ef8a9b; --wine-soft: #3b1f27; --green: #6fcf97; --green-soft: #173527; --red: #f08a80; --red-soft: #3d1f1d;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: var(--indigo-2); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 650; line-height: 1.2; margin: 0 0 .4em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.08rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--ink-3); }
.small { font-size: .875rem; }
.ro { font-weight: 600; }
:focus-visible { outline: 2px solid var(--saffron); outline-offset: 2px; border-radius: 6px; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 252px; flex: 0 0 252px; background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; gap: 11px; align-items: center; text-decoration: none; color: var(--ink); padding: 4px 8px 18px; }
.brand-mark svg { width: 40px; height: 40px; display: block; }
.brand-mark rect { fill: var(--indigo); }
.brand-mark path { fill: var(--saffron); }
.brand-name { display: block; font-family: var(--serif); font-size: 1.35rem; font-weight: 650; line-height: 1.1; }
.brand-sub { display: block; font-size: .76rem; color: var(--ink-3); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { text-decoration: none; color: var(--ink-2); padding: 8px 12px; border-radius: 9px; font-weight: 500; font-size: .94rem; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--indigo-soft); color: var(--indigo); font-weight: 650; }
.nav-group { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); padding: 14px 12px 4px; font-weight: 700; }
.sidebar-foot { margin-top: auto; padding: 14px 8px 0; font-size: .8rem; color: var(--ink-3); }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5; }
.topbar-title { font-weight: 650; color: var(--ink-2); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; gap: 8px; }
.menu-btn { display: none; }
.main { padding: 28px; max-width: 1080px; width: 100%; margin: 0 auto; outline: none; }

/* ---------- primitives ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }
.section { margin-top: 28px; }
.eyebrow { font-size: .74rem; text-transform: uppercase; letter-spacing: .09em; color: var(--wine); font-weight: 700; margin-bottom: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: .8rem; font-weight: 600; white-space: nowrap; }
.chip.indigo { background: var(--indigo-soft); color: var(--indigo); }
.chip.saffron { background: var(--saffron-soft); color: color-mix(in srgb, var(--saffron) 55%, var(--ink)); }
.chip.wine { background: var(--wine-soft); color: var(--wine); }
.chip.green { background: var(--green-soft); color: var(--green); }
.level-chip { background: var(--indigo); color: #fff; }
:root[data-theme="dark"] .level-chip { color: #10131c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .level-chip { color: #10131c; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 9px 16px; border-radius: 10px; font-weight: 600; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, transform .05s; font-size: .94rem; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.btn.primary:hover { background: var(--indigo-2); }
:root[data-theme="dark"] .btn.primary { color: #10131c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #10131c; } }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 5px 10px; font-size: .84rem; border-radius: 8px; }
.btn.mic.listening { background: var(--wine); border-color: var(--wine); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--wine) 50%, transparent); } 50% { box-shadow: 0 0 0 8px transparent; } }
.icon-btn { border: 0; background: transparent; padding: 6px; border-radius: 8px; cursor: pointer; color: var(--ink-2); }
.icon-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; display: block; }
.icon-btn:hover { background: var(--surface-2); }
.speak-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; width: 34px; height: 34px; display: inline-grid; place-items: center; cursor: pointer; color: var(--indigo); flex: 0 0 auto; }
.speak-btn:hover { background: var(--indigo-soft); }
.speak-btn svg { width: 17px; height: 17px; fill: currentColor; }
.speak-btn.playing { background: var(--indigo); color: #fff; }

input[type=text], input[type=password], input[type=number], select, textarea { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--indigo) 40%, transparent); border-color: var(--indigo); }
label.field { display: block; }
label.field > span { display: block; font-size: .85rem; font-weight: 650; color: var(--ink-2); margin-bottom: 5px; }
.help { font-size: .82rem; color: var(--ink-3); margin-top: 4px; }

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--indigo), var(--indigo-2)); border-radius: 99px; transition: width .4s; }
.progress.saffron > i { background: linear-gradient(90deg, var(--saffron), #f3c766); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-weight: 600; font-size: .92rem; opacity: 0; pointer-events: none; transition: all .25s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.callout { border-radius: var(--radius-sm); padding: 12px 14px; background: var(--saffron-soft); border: 1px solid color-mix(in srgb, var(--saffron) 35%, transparent); font-size: .92rem; }
.callout.indigo { background: var(--indigo-soft); border-color: color-mix(in srgb, var(--indigo) 25%, transparent); }
.callout.wine { background: var(--wine-soft); border-color: color-mix(in srgb, var(--wine) 25%, transparent); }
.callout.green { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 25%, transparent); }
.callout.red { background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 25%, transparent); }

/* ---------- dashboard ---------- */
.hero { background: var(--indigo); color: #fff; border-radius: 18px; padding: 26px 28px; position: relative; overflow: hidden; }
.hero h1 { color: #fff; }
.hero p { color: rgba(255,255,255,.85); max-width: 560px; }
:root[data-theme="dark"] .hero { background: #1f2f5e; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .hero { background: #1f2f5e; } }
.hero .motif { position: absolute; right: -20px; top: -10px; width: 260px; opacity: .22; }
.hero .btn.primary { background: var(--saffron); border-color: var(--saffron); color: #1d2233; }
.hero .btn { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.25); color: #fff; }
.skill-card { display: flex; flex-direction: column; gap: 8px; }
.skill-card .lvl { font-family: var(--serif); font-size: 1.7rem; font-weight: 650; line-height: 1; }
.skill-card .name { font-size: .85rem; color: var(--ink-3); font-weight: 650; }
.tile { display: block; text-decoration: none; color: inherit; transition: transform .12s, border-color .12s; }
.tile:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--indigo) 40%, var(--line)); }
.tile .tile-icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--indigo-soft); color: var(--indigo); margin-bottom: 10px; font-size: 1.2rem; }
.tile.wine .tile-icon { background: var(--wine-soft); color: var(--wine); }
.tile.saffron .tile-icon { background: var(--saffron-soft); color: color-mix(in srgb, var(--saffron) 60%, var(--ink)); }
.tile.green .tile-icon { background: var(--green-soft); color: var(--green); }
.tile p { font-size: .9rem; color: var(--ink-2); margin: 0; }

/* ---------- exercises ---------- */
.ex-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.ex-head .progress { flex: 1; }
.prompt-ro { font-family: var(--serif); font-size: clamp(1.4rem, 3vw, 1.9rem); font-weight: 650; line-height: 1.25; }
.prompt-en { color: var(--ink-2); font-size: 1.05rem; }
.choices { display: grid; gap: 10px; margin-top: 16px; }
.choices.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.choice { text-align: left; border: 1.5px solid var(--line); background: var(--surface); padding: 12px 14px; border-radius: 12px; cursor: pointer; font-weight: 550; transition: border-color .12s, background .12s; width: 100%; }
.choice:hover:not(:disabled) { border-color: var(--indigo); background: var(--indigo-soft); }
.choice .sub { display: block; font-weight: 450; font-size: .86rem; color: var(--ink-3); margin-top: 2px; }
.choice.correct { border-color: var(--green); background: var(--green-soft); }
.choice.wrong { border-color: var(--red); background: var(--red-soft); }
.choice.partial { border-color: var(--saffron); background: var(--saffron-soft); }
.choice:disabled { cursor: default; }
.feedback { margin-top: 14px; }
.kbd { font-family: ui-monospace, Consolas, monospace; font-size: .78rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; }
.flashcard { min-height: 230px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; cursor: pointer; user-select: none; }
.flashcard .ex { color: var(--ink-2); font-style: italic; }
.word-diff { display: flex; flex-wrap: wrap; gap: 6px; font-size: 1.15rem; font-weight: 600; }
.word-diff span { padding: 2px 8px; border-radius: 7px; }
.word-diff .ok { background: var(--green-soft); color: var(--green); }
.word-diff .miss { background: var(--red-soft); color: var(--red); text-decoration: underline wavy; }
.word-diff .close { background: var(--saffron-soft); color: color-mix(in srgb, var(--saffron) 55%, var(--ink)); }
.tokens { display: flex; flex-wrap: wrap; gap: 8px; min-height: 52px; padding: 10px; border: 1.5px dashed var(--line); border-radius: 12px; }
.tokens.bank { border-style: solid; background: var(--surface-2); }
.token { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 9px; cursor: pointer; font-weight: 600; }
.token:hover { border-color: var(--indigo); }
.score-ring { --v: 0; width: 84px; height: 84px; border-radius: 50%; background: conic-gradient(var(--indigo) calc(var(--v) * 1%), var(--surface-2) 0); display: grid; place-items: center; }
.score-ring b { width: 66px; height: 66px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-family: var(--serif); font-size: 1.3rem; }

/* ---------- role-play ---------- */
.scene { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 18px; align-items: start; }
.chat { display: flex; flex-direction: column; gap: 12px; min-height: 300px; }
.bubble { max-width: 86%; padding: 12px 15px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.bubble.npc { align-self: flex-start; border-top-left-radius: 5px; }
.bubble.me { align-self: flex-end; background: var(--indigo-soft); border-color: color-mix(in srgb, var(--indigo) 20%, transparent); border-top-right-radius: 5px; }
.bubble .who { font-size: .76rem; font-weight: 700; color: var(--wine); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 3px; display: flex; align-items: center; gap: 8px; }
.bubble .txt { font-size: 1.06rem; font-weight: 550; }
.bubble .tr { font-size: .88rem; color: var(--ink-3); margin-top: 4px; }
.bubble .tr.hidden { filter: blur(5px); cursor: pointer; user-select: none; }
.bubble .note { font-size: .86rem; margin-top: 8px; }
.persona { display: flex; gap: 10px; align-items: center; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: var(--wine); flex: 0 0 auto; font-size: .95rem; }
.avatar.indigo { background: var(--indigo); }
.avatar.saffron { background: var(--saffron); color: #1d2233; }
.avatar.green { background: var(--green); }
.reply-box { position: sticky; bottom: 0; background: var(--bg); padding-top: 12px; }
.mission-card .meta { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 10px; }

.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.table-wrap { overflow-x: auto; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: .88rem; color: var(--ink-2); }
.tab.active { background: var(--indigo); border-color: var(--indigo); color: #fff; }
:root[data-theme="dark"] .tab.active { color: #10131c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tab.active { color: #10131c; } }
.spark { display: block; width: 100%; height: 120px; }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 7px; height: 7px; background: var(--ink-3); border-radius: 50%; animation: blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%,100% { opacity: .2; } 50% { opacity: 1; } }
.correction { font-size: .88rem; border-left: 3px solid var(--saffron); padding: 4px 10px; margin-top: 6px; }
.correction s { color: var(--red); }
.correction b { color: var(--green); }
details summary { cursor: pointer; font-weight: 650; }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-3); }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .scene { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: block; }
  .main { padding: 18px 16px; }
  .topbar { padding: 10px 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .choices.two { grid-template-columns: 1fr; }
  .bubble { max-width: 94%; }
  .hero { padding: 22px 18px; }
  .streak-chip { display: none; }
}

/* chart series — validated default categorical slots 1–5 (fixed order) */
:root { --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100; --series-5: #e87ba4; --chart-grid: #e6e2d8; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --chart-grid: #2e3345; } }
:root[data-theme="dark"] { --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --chart-grid: #2e3345; }
.chart-wrap { position: relative; }
.chart-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 10px; padding: 8px 10px; font-size: .82rem; min-width: 150px; display: none; z-index: 2; }
.chart-tip .sw, .legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--ink-2); margin-bottom: 8px; }

/* edit mode */
.edit-toggle { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--ink-2); margin-bottom: 10px; cursor: pointer; }
.edit-toggle input { width: auto; accent-color: var(--wine); }
body.editing .topbar { box-shadow: inset 0 -3px 0 var(--wine); }
.edit-btn { border-color: color-mix(in srgb, var(--wine) 45%, var(--line)); color: var(--wine); background: var(--wine-soft); }
.edit-btn:hover { background: var(--wine-soft); filter: brightness(.97); }
dialog.editor { border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog.editor::backdrop { background: rgba(20, 22, 32, .45); }

/* voice-source indicator: badge on play buttons + top-bar chip */
.speak-btn { position: relative; }
.speak-btn[data-mark]::after { content: attr(data-mark); position: absolute; right: -5px; top: -5px; min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px; font: 700 9.5px/15px var(--font); text-align: center; color: #fff; background: var(--green); box-shadow: 0 0 0 2px var(--surface); }
.speak-btn[data-src="browser"]::after, .speak-btn[data-src="none"]::after { background: var(--saffron); color: #1d2233; }
.speak-btn[data-src="eleven"]::after { background: var(--indigo); }
.voice-chip.ok { background: var(--green-soft); color: var(--green); }
.voice-chip.warn { background: var(--saffron-soft); color: color-mix(in srgb, var(--saffron) 55%, var(--ink)); }
