:root {
  --bg: #07080b;
  --surface: #0f1117;
  --surface-2: #151822;
  --line: #1f2330;
  --text: #eceef3;
  --muted: #8b91a3;
  --accent: #3d8bff;
  --accent-soft: rgba(61, 139, 255, 0.14);
  --accent-glow: rgba(61, 139, 255, 0.35);
  --danger: #ff6b6b;
  --radius: 18px;
  --maxw: 720px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: var(--maxw);
  margin: 0 auto;
}

/* Header */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: 0.01em; }
.mark {
  display: inline-block; flex: none;
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid var(--accent);
  box-shadow: 0 0 14px var(--accent-glow);
  position: relative;
}
.mark::after {
  content: ""; position: absolute; inset: 4px; border-radius: 50%; background: var(--accent);
}
.mark.big { width: 44px; height: 44px; border-width: 3px; box-shadow: 0 0 40px var(--accent-glow); }
.mark.big::after { inset: 12px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: #2c3243; }

/* Thread */
.thread { flex: 1; overflow-y: auto; padding: 8px 16px 24px; scroll-behavior: smooth; }
.hero { text-align: center; padding: 9vh 0 28px; }
.hero h1 { font-size: 30px; line-height: 1.2; font-weight: 600; letter-spacing: -0.02em; margin: 22px 0 0; }
.hero h1 span { color: var(--accent); }
.thread.started .hero { display: none; }

.messages { display: flex; flex-direction: column; gap: 18px; }
.msg { max-width: 100%; overflow-wrap: anywhere; }
.msg.assistant { color: var(--text); }
.msg.user {
  align-self: flex-end;
  max-width: 85%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: var(--radius) var(--radius) 6px var(--radius);
  white-space: pre-wrap;
}
.msg p { margin: 0 0 0.75em; }
.msg p:last-child, .msg ul:last-child, .msg ol:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 0 0 0.75em; padding-left: 1.3em; }
.msg li { margin: 0.2em 0; }
.msg strong { font-weight: 600; color: #fff; }
.msg.error { color: var(--danger); font-size: 15px; }
.typing { display: inline-flex; gap: 5px; padding: 6px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: 0.35; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 50% { opacity: 1; } }

/* Composer */
.composer { padding: 8px 12px calc(env(safe-area-inset-bottom) + 10px); }
.field {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 6px 6px 6px 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field:focus-within { border-color: rgba(61, 139, 255, 0.55); box-shadow: 0 0 0 4px var(--accent-soft); }
textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; line-height: 1.5; padding: 8px 0; max-height: 180px;
}
textarea::placeholder { color: #5d6376; }
.send {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  box-shadow: 0 0 18px var(--accent-glow);
  transition: opacity 0.15s, transform 0.1s;
}
.send:active { transform: scale(0.94); }
.send:disabled { opacity: 0.35; box-shadow: none; cursor: default; }
.send .i-stop { display: none; }
.busy .send .i-send { display: none; }
.busy .send .i-stop { display: block; }
.note { margin: 8px 0 0; text-align: center; font-size: 12px; color: #5d6376; }

/* Access code sheet */
.sheet {
  width: min(92vw, 380px); border: 1px solid var(--line); border-radius: 20px;
  background: var(--surface); color: var(--text); padding: 24px;
}
.sheet::backdrop { background: rgba(3, 4, 6, 0.75); backdrop-filter: blur(4px); }
.sheet h2 { margin: 0 0 6px; font-size: 20px; font-weight: 600; }
.sheet p { margin: 0 0 16px; color: var(--muted); }
.sheet input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; margin-bottom: 12px;
}
.sheet input:focus { outline: 0; border-color: var(--accent); }
.sheet .err { color: var(--danger); font-size: 14px; margin: -4px 0 12px; }
.primary {
  width: 100%; padding: 12px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font: 600 16px/1 Inter, system-ui, sans-serif;
}

@media (min-width: 720px) {
  .hero { padding-top: 14vh; }
  .hero h1 { font-size: 38px; }
}
@media (prefers-reduced-motion: reduce) {
  .thread { scroll-behavior: auto; }
  .typing i { animation: none; opacity: 0.7; }
}

/* ---------- Phase 2: accounts ---------- */
[hidden] { display: none !important; }
.actions { display: flex; gap: 8px; }
.screen { flex: 1; overflow-y: auto; padding: 8vh 20px 24px; text-align: center; }
.screen h1 { font-size: 30px; line-height: 1.2; font-weight: 600; letter-spacing: -0.02em; margin: 22px 0 32px; }
.screen h1 span { color: var(--accent); }
.screen h2 { font-size: 22px; font-weight: 600; margin: 22px 0 10px; }
.screen p { color: var(--muted); max-width: 420px; margin: 0 auto 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; max-width: 380px; margin: 0 auto; text-align: left; }
.stack label { color: var(--muted); font-size: 15px; }
.stack label strong { color: var(--text); font-weight: 500; }
.stack input, .sheet input {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit;
}
.stack input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
#otpInput { letter-spacing: 0.3em; font-size: 20px; text-align: center; }
.primary:disabled { opacity: 0.5; cursor: default; }
.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: 15px; cursor: pointer; padding: 8px; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--text); }
.fine { font-size: 13px; color: #5d6376 !important; margin-top: 18px !important; }
.fine.left { text-align: left; margin: 0 0 16px !important; }
.err { color: var(--danger) !important; font-size: 14px; }
.screen .err { margin-top: 14px; }

.sheet.side {
  margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; width: min(92vw, 400px);
  border-radius: 20px 0 0 20px; border-right: 0; padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  display: none; flex-direction: column;
}
.sheet.side[open] { display: flex; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); display: flex; flex-direction: column; }
.row-btn {
  text-align: left; background: none; border: 0; color: var(--text); font: inherit; padding: 12px 4px; cursor: pointer; border-radius: 10px;
}
.row-btn:hover { background: var(--surface-2); }
.row-btn.muted { color: var(--muted); }
.row-btn.muted span { font-size: 13px; color: #5d6376; display: block; }
.row-btn.danger { color: var(--danger); font-size: 15px; }
.row-btn.armed { background: rgba(255, 107, 107, 0.12); }

.convs { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.convs li button {
  width: 100%; text-align: left; background: none; border: 0; color: var(--text); font: inherit; cursor: pointer;
  padding: 10px 8px; border-radius: 10px; display: flex; flex-direction: column; gap: 2px;
}
.convs li button:hover, .convs li button.current { background: var(--surface-2); }
.convs .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convs .d { font-size: 12px; color: var(--muted); }
.convs .empty { color: var(--muted); padding: 8px; }

.memory { overflow-y: auto; flex: 1; }
.memory h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); margin: 16px 0 6px; }
.memory h3:first-child { margin-top: 0; }
.memory .item { display: flex; gap: 8px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.memory .item p { margin: 0; flex: 1; font-size: 15px; line-height: 1.5; }
.memory .item button { flex: none; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 6px; font-size: 18px; line-height: 1; }
.memory .item button:hover { color: var(--danger); }
.memory .empty { color: var(--muted); }

/* ---------- Phase 3: the three experiences ---------- */
.starts { display: grid; gap: 10px; margin: 4px 0 8px; }
.thread.started .starts { display: none; }
.start {
  display: flex; flex-direction: column; gap: 2px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px 16px; color: var(--text); font: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.start:hover { border-color: #2c3243; background: var(--surface-2); }
.start .s-t { font-weight: 600; }
.start .s-d { font-size: 14px; color: var(--muted); }
.start.now { border-color: rgba(61, 139, 255, 0.55); box-shadow: 0 0 0 1px rgba(61, 139, 255, 0.25), 0 0 24px rgba(61, 139, 255, 0.12); }
.start.now .s-t { color: var(--accent); }
@media (min-width: 720px) { .starts { grid-template-columns: repeat(3, 1fr); } }

/* ---------- Phase 4: feedback ---------- */
a.row-btn { text-decoration: none; display: block; }
#feedbackSheet textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; resize: vertical; max-height: 40vh;
}
#feedbackSheet textarea:focus { outline: 0; border-color: var(--accent); }
.rate { display: flex; gap: 8px; margin-bottom: 12px; }
.rate button {
  flex: 1; padding: 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
  color: var(--muted); font: inherit; cursor: pointer;
}
.rate button[aria-pressed="true"] { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
.sheet .row { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 12px; }
.primary.small { width: auto; padding: 11px 22px; }
.ok { color: #5fd38a !important; margin: 10px 0 0 !important; }
