:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --ink: #16181a;
  --muted: #6b6f73;
  --faint: #9a9ea3;
  --line: rgba(20, 24, 28, .08);
  --hear: #a35a00;
  --shadow: 0 1px 2px rgba(16, 24, 32, .04), 0 4px 16px rgba(16, 24, 32, .05);
  --radius: 20px;
  --nav-h: 68px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1112;
    --surface: #1a1d1f;
    --surface-2: #24282b;
    --ink: #eef0f1;
    --muted: #a0a6ab;
    --faint: #6f757a;
    --line: rgba(255, 255, 255, .08);
    --hear: #f0b35a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

/* One accent per situation */
body { --accent: #16875a; }
body[data-cat="daily"] { --accent: #2f6fde; }
body[data-cat="food"] { --accent: #e0592a; }
body[data-cat="store"] { --accent: #7c4ddb; }
body[data-cat="garden"] { --accent: #16875a; }
body[data-cat="gas"] { --accent: #d6334a; }
body[data-cat="pharmacy"] { --accent: #0b8a93; }
body[data-cat="doctor"] { --accent: #b23a48; }
body[data-cat="clean"] { --accent: #c2378a; }
body[data-cat="repair"] { --accent: #b86a0b; }
body[data-cat="taxi"] { --accent: #a88400; }
body[data-cat="police"] { --accent: #2b4c9e; }
body[data-cat="bank"] { --accent: #66731c; }
body[data-cat="house"] { --accent: #8a5a44; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  --accent-ink: color-mix(in srgb, var(--accent) 78%, #000);
  --accent-soft: color-mix(in srgb, var(--accent) 11%, var(--surface));
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 600px;
  margin: 0 auto;
  padding: 0 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
@media (prefers-color-scheme: dark) {
  body { --accent-ink: color-mix(in srgb, var(--accent) 60%, #fff); --accent-soft: color-mix(in srgb, var(--accent) 20%, var(--surface)); }
}
button { font: inherit; color: inherit; cursor: pointer; }
svg { stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

/* Header */
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -16px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 36px; height: 36px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  font-size: .9rem;
  letter-spacing: -.5px;
  transition: background-color .25s;
}
.brand h1 { margin: 0; font-size: 1.1rem; font-weight: 800; letter-spacing: -.3px; line-height: 1.1; }
.brand .sub { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.modes { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.mode {
  border: 0;
  background: transparent;
  padding: 7px 11px;
  border-radius: 9px;
  font-size: .88rem;
  font-weight: 600;
  color: var(--muted);
}
.mode.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
@media (max-width: 420px) {
  .brand .sub { display: none; }
  .mode { padding: 7px 10px; }
}

/* Situation heading */
.hero { display: flex; align-items: center; gap: 14px; padding: 10px 2px 16px; }
.hero-ic {
  width: 56px; height: 56px; flex: none;
  display: grid; place-items: center;
  font-size: 1.9rem;
  border-radius: 18px;
  background: var(--accent-soft);
  transition: background-color .25s;
}
.hero h2 { margin: 0; font-size: 1.7rem; font-weight: 800; letter-spacing: -.6px; line-height: 1.1; }
.hero p { margin: 3px 0 0; font-size: .85rem; color: var(--muted); }

/* Bottom situation bar */
.cats {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 30;
  width: 100%;
  max-width: 600px;
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line);
}
.cats .track {
  display: flex;
  gap: 2px;
  padding: 0 6px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scroll-padding: 0 36px;
  scrollbar-width: none;
  --fl: 0px;
  --fr: 0px;
  -webkit-mask-image: linear-gradient(to right, transparent, #000 var(--fl), #000 calc(100% - var(--fr)), transparent);
  mask-image: linear-gradient(to right, transparent, #000 var(--fl), #000 calc(100% - var(--fr)), transparent);
}
.cats .track::-webkit-scrollbar { display: none; }
.cats.more-left .track { --fl: 36px; }
.cats.more-right .track { --fr: 36px; }
.chip {
  flex: 0 0 auto;
  min-width: 70px;
  scroll-snap-align: start;
  border: 0;
  background: transparent;
  border-radius: 14px;
  height: 56px;
  padding: 4px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: .74rem;
  font-weight: 600;
  transition: background-color .2s, color .2s;
}
.chip .ic { font-size: 1.35rem; line-height: 1; filter: grayscale(.6); opacity: .75; transition: filter .2s, opacity .2s, transform .2s; }
.chip .nm { white-space: nowrap; }
.chip.active { color: var(--accent-ink); background: var(--accent-soft); }
.chip.active .ic { filter: none; opacity: 1; transform: translateY(-1px) scale(1.08); }

/* Search */
.search { position: relative; display: block; margin-bottom: 4px; }
.search svg { position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); color: var(--faint); fill: none; }
#search {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 13px 14px 13px 42px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
#search::placeholder { color: var(--faint); }

.list-tools { display: flex; justify-content: space-between; align-items: center; font-size: .8rem; color: var(--muted); margin: 10px 4px 8px; }
.link { border: 0; background: none; color: var(--accent-ink); font-weight: 600; font-size: .85rem; padding: 6px 4px; }

/* Topic keywords that expand into phrases */
.topic {
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  overflow: hidden;
}
.topic summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: -.2px;
  user-select: none;
  -webkit-user-select: none;
}
.topic summary::-webkit-details-marker { display: none; }
.t-ic {
  width: 42px; height: 42px; flex: none;
  display: grid; place-items: center;
  font-size: 1.3rem;
  border-radius: 13px;
  background: var(--accent-soft);
}
.t-name { flex: 1; display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.t-es { font-size: .8rem; font-weight: 500; color: var(--muted); }
.t-n { font-size: .75rem; font-weight: 600; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 3px 9px; }
.chev {
  width: 9px; height: 9px; margin: 0 4px 0 2px; flex: none;
  border-right: 2px solid var(--faint);
  border-bottom: 2px solid var(--faint);
  transform: rotate(-45deg);
  transition: transform .2s;
}
.topic[open] .chev { transform: rotate(45deg) translate(-2px, -2px); }
.topic[open] summary { border-bottom: 1px solid var(--line); }
.topic h3 {
  margin: 14px 16px 2px;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--faint);
}
.topic h3.h-hear { color: var(--hear); }

/* Phrase rows */
.list { list-style: none; margin: 0; padding: 0; }
.topic .list { padding: 0 6px 4px; }
.item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 8px 12px 10px;
  border-bottom: 1px solid var(--line);
}
.topic .item:last-child { border-bottom: 0; }
#list .item { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; margin-bottom: 8px; box-shadow: var(--shadow); padding: 12px; }
.item .txt { flex: 1; min-width: 0; }
.item .l-es { font-weight: 700; color: var(--accent-ink); font-size: 1.06rem; line-height: 1.3; }
.item.hear .l-es { color: var(--hear); }
.item .l-pr { color: var(--muted); font-size: .8rem; margin-top: 2px; font-style: italic; }
.item .l-en { font-size: .95rem; margin-top: 4px; line-height: 1.35; }
.item .l-note {
  font-size: .82rem;
  color: var(--muted);
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--surface-2);
  line-height: 1.4;
}
.item.learned .l-es::after { content: " ✓"; color: var(--accent); }
.item .btns { display: flex; flex-direction: column; gap: 6px; }
.item .btns button {
  flex: 0 0 auto;
  border: 0;
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-radius: 12px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  transition: transform .08s;
}
.item .btns button:active { transform: scale(.92); }
.item .btns svg { width: 19px; height: 19px; fill: none; }
.item .btns [data-say] svg path:first-child { fill: currentColor; }
.l-where { font-size: .72rem; color: var(--muted); margin-bottom: 3px; font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

/* Word chips */
.words { display: grid; grid-template-columns: repeat(auto-fill, minmax(138px, 1fr)); gap: 8px; padding: 6px 14px 16px; }
.word {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 9px 11px;
  text-align: left;
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: transform .08s;
}
.word:active { transform: scale(.97); }
.w-es { font-weight: 700; color: var(--accent-ink); }
.w-en { font-size: .78rem; color: var(--muted); }

.foot { text-align: center; font-size: .75rem; color: var(--faint); padding: 14px 10px 6px; margin: 0; line-height: 1.5; }

/* Practice: progress */
.progress-row { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; color: var(--muted); }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; margin: 8px 0 14px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .3s; }

/* Practice: card */
#cardsView { flex: 1; display: flex; flex-direction: column; }
.stage { position: relative; flex: 1; min-height: 330px; max-height: 460px; perspective: 1200px; }
.card {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.2,.7,.3,1);
  cursor: pointer;
  outline: none;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.card.no-anim { transition: none; }
.card.flipped { transform: rotateY(180deg); }
.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: 0 12px 40px rgba(16, 24, 32, .1);
  padding: 26px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: auto;
}
.back { transform: rotateY(180deg); background: linear-gradient(180deg, var(--accent-soft), var(--surface) 55%); }
.tag {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--faint);
  white-space: nowrap;
}
.prompt { font-size: 1.75rem; font-weight: 700; line-height: 1.25; margin: 0; letter-spacing: -.4px; }
.prompt.is-es { color: var(--accent-ink); }
.hint { position: absolute; bottom: 16px; font-size: .78rem; color: var(--faint); }
.es { font-size: 1.85rem; font-weight: 800; color: var(--accent-ink); margin: 0 0 8px; line-height: 1.2; letter-spacing: -.4px; }
.pr { font-size: 1rem; color: var(--muted); font-style: italic; margin: 0 0 14px; }
.en { font-size: 1.1rem; margin: 0 0 12px; }
.note { font-size: .9rem; color: var(--muted); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin: 0; line-height: 1.4; }
.note:empty { display: none; }
.card.swipe-right .face { box-shadow: 0 0 0 3px var(--accent), 0 12px 40px rgba(0,0,0,.12); }
.card.swipe-left .face { box-shadow: 0 0 0 3px #e0a019, 0 12px 40px rgba(0,0,0,.12); }

.done {
  position: absolute;
  inset: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  box-shadow: 0 12px 40px rgba(16, 24, 32, .1);
}
.done .big { font-size: 3rem; }
.done h2 { color: var(--accent-ink); margin: 8px 0; }
.done p { color: var(--muted); margin: 0 0 18px; }

/* Practice: buttons */
.actions { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; margin-top: 18px; }
.btn {
  border: 0;
  border-radius: 16px;
  padding: 16px 12px;
  font-size: 1.05rem;
  font-weight: 700;
  min-height: 56px;
  transition: transform .08s;
}
.btn:active { transform: scale(.96); }
.btn.again { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line), var(--shadow); }
.btn.got { background: var(--accent); color: #fff; }
.btn.speak { background: var(--accent-soft); color: var(--accent-ink); width: 60px; display: grid; place-items: center; }
.btn.speak svg { width: 24px; height: 24px; fill: none; }
.btn.speak svg path:first-child { fill: currentColor; }
.btn.primary { background: var(--accent); color: #fff; padding: 14px 22px; }
.swipe-hint { text-align: center; font-size: .78rem; color: var(--faint); margin: 10px 0 0; }
.tools { display: flex; justify-content: center; gap: 20px; margin-top: 6px; }
.tools .link { color: var(--muted); }

@media (min-height: 800px) {
  .prompt { font-size: 2rem; }
  .es { font-size: 2.1rem; }
}

/* Show-it-big overlay for handing the phone to staff */
.show {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--accent);
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px;
  text-align: center;
  animation: pop .18s ease-out;
}
@keyframes pop { from { opacity: 0; transform: scale(.98); } }
.show-es { font-size: clamp(2.1rem, 10vw, 3.6rem); font-weight: 800; line-height: 1.12; margin: 0 0 18px; letter-spacing: -1px; }
.show-en { font-size: 1.1rem; opacity: .85; margin: 0; }
.show-hint { position: absolute; bottom: calc(24px + env(safe-area-inset-bottom)); font-size: .8rem; opacity: .65; }

/* Talk: voice dictation */
body.talking .hero, body.talking .cats { display: none; }
body.talking { padding-bottom: calc(env(safe-area-inset-bottom) + 12px); }
#talkView { padding-top: 10px; }
.mics { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mic {
  border: 0;
  border-radius: var(--radius);
  padding: 18px 10px 16px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line), var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: transform .08s, background-color .2s;
}
.mic:active { transform: scale(.97); }
.mic:disabled { opacity: .45; }
.mic .m-flag { font-size: 2.4rem; line-height: 1; }
.mic .m-name { font-weight: 800; font-size: 1.05rem; }
.mic .m-hint { font-size: .78rem; color: var(--muted); }
.mic.rec { background: var(--accent); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
.mic.rec .m-hint { color: #fff; opacity: .9; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--accent) 22%, transparent); } }
.type-row { display: flex; gap: 8px; margin-top: 12px; }
.type-row input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 1rem; color: var(--ink);
  border: 0; border-radius: 14px; padding: 12px 14px;
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--line);
}
.type-go { border: 0; border-radius: 14px; padding: 0 12px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; white-space: nowrap; }
.talk-empty { color: var(--muted); font-size: .92rem; line-height: 1.45; text-align: center; margin: 22px 8px 0; }
.turns { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.turn { background: var(--surface); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); animation: pop .18s ease-out; }
.turn .t-who { font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.turn .t-es { font-size: 1.5rem; font-weight: 800; color: var(--accent-ink); line-height: 1.2; margin: 6px 0 0; letter-spacing: -.3px; overflow-wrap: anywhere; }
.turn .t-en { font-size: 1rem; margin: 6px 0 0; line-height: 1.35; overflow-wrap: anywhere; }
.turn .t-wait { color: var(--muted); margin: 6px 0 0; }
.turn .t-heard { margin: 6px 0 0; font-style: italic; }
.turn .t-err { color: var(--hear); margin: 6px 0 0; font-size: .92rem; }
.turn .t-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.turn .t-src { font-size: .72rem; color: var(--faint); }
.turn .t-src.book { color: var(--accent-ink); font-weight: 700; }
.turn .t-say { border: 0; width: 40px; height: 40px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; }
.turn .t-say svg { width: 20px; height: 20px; fill: none; }
.turn .t-say svg path:first-child { fill: currentColor; }

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