:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --text: #16161a;
  --muted: #6b6b76;
  --line: #e4e4e9;
  --accent: #10a37f;
  --accent-ink: #ffffff;
  --danger: #e5484d;
  --user: #ececf1;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f12; --panel: #18181d; --text: #ececf1; --muted: #9a9aa6; --line: #2a2a31;
    --user: #26262d; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  --bg: #0f0f12; --panel: #18181d; --text: #ececf1; --muted: #9a9aa6; --line: #2a2a31;
  --user: #26262d; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 Inter, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }

.screen { display: none; min-height: 100vh; min-height: 100dvh; }
.screen.active { display: block; }

.logo { font-weight: 700; font-size: 28px; letter-spacing: -.02em; }
.logo.small { font-size: 18px; }

.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 999px; padding: 8px 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.big { padding: 14px 32px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: default; }

/* name */
#screen-name.active { display: grid; place-items: center; padding: 16px; }
.name-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 32px; box-shadow: var(--shadow); }
.name-card form { display: grid; gap: 10px; margin-top: 24px; }
.name-card label { font-weight: 600; }
.name-card input, .text-form input {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; outline: none;
}
.name-card input:focus, .text-form input:focus { border-color: var(--accent); }
.fine { font-size: 12px; color: var(--muted); margin: 18px 0 0; }

/* lobby */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--panel); gap: 12px; flex-wrap: wrap; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lobby { max-width: 1360px; margin: 0 auto; padding: 24px 16px 48px; }
.lobby h2 { font-size: 26px; letter-spacing: -.02em; margin: 8px 0 20px; }
.row-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.row-head h3 { margin: 0; font-size: 18px; }
.cast { display: grid; grid-auto-flow: column; grid-auto-columns: 240px; gap: 16px; overflow-x: auto; padding: 4px 4px 16px; scroll-snap-type: x mandatory; }
.card { scroll-snap-align: start; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; text-align: center; box-shadow: var(--shadow); transition: transform .15s, border-color .15s; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.avatar { border-radius: 50%; object-fit: cover; display: block; }
.card .avatar { width: 112px; height: 112px; margin-bottom: 10px; border: 3px solid var(--panel); box-shadow: 0 0 0 2px var(--line); }
.card .name { font-weight: 600; font-size: 16px; }
.card .job { font-size: 13px; }
.card .tag { font-size: 13px; color: var(--muted); min-height: 40px; margin: 6px 0 10px; }
.card .accent { font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; color: var(--muted); }
.card .last { font-size: 12px; color: var(--accent); min-height: 18px; }
.card .btn { margin-top: auto; width: 100%; }
.model-status { font-size: 13px; color: var(--muted); min-height: 20px; }

/* call */
.call { display: grid; grid-template-columns: 1fr 1fr; height: 100vh; height: 100dvh; }
.call-stage { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 6px; position: relative; text-align: center; }
.back { position: absolute; top: 16px; left: 16px; }
.call-stage h2 { margin: 18px 0 0; font-size: 26px; letter-spacing: -.02em; }
.avatar-wrap { position: relative; width: 200px; height: 200px; }
.avatar.xl { width: 200px; height: 200px; position: relative; z-index: 1; }
.ring { position: absolute; inset: -10px; border-radius: 50%; background: var(--accent); opacity: .18; transform: scale(var(--level, 1)); transition: transform .08s linear; }
.ring.user { background: #6e56cf; }
.status { margin-top: 12px; font-weight: 500; min-height: 24px; }
.load-bar { width: 240px; height: 6px; border-radius: 6px; background: var(--line); overflow: hidden; }
.load-bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.controls { display: flex; gap: 16px; margin-top: 22px; align-items: center; }
.round { width: 60px; height: 60px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); display: grid; place-items: center; color: var(--text); }
.round svg { width: 26px; height: 26px; fill: currentColor; }
.round.off { background: var(--text); color: var(--bg); }
.round.end { background: var(--danger); border-color: var(--danger); color: #fff; }
.rec-dot { width: 20px; height: 20px; border-radius: 50%; background: var(--danger); display: block; }
.round.recording .rec-dot { border-radius: 4px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .35; } }
.rec-indicator { color: var(--danger); font-size: 13px; margin-top: 10px; }
.toggle { font-size: 13px; color: var(--muted); margin-top: 14px; display: flex; gap: 6px; align-items: center; }

.call-side { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.transcript { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.old { opacity: .55; }
.divider { text-align: center; font-size: 12px; color: var(--muted); margin: 6px 0; }
.text-form { display: flex; gap: 8px; padding: 14px; border-top: 1px solid var(--line); }
.text-form input { flex: 1; min-width: 0; }


/* name chip */
.name-chip { display: flex; align-items: center; gap: 6px; }
.name-chip input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; width: 160px; outline: none; }
.btn.small { padding: 5px 12px; font-size: 13px; }

/* caption under the avatar */
.caption { max-width: 440px; min-height: 48px; margin: 10px 0 0; color: var(--muted); font-size: 15px; }

/* scoring panel */
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.side-head h3 { margin: 0; font-size: 16px; }
.avg { font-size: 13px; color: var(--muted); }
.avg b { color: hsl(var(--hue, 0) 65% 42%); font-size: 16px; }
.scores { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; }
.scores .empty { margin: 8px 0; font-size: 14px; }
.score-card { border: 1px solid var(--line); border-left: 4px solid hsl(var(--hue, 0) 65% 45%); border-radius: 12px; background: var(--panel); animation: fadein .6s ease both; }
.score-card.pending { border-left-color: var(--line); }
.score-card summary { list-style: none; display: flex; gap: 12px; align-items: center; padding: 10px 12px; cursor: pointer; }
.score-card summary::-webkit-details-marker { display: none; }
.badge { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: hsl(var(--hue, 0) 65% 42%); transition: background .6s; }
.pending .badge { background: var(--line); color: var(--muted); animation: pulse 1.2s infinite; }
.said { font-size: 14px; }
.verdict { font-size: 12px; color: var(--muted); }
.score-card .detail { padding: 0 14px 12px 64px; font-size: 13px; display: grid; gap: 8px; animation: fadein .3s ease both; }
.sub { color: var(--muted); }
.issue s { color: var(--danger); }
.issue b { color: hsl(120 55% 35%); }
.issue p, .native p { margin: 2px 0 0; color: var(--muted); }
.native { border-top: 1px dashed var(--line); padding-top: 8px; }
.her-line { font-size: 13px; color: var(--muted); padding: 2px 4px 2px 12px; border-left: 2px solid var(--line); }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 50% { opacity: .5; } }

/* sessions dashboard */
#screen-sessions .topbar { justify-content: space-between; }
.dash { display: grid; grid-template-columns: 360px 1fr; height: calc(100vh - 61px); height: calc(100dvh - 61px); }
.session-list { border-right: 1px solid var(--line); overflow-y: auto; padding: 12px; display: grid; align-content: start; gap: 8px; }
.session { display: flex; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); cursor: pointer; text-align: left; width: 100%; color: var(--text); }
.session.active { border-color: var(--accent); }
.session .avatar { width: 44px; height: 44px; flex: none; }
.session .meta { flex: 1; min-width: 0; }
.session .meta div:last-child { font-size: 12px; color: var(--muted); }
.session .badge { width: 36px; height: 36px; font-size: 14px; }
.session .badge.none { background: var(--line); color: var(--muted); }
.session-detail { overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 10px; max-width: 760px; }
.session-head { display: flex; gap: 14px; align-items: center; margin-bottom: 6px; }
.session-head .avatar { width: 64px; height: 64px; }
.session-head h3 { margin: 0; }
.wrap-msg { background: var(--user); border-radius: 14px; padding: 14px 16px; font-size: 16px; }
.just-ended { border: 1px solid var(--accent); }

/* drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow); z-index: 10; display: flex; flex-direction: column; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0; }
.rec-list { overflow-y: auto; padding: 16px 20px; display: grid; gap: 14px; }
.rec { border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: grid; gap: 10px; }
.rec-top { display: flex; gap: 12px; align-items: center; }
.rec-top .avatar { width: 40px; height: 40px; }
.rec audio { width: 100%; }
.rec-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.rec-actions a, .rec-actions button { font-size: 13px; padding: 6px 12px; text-decoration: none; }
.rec details { font-size: 13px; }
.rec details p { margin: 4px 0; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; z-index: 20; font-size: 14px; max-width: calc(100vw - 32px); }

/* ================= responsive: tablets and phones ================= */

/* Notch / home-bar safe areas (viewport-fit=cover). */
.topbar { padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); padding-top: max(14px, env(safe-area-inset-top)); }
.toast { bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px)); }
.drawer { padding-bottom: env(safe-area-inset-bottom); }
.all-sessions { display: none; }

/* People: a grid that fills the width instead of a sideways carousel. */
.cast { grid-auto-flow: row; grid-auto-columns: auto; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
        overflow: visible; scroll-snap-type: none; padding: 4px 0 16px; }

/* Touch screens: bigger targets, no hover lift, 16px inputs so iOS doesn't zoom in. */
@media (hover: none) {
  .card:hover { transform: none; border-color: var(--line); }
}
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn.small { min-height: 38px; padding: 6px 14px; }
  .round { width: 64px; height: 64px; }
  .toggle { padding: 8px 0; }
  .toggle input { width: 20px; height: 20px; }
  .score-card summary { padding: 12px; }
}
input, textarea, select { font-size: 16px !important; }

