* { box-sizing: border-box; scrollbar-color: var(--cyan-dim) var(--night-900); scrollbar-width: thin; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  overflow: hidden;
  background: var(--night-900);
  color: var(--text);
  font: 400 var(--text-md)/1.5 var(--font-display);
  user-select: none;
}

/* Screentone fades out of two opposite corners. */
body::before, body::after {
  content: "";
  position: fixed;
  width: 260px;
  height: 260px;
  background: radial-gradient(circle, var(--cyan-dim) 1.2px, transparent 1.6px) 0 0 / 8px 8px;
  opacity: 0.45;
  pointer-events: none;
}
body::before { top: 0; left: 0; mask-image: radial-gradient(circle at 0 0, #000, transparent 70%); }
body::after { right: 0; bottom: 0; mask-image: radial-gradient(circle at 100% 100%, #000, transparent 70%); }

button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--sakura); outline-offset: 2px; }

.mono { font-family: var(--font-mono); font-size: var(--text-xs); }

/* AR-glasses framing */
.bracket { position: fixed; width: 34px; height: 34px; border: 0 solid var(--cyan); pointer-events: none; z-index: 2; }
.bracket.tl { top: 8px; left: 8px; border-width: 3px 0 0 3px; }
.bracket.tr { top: 8px; right: 8px; border-width: 3px 3px 0 0; }
.bracket.bl { bottom: 8px; left: 8px; border-width: 0 0 3px 3px; }
.bracket.br { bottom: 8px; right: 8px; border-width: 0 3px 3px 0; }

.topbar { position: relative; z-index: 3; display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-6) 0; }
.name { margin: 0; font-size: var(--text-xl); font-weight: 800; line-height: 1; color: var(--paper); -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill; }
.topbar .clock { margin-left: auto; font-size: var(--text-sm); color: var(--cyan); }

.icon-button {
  padding: var(--space-1) var(--space-3);
  background: var(--night-800);
  border: 2px solid var(--ink);
  border-radius: 999px;
  box-shadow: 2px 2px 0 var(--ink);
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
}
.icon-button:hover { background: var(--night-700); }
.icon-button:active { transform: translate(2px, 2px); box-shadow: none; }
.update-button { background: var(--sakura); color: var(--ink); }
.update-button:hover { background: var(--sakura); }
.update-button:disabled { cursor: progress; }

/* The stage holds the core; everything else orbits it. */
.stage { position: relative; min-height: 0; }
#orb { position: absolute; inset: 0; width: 100%; height: 100%; }
#leaders { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
#leaders line { stroke: var(--cyan); stroke-width: 1.5; }

.readout { position: absolute; bottom: var(--space-2); color: var(--text-dim); line-height: 1.4; }
.readout.left { left: var(--space-6); }
.readout.right { right: var(--space-6); text-align: right; }
.readout strong { color: var(--cyan); font-weight: 700; }

.credit-bar { display: block; width: 120px; height: 6px; margin-top: var(--space-1); background: var(--night-700); border: 1px solid var(--ink); }
.credit-bar i { display: block; height: 100%; width: 0; background: var(--amber); }
.credit-bar.warn i { background: var(--sakura); }

/* Callouts */
.callout {
  position: absolute;
  max-width: 200px;
  padding: var(--space-1) var(--space-3);
  background: var(--night-800);
  border: 2px solid var(--ink);
  outline: 1px solid var(--cyan);
  outline-offset: -4px;
  font-size: var(--text-sm);
  display: flex;
  white-space: pre;
}
.callout > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.callout > b { flex: none; }
.callout b { font-weight: 800; color: var(--cyan); }
.callout[data-status="failed"] b { color: var(--danger); }
.callout.slot-0 { top: 8%; right: 6%; }
.callout.slot-1 { top: 8%; left: 6%; }
.callout.slot-2 { bottom: 26%; right: 6%; }
.callout.slot-3 { bottom: 26%; left: 6%; }

.lock { position: absolute; inset: -9px; pointer-events: none; transition: inset 140ms cubic-bezier(.2, 1.6, .4, 1); }
.callout:not([data-status="running"]) .lock { opacity: 0; }
.callout.fresh .lock { inset: -26px; }
.lock i { position: absolute; width: 11px; height: 11px; border: 0 solid var(--sakura); }
.lock i:nth-child(1) { top: 0; left: 0; border-width: 3px 0 0 3px; }
.lock i:nth-child(2) { top: 0; right: 0; border-width: 3px 3px 0 0; }
.lock i:nth-child(3) { bottom: 0; left: 0; border-width: 0 0 3px 3px; }
.lock i:nth-child(4) { bottom: 0; right: 0; border-width: 0 3px 3px 0; }

/* Weather */
.weather-panel {
  position: absolute;
  z-index: 2;
  top: 30%;
  left: 5%;
  width: 230px;
  padding: var(--space-2) var(--space-3);
  background: var(--night-800);
  border: 2px solid var(--ink);
  outline: 1px solid var(--cyan);
  outline-offset: -4px;
}
.weather-now { display: flex; align-items: baseline; gap: var(--space-2); }
.weather-now strong { font-size: 1.75rem; line-height: 1.1; color: var(--cyan); }
.weather-now span { font-size: var(--text-sm); }
.weather-place { margin: 0 0 var(--space-1); color: var(--text-dim); font-size: var(--text-xs); }
.weather-days { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; font-size: var(--text-xs); }
.weather-days li { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: var(--space-1); }
.weather-days span:nth-child(2) { overflow: hidden; color: var(--text-dim); white-space: nowrap; text-overflow: ellipsis; }
@media (max-width: 720px) { .weather-panel { display: none; } }

/* Speech */
.speech { position: relative; z-index: 3; display: flex; flex-direction: column; align-items: center; min-height: 92px; padding: var(--space-3) var(--space-6) var(--space-2); }

.bubble {
  position: relative;
  width: fit-content;
  max-width: min(64ch, 100%);
  max-height: 22vh;
  overflow-y: auto;
  padding: var(--space-3) var(--space-5);
  background: var(--paper);
  color: var(--ink);
  border: var(--line-ink) solid var(--ink);
  border-radius: 22px;
  box-shadow: var(--hard-shadow);
  font-weight: 700;
  user-select: text;
}
.bubble-wrap { position: relative; max-width: 100%; }
.bubble-wrap::before, .bubble-wrap::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 0;
  height: 0;
  border-style: solid;
  border-color: transparent;
  transform: translateX(-50%);
}
.bubble-wrap::before { top: -16px; border-width: 0 13px 17px; border-bottom-color: var(--ink); }
.bubble-wrap::after { top: -10px; z-index: 1; border-width: 0 9px 12px; border-bottom-color: var(--paper); }

