/* Jarvis voice page. The orb, its rings and the stars are drawn on the canvas (orb.js); this is everything else. */

:root {
  color-scheme: dark;
  --bg: #02050a;
  --text: #e9f1f9;
  --muted: #8fa4b9;
  --faint: #5b6f83;
  --line: rgba(150, 200, 240, 0.16);
  --line-strong: rgba(150, 200, 240, 0.34);
  --glass: rgba(140, 190, 230, 0.06);
  --glass-strong: rgba(140, 190, 230, 0.13);
  --accent: #6fd0ff;
  --state: #7896b9;              /* follows what Jarvis is doing; the same colours as the orb */
  --panel: #08111b;
  --field: #0c1723;
  --danger: #ff9f7c;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}
body[data-state="ready"] { --state: #5fbeff; }
body[data-state="listening"] { --state: #96f0ff; }
body[data-state="thinking"] { --state: #ffbe5f; }
body[data-state="speaking"] { --state: #8ccdff; }
body[data-state="error"] { --state: #ff785a; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, a, input, select, label { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
[hidden] { display: none !important; }
.hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* The stars and the orb are drawn on one canvas behind everything; a vignette darkens the edges over it. */
#scene { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 120% 90% at 50% 36%, transparent 52%, rgba(0, 0, 0, 0.62) 100%);
}

/* ---------------------------------------------------------------- the main screen
   Header, then the orb with its status (fixed in place), then the conversation (which scrolls), then the dock.
   The orb never moves when a long reply comes in. */
main {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 18px max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  animation: iris 1.1s var(--ease) both;          /* the page opens like an iris around the orb */
}
@keyframes iris {
  from { clip-path: circle(0% at 50% 34%); }
  to { clip-path: circle(150% at 50% 34%); }
}

header { flex: none; width: 100%; min-height: 52px; display: flex; align-items: center; justify-content: space-between; }
.tools { display: flex; gap: 8px; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  padding-left: 2px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.46em;
  text-transform: uppercase;
  color: var(--muted);
}
.link {                                            /* connected, asleep on the server, or no connection */
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  transition: background 0.5s, box-shadow 0.5s;
}
.link[data-link="awake"] { background: #4fe0a8; box-shadow: 0 0 10px rgba(79, 224, 168, 0.65); }
.link[data-link="asleep"] { background: #7896b9; box-shadow: 0 0 8px rgba(120, 150, 185, 0.45); }
.link[data-link="offline"] { background: #ffbe5f; box-shadow: 0 0 10px rgba(255, 190, 95, 0.6); }

.icon {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--glass);
  color: var(--text);
  cursor: pointer;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.15s var(--ease);
}
.icon:hover { background: var(--glass-strong); border-color: var(--line-strong); }
.icon:active, .plain:active { transform: scale(0.94); }
.icon svg { width: 20px; height: 20px; }

.stage { flex: none; width: 100%; display: flex; flex-direction: column; align-items: center; padding-top: clamp(0px, 1.5vh, 18px); }
#orb {
  width: min(82vw, 45vh, 480px);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: grab;
  touch-action: none;                              /* so a finger can flick the orb instead of scrolling */
  -webkit-user-select: none;
  user-select: none;
}
#orb:active { cursor: grabbing; }

#status {                                          /* a small pill: a dot that pulses while Jarvis is busy, and a word */
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin: 2px 0 0;
  padding: 6px 15px 6px 12px;
  border: 1px solid var(--line);
  border: 1px solid color-mix(in srgb, var(--state) 38%, transparent);
  border-radius: 999px;
  background: rgba(3, 8, 14, 0.6);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--state);
  transition: color 0.6s, border-color 0.6s;
}
#status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 10px currentColor;
}
body[data-state="listening"] #status::before,
body[data-state="speaking"] #status::before { animation: beat 1s ease-in-out infinite; }
body[data-state="thinking"] #status::before,
body[data-state="waking"] #status::before { animation: beat 0.6s ease-in-out infinite; }
@keyframes beat { 50% { transform: scale(0.5); opacity: 0.5; } }

#hint { margin: 9px 0 0; min-height: 1.45em; max-width: 34ch; color: var(--muted); font-size: 0.9rem; line-height: 1.45; text-align: center; text-wrap: balance; }
#waiting {
  margin: 8px 0 0;
  padding: 4px 13px;
  border: 1px solid rgba(255, 190, 95, 0.35);
  border-radius: 999px;
  background: rgba(255, 190, 95, 0.07);
  color: #ffd59a;
  font-size: 0.82rem;
}

/* the conversation: what was heard, then the reply; it scrolls, fading out at its edges */
#captions {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 620px;
  margin-top: 4px;
  padding: 16px 6px 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  text-align: center;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 22px, #000 calc(100% - 16px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 22px, #000 calc(100% - 16px), transparent 100%);
}
#captions::-webkit-scrollbar { display: none; }
#heard { margin: 0 auto 10px; max-width: 36ch; color: var(--muted); font-size: 0.95rem; line-height: 1.45; overflow-wrap: anywhere; }
#reply {
  margin: 0 auto;
  max-width: 30ch;
  font-size: clamp(1.15rem, 4.8vw, 1.5rem);
  font-weight: 350;
  line-height: 1.5;
  letter-spacing: -0.005em;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}
