/*
 * Dos Tera: one input in the middle of the page, the translations under it.
 * Mobile first; light and dark follow the system.
 */

@import url("https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@400;500;600;700&family=Noto+Sans+HK:wght@400;500;700&display=swap");

:root {
  color-scheme: light dark;
  --ink: #20201e;
  --muted: #6c6b64;
  --paper: #f6f3ec;
  --surface: #fffdf8;
  --raised: #ffffff;
  --line: #dcd7cb;
  --accent: #c8502f;
  --accent-ink: #ffffff;
  --navy: #183a47;
  --focus: #2f6f8f;
  --jyutping: #a5462b;
  --error: #9c2f1e;
  --shadow: 0 18px 50px rgb(48 41 28 / 10%), 0 2px 6px rgb(48 41 28 / 6%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #ece8df;
    --muted: #a19d93;
    --paper: #151412;
    --surface: #1e1d1a;
    --raised: #262420;
    --line: #3a3732;
    --accent: #e0714f;
    --accent-ink: #1a0f0a;
    --navy: #8fc1d4;
    --focus: #8fc1d4;
    --jyutping: #f0a184;
    --error: #ff9b87;
    --shadow: 0 18px 50px rgb(0 0 0 / 40%), 0 2px 6px rgb(0 0 0 / 30%);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--paper); color: var(--ink); -webkit-text-size-adjust: 100%; }

body {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
  margin: 0;
  background: var(--paper);
  font-family: "DM Sans", "Noto Sans HK", system-ui, sans-serif;
  line-height: 1.5;
}

button, input, textarea, select { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

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

.visually-hidden {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Masthead */

.masthead {
  display: flex;
  width: min(760px, calc(100% - 32px));
  min-height: 60px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.brand strong { font-size: 15px; letter-spacing: -.015em; white-space: nowrap; }
.brand-native { color: var(--muted); font-size: 14px; }
.brand-flag { font-size: 18px; line-height: 1; }

.locale-switcher {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.locale-switcher a {
  display: grid;
  min-width: 40px;
  min-height: 34px;
  place-items: center;
  border-radius: 999px;
  color: var(--muted);
  font: 500 12px "DM Mono", "Noto Sans HK", monospace;
  letter-spacing: .06em;
  text-decoration: none;
}

.locale-switcher a.is-active { color: var(--paper); background: var(--ink); }

main {
  display: flex;
  width: min(760px, calc(100% - 32px));
  flex: 1;
  flex-direction: column;
  margin: 0 auto;
}

.site-footer {
  display: flex;
  width: min(760px, calc(100% - 32px));
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  margin: 40px auto 0;
  padding: 18px 0 calc(24px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* The translator */

.translator {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  padding: 24px 0 8px;
}

.translator[data-state="result"],
.translator[data-state="working"]:has(.results:not(:empty)) { justify-content: flex-start; }

.translator-intro { margin-bottom: 22px; text-align: center; }

.translator-intro h1 {
  margin: 0;
  font-size: clamp(28px, 7vw, 40px);
  font-weight: 600;
  letter-spacing: -.03em;
  line-height: 1.15;
}

.translator-lede { max-width: 34em; margin: 10px auto 0; color: var(--muted); font-size: 15px; }

.translator[data-state="result"] .translator-intro { display: none; }

.composer {
  padding: 12px 12px 10px 16px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--raised);
  box-shadow: var(--shadow);
}

.composer:focus-within { border-color: color-mix(in srgb, var(--focus) 60%, var(--line)); }

.composer-field {
  display: block;
  width: 100%;
  min-height: 28px;
  max-height: 40vh;
  padding: 6px 0;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 17px;
  line-height: 1.5;
  resize: none;
}

.composer-field::placeholder { color: var(--muted); }

.composer-bar { display: flex; align-items: center; gap: 8px; margin-top: 6px; }

.language-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 0 4px 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
}

.language-picker select {
  min-height: 34px;
  padding: 0 8px 0 2px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
}

.language-picker select option { color: initial; background: initial; }
.language-picker:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }

.composer-hint { flex: 1; margin: 0; color: var(--muted); font-size: 12px; text-align: right; }

.round-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
}

.round-button:disabled { cursor: default; opacity: .45; }

.send-button { border-color: var(--ink); color: var(--paper); background: var(--ink); }

.mic-button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); }
  50% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--accent) 0%, transparent); }
}

.translator-status { min-height: 1.5em; margin: 12px 4px 0; color: var(--muted); font-size: 14px; text-align: center; }
.translator-status[data-tone="error"] { color: var(--error); }

.working { display: grid; gap: 12px; margin-top: 8px; }

.working span {
  height: 92px;
  border-radius: 18px;
  background: linear-gradient(90deg, var(--surface) 0%, var(--raised) 50%, var(--surface) 100%);
  background-size: 200% 100%;
  border: 1px solid var(--line);
  animation: shimmer 1.2s linear infinite;
}

