/* ─────────────────────────────────────────────────────────────
   Dialect voice review — tokens
   Boxy, Material-style surfaces: 2px cards/inputs, 4px buttons,
   outlined surfaces instead of shadows, left-indicator selection.
   ───────────────────────────────────────────────────────────── */
:root {
  --magenta: #E2136E;
  --magenta-dark: #B30F58;
  --magenta-tint: #FCE4EE;
  --magenta-tint-2: #F7C6DA;
  --ink: #0E1B24;            /* the logo's own stroke colour */
  --ink-2: #4A5561;          /* secondary text */
  --ink-3: #7C8590;          /* tertiary text, placeholders */
  --ground: #F3F4F6;
  --surface: #FFFFFF;
  --outline: #DCDEE3;
  --outline-strong: #B9BEC7;
  --wave-idle: #E2E4E9;
  --focus: #0E1B24;

  --font-ui: "Hind Siliguri", "Noto Sans Bengali", system-ui, -apple-system, sans-serif;
  --font-sentence: "Tiro Bangla", "Noto Serif Bengali", "Kalpurush", serif;
  --font-ipa: "Charis SIL", "Doulos SIL", "Times New Roman", "Noto Serif", "DejaVu Serif", serif;

  --r-card: 2px;
  --r-ctrl: 4px;
  --appbar-h: 64px;
  --rail-w: 272px;
  --gutter: 20px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ── Buttons: contained / outlined / text ─────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 20px;
  border-radius: var(--r-ctrl);
  border: 1px solid transparent;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition: background-color .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.btn:disabled { opacity: .38; cursor: not-allowed; }

.btn-primary { background: var(--magenta); color: #fff; box-shadow: 0 1px 2px rgba(14, 27, 36, .18); }
.btn-primary:hover:not(:disabled) { background: var(--magenta-dark); box-shadow: 0 2px 4px rgba(14, 27, 36, .22); }
.btn-primary:active:not(:disabled) { box-shadow: none; }

.btn-outlined { background: var(--surface); color: var(--magenta-dark); border-color: var(--outline-strong); }
.btn-outlined:hover:not(:disabled) { background: var(--magenta-tint); border-color: var(--magenta); }

.btn-text { background: transparent; color: var(--magenta-dark); padding: 0 12px; }
.btn-text:hover:not(:disabled) { background: var(--magenta-tint); }

.btn-lg { min-height: 52px; padding: 0 28px; font-size: 18px; }

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--magenta-dark);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--magenta-tint-2);
  text-underline-offset: 3px;
}
.link:hover { text-decoration-color: var(--magenta); }

/* ── Fields ───────────────────────────────────────────────── */
.field { display: block; margin: 0 0 22px; padding: 0; border: 0; min-width: 0; }
.field-label { display: block; font-weight: 600; margin-bottom: 8px; }
.field-label .optional { color: var(--ink-3); font-weight: 400; }
.field-help { display: block; margin-top: 8px; font-size: 14px; line-height: 1.45; color: var(--ink-2); }
.field-error { display: block; margin-top: 8px; color: var(--magenta-dark); font-size: 14px; }

.field input[type="text"],
.field textarea {
  width: 100%;
  border: 1px solid var(--outline-strong);
  border-radius: var(--r-card);
  background: var(--surface);
  padding: 12px 14px;
  transition: border-color .12s ease, box-shadow .12s ease;
  resize: vertical;
}
.field input[type="text"]:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--magenta);
  box-shadow: inset 0 0 0 1px var(--magenta);
}
.field input::placeholder, .field textarea::placeholder { color: var(--ink-3); }

