:root {
  --bg: #000513;
  --rail: #07101c;
  --panel: #07101c;
  --panel-hi: #0c1828;
  --field: #050b16;
  --ink: #e8eef4;
  --silver: #d5dce6;
  --muted: #8b97a8;
  --dim: #5c6b7c;
  --line: rgba(213, 220, 230, 0.18);
  --line-soft: rgba(213, 220, 230, 0.10);
  --cyan: #2ea8ff;
  --cyan-hi: #67d0ff;
  --cyan-soft: rgba(46, 168, 255, 0.14);
  --mine: #122033;
  --warn: #e07070;
  --on-cyan: #041018;
  --radius: 10px;
  --sans: "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --rail-w: 280px;
  --col: 760px;
}

* { box-sizing: border-box; }

html, body { height: 100%; overflow: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
}

button, input, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

a { color: var(--cyan-hi); text-decoration: none; }
a:hover { text-decoration: underline; }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.shell {
  position: fixed;
  inset: 0;
  display: flex;
  overflow: hidden;
}

.rail {
  width: var(--rail-w);
  flex: 0 0 var(--rail-w);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  background: var(--rail);
  border-right: 1px solid var(--line-soft);
  padding: 1.4rem 1rem 1rem;
  overflow: auto;
}

.word {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.28em;
  color: var(--silver);
}

.lede, .hint, .status { color: var(--muted); }
.lede { margin: 0.45rem 0 0; font-size: 0.92rem; }
.status { margin: 0.8rem 0 0; font-size: 0.82rem; }
.status::before {
  content: "";
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  margin-right: 0.4rem;
  border-radius: 50%;
  background: var(--dim);
  vertical-align: 0.05rem;
}
.status.ok { color: var(--silver); }
.status.ok::before { background: var(--cyan); }

.cards { display: flex; flex-direction: column; gap: 0.25rem; }
.cards button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
}
.cards button.on {
  background: var(--panel-hi);
  color: var(--ink);
  box-shadow: inset 2px 0 0 var(--cyan);
}

.rail-account { margin-top: auto; display: flex; flex-direction: column; gap: 0.55rem; }
.rail-account .hint { margin: 0; font-size: 0.85rem; }
.rail-link { margin: 0.2rem 0 0; font-size: 0.85rem; }

details { border-top: 1px solid var(--line-soft); padding-top: 0.45rem; }
summary {
  cursor: pointer;
  color: var(--silver);
  padding: 0.25rem 0;
}
details form { margin-top: 0.4rem; }

.warn { color: var(--warn); margin: 0; font-size: 0.85rem; }

.stage { flex: 1; min-width: 0; display: flex; }
main { flex: 1; min-width: 0; min-height: 0; display: flex; }

.panel { display: none; flex: 1; min-width: 0; min-height: 0; }
.panel.on { display: flex; }
.panel[hidden] { display: none !important; }

#ask { flex-direction: column; }
#ask:not(.asked) { justify-content: center; }
#ask:not(.asked) .thread { flex: 0 0 auto; overflow: visible; padding: 0; }
#ask:not(.asked) .greet { margin: 0; padding: 0; }
#ask:not(.asked) .ask-status { min-height: 0; }
#ask:not(.asked) .composer { margin-top: 1.6rem; margin-bottom: 0; }

.thread {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  display: flex;
  flex-direction: column;
  width: min(var(--col), calc(100% - 4.5rem));
  margin: 0 auto;
  padding: 2.5rem 0 0.5rem;
}
.log {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-top: auto;
}

.greet {
  margin: auto;
  text-align: center;
  padding-bottom: 1.5rem;
}
#ask.asked .greet { display: none; }

.display {
  margin: 0 0 0.6rem;
  font-size: 3.4rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  color: var(--silver);
  text-indent: 0.22em;
}
.greet .hint { max-width: 34rem; margin: 0 auto; }

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.55rem;
  margin-top: 1.4rem;
}
.chips button {
  background: transparent;
  color: var(--silver);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.8rem;
}
.chips button:hover { background: var(--cyan-soft); border-color: rgba(46, 168, 255, 0.45); }

.turn {
  display: flex;
  flex-direction: column;
  flex: none;
}
.mine {
  align-self: flex-end;
  max-width: min(36rem, 100%);
  margin: 0 0 1.1rem;
  padding: 0.75rem 1rem;
  background: var(--mine);
  border: 1px solid var(--line-soft);
  border-radius: 14px 14px 4px 14px;
}
.lead {
  display: none;
  width: 100%;
  max-height: 160px;
  object-fit: contain;
  object-position: left center;
  border-radius: 8px;
  background: var(--field);
  margin: 0 0 0.75rem;
}
.lead:not([hidden]) { display: block; }
.thinking {
  margin: 0 0 0.85rem;
}
.thinking-title {
  margin: 0 0 0.35rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cyan-hi);
}
.thinking ul {
  display: block;
  list-style: none;
  padding: 0;
  margin: 0;
}
.thinking li {
  margin: 0.12rem 0;
  padding: 0;
  border: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}