.bubble-wrap.error .bubble { background: #FFE3E3; }
.bubble-wrap.error::after { border-bottom-color: #FFE3E3; }

.dots span { display: inline-block; animation: dot 1s infinite; }
.dots span:nth-child(2) { animation-delay: 120ms; }
.dots span:nth-child(3) { animation-delay: 240ms; }
@keyframes dot { 50% { transform: translateY(-4px); } }

.sources { margin: var(--space-2) 0 0; color: var(--text-dim); font-size: var(--text-xs); }
.sources a { color: var(--cyan); }

.heard { min-height: 1.5em; margin: var(--space-2) 0 0; color: var(--text-dim); font-size: var(--text-sm); }

/* Composer */
.composer { position: relative; z-index: 3; display: flex; gap: var(--space-2); padding: var(--space-2) var(--space-6) var(--space-5); }
.composer input {
  flex: 1;
  min-width: 0;
  padding: var(--space-2) var(--space-4);
  background: var(--night-800);
  border: var(--line-ink) solid var(--ink);
  border-radius: 999px;
  user-select: text;
}
.composer input::placeholder { color: var(--text-dim); }

/* Example messages (practice brain only) */
.examples { position: relative; z-index: 3; display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-2); padding: 0 var(--space-6) var(--space-1); }
.example { padding: 2px var(--space-3); background: transparent; border: 1px solid var(--cyan-dim); border-radius: 999px; color: var(--cyan); font-size: var(--text-sm); cursor: pointer; }
.example:hover:not(:disabled) { background: var(--night-700); }
.example:disabled { opacity: 0.45; cursor: not-allowed; }
@media (max-height: 560px) { .examples { display: none; } }

.button {
  padding: var(--space-2) var(--space-4);
  background: var(--cyan);
  color: var(--ink);
  border: var(--line-ink) solid var(--ink);
  border-radius: 12px;
  box-shadow: 3px 3px 0 var(--ink);
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}
.button:active { transform: translate(3px, 3px); box-shadow: none; }
.button.quiet { background: var(--night-700); color: var(--text); }
a.button { display: inline-block; text-decoration: none; }
.button.warm { background: var(--sakura); }
.button.is-held { background: var(--sakura); transform: translate(3px, 3px); box-shadow: none; }

/* Confirm card */
.confirm {
  position: absolute;
  left: 50%;
  bottom: var(--space-3);
  z-index: 5;
  width: min(440px, calc(100% - 48px));
  padding: var(--space-4) var(--space-5);
  background: var(--night-800);
  border: var(--line-ink) solid var(--ink);
  outline: 2px solid var(--amber);
  outline-offset: -7px;
  box-shadow: var(--hard-shadow);
  transform: translateX(-50%);
}
.confirm h2 { margin: 0 0 var(--space-1); font-size: var(--text-lg); font-weight: 800; color: var(--amber); }
.confirm p { max-height: 34vh; margin: 0 0 var(--space-3); overflow-y: auto; overflow-wrap: anywhere; white-space: pre-wrap; }
.confirm .actions { display: flex; gap: var(--space-2); justify-content: flex-end; }

.confirm.ringing { outline-color: var(--sakura); }
.confirm.ringing h2 { color: var(--sakura); }
.confirm.ringing p { font-size: var(--text-lg); font-weight: 700; }

/* Alarms drawer */
.alarm-list { flex: 1; margin: 0; padding: 0; overflow-y: auto; list-style: none; }
.alarm-list li { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: var(--space-1) var(--space-2); padding: var(--space-2) 0; border-bottom: 1px solid var(--night-700); }
.alarm-list .what { font-weight: 800; overflow-wrap: anywhere; }
.alarm-list .when { grid-column: 1; color: var(--cyan); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.alarm-list .ringing .when { color: var(--sakura); font-weight: 800; }
.alarm-list .missed .when { color: var(--text-dim); }
.alarm-list .icon-button { grid-column: 2; grid-row: 1 / span 2; }

/* History drawer */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  width: min(340px, 100%);
  padding: var(--space-5);
  background: var(--night-800);
  border-left: var(--line-ink) solid var(--ink);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 180ms ease-out, visibility 180ms;
}
.drawer.open { transform: none; visibility: visible; }
.drawer header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }
.drawer h2 { margin: 0; font-size: var(--text-lg); font-weight: 800; }
.drawer input { width: 100%; margin-bottom: var(--space-3); padding: var(--space-2) var(--space-3); background: var(--night-900); border: 2px solid var(--ink); border-radius: 10px; user-select: text; }
.history-list { flex: 1; margin: 0; padding: 0; overflow-y: auto; list-style: none; user-select: text; }
.history-list li { margin-bottom: var(--space-3); font-size: var(--text-sm); overflow-wrap: anywhere; }
.history-list .who { display: block; color: var(--cyan); font-weight: 800; }
.history-list .user .who { color: var(--sakura); }
.history-empty { color: var(--text-dim); font-size: var(--text-sm); }

