:root {
  color-scheme: light dark;
  --bg: #f6f3ee;
  --panel: #ffffff;
  --side: #efebe4;
  --text: #24272b;
  --muted: #6b6f76;
  --line: #ddd7cd;
  --accent: #2f6f62;
  --accent-text: #ffffff;
  --mine: #e4ede9;
  --danger: #b3402f;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.55;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191c;
    --panel: #1f2226;
    --side: #131517;
    --text: #e6e3de;
    --muted: #9a9ea6;
    --line: #2f3338;
    --accent: #5fb3a1;
    --accent-text: #0f1513;
    --mine: #24332f;
    --danger: #e0715f;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); overscroll-behavior: none; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 0.55rem 0.9rem; }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.quiet { background: transparent; border-color: transparent; text-align: left; color: var(--muted); padding: 0.45rem 0.6rem; }
button.quiet:hover { color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-button { border: 0; background: transparent; padding: 0.4rem; border-radius: 8px; line-height: 0; }
.icon-button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

.error { color: var(--danger); margin: 0; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.9em; background: var(--side); padding: 0.05em 0.3em; border-radius: 4px; }

/* sign in */
.login { min-height: 100%; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: min(100%, 22rem); display: grid; gap: 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.6rem; }
.login-card h1 { margin: 0 0 0.3rem; font-size: 1.5rem; font-weight: 600; }
label { display: grid; gap: 0.3rem; font-size: 0.9rem; color: var(--muted); }
input, select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 0.6rem 0.7rem; color: var(--text); width: 100%; }

/* layout */
.app { height: 100dvh; display: grid; grid-template-columns: 18rem minmax(0, 1fr); }
.sidebar { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding: 0.8rem; gap: 0.7rem; }
.new-button { width: 100%; padding: 0.75rem; }
.conversation-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -0.3rem; }
.sidebar-foot { display: grid; border-top: 1px solid var(--line); padding-top: 0.5rem; }

.conversation { display: flex; align-items: center; border-radius: 10px; }
.conversation.current { background: var(--panel); }
.conversation-open { flex: 1; min-width: 0; text-align: left; border: 0; background: transparent; padding: 0.55rem 0.6rem; display: grid; gap: 0.05rem; }
.conversation-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-date { color: var(--muted); font-size: 0.78rem; }
.conversation-menu { border: 0; background: transparent; color: var(--muted); padding: 0.4rem 0.55rem; font-size: 1.1rem; line-height: 1; }
.conversation-actions { display: flex; gap: 0.4rem; padding: 0 0.6rem 0.5rem; }
.conversation-actions button { font-size: 0.85rem; padding: 0.3rem 0.6rem; }
.conversation-actions .danger { color: var(--danger); }
.day-label { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 0.7rem 0.6rem 0.2rem; }
.empty { color: var(--muted); padding: 0.6rem; font-size: 0.9rem; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.8rem; border-bottom: 1px solid var(--line); padding-top: max(0.5rem, env(safe-area-inset-top)); }
.title { flex: 1; min-width: 0; margin: 0; font-size: 1rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model { width: auto; max-width: 45%; font-size: 0.85rem; padding: 0.35rem 0.5rem; color: var(--muted); }
#toggle-sidebar { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 1.2rem max(1rem, calc((100% - 44rem) / 2)); display: flex; flex-direction: column; gap: 1rem; }
.message { max-width: 100%; overflow-wrap: anywhere; }
.message p { margin: 0 0 0.7em; }
.message p:last-child, .message ul:last-child, .message ol:last-child { margin-bottom: 0; }
.message ul, .message ol { margin: 0 0 0.7em; padding-left: 1.3em; }
.message h4 { margin: 0.9em 0 0.3em; font-size: 1rem; }
.message.mine { align-self: flex-end; background: var(--mine); border-radius: var(--radius); padding: 0.7rem 0.95rem; max-width: min(100%, 38rem); color: var(--text); }
.message.mine.long { font-size: 0.92rem; }
.message.coach { align-self: flex-start; padding: 0 0.2rem; }
.message.notice { align-self: center; color: var(--muted); font-size: 0.85rem; }
.message.notice.failed { color: var(--danger); }
.waiting { display: inline-flex; gap: 5px; padding: 0.4rem 0.2rem; }
.waiting i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: pulse 1.2s infinite ease-in-out; }
.waiting i:nth-child(2) { animation-delay: 0.2s; }
.waiting i:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
.welcome { margin: auto; text-align: center; color: var(--muted); max-width: 24rem; }

