:root {
  --navy: #14213D;
  --amber: #E0A93B;
  --bg: #f6f7f9;
  --card: #fff;
  --ink: #16181d;
  --line: #d9dde3;
  --muted: #555b66;
  --ai: #fff;
  --me: #14213D;
  --me-ink: #fff;
  --chip: #fff;
  --danger: #b42318;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1420; --card: #171d2b; --ink: #e8eaef; --line: #2c3446; --muted: #a3aab8;
    --ai: #1c2334; --me: #E0A93B; --me-ink: #14213D; --chip: #1c2334; --danger: #ff8a7a;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1420; --card: #171d2b; --ink: #e8eaef; --line: #2c3446; --muted: #a3aab8;
  --ai: #1c2334; --me: #E0A93B; --me-ink: #14213D; --chip: #1c2334; --danger: #ff8a7a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 17px/1.55 "Source Sans 3", system-ui, sans-serif; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* header */
.top { background: var(--navy); color: #fff; border-bottom: 3px solid var(--amber); flex: none; }
.top-inner { max-width: 820px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand > div:last-child { min-width: 0; }
.name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 520px) {
  .top-inner { gap: 8px; }
  .name { font-size: 1.05rem; }
  .menu-btn .long { display: none; }
  .badge { font-size: .65rem; padding: 2px 7px; }
}
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--amber); color: var(--navy); display: grid; place-items: center; font-weight: 700; font-size: .9rem; flex: none; }
.name { font-family: "Source Serif 4", Georgia, serif; font-weight: 700; font-size: 1.15rem; line-height: 1.2; }
.sub { font-size: .8rem; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.badge { background: var(--amber); color: var(--navy); font-weight: 700; font-size: .72rem; padding: 3px 9px; border-radius: 999px; letter-spacing: .08em; }
.menu-btn { font: inherit; font-size: .9rem; font-weight: 600; color: #fff; background: transparent; border: 1px solid rgba(255,255,255,.4); border-radius: 999px; padding: 5px 12px; cursor: pointer; }
.menu-btn:hover { border-color: var(--amber); }
.menu-btn .short { display: none; }
@media (max-width: 520px) { .menu-btn .short { display: inline; } }

/* conversation */
.log { flex: 1; overflow-y: auto; padding: 20px 16px 8px; scroll-behavior: smooth; }
.log > * { max-width: 820px; margin-left: auto; margin-right: auto; }
.row { display: flex; gap: 8px; margin-bottom: 10px; align-items: flex-end; }
.row.me { justify-content: flex-end; }
.row .avatar { width: 28px; height: 28px; font-size: .7rem; }
.row.ai .avatar.ghost { visibility: hidden; }
.msg { max-width: min(78%, 620px); padding: 10px 14px; border-radius: 16px; overflow-wrap: anywhere; }
@media (max-width: 520px) { .msg { max-width: 86%; } }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 4px 0 8px; padding-left: 20px; }
.row.ai .msg { background: var(--ai); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.row.me .msg { background: var(--me); color: var(--me-ink); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.row.err .msg { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.typing span { display: inline-block; width: 7px; height: 7px; margin: 0 2px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing span { animation: none; opacity: .6; } .log { scroll-behavior: auto; } }
.divider { text-align: center; color: var(--muted); font-size: .8rem; margin: 18px auto 14px; display: flex; align-items: center; gap: 10px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* practice menu inside the chat */
.log > .menu-card { margin: 0 auto 14px; padding-left: 36px; display: grid; gap: 12px; }
.menu-card > .menu-group { max-width: 620px; }
@media (max-width: 520px) { .log > .menu-card { padding-left: 0; } }
.menu-group h3 { font-size: .75rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 6px 2px; }
.menu-items { display: grid; gap: 6px; }
.pick { display: block; width: 100%; text-align: left; font: inherit; color: var(--ink); background: var(--chip); border: 1px solid var(--line); border-radius: 12px; padding: 9px 13px; cursor: pointer; }
.pick:hover:not(:disabled) { border-color: var(--amber); box-shadow: inset 3px 0 0 var(--amber); }
.pick small { display: block; color: var(--muted); font-size: .85rem; line-height: 1.35; margin-top: 1px; }
.pick:disabled { cursor: default; opacity: .55; }
.pick.chosen { opacity: 1; border-color: var(--navy); box-shadow: inset 3px 0 0 var(--amber); }

/* composer */
.composer { flex: none; border-top: 1px solid var(--line); background: var(--card); padding-bottom: env(safe-area-inset-bottom); }
.composer-inner { max-width: 820px; margin: 0 auto; padding: 10px 16px 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chips:empty { display: none; }
.chip { font: inherit; font-size: .92rem; color: var(--ink); background: var(--chip); border: 1px solid var(--line); border-radius: 999px; padding: 5px 13px; cursor: pointer; }
.chip:hover { border-color: var(--amber); }
.chip.quiet { color: var(--muted); }
.say { display: flex; gap: 8px; align-items: flex-end; }
.say textarea, .say input {
  flex: 1; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 20px; padding: 9px 15px; resize: none; max-height: 200px; line-height: 1.4;
}
.say textarea:focus, .say input:focus { outline: 2px solid var(--amber); outline-offset: 0; }
.send { flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--navy); color: #fff; display: grid; place-items: center; cursor: pointer; }
.send:disabled { opacity: .45; cursor: default; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .send { background: var(--amber); color: var(--navy); } }
:root[data-theme="dark"] .send { background: var(--amber); color: var(--navy); }
.fine { color: var(--muted); font-size: .75rem; margin: 6px 0 0; text-align: center; }
