/* Dori Live: one screen, mobile first (designed on a 412 x 915 phone), the character is the hero.
   Palette = Dori OS (one dark base, one violet accent) + one colour per conversation state. */
:root {
  --bg: #0a0d16;
  --bg2: #0e1220;
  --panel: #131829;
  --panel2: #182038;
  --line: #232a42;
  --text: #e9ecf5;
  --dim: #8a93ab;
  --accent: #8b7cf7;
  --accent-dk: #6c5ce7;
  --cyan: #4cd3e9;
  --amber: #ffc23d;
  --blue: #5b9bf0;
  --danger: #ef5a6f;
  --st: var(--accent);
  --lvl: 0;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
body[data-state="listening"] { --st: var(--cyan); }
body[data-state="thinking"] { --st: var(--amber); }
body[data-state="talking"] { --st: var(--accent); }
body[data-state="working"] { --st: var(--blue); }
body[data-state="offline"] { --st: #6b7389; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Rubik', system-ui, sans-serif;
  font-weight: 500;
  color: var(--text);
  background: radial-gradient(900px 620px at 50% -12%, #18204a 0%, var(--bg) 62%) fixed, var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg use { pointer-events: none; }
.icon-btn svg, .side .ic svg, .send svg, .talk svg, .chip svg, .badge svg {
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
}

/* ── top bar ── */
.top { flex: 0 0 auto; height: 60px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px 0 12px; gap: 10px; }
.pill {
  display: inline-flex; align-items: center; gap: 9px;
  height: 36px; padding: 0 16px 0 14px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line);
  font-weight: 800; font-size: 15px; letter-spacing: 0.2px; white-space: nowrap;
  transition: border-color 0.3s;
}
.pill .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--st); box-shadow: 0 0 0 0 var(--st); transition: background 0.3s; }
body[data-state="listening"] .pill, body[data-state="talking"] .pill, body[data-state="thinking"] .pill, body[data-state="working"] .pill { border-color: color-mix(in srgb, var(--st) 45%, var(--line)); }
body[data-state="listening"] .pill .dot, body[data-state="talking"] .pill .dot { animation: dotPulse 1.4s ease-out infinite; }
body[data-state="thinking"] .pill .dot, body[data-state="working"] .pill .dot { animation: dotBlink 1s ease-in-out infinite; }
@keyframes dotPulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--st) 70%, transparent); } 100% { box-shadow: 0 0 0 9px transparent; } }
@keyframes dotBlink { 50% { opacity: 0.35; } }
.tools { display: flex; align-items: center; gap: 8px; }
/* every control is at least 48 px to the finger; the thumbs keep their 40 px circle inside a 48 px button */
.picker { display: flex; gap: 0; }
.thumb {
  position: relative; width: 48px; height: 48px; display: grid; place-items: center; flex: 0 0 auto;
  opacity: 0.62; transition: opacity 0.2s, transform 0.2s;
}
.thumb svg { display: block; width: 40px; height: 40px; border-radius: 50%; clip-path: circle(50%); }
.thumb::after { content: ''; position: absolute; inset: 4px; border-radius: 50%; pointer-events: none; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1); transition: box-shadow 0.2s; }
.thumb[aria-checked="true"] { opacity: 1; transform: scale(1.04); }
.thumb[aria-checked="true"]::after { box-shadow: 0 0 0 2.5px var(--bg), 0 0 0 5px var(--accent); }
.icon-btn { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; color: var(--dim); background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); flex: 0 0 auto; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn[aria-expanded="true"] { color: var(--text); border-color: var(--accent); }

