:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --soft: #f4f4f2;
  --text: #1d1f23;
  --muted: #666b73;
  --border: #e3e1dc;
  --accent: #3d5afe;
  --accent-ink: #ffffff;
  --me: #3d5afe;
  --them: #0e9f6e;
  --danger: #d93025;
  --rec: #e53935;
  --radius: 14px;
  color-scheme: light;
}
/* Dark: follows the device unless the user picked a theme in Settings (data-theme on <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131417;
    --surface: #1c1e22;
    --soft: #131417;
    --text: #eceef1;
    --muted: #9aa0a8;
    --border: #2d3036;
    --accent: #7b8cff;
    --accent-ink: #0d0f14;
    --me: #7b8cff;
    --them: #34d399;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131417;
  --surface: #1c1e22;
  --soft: #131417;
  --text: #eceef1;
  --muted: #9aa0a8;
  --border: #2d3036;
  --accent: #7b8cff;
  --accent-ink: #0d0f14;
  --me: #7b8cff;
  --them: #34d399;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Heebo", system-ui, sans-serif;
  line-height: 1.55;
}
[hidden] { display: none !important; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { font-weight: 700; }

main { max-width: 820px; margin: 0 auto; padding: 24px 16px 64px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; margin-bottom: 16px;
}
.card.narrow { max-width: 560px; margin-inline: auto; }
h1 { font-size: 1.6rem; margin: 0 0 8px; }
h2 { font-size: 1.2rem; margin: 0 0 16px; }
.muted { color: var(--muted); }

label { display: block; margin-bottom: 14px; font-weight: 500; }
label.inline { display: inline-flex; gap: 8px; align-items: center; margin: 0; max-width: 100%; white-space: nowrap; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--soft);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-top: 4px;
}
label.inline select { width: auto; min-width: 0; max-width: 100%; flex: 1 1 auto; margin: 0; }
textarea { resize: vertical; }

button { font: inherit; cursor: pointer; border-radius: 10px; border: 0; padding: 10px 18px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.link { background: none; color: var(--muted); text-decoration: underline; padding: 4px; }
.danger { background: var(--danger); color: #fff; }
.danger.outline { background: none; color: var(--danger); border: 1px solid var(--danger); }

.tabs { display: flex; gap: 4px; margin: 16px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab { background: none; color: var(--muted); border-bottom: 2px solid transparent; border-radius: 0; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 700; }

.row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.steps { padding-inline-start: 20px; color: var(--muted); }
.challenge {
  margin: 16px 0; padding: 16px 20px; background: var(--soft); border-inline-start: 4px solid var(--accent);
  border-radius: 8px; font-size: 1.15rem; line-height: 1.8;
}
.recorder { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.record { background: var(--rec); color: #fff; font-weight: 700; }
.record.recording { animation: pulse 1.2s infinite; }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); }
.consent { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.consent input { width: auto; margin-top: 6px; flex: none; }

.result { margin-top: 16px; padding: 16px; background: var(--soft); border-radius: 10px; }
.translated { font-size: 1.2rem; margin: 0 0 10px; }
audio { width: 100%; max-width: 420px; }

.ptt-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.ptt {
  padding: 28px 12px; font-size: 1.1rem; font-weight: 700; color: #fff;
  user-select: none; touch-action: none; -webkit-user-select: none;
}
.ptt.me { background: var(--me); }
.ptt.them { background: var(--them); }
.ptt.recording { outline: 4px solid var(--rec); animation: pulse 1.2s infinite; }

.log { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.log li { padding: 12px 14px; border-radius: 12px; background: var(--soft); border-inline-start: 4px solid var(--me); }
.log li.them { border-inline-start-color: var(--them); }
.log .orig { color: var(--muted); font-size: .9rem; }
.log .tr { font-size: 1.05rem; margin: 4px 0 6px; }

.facts { padding-inline-start: 20px; }
.facts li { margin-bottom: 6px; }
.danger-zone { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 20px; }

.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; }
.status { color: var(--muted); min-height: 1.2em; margin: 8px 0 0; }

@keyframes pulse { 50% { opacity: .7; } }

@media (max-width: 520px) {
  .ptt-row { grid-template-columns: 1fr; }
  .card { padding: 18px; }
  label.inline { display: flex; width: 100%; flex-wrap: wrap; }
  label.inline select { min-width: 11em; }
}

small { display: block; font-weight: 400; margin-top: 4px; font-size: .85rem; }
.row.between { justify-content: space-between; }
h2.spaced { margin-top: 32px; }

/* ---------- phrasebook & live translator ---------- */
.small { font-size: .88rem; }
.icon-btn { background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 6px 10px; border-radius: 10px; line-height: 1; }
.icon-btn:hover { border-color: var(--accent); }