.reply pre {
  margin: 0;
  white-space: pre-wrap;
  font: inherit;
  font-size: 1.05rem;
  line-height: 1.6;
}
.reply ul.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  list-style: none;
  padding: 0.9rem 0 0;
  margin: 0;
}
.reply ul.sources li {
  margin: 0;
  padding: 0.28rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  background: var(--panel);
}

.ask-status {
  width: min(var(--col), calc(100% - 4.5rem));
  margin: 0 auto;
  min-height: 1.2rem;
  font-size: 0.85rem;
}

.composer {
  width: min(var(--col), calc(100% - 4.5rem));
  margin: 0.35rem auto 1.5rem;
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  padding: 0.55rem 0.55rem 0.55rem 1rem;
  background: #10243a;
  border: 1px solid rgba(213, 220, 230, 0.28);
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}
.composer textarea {
  flex: 1;
  width: auto;
  min-height: 2.5rem;
  max-height: 9rem;
  margin: 0;
  padding: 0.45rem 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  resize: none;
}
.composer textarea:focus { outline: none; }
.composer button {
  background: var(--cyan);
  color: var(--on-cyan);
  border: 0;
  border-radius: 8px;
  padding: 0.55rem 0.95rem;
  font-weight: 650;
}
.composer button:hover { background: var(--cyan-hi); }

.page { flex: 1; min-width: 0; min-height: 0; overflow: auto; }
.log-body {
  margin: 0.8rem 0 0;
  max-height: min(62vh, 36rem);
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem 0.75rem;
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
  color: var(--silver);
}
.page-inner {
  width: min(var(--col), calc(100% - 4.5rem));
  margin: 0 auto;
  padding: 2.6rem 0 3rem;
}

h2 { font-size: 1.55rem; font-weight: 600; letter-spacing: 0.04em; margin: 0 0 0.35rem; }
h3 { font-size: 1rem; font-weight: 600; margin: 1.4rem 0 0.4rem; color: var(--silver); }

label { display: block; margin: 0.75rem 0 0.3rem; color: var(--muted); font-size: 0.88rem; }

input, textarea {
  width: 100%;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
}

.page button, .rail-account button, button.small {
  background: var(--panel-hi);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.85rem;
}
.page form button[type="submit"], .rail-account form button[type="submit"] {
  margin-top: 0.75rem;
  background: var(--cyan);
  color: var(--on-cyan);
  border-color: transparent;
  font-weight: 650;
}
button.small { padding: 0.25rem 0.6rem; margin: 0.35rem 0.3rem 0 0; font-size: 0.85rem; }

.row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.8rem; }

ul { padding-left: 1.1rem; }
li { margin: 0.45rem 0; }
li p { margin: 0.2rem 0 0; color: var(--muted); }

.shelf {
  margin-top: 1.2rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--line-soft);
}

.brain, .phone-kicker, .phone-lead, .phone-tabs { display: none; }