/* ── the stage card ── */
.stage-card {
  position: relative; flex: 1 1 auto; min-height: 0; margin: 0 12px;
  border-radius: 30px; overflow: hidden; background: #161b3f;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.07) inset, 0 20px 44px rgba(0, 0, 0, 0.42);
  isolation: isolate;
}
.stage-card::after { /* the state glow: a soft rim in the state colour, stronger with the voice */
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--st) calc(30% + var(--lvl) * 60%), transparent);
  opacity: 0; transition: opacity 0.35s;
}
body[data-state="listening"] .stage-card::after, body[data-state="talking"] .stage-card::after, body[data-state="thinking"] .stage-card::after, body[data-state="working"] .stage-card::after { opacity: 1; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; cursor: pointer;
  transition: filter 0.7s ease; -webkit-mask-image: linear-gradient(to bottom, #000 82%, rgba(0, 0, 0, 0.55) 100%); mask-image: linear-gradient(to bottom, #000 82%, rgba(0, 0, 0, 0.55) 100%); }
body[data-state="offline"] #stage { filter: saturate(0.35) brightness(0.5); }
.badges {
  position: absolute; left: 12px; right: 12px; bottom: 14px; z-index: 2; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.chips { display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: 100%; }
.chip, .badge, .toast {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%; white-space: nowrap;
  padding: 8px 16px 9px 14px; border-radius: 999px; font-size: 14.5px; font-weight: 800; color: var(--text);
  background: rgba(10, 13, 24, 0.8); border: 1px solid rgba(255, 255, 255, 0.12);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}
.chip { border-color: color-mix(in srgb, var(--blue) 55%, transparent); color: #dfe8ff; animation: chipIn 0.35s cubic-bezier(0.2, 1.4, 0.4, 1); }
.chip svg { width: 16px; height: 16px; color: var(--blue); flex: 0 0 auto; animation: spin 0.9s linear infinite; }
.chip .task { font-weight: 500; color: #b8c4e6; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes chipIn { from { transform: translateY(8px) scale(0.92); opacity: 0; } }
.badge { display: none; }
.badge svg { width: 18px; height: 18px; flex: 0 0 auto; }
/* the badge says WHY the link is down: the PC cannot be reached ("המחשב ישן"), or the sidecar closed us on purpose */
body[data-link="down"] .sleep { display: inline-flex; }
body[data-link="held"] .held { display: inline-flex; }
.badge.held { border-color: color-mix(in srgb, var(--blue) 50%, transparent); }
/* the brain has no Claude login: said once and kept, not only in a 2.6 s toast */
body[data-auth="missing"]:not([data-state="offline"]):not([data-state="talking"]) .authb { display: inline-flex; }
.badge.authb { border-color: color-mix(in srgb, var(--amber) 60%, transparent); color: #ffe3a3; }
.badge.authb svg { color: var(--amber); }
body.half[data-state="talking"] .hint { display: inline-flex; }
.toast { white-space: normal; text-align: center; justify-content: center; border-radius: 16px; line-height: 1.35; max-width: min(100%, 340px); animation: chipIn 0.25s ease-out; }
.toast[hidden] { display: none; }

/* ── captions ── */
/* 124 px = the heard line + three lines of the reply: a third line must never show half cut */
.caption { flex: 0 0 auto; height: 124px; padding: 12px 24px 0; display: flex; flex-direction: column; gap: 6px; overflow: hidden; }
.heard { display: flex; align-items: center; gap: 8px; min-height: 22px; font-size: 14.5px; color: var(--dim); white-space: nowrap; overflow: hidden; opacity: 0; transition: opacity 0.25s; }
.heard.on { opacity: 1; }
.heard .who { flex: 0 0 auto; font-size: 11.5px; font-weight: 800; letter-spacing: 0.3px; padding: 2px 8px 3px; border-radius: 6px; background: rgba(255, 255, 255, 0.07); color: #b2bad0; }
.heard .txt { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.heard .dots { display: none; gap: 4px; align-items: center; height: 14px; }
.heard .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--cyan); animation: hop 1s ease-in-out infinite; }
.heard .dots i:nth-child(2) { animation-delay: 0.15s; } .heard .dots i:nth-child(3) { animation-delay: 0.3s; }
.heard.live { opacity: 1; }
.heard.live .dots { display: inline-flex; }
@keyframes hop { 0%, 60%, 100% { transform: translateY(0); opacity: 0.45; } 30% { transform: translateY(-4px); opacity: 1; } }
/* the box is three lines tall and anchored at the bottom: when two clauses need more, the OLDEST line slides out under a fade
   at the top, and the words Dori is saying now stay in view (a clamp would cut those instead) */
.say {
  --lines: 3;
  font-size: 19.5px; line-height: 1.38; font-weight: 500; color: var(--text);
  max-height: calc(1.38em * var(--lines)); overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end;
}
.say-in { display: block; text-wrap: pretty; }
.say.over { -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 1.1em); mask-image: linear-gradient(to bottom, transparent 0, #000 1.1em); }
.say.hint-text { color: var(--dim); font-size: 17px; }
.say .cut { color: var(--dim); }

/* ── typed fallback ── */
.type-bar { flex: 0 0 auto; display: flex; gap: 8px; padding: 2px 16px 8px; }
.type-bar[hidden] { display: none; }
.type-bar input {
  flex: 1 1 auto; min-width: 0; height: 48px; border-radius: 24px; padding: 0 18px;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  font: 500 16.5px 'Rubik', system-ui, sans-serif; -webkit-user-select: text; user-select: text;
}
.type-bar input::placeholder { color: var(--dim); }
.type-bar .send { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; flex: 0 0 auto; }
.type-bar .send svg { width: 22px; height: 22px; stroke-width: 2.4; }

/* ── controls ── */
.controls { flex: 0 0 auto; display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; padding: 6px 14px 18px; }
.side { justify-self: center; display: flex; flex-direction: column; align-items: center; gap: 7px; width: 96px; padding-top: 10px; color: var(--dim); }
.side .ic { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line); transition: background 0.2s, color 0.2s, border-color 0.2s; }
.side .ic svg { width: 23px; height: 23px; }
.side .lbl { font-size: 12.5px; font-weight: 800; line-height: 1.15; text-align: center; display: flex; flex-direction: column; }
.side .lbl small { font-size: 11px; font-weight: 500; }
.side[aria-pressed="true"], .side[aria-checked="true"] { color: var(--text); }
.side[aria-pressed="true"] .ic, .side[aria-checked="true"] .ic { background: color-mix(in srgb, var(--accent) 22%, var(--panel)); border-color: var(--accent); color: #fff; }
.talk-wrap { display: flex; flex-direction: column; align-items: center; gap: 15px; }
.talk {
  position: relative; width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  background: linear-gradient(160deg, #9d90ff 0%, var(--accent-dk) 100%);
  box-shadow: 0 10px 26px rgba(108, 92, 231, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: transform 0.15s, background 0.3s, box-shadow 0.3s;
}
.talk:active { transform: scale(0.95); }
.talk svg { width: 34px; height: 34px; position: relative; z-index: 1; }
.talk .ic-stop { display: none; }
.talk .ring { position: absolute; inset: -6px; border-radius: 50%; border: 3px solid var(--st); opacity: 0; transform: scale(calc(1 + var(--lvl) * 0.1)); transition: opacity 0.3s, border-color 0.3s; }
body[data-conv="on"] .talk { background: var(--panel2); box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.08); }
body[data-conv="on"] .talk .ic-mic { display: none; }
body[data-conv="on"] .talk .ic-stop { display: block; color: #ff8a9a; }
body[data-conv="on"] .talk .ring { opacity: 1; }
body[data-state="offline"] .talk { filter: saturate(0.4); opacity: 0.75; }
.talk-lbl { font-size: 14px; font-weight: 800; color: var(--text); white-space: nowrap; }

/* ── pairing ── */
.pair { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: 18px; background: rgba(4, 6, 12, 0.72); }
.pair[hidden] { display: none; }
.pair-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 18px 18px 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5); }
.pair-card b { display: block; font-size: 19px; font-weight: 900; margin-bottom: 6px; }
.pair-card p { margin: 6px 0 12px; font-size: 14.5px; line-height: 1.45; color: var(--dim); }
.pair-card .mono { direction: ltr; unicode-bidi: isolate; color: var(--text); font-weight: 800; }
.pair-card form { display: flex; gap: 8px; }
.pair-card input { flex: 1 1 auto; min-height: 50px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: 800 20px Rubik, sans-serif; letter-spacing: 2px; text-align: center; direction: ltr; }
.pair-card button { min-height: 50px; padding: 0 20px; border-radius: 14px; background: var(--accent-dk); color: #fff; font-size: 16px; font-weight: 900; }
.pair-err { color: var(--danger) !important; font-weight: 800; min-height: 1.2em; margin: 8px 0 0 !important; }

/* ── debug drawer ── */
.sheet-back { position: fixed; inset: 0; background: rgba(4, 6, 12, 0.5); z-index: 20; }
.sheet-back[hidden], .sheet[hidden] { display: none; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 560px; margin: 0 auto;
  max-height: 72vh; overflow: auto; padding: 14px 16px calc(18px + var(--safe-b));
  background: var(--panel); border-top: 1px solid var(--line); border-radius: 22px 22px 0 0;
  box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.5); -webkit-user-select: text; user-select: text;
  animation: sheetIn 0.25s ease-out;
}
@keyframes sheetIn { from { transform: translateY(30px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-head b { font-size: 17px; font-weight: 900; }
.sheet h3 { font-size: 14px; font-weight: 800; margin: 14px 0 6px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 12px; border-radius: 14px; background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line); }
.setting b { display: block; font-size: 14.5px; font-weight: 800; }
.setting small { display: block; margin-top: 3px; font-size: 12px; line-height: 1.35; color: var(--dim); }
.seg { flex: 0 0 auto; display: flex; padding: 3px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); }
.seg button { min-height: 44px; padding: 0 15px; border-radius: 999px; font-size: 13.5px; font-weight: 800; color: var(--dim); white-space: nowrap; }
/* the darker violet: white text on the lighter one was 3.3:1 */
.seg button[aria-checked="true"] { background: var(--accent-dk); color: #fff; }
.seg button:disabled { opacity: 0.35; cursor: not-allowed; }
.sheet h3 small { font-weight: 500; color: var(--dim); font-size: 12px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; font-size: 13px; }
.kv dt { color: var(--dim); }
.kv dd { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tbl th { color: var(--dim); font-weight: 800; text-align: start; padding: 5px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 6px 6px; border-bottom: 1px solid rgba(255, 255, 255, 0.04); white-space: nowrap; }
.tbl td.good { color: #7ee2a8; } .tbl td.mid { color: var(--amber); } .tbl td.bad { color: var(--danger); }
.tbl tr.empty td { color: var(--dim); text-align: center; padding: 14px; white-space: normal; }


/* short phones: tighten the chrome, the character keeps the space */
@media (max-height: 700px) {
  .top { height: 52px; }
  .caption { height: 86px; padding-top: 8px; }
  .say { font-size: 17.5px; --lines: 2; }
  .talk { width: 74px; height: 74px; }
  .side .ic { width: 46px; height: 46px; }
  .controls { padding-bottom: 10px; }
}
/* desktop: the same column, a little more air */
@media (min-width: 700px) and (min-height: 760px) {
  #app { padding-top: 18px; padding-bottom: 14px; }
  .stage-card { border-radius: 34px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
