:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #6b6f76;
  --line: #e2e0db;
  --accent: #1f4e79;
  --accent-text: #ffffff;
  --listen: #d1343b;
  --ok: #2e7d4f;
  --bad: #b3261e;
  --live: #8a8f96;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 6px 20px rgba(20, 30, 50, .06);
  --size: 28px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121416;
    --surface: #1c1f23;
    --text: #eceff3;
    --muted: #9aa1aa;
    --line: #2c3036;
    --accent: #3d7cc4;
    --listen: #ef4950;
    --ok: #4cb27a;
    --bad: #ff6b60;
    --live: #7d848d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---- header ---- */
.top {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: inherit; text-decoration: none; border-radius: 8px; }
.brand img { border-radius: 7px; }
.phone { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.phone[data-state="up"] .dot { background: var(--ok); }
.phone[data-state="listening"] { color: var(--listen); font-weight: 600; }
.phone[data-state="listening"] .dot { background: var(--listen); animation: blink 1s ease-in-out infinite; }
.phone[data-state="down"] .dot { background: var(--bad); }
@keyframes blink { 50% { opacity: .25; } }
.tools { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }

button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 600;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.ghost { background: transparent; }
button:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---- signing in ---- */
.center { flex: 1; display: grid; place-items: center; padding: 24px 16px; }
.intro { max-width: 420px; width: 100%; text-align: center; padding: 32px 28px; }
.intro h1 { margin: 0 0 8px; font-size: 26px; }
.intro p { color: var(--muted); }
.google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  margin: 12px 0 4px;
  font-size: 16px;
}
.google svg { width: 20px; height: 20px; }

/* ---- layout ---- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  padding: 24px;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
  .top { padding: 12px 16px; }
}

.boxes {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 16px;
  height: calc(100vh - 112px);
  min-height: 420px;
}
@media (max-width: 860px) { .boxes { height: auto; grid-template-rows: none; } }

.paper {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.box-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px 12px 28px;
  border-bottom: 1px solid var(--line);
}
.box-head h2 { margin: 0; font-size: 15px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.box-head button { margin-left: auto; min-height: 34px; }
.box-head select {
  min-height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 0 8px;
  font-weight: 600;
}
.scroll { flex: 1; overflow-y: auto; padding: 20px 28px 28px; min-height: 0; }
@media (max-width: 860px) { .scroll { min-height: 30vh; padding: 16px 20px; } }
.transcript {
  font-size: var(--size);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-width: 46em;
}
.live, .grey { color: var(--live); }
.live:not(:empty)::after {
  content: "";
  display: inline-block;
  width: .45em;
  height: .45em;
  margin-left: .25em;
  border-radius: 50%;
  background: var(--listen);
  vertical-align: middle;
  animation: blink 1s ease-in-out infinite;
}
.empty { color: var(--muted); font-size: 20px; margin: 0; }
.status { color: var(--muted); font-size: 15px; margin: 0 0 12px; }
.status:empty { display: none; }
#translation-start { margin-bottom: 12px; }

.panel { display: flex; flex-direction: column; gap: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
}
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.note { margin: 12px 0 0; }

/* ---- the phone link ---- */
.pairing h2 { margin: 0 0 8px; font-size: 18px; }
.pairing ol { margin: 0 0 14px; padding-left: 20px; font-size: 15px; display: grid; gap: 4px; overflow-wrap: anywhere; }
.qr {
  background: #fff;
  border-radius: 12px;
  padding: 10px;
  width: 220px;
  margin: 0 auto 12px;
  border: 1px solid var(--line);
}
.qr img { display: block; width: 200px; height: 200px; image-rendering: pixelated; }
.small { color: var(--muted); font-size: 14px; margin: 0; overflow-wrap: anywhere; }
.small b { color: var(--text); }

.notice {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(640px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
}

.load-problem {
  margin: 16px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--bad);
  background: var(--surface);
  color: var(--text);
}

/* ---- tabs ---- */
.tabs { display: flex; gap: 4px; }
.tabs a {
  padding: 8px 14px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
}
.tabs a:hover { color: var(--text); background: var(--surface); }
.tabs a.active { color: var(--text); background: var(--surface); box-shadow: var(--shadow); }

/* ---- shared bits ---- */
.card h2 { margin: 0 0 10px; font-size: 18px; }
.card h3 { margin: 20px 0 6px; font-size: 15px; }
.field { display: grid; gap: 6px; margin: 12px 0; font-weight: 600; font-size: 15px; }
.field select, .field input, .field textarea, .add input {
  min-height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  padding: 6px 10px;
  font: inherit;
  font-weight: 400;
}
.field textarea { resize: vertical; line-height: 1.5; }
.wide { width: 100%; margin: 8px 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tag {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}
button.link {
  min-height: 0;
  padding: 2px 6px;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
}
button.danger, button.link.danger { color: var(--bad); }
.empty-small { color: var(--muted); margin: 8px 0; }

/* ---- template sections in the note ---- */
.note-section { margin: 0 0 18px; padding-left: 14px; border-left: 4px solid transparent; }
.note-section.current { border-left-color: var(--accent); }
.section-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  font-size: calc(var(--size) * .62);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}
.note-section.current .section-title { color: var(--accent); }
.section-title .here {
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
}
.section-body { min-height: 1.5em; }

/* ---- History ---- */
.layout.history { grid-template-columns: 340px minmax(0, 1fr); align-items: start; }
@media (max-width: 860px) { .layout.history { grid-template-columns: 1fr; } }
.history-list ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; max-height: calc(100vh - 220px); overflow-y: auto; }
.history-item {
  width: 100%;
  min-height: 0;
  padding: 10px 12px;
  text-align: left;
  display: grid;
  gap: 2px;
  font-weight: 400;
}
.history-item.chosen { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.history-item .preview { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-detail { min-height: 50vh; }
.history-detail > .empty-small { padding: 24px 28px; }
.history-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.history-sub { margin: 28px 0 8px; color: var(--muted); font-size: 15px; text-transform: uppercase; letter-spacing: .06em; }
.history-sub:empty { display: none; }

/* ---- Settings ---- */
.settings {
  flex: 1;
  display: grid;
  gap: 16px;
  padding: 24px;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  align-content: start;
}
#settings-admin { display: grid; gap: 16px; }
#settings-admin[hidden] { display: none; }
.people, .templates { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.people li, .templates li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg);
  overflow-wrap: anywhere;
}
.templates li > div:first-child { display: grid; gap: 2px; min-width: 0; }
.add { display: flex; gap: 8px; margin-top: 8px; }
.add input { flex: 1; min-width: 0; }
.editor { margin-top: 12px; padding-top: 4px; border-top: 1px solid var(--line); }
.choice { border: 0; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.choice legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.choice label { display: flex; gap: 8px; align-items: flex-start; font-size: 15px; cursor: pointer; }
.choice input { margin-top: 4px; accent-color: var(--accent); }
.templates li > .row { flex: none; flex-wrap: nowrap; }
