:root {
  --bg: #0f1220;
  --panel: #181c2e;
  --panel-2: #20253b;
  --text: #e9ecf5;
  --muted: #a7b0cb;
  --accent: #6d8bff;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 16px;
}

* { box-sizing: border-box; }
[v-cloak] { display: none; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid #262b44;
  position: sticky;
  top: 0;
  background: rgba(15, 18, 32, 0.85);
  backdrop-filter: blur(8px);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; }
.brand .logo { font-size: 1.2rem; }

.engine-badge {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid #2c3252;
}
.engine-badge.engine-mock { color: var(--warn); border-color: #5a4a1e; }
.engine-badge.engine-gemini { color: var(--accent); border-color: #2f3b73; }
.engine-badge.engine-azure { color: var(--ok); border-color: #1f5a44; }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.lang-select { display: inline-flex; align-items: center; gap: 4px; background: var(--panel-2); border: 1px solid #2c3252; border-radius: 999px; padding: 2px 8px 2px 10px; }
.lang-select .globe { font-size: .8rem; opacity: .85; }
.lang-select select { background: transparent; border: none; color: var(--text); font-size: .82rem; padding: 3px 2px; outline: none; cursor: pointer; max-width: 120px; }
.lang-select select option { background: var(--panel-2); color: var(--text); }

.container {
  max-width: 620px;
  margin: 0 auto;
  padding: 18px 16px 90px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tabs { display: flex; gap: 8px; }
.tabs button {
  flex: 1;
  min-height: 44px;
  padding: 11px;
  border-radius: 12px;
  border: 1px solid #2c3252;
  background: var(--panel);
  color: var(--muted);
  font-size: .92rem;
  cursor: pointer;
}
.tabs button.active { background: var(--panel-2); color: var(--text); border-color: var(--accent); }

.card {
  background: var(--panel);
  border: 1px solid #262b44;
  border-radius: var(--radius);
  padding: 18px;
}

.prompt-meta { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.prompt-meta select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #2c3252;
  border-radius: 10px;
  padding: 7px 10px;
  font-size: .85rem;
  max-width: 60%;
}
.prompt-text { font-size: 1.45rem; line-height: 1.35; font-weight: 600; margin: 4px 0; }
.prompt-text.muted { font-size: 1.05rem; font-weight: 500; }
.prompt-focus { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }

.recorder { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.record-btn {
  width: 100%;
  max-width: 280px;
  padding: 18px;
  font-size: 1.15rem;
  font-weight: 700;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: transform .08s ease, background .2s ease;
}
.record-btn:active { transform: scale(.98); }
.record-btn.recording { background: var(--bad); animation: pulse 1.4s infinite; }
.record-btn.busy { background: var(--panel-2); color: var(--muted); cursor: progress; }
.record-btn:disabled { opacity: .8; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(248,113,113,.4); } 50% { box-shadow: 0 0 0 12px rgba(248,113,113,0); } }

.hint { color: var(--muted); font-size: .8rem; margin: 0; }
.error { color: var(--bad); font-size: .88rem; margin: 4px 0 0; text-align: center; }

/* Result */
.score-row { display: flex; align-items: center; gap: 18px; }
.score-ring {
  width: 88px; height: 88px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 4px solid var(--muted);
  flex-shrink: 0;
}
.score-ring.ok { border-color: var(--ok); }
.score-ring.warn { border-color: var(--warn); }
.score-ring.bad { border-color: var(--bad); }
.score-num { font-size: 1.9rem; font-weight: 800; line-height: 1; }
.score-label { font-size: .65rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.score-side h3 { margin: 0 0 4px; font-size: 1.1rem; }

/* Sub-score bars (Azure: accuracy / fluency / completeness / prosody) */
.subscores { margin-top: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.subscore-head { display: flex; justify-content: space-between; font-size: .74rem; color: var(--muted); margin-bottom: 3px; }
.bar { height: 6px; background: #232842; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--muted); transition: width .4s ease; }
.bar-fill.ok { background: var(--ok); }
.bar-fill.warn { background: var(--warn); }
.bar-fill.bad { background: var(--bad); }

/* Per-word phoneme breakdown */
.breakdown { margin: 18px 0 4px; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; font-size: .76rem; }
.lg { position: relative; padding-left: 16px; color: var(--muted); }
.lg::before { content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 10px; height: 10px; border-radius: 3px; }
.lg.ok::before { background: var(--ok); }
.lg.warn::before { background: var(--warn); }
.lg.bad::before { background: var(--bad); }

.word-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.wordblock {
  background: var(--panel-2);
  border: 1px solid #2c3252;
  border-top: 3px solid var(--muted);
  border-radius: 10px;
  padding: 7px 10px 9px;
}
.wordblock.ok { border-top-color: var(--ok); }
.wordblock.warn { border-top-color: var(--warn); }
.wordblock.bad { border-top-color: var(--bad); }
.wordblock.omitted { opacity: .6; }
.wordblock.omitted .wb-text { text-decoration: line-through; }
.wordblock.inserted { border-style: dashed; }

.wb-word { display: flex; align-items: baseline; gap: 6px; font-size: 1.05rem; font-weight: 600; }
.wb-score { font-size: .7rem; font-weight: 700; color: var(--muted); margin-left: auto; }
.wb-flag { font-size: .62rem; text-transform: uppercase; letter-spacing: .05em; color: var(--warn); border: 1px solid #4a3f1c; border-radius: 999px; padding: 0 6px; }

.phonemes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.ph {
  font-family: "SF Mono", "Cascadia Code", Consolas, ui-monospace, monospace;
  font-size: .82rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: #1b2036;
  color: #b9c2dd;
  white-space: nowrap;
}
.ph.p-ok { color: #bfe6d6; }
.ph.p-warn { background: rgba(251, 191, 36, .16); color: var(--warn); }
.ph.p-bad { background: rgba(248, 113, 113, .18); color: var(--bad); }
.ph-sub { font-weight: 800; margin-left: 1px; }
.wordblock { cursor: pointer; }
.wordblock.expanded { flex-basis: 100%; }
.wb-caret { margin-left: 6px; color: var(--muted); font-size: .8rem; }

/* Expanded word panel — touch-sized controls (>=44px) */
.wordpanel { margin-top: 10px; padding-top: 10px; border-top: 1px solid #2c3252; cursor: default; }
.wp-audio { display: flex; flex-wrap: wrap; gap: 8px; }
.audbtn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 11px; border: 1px solid transparent;
  background: var(--accent); color: #fff; font-weight: 700; font-size: .9rem; cursor: pointer;
}
.audbtn.you { background: var(--panel-2); border-color: #2c3252; color: var(--text); }
.audbtn.mini { flex: 0 0 auto; min-height: 40px; min-width: 44px; padding: 0 10px; background: transparent; border-color: #2c3252; color: var(--text); font-size: 1rem; }
.ph-rows { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.ph-row {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 4px 10px;
  background: #1b2036; border-left: 3px solid var(--muted); border-radius: 8px;
}
.ph-row.p-ok { border-left-color: var(--ok); }
.ph-row.p-warn { border-left-color: var(--warn); }
.ph-row.p-bad { border-left-color: var(--bad); }
.phr-ipa { flex: 0 0 auto; font-family: "SF Mono", "Cascadia Code", Consolas, ui-monospace, monospace; font-size: 1.05rem; font-weight: 700; }
.phr-said { flex: 1 1 auto; min-width: 0; color: var(--bad); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phr-score { margin-left: auto; flex: 0 0 auto; font-weight: 700; font-size: .85rem; }
.phr-status { flex: 0 0 auto; font-size: .76rem; color: var(--muted); }

/* Hover/tap detail card + clarified legend */
.legend-info { margin: 8px 0 0; line-height: 1.4; }
.detail-card {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  margin: 12px 0; padding: 10px 14px;
  background: var(--panel-2); border: 1px solid #2c3252; border-radius: 12px;
}
.dc-item { display: inline-flex; align-items: center; gap: 6px; }
.dc-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.dc-ipa { font-family: "SF Mono", "Cascadia Code", Consolas, ui-monospace, monospace; font-size: 1.05rem; font-weight: 700; }
.dc-said { color: var(--bad); }
.dc-val { font-weight: 700; }
.dc-status { font-size: .8rem; padding: 1px 9px; border-radius: 999px; }
.dc-status.p-ok { color: var(--ok); background: rgba(52, 211, 153, .14); }
.dc-status.p-warn { color: var(--warn); background: rgba(251, 191, 36, .16); }
.dc-status.p-bad { color: var(--bad); background: rgba(248, 113, 113, .18); }
.dc-summary { font-size: .85rem; }
.detail-card.pinned { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.dc-unpin {
  margin-left: auto; background: transparent; border: none; color: var(--muted);
  cursor: pointer; font-size: .76rem; padding: 2px 6px; border-radius: 6px; white-space: nowrap;
}
.dc-unpin:hover { color: var(--text); }
.detail-hint { margin: 12px 0; font-style: italic; }

/* Replay of your own recording */
.replay-row { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.replay-label { font-size: .85rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.replay-row audio { height: 36px; flex: 1; min-width: 200px; max-width: 100%; }

.transcript { margin: 10px 0; color: var(--muted); font-size: .9rem; }
.transcript summary { cursor: pointer; }
.transcript p { margin: 8px 0 0; }

.sounds, .tips { margin-top: 16px; }
h4 { margin: 0 0 8px; font-size: .95rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--panel-2);
  border: 1px solid #2c3252;
  color: var(--text);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: .85rem;
}
.tips ul { margin: 0; padding-left: 18px; }
.tips li { margin: 6px 0; line-height: 1.4; }

.result-actions { display: flex; gap: 10px; margin-top: 18px; }
.result-actions button, button.ghost {
  flex: 1; padding: 11px; border-radius: 12px; cursor: pointer; font-size: .92rem;
  border: 1px solid #2c3252; background: var(--accent); color: white; font-weight: 600;
}
button.ghost { background: transparent; color: var(--text); }

/* Progress */
.progress-head { display: flex; justify-content: space-between; align-items: baseline; }
.spark { width: 100%; height: 70px; color: var(--accent); margin: 8px 0; }
.history { list-style: none; margin: 8px 0 0; padding: 0; }
.history li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid #232842; }
.h-score { font-weight: 700; width: 34px; text-align: center; border-radius: 6px; padding: 2px 0; }
.h-score.ok { color: var(--ok); }
.h-score.warn { color: var(--warn); }
.h-score.bad { color: var(--bad); }
.h-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }

.muted { color: var(--muted); }
.small { font-size: .8rem; }
.foot { text-align: center; padding: 18px; }
.foot code { background: var(--panel-2); padding: 2px 6px; border-radius: 6px; }

/* Sample-audio controls (Hear it / Slow / voice source) */
.audio-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.audio-row .ghost, .gen-hear {
  flex: 0 0 auto; min-height: 40px; padding: 6px 12px; font-size: .8rem; border-radius: 9px;
}
.tts-src { margin-left: auto; }
.tts-src select {
  background: var(--panel); color: var(--muted);
  border: 1px solid #2c3252; border-radius: 8px; padding: 5px 8px; font-size: .78rem;
}
.dc-audio { display: inline-flex; gap: 6px; }

/* Generate-from-text (custom practice) */
.custom-input {
  width: 100%; background: var(--panel-2); color: var(--text);
  border: 1px solid #2c3252; border-radius: 10px; padding: 10px 12px;
  font-size: .95rem; font-family: inherit; resize: vertical;
}
button.primary {
  width: 100%; margin-top: 10px; padding: 11px; border: none; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: .95rem; cursor: pointer;
}
button.primary:disabled { opacity: .5; cursor: default; }
.gen-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.gen-list li {
  display: flex; align-items: center; gap: 8px; padding: 9px 11px;
  background: var(--panel-2); border: 1px solid #2c3252; border-radius: 10px; cursor: pointer;
}
.gen-list li.active { border-color: var(--accent); background: #20294a; }
.gen-text { flex: 1; font-size: .95rem; line-height: 1.35; }

/* One-at-a-time sentence navigator (mobile-first: active sentence above Record) */
.sentence-nav { display: flex; flex-direction: column; gap: 12px; }
.sentence-nav .prompt-text { margin: 2px 0 0; }
.sentence-nav .audio-row { margin-top: 0; }
.nav-row { display: flex; align-items: center; justify-content: center; gap: 16px; }
.nav-btn {
  flex: 0 0 auto; min-width: 64px; min-height: 48px; padding: 0;
  font-size: 1.7rem; line-height: 1; border-radius: 12px; background: var(--panel-2);
}
.nav-btn:active { transform: scale(.97); }
.nav-count { min-width: 64px; text-align: center; font-size: .95rem; font-weight: 700; color: var(--muted); }
.gen-edit { align-self: flex-start; flex: 0 0 auto; min-height: 40px; padding: 6px 12px; font-size: .82rem; border-radius: 9px; }