.composer { border-top: 1px solid var(--line); padding: 0.6rem max(0.8rem, calc((100% - 44rem) / 2)); padding-bottom: max(0.6rem, env(safe-area-inset-bottom)); display: grid; gap: 0.5rem; background: var(--bg); }
.composer textarea { resize: none; max-height: 40dvh; min-height: 2.9rem; background: var(--panel); line-height: 1.45; }
.composer-row { display: flex; align-items: center; gap: 0.6rem; }
.status { color: var(--muted); font-size: 0.85rem; display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.status.failed { color: var(--danger); }
.status button { font-size: 0.85rem; padding: 0.2rem 0.6rem; }

.mic { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.7rem 1.1rem; border-radius: 999px; font-weight: 600; min-width: 8.2rem; justify-content: center; }
.mic-dot { width: 0.75rem; height: 0.75rem; border-radius: 50%; background: var(--danger); }
.mic[aria-pressed="true"] { background: var(--danger); border-color: var(--danger); color: #fff; }
.mic[aria-pressed="true"] .mic-dot { background: #fff; border-radius: 2px; }
.mic-time { font-variant-numeric: tabular-nums; font-weight: 400; }
.level { flex: 1; height: 4px; border-radius: 2px; background: transparent; overflow: hidden; }
.level.on { background: var(--line); }
#level-bar { display: block; height: 100%; width: 0; background: var(--accent); transition: width 90ms linear; }
.send { margin-left: auto; padding: 0.7rem 1.4rem; border-radius: 999px; }

/* dialogs */
dialog.sheet { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); padding: 1rem; width: min(100vw - 1.5rem, 42rem); max-height: min(100dvh - 1.5rem, 46rem); }
dialog.sheet[open] { display: flex; flex-direction: column; gap: 0.8rem; }
dialog.sheet.small { width: min(100vw - 1.5rem, 26rem); }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog header, dialog footer { display: flex; align-items: center; gap: 0.6rem; }
dialog header { justify-content: space-between; }
dialog header h3 { margin: 0; font-size: 1.05rem; }
dialog footer .primary { margin-left: auto; }
.tabs { display: flex; gap: 0.3rem; }
.tabs button { border-color: transparent; background: transparent; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--side); color: var(--text); }
.notes-entries { overflow-y: auto; display: grid; gap: 0.6rem; min-height: 6rem; }
.note { display: grid; grid-template-columns: 1fr auto; gap: 0.3rem; align-items: start; }
.note textarea { resize: vertical; min-height: 4.2rem; font-size: 0.95rem; }
.note button { border: 0; background: transparent; color: var(--muted); padding: 0.4rem; }

.toast { position: fixed; left: 50%; bottom: 6.5rem; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 0.55rem 0.9rem; border-radius: 10px; font-size: 0.9rem; max-width: calc(100vw - 2rem); z-index: 30; }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  #toggle-sidebar { display: inline-block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(86vw, 20rem); z-index: 20; transform: translateX(-102%); transition: transform 160ms ease; padding-top: max(0.8rem, env(safe-area-inset-top)); padding-bottom: max(0.8rem, env(safe-area-inset-bottom)); }
  .app.sidebar-open .sidebar { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgb(0 0 0 / 0.4); z-index: 15; }
  .model { max-width: 38%; }
}

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