.reveal { animation: wipe 0.55s var(--ease) both; }  /* new words wipe in from the middle */
@keyframes wipe {
  from { clip-path: inset(0 50% 0 50%); opacity: 0; }
  to { clip-path: inset(0 0 0 0); opacity: 1; }
}
#music {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 14px;
  padding: 8px 20px;
  border-color: rgba(30, 215, 96, 0.5);
  background: rgba(30, 215, 96, 0.1);
  color: #7ff0a8;
  text-decoration: none;
}

/* the dock: "End conversation" above the typing box */
.dock { flex: none; width: 100%; max-width: 540px; display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 8px; }
#end { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 15px 0 11px; color: var(--muted); font-size: 0.84rem; }
#end svg { width: 15px; height: 15px; }
#end:hover { color: var(--text); }
#typed {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 4px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(8, 16, 26, 0.72);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  transition: border-color 0.2s;
}
#typed:focus-within { border-color: color-mix(in srgb, var(--accent) 70%, transparent); }
#text { flex: 1; min-width: 0; min-height: 44px; border: 0; background: none; color: var(--text); font: inherit; font-size: 16px; outline: none; }
#text::placeholder { color: var(--faint); }
#typed .icon { border-color: transparent; background: rgba(111, 208, 255, 0.12); color: var(--muted); }
#text:not(:placeholder-shown) + .icon { background: var(--accent); color: #03131d; }   /* lights up once there is something to send */

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
#orb:focus-visible { outline-offset: -8px; }
#text:focus-visible { outline: none; }