/* Settings and first run */
dialog {
  width: min(560px, calc(100% - 32px));
  max-height: calc(100% - 48px);
  padding: var(--space-5);
  background: var(--night-800);
  color: var(--text);
  border: var(--line-ink) solid var(--ink);
  box-shadow: var(--hard-shadow);
}
dialog::backdrop { background: rgb(5 8 20 / 0.72); }
dialog h2 { margin: 0; font-size: var(--text-xl); font-weight: 800; }
dialog h3 { margin: var(--space-5) 0 var(--space-2); font-size: var(--text-lg); font-weight: 800; color: var(--cyan); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }

.field { display: grid; grid-template-columns: 11rem minmax(0, 1fr); align-items: center; gap: var(--space-1) var(--space-3); margin-bottom: var(--space-3); }
.field input[type="text"], .field input[type="number"], .field select { width: 100%; padding: var(--space-1) var(--space-2); background: var(--night-900); border: 2px solid var(--ink); border-radius: 8px; user-select: text; }
.field select option { background: var(--night-900); }
.field input[type="range"] { width: 100%; accent-color: var(--sakura); }
.field input[type="checkbox"] { justify-self: start; width: 20px; height: 20px; accent-color: var(--sakura); }
.field .hint, .field .field-error { grid-column: 2; font-size: var(--text-xs); }
.field .hint { color: var(--text-dim); }
.field .field-error { color: var(--danger); font-weight: 700; }
.field textarea { width: 100%; padding: var(--space-1) var(--space-2); background: var(--night-900); border: 2px solid var(--ink); border-radius: 8px; user-select: text; resize: vertical; font: inherit; color: inherit; }
.form-heading { margin: var(--space-4) 0 var(--space-1); font-size: var(--text-md, 1rem); }
.form-note { margin: 0 0 var(--space-3); color: var(--text-dim); font-size: var(--text-xs); }
.field .about-save { justify-self: start; }
.version-control { display: flex; align-items: center; gap: var(--space-3); }
.custom-form { margin-top: var(--space-3); }
.custom-row .custom-actions { display: flex; gap: var(--space-2); }
#custom-add { margin-top: var(--space-2); }
#connections .form-heading { margin-top: var(--space-4); }
.field > a.button { grid-column: 1 / -1; justify-self: start; white-space: nowrap; }
.history-list .when { display: block; color: var(--text-dim); font-size: var(--text-xs); }
.field input[type="password"] { width: 100%; padding: var(--space-1) var(--space-2); background: var(--night-900); border: 2px solid var(--ink); border-radius: 8px; user-select: text; }
.sign-in-error { margin: 0; color: var(--danger); font-size: var(--text-sm); font-weight: 700; }
.field .voice-sample { grid-column: 2; justify-self: start; }