@keyframes shimmer { to { background-position: -200% 0; } }

/* Results */

.results { display: grid; gap: 12px; margin-top: 4px; }
.results:empty { display: none; }

.source { padding: 0 4px; }
.source p { margin: 0; }
.source-label { color: var(--muted); font-size: 13px; }
.source-detected { font-style: italic; }
.source-text { margin-top: 2px !important; font-size: 16px; overflow-wrap: anywhere; white-space: pre-wrap; }
.source-heard { margin-top: 4px !important; color: var(--muted); font-size: 13px; }

.card {
  min-width: 0;
  padding: 14px 16px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--raised);
}

.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }

.card-name {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.card-name:focus { outline: none; }
.card-actions { display: flex; gap: 6px; }

.pill-button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.pill-button:disabled { color: var(--muted); cursor: default; }
.pill-button[aria-busy="true"] .icon { animation: fade 1s ease-in-out infinite alternate; }
.card-play:not(:disabled) { border-color: var(--ink); color: var(--paper); background: var(--ink); }
.card-play.is-playing { border-color: var(--accent); color: var(--accent-ink); background: var(--accent); }

.icon { width: 16px; height: 16px; }
.icon-play path, .icon-stop path { fill: currentColor; }
.icon-copy path, .icon-check path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@keyframes fade { to { opacity: .3; } }

.card-text { margin: 10px 0 0; font-size: 19px; line-height: 1.55; overflow-wrap: anywhere; white-space: pre-wrap; }
.card-hint { margin: 10px 0 0; color: var(--muted); font-size: 12px; }

/* While a translation is written: the card holds a line for it, the words
   settle in as they arrive, and Papiamentu reads a shade lighter until the
   dictionary has checked it. Nothing blinks and nothing moves what is
   already there. */

.card-placeholder {
  display: block;
  width: 62%;
  height: 1.55em;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--surface) 0%, color-mix(in srgb, var(--line) 55%, var(--raised)) 50%, var(--surface) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
}

.cantonese .card-placeholder { width: 70%; height: 56px; }

.fresh { animation: settle .35s ease-out both; }

@keyframes settle { from { opacity: 0; } }

.card[data-language="pap"] .card-text { transition: color .4s ease; }
.card[data-language="pap"][aria-busy="true"] .card-text { color: color-mix(in srgb, var(--ink) 70%, var(--raised)); }

.card-note { min-height: 1.5em; }
.card:not([aria-busy]) .card-note:empty { display: none; }

mark.corrected {
  color: inherit;
  background: none;
  text-decoration: underline dotted color-mix(in srgb, var(--accent) 75%, transparent);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

/* Cantonese: every character with its Jyutping beneath, a word per button. */

.cantonese {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 8px;
  margin-top: 12px;
  font-family: "Noto Sans HK", sans-serif;
  white-space: normal;
}

/* A word the model left unsegmented can be a whole phrase long, so a chip
   wraps inside the card rather than pushing the page sideways. */
.word {
  display: inline-flex;
  max-width: 100%;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 3px;
  padding: 4px 5px 3px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: color-mix(in srgb, var(--ink) 4%, transparent);
  cursor: pointer;
}

.syllable { display: inline-flex; min-width: 1.1em; flex-direction: column; align-items: center; }
.syllable-character { font-size: 25px; line-height: 1.25; }

.syllable-jyutping {
  color: var(--jyutping);
  font: 500 11.5px/1.3 "DM Mono", monospace;
  white-space: nowrap;
}

.word-plain { align-self: flex-start; font-size: 25px; line-height: 1.25; }
.cantonese > .word-plain { padding: 4px 0 0; }

.word.is-draft { cursor: default; }

/* A syllable whose Jyutping is still on its way keeps the line for it. */
.syllable-jyutping:empty::before { content: "\00a0"; }

button.word:hover { border-color: var(--line); background: color-mix(in srgb, var(--accent) 7%, transparent); }
.word.is-playing { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }
.word[aria-busy="true"] { animation: fade .6s ease-in-out infinite alternate; }

.phrase.unpaired { display: inline-flex; flex-direction: column; align-items: flex-start; }
.phrase.unpaired .word { font-size: 25px; line-height: 1.25; }
.phrase-jyutping { color: var(--jyutping); font: 500 12px/1.4 "DM Mono", monospace; }

.privacy-note { margin: 22px 8px 0; color: var(--muted); font-size: 12px; text-align: center; }

/* Credits */

.page { padding: 28px 0; }
.page h1 { margin: 0 0 16px; font-size: 30px; letter-spacing: -.02em; }
.credits-page p { line-height: 1.7; overflow-wrap: anywhere; }

@media (min-width: 640px) {
  .translator { padding-top: 40px; }
  .composer-field { font-size: 18px; }
}

@media (max-width: 480px) {
  .composer-hint { display: none; }
  .composer-bar { justify-content: flex-end; }
  .language-picker { margin-right: auto; }
  .brand-native { display: none; }
}

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