.code-row { display: flex; gap: 8px; align-items: stretch; }
.code-row input {
  font-weight: 600;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
.code-row .btn { flex: none; }

.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented label { position: relative; }
.segmented input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.segmented span {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--r-ctrl);
  border: 1px solid var(--outline-strong);
  background: var(--surface);
  font-weight: 500;
  transition: border-color .12s, background-color .12s, color .12s;
}
.segmented input:checked + span { background: var(--magenta-tint); border-color: var(--magenta); color: var(--magenta-dark); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ── App bar ──────────────────────────────────────────────── */
.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--appbar-h);
  padding: 0 var(--gutter);
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--outline);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 18px;
  white-space: nowrap;
}
.appbar-right { display: flex; align-items: center; gap: 10px; }
.dialect-chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: var(--r-ctrl);
  background: var(--magenta-tint);
  color: var(--magenta-dark);
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
}
.counter {
  min-height: 32px;
  padding: 0 12px;
  border-radius: var(--r-ctrl);
  border: 1px solid var(--outline-strong);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.counter:hover { border-color: var(--magenta); color: var(--magenta-dark); }

/* ── Screens ─────────────────────────────────────────────── */
.screen {
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 var(--gutter);
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

/* ── Welcome ─────────────────────────────────────────────── */
.welcome {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 440px;
  gap: 64px;
  align-items: start;
  padding: 64px 0 40px;
}
.welcome-copy { max-width: 620px; }
.welcome-kicker {
  font-family: var(--font-sentence);
  font-size: 24px;
  color: var(--magenta);
  margin: 0 0 12px;
  min-height: 1.4em;
}
.welcome-title {
  font-size: clamp(30px, 4.4vw, 42px);
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 0 0 20px;
  max-width: 20ch;
}
.welcome-lead { font-size: 19px; margin: 0 0 18px; max-width: 58ch; }
.welcome-tips { margin: 0; padding: 0 0 0 20px; color: var(--ink-2); max-width: 56ch; }
.welcome-tips li { margin-bottom: 4px; }
.welcome-tips li::marker { color: var(--magenta); }

.welcome-form {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-top: 4px solid var(--magenta);
  border-radius: var(--r-card);
  padding: 26px 26px 24px;
  margin-top: 8px;
}
.welcome-form .btn-lg { width: 100%; }
.welcome-resume { margin-top: 18px; color: var(--ink-2); font-size: 15px; }

/* ── Review layout ───────────────────────────────────────── */
.screen-review {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  gap: 32px;
  align-items: start;
  padding-top: 24px;
}

.rail {
  position: sticky;
  top: calc(var(--appbar-h) + 16px);
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - var(--appbar-h) - 32px);
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--r-card);
}
.rail-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--outline);
}
.rail-title { font-weight: 700; }
.rail-progress { color: var(--ink-2); font-size: 15px; font-variant-numeric: tabular-nums; }
.rail-list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; min-height: 0; }
.rail-item {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px 9px 12px;
  border: 0;
  border-left: 4px solid transparent;
  background: transparent;
  text-align: left;
  color: var(--ink);
  transition: background-color .1s;
}
.rail-item:hover { background: var(--ground); }
.rail-item.is-current { background: var(--magenta-tint); border-left-color: var(--magenta); }
.rail-item .rail-no { font-variant-numeric: tabular-nums; color: var(--ink-3); font-weight: 500; }
.rail-item.is-current .rail-no { color: var(--magenta-dark); }
.rail-item .rail-snippet {
  font-family: var(--font-sentence);
  font-size: 15px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 0;
}
.rail-item .rail-pick {
  font-size: 13px;
  font-weight: 700;
  min-width: 22px;
  height: 22px;
  border-radius: var(--r-ctrl);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  color: #fff;
  background: var(--magenta);
}
.rail-item .rail-pick.is-empty { background: transparent; border: 1px dashed var(--outline-strong); }
.rail-review { margin: 8px 12px 12px; }

/* progress strip (mobile) */
.progress-strip { display: none; gap: 3px; margin: 0 0 16px; }
.progress-strip span { flex: 1; height: 5px; background: var(--outline); }
.progress-strip span.is-done { background: var(--magenta); }
.progress-strip span.is-current { background: var(--ink); }

/* sentence card — the hero */
.work { min-width: 0; }
.sentence-card {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--r-card);
  padding: 20px 26px 26px;
  margin-bottom: 24px;
}
.sentence-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 15px;
}
.sentence-no { font-weight: 600; color: var(--magenta-dark); font-variant-numeric: tabular-nums; }
.ipa-toggle { font-size: 15px; font-weight: 500; }
.sentence-text {
  font-family: var(--font-sentence);
  font-size: clamp(22px, 2.6vw, 29px);
  line-height: 1.75;
  margin: 0;
  word-break: break-word;
}
.sentence-ipa {
  font-family: var(--font-ipa);
  font-size: 17px;
  line-height: 1.7;
  color: var(--ink-2);
  margin: 14px 0 0;
  padding-top: 14px;
  border-top: 1px dashed var(--outline);
  word-break: break-word;
}

/* voices */
.voices-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  margin: 0 2px 10px;
}
.voices-title { font-size: 18px; font-weight: 600; margin: 0; }
.voices-title.is-unlocked { color: var(--magenta-dark); }
.voices-hint { font-size: 14px; color: var(--ink-3); }

.voices {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--outline);
  border-radius: var(--r-card);
  background: var(--surface);
  margin-bottom: 24px;
}
.voice {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px 14px 12px;
  border-left: 4px solid transparent;
  transition: background-color .12s ease, border-color .12s ease;
}
.voice + .voice { border-top: 1px solid var(--outline); }
.voice.is-playing { background: var(--ground); }
.voice.is-chosen { border-left-color: var(--magenta); background: var(--magenta-tint); }
.voice.is-chosen.is-playing { background: var(--magenta-tint); }