/* small buttons */
.plain {
  min-height: 40px;
  padding: 6px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.15s var(--ease);
}
.plain:hover { background: var(--glass-strong); }
.plain.danger { color: var(--danger); border-color: rgba(255, 150, 110, 0.38); }
.plain.armed { background: #b3401f; border-color: #b3401f; color: #fff; }
.plain:disabled { opacity: 0.5; cursor: default; }

/* ---------------------------------------------------------------- projector view: only the orb, on pure black
   Black is no light, so on a fog screen only the orb shows. Everything else on the page is put away. */
body.display { background: #000; cursor: none; }
body.display::after { display: none; }
body.display header, body.display #status, body.display #hint, body.display #waiting,
body.display #captions, body.display .dock { display: none !important; }
body.display main { max-width: none; padding: 0; justify-content: center; animation: none; }
body.display .stage { padding: 0; }
body.display #orb { width: min(94vw, 94vh); }
body.display.mirror main, body.display.mirror #scene { transform: scaleX(-1); }
#display-note {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 3;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(8, 16, 26, 0.85);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  max-width: 92vw;
}

/* ---------------------------------------------------------------- panels: each opens as a circle from its button */
dialog.panel {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
}
dialog.panel::backdrop { background: rgba(2, 5, 10, 0.64); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 560px;
  max-height: 92vh;
  max-height: 92dvh;
  margin: 0 auto;
  padding: 10px 16px max(22px, env(safe-area-inset-bottom));
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  background: linear-gradient(180deg, #0c1826 0%, var(--panel) 140px);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  clip-path: circle(0px at var(--ox, 90%) var(--oy, 0%));
  transition: clip-path 0.5s var(--ease);
}
.sheet::before {                                   /* the grab bar of a phone sheet */
  content: "";
  display: block;
  width: 38px;
  height: 4px;
  margin: 0 auto 8px;
  border-radius: 2px;
  background: rgba(150, 200, 240, 0.22);
}
dialog.open .sheet { clip-path: circle(var(--r, 150%) at var(--ox, 90%) var(--oy, 0%)); }
@media (min-width: 640px) and (min-height: 640px) {
  .sheet { top: 50%; bottom: auto; transform: translateY(-50%); padding-top: 18px; border-bottom: 1px solid var(--line); border-radius: 24px; }
  .sheet::before { display: none; }
}
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -16px;
  padding: 4px 16px 8px;
  background: linear-gradient(180deg, #0c1826 70%, rgba(12, 24, 38, 0));
}
.sheet h2 { margin: 0; font-size: 1.05rem; font-weight: 600; letter-spacing: 0.01em; color: var(--text); }
.sheet h3 { margin: 18px 0 4px; font-size: 0.72rem; font-weight: 650; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); }
.sheet label { display: block; margin: 14px 0 6px; color: var(--muted); font-size: 0.88rem; }
.sheet select {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}
.sheet select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.about { margin: 6px 0 0; min-height: 1.4em; color: var(--muted); font-size: 0.88rem; line-height: 1.45; text-align: center; }

/* settings come in groups, each a softly lit card */
.group {
  margin-top: 12px;
  padding: 2px 16px 16px;
  border: 1px solid rgba(150, 200, 240, 0.1);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
}
.group h3 { margin: 14px 0 2px; color: var(--accent); opacity: 0.9; }

/* on/off settings are switches, with the words on the left */
.sheet label.check {
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 50px;
  margin: 8px 0 0;
  color: var(--text);
  font-size: 0.97rem;
  line-height: 1.35;
  cursor: pointer;
}
.sheet input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 50px;
  height: 30px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #1a2633;
  cursor: pointer;
  transition: background 0.25s, border-color 0.25s;
}
.sheet input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #c4d2df;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  transition: transform 0.25s var(--ease), background 0.25s;
}
.sheet input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.sheet input[type="checkbox"]:checked::before { transform: translateX(20px); background: #fff; }
.sheet input[type="checkbox"]:disabled { opacity: 0.45; cursor: default; }
.sheet input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

#clap-test { display: block; margin: 14px auto 0; }
.meter { height: 8px; margin: 12px 0 0; overflow: hidden; border: 1px solid var(--line); border-radius: 999px; background: var(--field); }
.meter span { display: block; width: 0; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #3aa8e0, var(--accent)); transition: width 0.08s linear; }

/* ---------------------------------------------------------------- notes */
#notes-sheet { min-height: min(70vh, 560px); }
#notes-sheet h2 { flex: 1; padding: 0 10px; }
#notes-find {
  width: 100%;
  min-height: 46px;
  margin: 6px 0 4px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}
.row { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid rgba(150, 200, 240, 0.1); }
.row .open, .row .what {
  flex: 1;
  min-width: 0;
  min-height: 50px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 2px;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
}
.row .open { cursor: pointer; }
.row .open:hover .name, .row .open:active .name { color: var(--accent); }
.row .name { min-width: 0; overflow-wrap: anywhere; }
.row .when { flex: none; color: var(--faint); font-size: 0.84rem; }
#bin-empty, #note-delete { display: block; margin: 18px auto 0; }
#note-text {
  margin: 10px 0 0;
  padding: 16px;
  max-height: 52vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--field);
  color: var(--text);
  font: 0.95rem/1.6 -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* The voices sit on a cylinder that can be dragged, flicked or stepped round. */
.carousel { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px; margin-top: 8px; }
.viewport { position: relative; height: 150px; overflow: hidden; perspective: 900px; cursor: grab; touch-action: pan-y; }
.viewport:active { cursor: grabbing; }
.ring { position: absolute; inset: 0; transform-style: preserve-3d; }
.card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 170px;
  height: 116px;
  margin: -58px 0 0 -85px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(160deg, #13293b, #0a1520);
  color: var(--text);
  font: inherit;
  text-align: center;
  cursor: pointer;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.card .name { font-size: 1.05rem; font-weight: 600; }
.card .kind { font-size: 0.78rem; line-height: 1.3; color: var(--muted); }
.card[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 28px rgba(111, 208, 255, 0.3); }

/* ---------------------------------------------------------------- login */
body.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 26%, #0e2234 0%, var(--bg) 62%);
}
body.login form {
  position: relative;
  z-index: 1;
  width: min(92vw, 360px);
  display: grid;
  gap: 12px;
  padding: 30px 24px 24px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(8, 17, 27, 0.72);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
body.login h1 {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin: 0 0 8px;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.46em;
  text-transform: uppercase;
  color: var(--muted);
}
body.login h1::before {                            /* a small lit ring standing in for the orb */
  content: "";
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1px solid rgba(111, 208, 255, 0.55);
  box-shadow: 0 0 24px rgba(111, 208, 255, 0.35), inset 0 0 18px rgba(111, 208, 255, 0.25);
}
body.login label { color: var(--muted); font-size: 0.88rem; }
body.login input, body.login button {
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}
body.login button { cursor: pointer; background: var(--accent); border-color: var(--accent); color: #03131d; font-weight: 600; }
body.login .msg { margin: 0; min-height: 1.5em; color: var(--danger); font-size: 0.9rem; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  main, .reveal { animation: none; }
  .sheet, .sheet input[type="checkbox"]::before { transition: none; }
  #status::before { animation: none !important; }
}