html[data-device="phone"] .shell { flex-direction: column; padding: 0 12px; }
html[data-device="phone"] .rail {
  position: relative;
  width: auto;
  flex: 0 0 auto;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  height: calc(62px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 4px 0;
  border-right: 0;
  border-bottom: 1px solid var(--line-soft);
  overflow: visible;
}
html[data-device="phone"] .rail-top {
  display: flex;
  flex: 1;
  min-width: 0;
  align-items: center;
  gap: 8px;
}
html[data-device="phone"] .brain {
  display: block;
  width: 26px;
  height: 26px;
  object-fit: contain;
  flex: none;
}
html[data-device="phone"] .word,
html[data-device="phone"] .lede,
html[data-device="phone"] nav.cards,
html[data-device="phone"] .rail-account .hint { display: none; }
html[data-device="phone"] .status {
  margin: 0;
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
html[data-device="phone"] .rail-account {
  margin: 0;
  width: auto;
  flex-direction: row;
  align-items: center;
  gap: 0;
}
html[data-device="phone"] .rail-link { display: none; }
html[data-device="phone"] details { border: 0; padding: 0; }
html[data-device="phone"] summary,
html[data-device="phone"] #logout-form button {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 14px;
  padding: 0.35rem 0.45rem;
}
html[data-device="phone"] details[open] {
  position: absolute;
  top: 100%;
  left: -12px;
  right: -12px;
  z-index: 6;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 0.7rem 1rem 1rem;
}
html[data-device="phone"] details[open] summary { color: var(--silver); }
html[data-device="phone"] .stage,
html[data-device="phone"] main,
html[data-device="phone"] #ask {
  min-height: 0;
  flex: 1 1 auto;
}
html[data-device="phone"] .stage { flex-direction: column; }
html[data-device="phone"] .thread {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 0 0.4rem;
}
html[data-device="phone"] .display,
html[data-device="phone"] .greet > .hint { display: none; }
html[data-device="phone"] .chips { margin-top: 1rem; }
html[data-device="phone"] .chips button { font-size: 13px; }
html[data-device="phone"] .phone-kicker {
  display: block;
  margin: 2.2rem 0 0.55rem;
  text-align: center;
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
html[data-device="phone"] .phone-kicker::before {
  content: "";
  display: block;
  width: 38px;
  height: 1px;
  margin: 0 auto 0.7rem;
  background: rgba(46, 168, 255, 0.55);
}
html[data-device="phone"] .phone-lead {
  display: block;
  max-width: 22rem;
  margin: 0 auto;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.35;
}
html[data-device="phone"] #ask:not(.asked) { justify-content: flex-start; }
html[data-device="phone"] #ask:not(.asked) .thread { flex: 1 1 auto; overflow: auto; }
html[data-device="phone"] #ask:not(.asked) .greet { margin: 0; padding: 0; }
html[data-device="phone"] .ask-status { width: 100%; min-height: 0; margin: 0; }
html[data-device="phone"] .composer {
  width: 100%;
  height: 60px;
  margin: 0 0 6px;
  padding: 6px;
  align-items: center;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  box-shadow: none;
}
html[data-device="phone"] .composer textarea {
  min-height: 0;
  padding: 0 6px;
}
html[data-device="phone"] .composer button {
  width: 76px;
  height: 48px;
  flex: none;
  border-radius: 8px;
}
html[data-device="phone"] .mine {
  max-width: 86%;
  border-radius: 10px;
  background: var(--mine);
}
html[data-device="phone"] .reply {
  position: relative;
  align-self: flex-start;
  max-width: 94%;
  background: var(--panel-hi);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.85rem 0.9rem 0.8rem 1rem;
}
html[data-device="phone"] .reply::before {
  content: "";
  position: absolute;
  left: 0;
  top: 14px;
  bottom: 14px;
  width: 1.5px;
  background: rgba(46, 168, 255, 0.55);
}
html[data-device="phone"] .reply::after {
  content: "";
  position: absolute;
  left: -1.5px;
  top: 10px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--cyan-hi);
}
html[data-device="phone"] .phone-tabs {
  display: flex;
  flex: none;
  height: 58px;
  margin: 0 0 calc(4px + env(safe-area-inset-bottom));
  padding: 0 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
html[data-device="phone"] .phone-tabs button {
  position: relative;
  flex: 1;
  background: transparent;
  border: 0;
  border-radius: 0;
  color: var(--muted);
  font-size: 11px;
  padding: 0;
  white-space: nowrap;
}
html[data-device="phone"] .phone-tabs button.on { color: var(--ink); }
html[data-device="phone"] .phone-tabs button.on::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 26px;
  height: 1.5px;
  margin-left: -13px;
  background: var(--cyan);
}
html[data-device="phone"] .page-inner { width: 100%; padding-top: 0.8rem; }
html[data-device="phone"] .log-body { max-height: none; min-height: 12rem; }

.boot {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--silver);
}
.boot.off { opacity: 0; pointer-events: none; transition: opacity 0.28s ease; }
.boot-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1.5rem 0.5rem;
}
.boot-mark {
  width: min(220px, 62vw);
  height: auto;
  max-height: min(328px, 52vh);
  object-fit: contain;
}
.boot-status {
  margin: 0.85rem 0 0;
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--silver);
}
.boot-pct {
  margin: 0.35rem 0 0;
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", monospace;
  font-size: 0.78rem;
  color: var(--cyan);
}
.boot-track {
  width: min(280px, 72vw);
  height: 2px;
  margin-top: 0.55rem;
  border-radius: 2px;
  background: var(--panel-hi);
  overflow: hidden;
}
.boot-fill {
  width: 2%;
  height: 100%;
  border-radius: 2px;
  background: var(--cyan);
}
.boot-foot {
  margin: 0;
  padding: 0.4rem 1rem calc(0.9rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  text-align: center;
}
.boot-foot span {
  color: var(--dim);
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.boot-foot strong {
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.boot-foot a {
  color: var(--dim);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}
html[data-device="phone"] .boot-mark { width: min(180px, 58vw); max-height: 42vh; }