.level-picker { display: inline-flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin: 4px 0 6px; }
.level { background: var(--surface); color: var(--muted); border-radius: 0; padding: 10px 16px; }
.level + .level { border-inline-start: 1px solid var(--border); }
.level.active { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

.chips { display: grid; gap: 8px; margin: 12px 0; }
.chip { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; font-size: .9rem; }
.chip.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.chips-label { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; align-self: center; margin-right: 2px; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { white-space: nowrap; flex: none; }

.phrases { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.phrase {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
}
.phrase .src { grid-column: 1; color: var(--muted); font-size: .9rem; }
.phrase .dst { grid-column: 1; font-size: 1.15rem; font-weight: 500; }
.phrase .actions { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: 6px; }

.suggest-form {
  padding: 12px 14px; border: 1px dashed var(--accent); border-radius: 12px; background: var(--soft);
}
.suggest-form textarea, .suggest-form input { width: 100%; }
.suggest-form .row { margin: 8px 0 0; }

.suggestions { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 10px; }
.suggestion { padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.suggestion .now { margin: 6px 0; font-size: 1.05rem; }
.suggestion textarea { width: 100%; font-size: 1.05rem; }
.suggestion .row { margin: 8px 0 0; gap: 10px; }
.verdict { margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: var(--soft); font-size: .92rem; }
.verdict.v-good { border-inline-start: 4px solid var(--them); }
.verdict.v-unsure { border-inline-start: 4px solid #e0a800; }
.verdict.v-bad { border-inline-start: 4px solid var(--danger); }
.verdict.v-none { border-inline-start: 4px solid var(--border); }

.live-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.live-grid textarea { margin: 0; min-height: 120px; }
.live-output {
  min-height: 120px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--soft); font-size: 1.15rem; white-space: pre-wrap;
}
.live-output:empty::before { content: "Translation"; color: var(--muted); }
.interim { padding: 12px 14px; border: 1px dashed var(--accent); border-radius: 12px; margin-bottom: 12px; }
.interim .orig { color: var(--muted); }
.interim .tr { font-size: 1.15rem; margin-top: 4px; }
.interim .tr:empty::before { content: "…"; color: var(--muted); }
.ptt:disabled { opacity: .45; }

@media (max-width: 640px) {
  .live-grid { grid-template-columns: 1fr; }
  .level { padding: 10px 10px; }
  .phrase { grid-template-columns: 1fr; }
  .phrase .actions { grid-column: 1; grid-row: auto; margin-top: 6px; }
}

/* ------------------------------------------------------------ settings */
.setting { margin: 14px 0; }
.setting-label { display: block; font-weight: 600; margin-bottom: 6px; }
.volume-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.volume-row input[type="range"] { flex: 1 1 200px; margin: 0; padding: 0; border: 0; accent-color: var(--accent); }
.volume-value { min-width: 3.5em; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ phones */
@media (max-width: 640px) {
  main { padding: 16px 12px 48px; }
  .topbar { padding: 10px 14px; }

  /* Category chips: one sideways-scrolling row each. */
  .chip-row { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: -12px; padding-inline: 12px; }
  .chip-row::-webkit-scrollbar { display: none; }

  .level-picker { display: flex; }
  .level-picker .level { flex: 1; white-space: nowrap; padding: 10px 6px; font-size: .92rem; }
  .suggestion .row button, .suggest-form .row button { flex: 1 1 auto; }
  #auth-submit { width: 100%; padding: 14px; }
}

/* ------------------------------------------------------------ side menu */
.menu-btn { font-size: 1.2rem; padding: 6px 12px; }
.page-title { font-weight: 700; }
.topbar { gap: 12px; justify-content: flex-start; }
.topbar .brand { margin-inline-end: auto; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 30;
  display: flex; flex-direction: column; gap: 8px; padding: 18px 12px;
  background: var(--surface); border-inline-end: 1px solid var(--border); overflow-y: auto;
}
.sidebar-head { padding: 0 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.who { color: var(--muted); font-size: .82rem; margin-top: 4px; overflow-wrap: anywhere; }
.menu { display: grid; gap: 2px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: start;
  background: none; color: var(--text); padding: 11px 12px; border-radius: 10px; font-weight: 500;
}
.menu-item:hover { background: var(--soft); }
.menu-item.active { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); font-weight: 700; }
.menu-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.logout { margin-top: auto; color: var(--muted); }
.badge { margin-inline-start: auto; background: var(--danger); color: #fff; border-radius: 999px; font-size: .72rem; font-weight: 700; padding: 1px 8px; }
.scrim { position: fixed; inset: 0; z-index: 25; background: rgb(0 0 0 / .35); }

/* Computers: the menu is always there; the top bar isn't needed. */
@media (min-width: 901px) {
  body.signed-in { padding-inline-start: 260px; }
  body.signed-in .topbar { display: none; }
  .menu-btn, .scrim { display: none !important; }
}
/* Phones and tablets: the menu slides in from the side. */
@media (max-width: 900px) {
  .sidebar {
    width: min(300px, 84vw); transform: translateX(-100%); visibility: hidden;
    transition: transform .22s ease, visibility .22s;
  }
  body.menu-open .sidebar { transform: none; visibility: visible; box-shadow: 0 0 40px rgb(0 0 0 / .25); }
  body.menu-open { overflow: hidden; }
  body.signed-in .topbar { position: sticky; top: 0; z-index: 20; }
  body.signed-in .topbar .brand { display: none; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

/* ------------------------------------------------------------ home */
.hero h1 { margin-bottom: 4px; }
.home-search { display: flex; gap: 8px; margin-top: 12px; }
.home-search input { margin: 0; }
.home-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.home-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: start;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px;
}
.home-card:hover { border-color: var(--accent); }
.home-card strong { font-size: 1.05rem; }
.home-icon { font-size: 1.7rem; line-height: 1; margin-bottom: 4px; }
.daily { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.daily-text { font-size: 1.4rem; font-weight: 500; margin: 2px 0; }
.inline-link { padding: 0; }

/* ------------------------------------------------------------ conversations */
.history { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 10px; }
.conv { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); padding: 12px 14px; }
.conv summary { cursor: pointer; list-style-position: inside; }
.conv.compact { cursor: pointer; }
.conv.compact:hover { border-color: var(--accent); }
.conv-line { margin-top: 10px; padding-inline-start: 10px; border-inline-start: 3px solid var(--me); }
.conv-line.them { border-inline-start-color: var(--them); }
.conv-line .orig { color: var(--muted); font-size: .92rem; }
.conv-line .tr { font-size: 1.05rem; }
.feedback-text { white-space: pre-wrap; margin: 8px 0; }
.notice { border-inline-start: 4px solid var(--accent); }
.admin-note { border-top: 1px dashed var(--border); padding-top: 10px; }

@media (max-width: 640px) {
  .home-search { flex-direction: column; }
  .home-grid { gap: 10px; }
  .home-card { padding: 14px; }
}