.play {
  width: 48px;
  height: 48px;
  border-radius: var(--r-ctrl);
  border: 1px solid var(--magenta);
  background: var(--surface);
  color: var(--magenta);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color .1s, color .1s;
}
.play:hover { background: var(--magenta-tint); }
.play svg { width: 22px; height: 22px; fill: currentColor; }
.voice.is-playing .play { background: var(--magenta); color: #fff; }
.play.is-loading { border-style: dashed; color: var(--ink-3); border-color: var(--outline-strong); }

.track { min-width: 0; }
.track-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 15px;
  margin-bottom: 4px;
}
.voice-name { font-weight: 700; }
.voice-name .key {
  display: inline-block;
  margin-left: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
  border: 1px solid var(--outline-strong);
  border-radius: 2px;
  padding: 0 5px;
  line-height: 17px;
  vertical-align: 2px;
}
.time { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.wave { display: block; width: 100%; height: 44px; cursor: pointer; }

.choose {
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--r-ctrl);
  border: 1px solid var(--outline-strong);
  background: var(--surface);
  color: var(--ink-2);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color .1s, border-color .1s, color .1s;
}
.choose svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.choose:hover:not(:disabled) { border-color: var(--magenta); color: var(--magenta-dark); }
.choose:disabled { opacity: .38; cursor: not-allowed; }
.choose[aria-pressed="true"] { background: var(--magenta); border-color: var(--magenta); color: #fff; }

.comment-field { margin-bottom: 20px; }

.worknav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--outline);
}
.worknav-status { color: var(--ink-2); font-size: 15px; text-align: center; }

/* ── Summary ─────────────────────────────────────────────── */
.summary { max-width: 780px; padding: 40px 0; }
.summary-title { font-size: 32px; margin: 0 0 6px; letter-spacing: -0.01em; }
.summary-lead { color: var(--ink-2); margin: 0 0 22px; }
.summary-list {
  list-style: none;
  margin: 0 0 28px;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--r-card);
}
.summary-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
}
.summary-row + .summary-row { border-top: 1px solid var(--outline); }
.summary-row .s-no { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.summary-row .s-text { font-family: var(--font-sentence); font-size: 17px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.summary-row .s-pick {
  font-weight: 700;
  color: #fff;
  background: var(--magenta);
  border-radius: var(--r-ctrl);
  padding: 2px 10px;
  font-size: 15px;
}
.summary-row .s-pick.is-empty { background: transparent; color: var(--magenta-dark); border: 1px dashed var(--magenta-tint-2); }
.summary-row.is-missing .s-text { color: var(--ink-3); }
.summary-actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.summary-error { color: var(--magenta-dark); margin-top: 16px; font-weight: 500; }

/* ── Done ────────────────────────────────────────────────── */
.done { max-width: 580px; padding: 64px 0; }
.done-mark { margin-bottom: 22px; }
.done-title { font-size: 34px; margin: 0 0 10px; letter-spacing: -0.01em; }
.done-lead { color: var(--ink-2); font-size: 18px; margin: 0 0 16px; }
.done-code {
  margin: 0 0 28px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-left: 4px solid var(--magenta);
  border-radius: var(--r-card);
  color: var(--ink-2);
}
.done-code strong { color: var(--ink); letter-spacing: 0.04em; }
.done-actions { display: flex; flex-wrap: wrap; gap: 12px; }

/* ── Snackbar ────────────────────────────────────────────── */
.snackbar {
  position: fixed;
  left: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  background: var(--ink);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--r-ctrl);
  font-size: 15px;
  z-index: 30;
  max-width: calc(100vw - 48px);
  box-shadow: 0 4px 12px rgba(14, 27, 36, .3);
}

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 860px) {
  body { font-size: 16px; }
  .brand-text { display: none; }
  .appbar { height: 56px; }
  .appbar-right { gap: 8px; }
  .counter-word { display: none; }

  .welcome { display: block; padding-top: 32px; }
  .welcome-form { margin-top: 26px; padding: 20px 18px 18px; }
  .code-row { flex-wrap: wrap; }
  .code-row input { min-width: 0; flex: 1 1 200px; }

  .screen-review { display: block; padding-top: 16px; padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px)); }
  .rail { display: none; }
  .progress-strip { display: flex; }

  .sentence-card { padding: 16px 18px 20px; }
  .sentence-text { font-size: 21px; line-height: 1.8; }
  .voices-hint { display: none; }

  .voice {
    grid-template-columns: 44px minmax(0, 1fr);
    grid-template-areas: "play track" "choose choose";
    gap: 10px 12px;
    padding: 12px 12px 12px 10px;
  }
  .play { grid-area: play; width: 44px; height: 44px; }
  .track { grid-area: track; }
  .choose { grid-area: choose; justify-content: center; width: 100%; min-height: 44px; }
  .voice-name .key { display: none; }

  .worknav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 15;
    padding: 12px var(--gutter);
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--outline);
  }
  .worknav .btn { flex: 1; }
  .worknav-status { display: none; }

  .summary-row { grid-template-columns: 26px minmax(0, 1fr) auto; grid-template-areas: "no text pick" ". edit edit"; padding: 12px; }
  .summary-row .s-no { grid-area: no; }
  .summary-row .s-text { grid-area: text; }
  .summary-row .s-pick { grid-area: pick; }
  .summary-row .s-edit { grid-area: edit; justify-self: start; }
  .summary-actions .btn { flex: 1; }

  .snackbar { left: 16px; right: 16px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
