:root {
  --bg: #0b0d10; --panel: #14181e; --panel2: #1b2028; --line: #262d37;
  --text: #eef1f5; --muted: #8b95a3; --accent: #e8a45c; --accent-ink: #1a1006;
  --ok: #4cc38a; --work: #e8a45c; --wait: #6aa8ff; --bad: #ff6b6b;
  --r: 16px; --top-h: 65px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; background: var(--bg); color: var(--text); font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, textarea, select { font: inherit; color: inherit; }
.err { color: var(--bad); min-height: 1.4em; }

/* login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(380px, 100%); display: grid; gap: 14px; text-align: center; justify-items: center; }
.login h1 { margin: 0 0 8px; letter-spacing: .02em; }
.login input { width: 100%; }

input, textarea, select { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; width: 100%; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 120px; }

.btn { border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; padding: 12px 18px; cursor: pointer; font-weight: 600; min-height: 48px; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.big { width: 100%; font-size: 1.1em; min-height: 56px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; }

/* shell */
.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.top { height: var(--top-h); display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 5; }
.top .brand { font-weight: 700; display: flex; align-items: center; gap: 8px; margin-right: auto; }
.tabs { display: flex; gap: 6px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; border: 0; background: transparent; padding: 10px 16px; border-radius: 10px; color: var(--muted); font-weight: 600; cursor: pointer; min-height: 44px; }
.tab.on { background: var(--panel2); color: var(--text); }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.conn.ok { background: var(--ok); } .conn.bad { background: var(--bad); }
main { flex: 1; min-width: 0; width: 100%; max-width: 1100px; margin: 0 auto; padding: 16px; }
.view[hidden] { display: none !important; }

/* drive — fits the viewport, never scrolls */
#v-drive { height: calc(100dvh - var(--top-h)); overflow: hidden; margin: -16px; padding: 16px; }
.drive { height: 100%; display: grid; grid-template-columns: minmax(240px, 400px) minmax(0, 1fr); gap: clamp(16px, 4vw, 48px); align-items: center; }
.talk-wrap { display: grid; justify-items: center; gap: 14px; min-width: 0; }
.talk { width: min(320px, 38vh, 70vw); aspect-ratio: 1; border-radius: 50%; border: 0; cursor: pointer; background: radial-gradient(circle at 50% 40%, #f3b877, var(--accent)); color: var(--accent-ink); display: grid; place-items: center; box-shadow: 0 0 0 0 rgba(232,164,92,.5); transition: transform .15s; user-select: none; }
.talk:active { transform: scale(.97); }
.talk svg { width: 38%; height: 38%; }
.talk.listening { background: radial-gradient(circle at 50% 40%, #ff8f8f, var(--bad)); animation: pulse 1.2s infinite; }
.talk.thinking, .talk.transcribing { background: radial-gradient(circle at 50% 40%, #3b4452, #252c36); color: var(--text); }
.talk.speaking { background: radial-gradient(circle at 50% 40%, #8fc0ff, var(--wait)); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,107,107,.5); } 70% { box-shadow: 0 0 0 36px rgba(255,107,107,0); } 100% { box-shadow: 0 0 0 0 rgba(255,107,107,0); } }
.state { font-size: 1.25rem; font-weight: 700; color: var(--muted); min-height: 1.6em; text-align: center; }
.drive-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.voice-select { width: auto; padding: 10px 14px; appearance: none; -webkit-appearance: none; }

.stage { min-width: 0; overflow: hidden; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; gap: 12px; height: 100%; max-height: 560px; align-content: center; }
.said { color: var(--muted); font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1.5em; }
/* subtitle: fixed box, one short chunk at a time */
.subtitle { display: grid; place-items: center; text-align: center; min-height: 0; overflow: hidden;
  font-size: clamp(1.5rem, 3.4vw, 2.6rem); line-height: 1.3; font-weight: 700; padding: 8px 4px; }
.subtitle span { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; max-width: 22ch; animation: subin .18s ease-out; }
.subtitle.idle { font-size: clamp(1.1rem, 2.2vw, 1.5rem); font-weight: 500; color: var(--muted); }
.subtitle.idle span { max-width: 32ch; }
@keyframes subin { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.stage-actions { display: flex; gap: 8px; justify-content: center; min-height: 48px; }
.typebox { display: flex; gap: 8px; min-width: 0; }
.typebox input { min-width: 0; }

/* sheet (full text / history) */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 30; display: grid; place-items: center; padding: 16px; }
.sheet[hidden] { display: none; }
.sheet-card { width: min(760px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); }
.sheet-h { display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--line); }
.sheet-h h2 { margin: 0; font-size: 1.1rem; flex: 1; }
.sheet-body { overflow-y: auto; padding: 16px 20px 20px; font-size: 1.15rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; overscroll-behavior: contain; }
.sheet-body .m { padding: 12px 14px; border-radius: 12px; background: var(--panel2); margin-bottom: 8px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 1rem; }
.sheet-body .m.me { background: transparent; color: var(--muted); border: 1px solid var(--line); }

/* sessions */
.section-h { display: flex; align-items: center; gap: 12px; margin: 8px 0 12px; }
.section-h h2 { margin: 0; font-size: 1.1rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin-right: auto; }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); margin-bottom: 28px; }
.card { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; cursor: pointer; display: grid; gap: 8px; text-align: left; }
.card:hover { border-color: #37404d; }
.card .h { display: flex; align-items: center; gap: 10px; }
.card .t { font-weight: 700; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .proj { color: var(--muted); font-size: .9rem; }
.card .u { overflow-wrap: anywhere; color: var(--muted); font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .a { overflow-wrap: anywhere; font-size: .95rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.working { background: var(--work); animation: blink 1.4s infinite; }
.dot.idle, .dot.done { background: var(--ok); }
.dot.blocked { background: var(--bad); }
@keyframes blink { 50% { opacity: .35; } }
.badge { font-size: .78rem; padding: 3px 9px; border-radius: 99px; background: var(--panel2); color: var(--muted); white-space: nowrap; margin-left: auto; }
.empty-note { color: var(--muted); padding: 20px 0; }

/* detail */
.detail-h { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.detail-h h2 { margin: 0; font-size: 1.2rem; flex: 1 1 160px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.screen { background: #06080a; border: 1px solid var(--line); border-radius: var(--r); padding: 14px; font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-word; height: calc(100dvh - var(--top-h) - 190px); min-height: 220px; overflow: auto; margin: 0; }
.composer { display: flex; gap: 8px; margin-top: 12px; align-items: flex-end; }
.composer textarea { min-height: 56px; height: 56px; min-width: 0; }
.mic { width: 56px; min-width: 56px; height: 56px; padding: 0; display: grid; place-items: center; }
.mic.on { background: var(--bad); color: #fff; }
.mic svg { width: 22px; height: 22px; }

/* new */
.form { display: grid; gap: 14px; max-width: 720px; }
.form label { color: var(--muted); font-weight: 600; font-size: .95rem; }
.row { display: flex; gap: 8px; min-width: 0; }
.row > input, .row > textarea { min-width: 0; }

/* brain */
.brain { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
.items { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.items li { display: flex; gap: 10px; align-items: flex-start; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.items li .txt { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.items li .meta { color: var(--muted); font-size: .82rem; }
.items li.done .txt { text-decoration: line-through; color: var(--muted); }
.items li button { min-height: 40px; padding: 8px 12px; }
.items .none { color: var(--muted); background: transparent; border: 0; padding: 4px 0; }
.card.muted { opacity: .55; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 12px 18px; border-radius: 12px; z-index: 20; max-width: calc(100% - 32px); }

@media (max-width: 760px) {
  :root { --top-h: 58px; }
  .top { padding: 8px 12px; }
  .top .brand span { display: none; }
  .tab { padding: 10px 10px; }
  .drive { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); align-items: stretch; gap: 12px; }
  .talk { width: min(220px, 28dvh, 60vw); }
  .state { font-size: 1.05rem; }
  .stage { max-height: none; align-content: stretch; }
  .subtitle { font-size: clamp(1.35rem, 6vw, 1.8rem); }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .brain { grid-template-columns: minmax(0, 1fr); }
  .screen { height: calc(100dvh - var(--top-h) - 250px); min-height: 160px; }
}
@media (max-width: 760px) and (max-height: 720px) {
  .talk { width: min(170px, 26dvh, 50vw); }
  .talk-wrap { gap: 8px; }
  .drive-row { flex-wrap: nowrap; }
  .drive-row .btn { min-height: 40px; padding: 8px 10px; font-size: .9rem; }
  .said { font-size: .95rem; }
  .stage { gap: 8px; }
  .stage-actions { min-height: 40px; }
  .stage-actions .btn { min-height: 40px; padding: 8px 12px; }
}
@media (max-height: 560px) and (min-width: 761px) {
  .talk { width: min(220px, 34vh); }
  .drive-row .btn { min-height: 40px; padding: 8px 12px; }
}
@media (max-height: 480px) { .screen { min-height: 120px; height: calc(100dvh - var(--top-h) - 170px); } }