.accounts { margin: 0; padding: 0; list-style: none; }
.accounts li { display: flex; align-items: center; justify-content: space-between; padding: var(--space-2) 0; border-bottom: 1px solid var(--night-700); }
.accounts .connection-state { flex: 1; margin-left: var(--space-3); color: var(--text-dim); font-size: var(--text-sm); }
.accounts .connection-state.on { color: var(--cyan); }
.note { color: var(--text-dim); font-size: var(--text-sm); }

.steps { display: flex; gap: var(--space-2); margin: 0 0 var(--space-4); padding: 0; list-style: none; font-size: var(--text-sm); color: var(--text-dim); }
.steps li[aria-current="step"] { color: var(--sakura); font-weight: 800; }
.step-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-4); }
.step-status { min-height: 1.5em; font-weight: 700; }

/* Practice-mode control panel (browser only) */
.mock-panel { position: fixed; left: 12px; top: 150px; z-index: 4; width: 170px; padding: var(--space-2); background: var(--paper); color: var(--ink); border: 2px solid var(--ink); font-size: var(--text-xs); }
.mock-panel summary { font-weight: 800; cursor: pointer; }
.mock-panel .group { margin-top: var(--space-1); display: flex; flex-wrap: wrap; gap: 3px; }
.mock-panel button { padding: 1px 5px; background: #fff; border: 1px solid var(--ink); border-radius: 4px; color: var(--ink); cursor: pointer; }

/* Narrow windows */
@media (max-width: 720px) {
  .topbar, .composer, .speech { padding-left: var(--space-4); padding-right: var(--space-4); }
  .readout.left { left: var(--space-4); }
  .readout.right { right: var(--space-4); }
  .field { grid-template-columns: 1fr; }
  .field .hint, .field .field-error { grid-column: 1; }
}

/* Overlay window */
body[data-mode="overlay"] { display: block; background: transparent; }
body[data-mode="overlay"]::before, body[data-mode="overlay"]::after { display: none; }
body[data-mode="overlay"].solid { background: var(--night-900); border: var(--line-ink) solid var(--ink); border-radius: 28px; }
body[data-mode="overlay"] .stage { position: absolute; inset: 0; }
body[data-mode="overlay"] .speech { position: absolute; left: 0; right: 0; bottom: 0; min-height: 0; padding: 0 var(--space-2) var(--space-2); }
body[data-mode="overlay"] .bubble { max-height: 74px; padding: var(--space-1) var(--space-3); border-radius: 14px; box-shadow: 2px 2px 0 var(--ink); font-size: var(--text-xs); }
body[data-mode="overlay"] .sources { margin-top: 2px; padding: 0 var(--space-2); max-width: 100%; overflow: hidden; background: var(--night-900); border-radius: 8px; white-space: nowrap; text-overflow: ellipsis; }
body[data-mode="overlay"] .callout { max-width: 130px; padding: 2px var(--space-2); font-size: var(--text-xs); overflow: hidden; text-overflow: ellipsis; }
body[data-mode="overlay"] .callout.slot-0, body[data-mode="overlay"] .callout.slot-2 { right: 4px; }
body[data-mode="overlay"] .callout.slot-1, body[data-mode="overlay"] .callout.slot-3 { left: 4px; }
body[data-mode="overlay"] .callout.slot-0, body[data-mode="overlay"] .callout.slot-1 { top: 4px; }
body[data-mode="overlay"] .confirm { top: 50%; bottom: auto; width: calc(100% - 16px); padding: var(--space-2) var(--space-3); transform: translate(-50%, -50%); }
body[data-mode="overlay"] .confirm h2 { font-size: var(--text-md); }
body[data-mode="overlay"] .confirm p { font-size: var(--text-xs); }

@media (prefers-reduced-motion: reduce) {
  .dots span { animation: none; }
  .lock, .drawer { transition: none; }
}
