:root {
  /* Spanish flag palette — rojo (red) + gualda (gold) */
  --bg: #fff9e9;
  --card: #ffffff;
  --ink: #2a1613;
  --muted: #7c6a63;
  --brand: #c60b1e;        /* flag red */
  --brand-soft: #fdeaec;
  --mic: #f7c600;          /* record-mic colour (per flag) */
  --mic-ink: #2a1613;
  --stripe: linear-gradient(90deg, #c60b1e 0 25%, #f7c600 25% 75%, #c60b1e 75%);
  --good: #16a34a;
  --good-soft: #dcfce7;
  --bad: #dc2626;
  --warn: #b8860b;
  --line: #efe4c9;
  --shadow: 0 8px 30px rgba(140, 20, 20, 0.10);
  --radius: 20px;
}

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

html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-text-size-adjust: 100%;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 18px;
  background: rgba(255, 249, 233, 0.88);
  backdrop-filter: saturate(180%) blur(10px);
  /* flag stripe under the bar (set per language) */
  border-bottom: 4px solid transparent;
  border-image: var(--stripe) 1;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 26px; }
.brand h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; }
.lang-picker select {
  font-size: 16px; padding: 8px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  box-shadow: var(--shadow);
}

main { max-width: 680px; margin: 0 auto; padding: 18px 18px 60px; }

/* Ask box */
.ask-label { display: block; font-weight: 600; margin: 6px 2px 8px; }
.input-wrap { position: relative; }
#input {
  width: 100%; font-size: 19px; padding: 16px 64px 16px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  box-shadow: var(--shadow); resize: none; font-family: inherit;
}
#input:focus { outline: 3px solid var(--brand-soft); border-color: var(--brand); }
.mic-mini {
  position: absolute; right: 10px; bottom: 10px;
  width: 44px; height: 44px; border-radius: 999px; border: none; cursor: pointer;
  font-size: 20px; background: var(--brand-soft); color: var(--brand);
}
.mic-mini:active { transform: scale(0.94); }
.mic-mini.recording { background: var(--bad); color: #fff; animation: pulse 1.2s infinite; }
.mic-mini.busy { opacity: .5; pointer-events: none; }
.ask-row { margin-top: 12px; display: flex; gap: 10px; align-items: stretch; }
.ask-row #go { flex: 1; white-space: nowrap; }
.ask-row #clear { flex: 0 0 auto; white-space: nowrap; color: var(--muted); }

/* Example phrases: one tidy, swipeable row that bleeds to the screen edges. */
.chips-label { margin: 18px 2px 8px; font-size: 13px; color: var(--muted); }
.chips {
  display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
  margin: 0 -18px; padding: 2px 18px 6px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; white-space: nowrap; scroll-snap-align: start;
  font-size: 14px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  cursor: pointer;
}
.chip:active { background: var(--brand-soft); }

/* Buttons */
.btn {
  font-size: 17px; font-weight: 600; font-family: inherit;
  padding: 14px 18px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); cursor: pointer; transition: transform .06s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: var(--shadow); }
.btn.ghost { background: transparent; }
.btn.round { border-radius: 999px; padding: 12px 18px; }
.btn.link { background: none; border: none; color: var(--brand); padding: 10px 4px; font-size: 16px; }
.btn.link.small { font-size: 14px; padding: 4px; }
.btn.busy { opacity: .6; pointer-events: none; }

/* Result */
.result { margin-top: 22px; display: grid; gap: 18px; }
.phrase-card, .practice {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.english { margin: 0 0 4px; color: var(--muted); font-size: 15px; }
.target {
  margin: 4px 0; font-size: 30px; font-weight: 700; letter-spacing: -0.02em;
  line-height: 1.25;
}
.pron { margin: 2px 0 14px; color: var(--brand); font-size: 16px; font-style: italic; }
.speak-row { display: flex; flex-wrap: wrap; gap: 10px; }
.more { margin: 14px 0 4px; }
.more summary { cursor: pointer; color: var(--muted); font-size: 15px; }
.note { margin: 12px 0 0; font-size: 15px; color: var(--ink); }
.alt { margin: 6px 0 0; font-size: 15px; color: var(--muted); }
.alt b { color: var(--ink); }
.explain-box {
  margin-top: 10px; padding: 14px 16px; background: var(--brand-soft);
  border-radius: 14px; font-size: 15px; white-space: pre-wrap;
}
.explain-box h1, .explain-box h2, .explain-box h3 { font-size: 16px; margin: 8px 0 4px; }
.explain-box ul { margin: 6px 0; padding-left: 20px; }
.explain-box li { margin: 4px 0; }

/* Practice */
.practice h2 { margin: 0 0 4px; font-size: 20px; }
.practice-hint { margin: 0 0 14px; color: var(--muted); font-size: 15px; }
.mic-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.mic {
  width: 92px; height: 92px; border-radius: 999px; border: none; cursor: pointer;
  font-size: 40px; background: var(--mic); color: var(--mic-ink);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .18); transition: transform .08s ease;
}
.mic:active { transform: scale(0.95); }
.mic.recording { background: var(--bad); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,.45);} 50% { box-shadow: 0 0 0 18px rgba(220,38,38,0);} }
.mic-status { color: var(--muted); font-size: 15px; min-height: 22px; }

.score {
  margin-top: 16px; text-align: center; padding: 14px; border-radius: 14px;
  background: var(--good-soft); font-weight: 700; font-size: 18px;
}
.score.mid { background: #fef3c7; }
.score.low { background: #fee2e2; }
.score .pct { font-size: 34px; display: block; }

.heard { margin-top: 12px; font-size: 20px; text-align: center; line-height: 1.6; }
.heard .w-ok { color: var(--good); }
.heard .w-miss { color: var(--bad); text-decoration: underline dotted; }
.heard .said { display: block; margin-top: 6px; font-size: 14px; color: var(--muted); }

.practice-actions { margin-top: 16px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Saved */
.saved { margin-top: 30px; }
.saved-head { display: flex; align-items: center; justify-content: space-between; }
.saved h2 { font-size: 18px; margin: 0; }
.fav-list { display: grid; gap: 8px; margin: 10px 0; }
.fav {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 14px; cursor: pointer;
}
.fav .star { color: var(--warn); }
.fav .fav-t { font-weight: 600; }
.fav .fav-e { color: var(--muted); font-size: 13px; }
.history { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 6px; }
.history li {
  padding: 12px 14px; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px;
}
.history .h-t { font-weight: 600; }
.history .h-e { color: var(--muted); font-size: 13px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px;
  font-size: 15px; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 20;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 560px) {
  .ask-row { flex-direction: row; align-items: center; }
  #go { white-space: nowrap; }
}