/* Tablet portrait and phones: stack the call, list → detail for sessions. */
@media (max-width: 820px) {
  .topbar { position: sticky; top: 0; z-index: 5; padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: 10px; }

  /* Call: everything in one screen. Stage on top, your scores scroll underneath. */
  .call { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); height: 100vh; height: 100dvh; }
  .call-stage { padding: max(56px, calc(env(safe-area-inset-top) + 48px)) 16px 14px; gap: 2px; }
  .back { top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); }
  .avatar-wrap, .avatar.xl { width: 160px; height: 160px; }
  .call-stage h2 { margin-top: 12px; font-size: 22px; }
  .status { margin-top: 6px; }
  .caption { min-height: 0; margin-top: 6px; }
  .controls { margin-top: 12px; }
  .toggle { margin-top: 6px; }
  .call-side { border-left: 0; border-top: 1px solid var(--line); min-height: 0; }
  .side-head { padding: 12px 16px; position: sticky; top: 0; background: var(--panel); }
  .scores { padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); }

  /* Sessions: the list, or one session with a way back. */
  .dash { grid-template-columns: 1fr; height: auto; }
  .session-list { border-right: 0; padding: 12px 16px; }
  .session-detail { padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); max-width: none; }
  .dash:not(.reading) .session-detail, .dash.reading .session-list { display: none; }
  .dash.reading .all-sessions { display: inline-flex; align-items: center; justify-self: start; margin: 12px 16px 0; }
  #screen-sessions .topbar > span { display: none; }
}

/* Phones. */
@media (max-width: 560px) {
  body { font-size: 15px; }
  .topbar { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); gap: 8px; }
  #screen-lobby .topbar { display: grid; grid-template-columns: 1fr auto; }
  #screen-lobby .topbar-right { display: contents; }
  #screen-lobby .topbar-right > [data-go] { padding: 6px 12px; font-size: 14px; }
  #screen-lobby .topbar .logo { grid-column: 1; }
  #screen-lobby .topbar-right > [data-go="sessions"] { grid-row: 1; grid-column: 2; justify-self: end; }
  #screen-lobby .topbar-right > [data-go="recordings"] { grid-row: 2; grid-column: 2; justify-self: end; }
  #screen-lobby #name-view, #screen-lobby #name-edit { grid-row: 2; grid-column: 1; min-width: 0; }
  #hello { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; font-size: 14px; }
  .name-chip input { width: 100%; min-width: 0; }
  #screen-lobby #name-edit { grid-column: 1 / -1; grid-row: 3; }

  .lobby { padding: 14px 14px calc(32px + env(safe-area-inset-bottom)); }
  .lobby h2 { font-size: 22px; margin: 4px 0 12px; }
  .row-head { flex-direction: column; gap: 0; }

  /* People as a list: face on the left, details and button on the right. */
  .cast { grid-template-columns: 1fr; gap: 10px; }
  .card { display: grid; grid-template-columns: 72px 1fr; column-gap: 14px; row-gap: 2px; text-align: left; padding: 14px; align-items: start; }
  .card .avatar { width: 72px; height: 72px; margin: 0; grid-row: 1 / span 5; }
  .card .name, .card .job, .card .accent, .card .tag, .card .last { grid-column: 2; }
  .card .accent { justify-self: start; }
  .card .tag { min-height: 0; margin: 4px 0 0; }
  .card .last { min-height: 0; }
  .card .last:empty { display: none; }
  .card .btn { grid-column: 1 / -1; margin-top: 10px; }

  .name-card { padding: 24px 20px; border-radius: 18px; }

  .avatar-wrap, .avatar.xl { width: 128px; height: 128px; }
  .ring { inset: -8px; }
  .call-stage h2 { font-size: 20px; }
  .btn.big { padding: 14px 40px; }
  .controls { gap: 18px; }
  .toggle { font-size: 12.5px; }
  .score-card .detail { padding-left: 14px; }

  .session-head .avatar { width: 52px; height: 52px; }
  .drawer { width: 100vw; border-left: 0; }
}

/* Short landscape phones: side by side again, smaller face. */
@media (max-height: 500px) and (orientation: landscape) {
  .call { grid-template-columns: 1fr 1fr; grid-template-rows: none; }
  .call-stage { padding-top: 48px; }
  .avatar-wrap, .avatar.xl { width: 96px; height: 96px; }
  .call-side { border-top: 0; border-left: 1px solid var(--line); }
}
