/* Pixelflo lens: Jarvis is an aperture iris inside a camera lens ring.
   States come from app.js via [data-state] on #ring and --lvl (mic level 0..1). */
@property --open { syntax: '<number>'; inherits: true; initial-value: 30; }
@property --twist { syntax: '<angle>'; inherits: true; initial-value: 0deg; }

:root {
  --bg: #0b0b0d;          /* lens-cap black */
  --brand: #5fd3a0;       /* Pixelflo brand colour: replace with your exact hex */
  --px-white: #f5f3ef;    /* wallpaper pixels */
  --px-red: #ff3a44;
  --body: #17191c;        /* anodised graphite */
  --panel: #1c1f23;
  --line: #2c3036;
  --text: #ebe7df;        /* engraved silver */
  --muted: #8d9199;
  --listen: #ff3a44;      /* REC red: listening */
  --think: #f5f3ef;       /* white: thinking */
  --speak: var(--brand);  /* brand: speaking */
  --err: #ef6a5b;
  --lvl: 0;
  font-family: "Lexend", system-ui, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
*, *::before, *::after { box-sizing: inherit; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { background: var(--bg); }

/* Live wallpaper (drawn by wallpaper.js) + a slow light sweep and edge glows on top */
#wallpaper { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; display: block; }
.atmos { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
  background:
    radial-gradient(circle at 1px 1px, rgba(245, 243, 239, .05) 1px, transparent 1.5px) 0 0 / 22px 22px,
    radial-gradient(60% 55% at 100% 100%, rgba(255, 58, 68, .2), transparent 70%),
    linear-gradient(0deg, rgba(255, 58, 68, .07), transparent 22%),
    radial-gradient(50% 45% at 0% 0%, rgba(95, 211, 160, .08), transparent 70%),
    radial-gradient(90% 80% at 50% 50%, transparent 55%, rgba(0, 0, 0, .65) 100%); }
.atmos::after { content: ""; position: absolute; top: -50%; bottom: -50%; left: -40%; width: 30%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .045), transparent);
  transform: translateX(0) rotate(12deg); animation: sweep 14s linear infinite; }
@keyframes sweep { to { transform: translateX(560%) rotate(12deg); } }
.stage { z-index: 1; }
button, input, select { font: inherit; color: inherit; }

.stage {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "voice time" "voice talk";
  gap: 2vh 5vw;
  padding: 5vh 5vw;
  position: relative;
}
@media (orientation: portrait) {
  .stage { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; grid-template-areas: "time" "voice" "talk"; }
}

/* Time */
.time { grid-area: time; }
.clock { font-weight: 200; font-size: clamp(3rem, 12vmin, 8rem); line-height: .95; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.date { color: var(--muted); font-size: clamp(1rem, 2.6vmin, 1.35rem); margin-top: .5em; font-weight: 300; }

/* ---------- The lens ---------- */
.voice { grid-area: voice; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2.5vh; min-height: 0; }
.ring {
  --c: #7d838c; --open: 30; --twist: 0deg;
  width: min(62vmin, 460px); aspect-ratio: 1; padding: 0; border: 0; border-radius: 50%;
  background: none; cursor: pointer; display: block;
  -webkit-tap-highlight-color: transparent;
  transition: --open .7s cubic-bezier(.3,1.4,.5,1), --twist .7s cubic-bezier(.3,1.4,.5,1);
}
.ring:focus-visible { outline: 2px solid var(--text); outline-offset: 6px; }
.lens { width: 100%; height: 100%; display: block; overflow: visible; transition: filter .5s; }
.ring .lens { filter: drop-shadow(0 0 18px rgba(0, 0, 0, .8)); }
.ring[data-state="recording"] .lens { filter: drop-shadow(0 0 30px rgba(255, 58, 68, .35)); }
.ring[data-state="thinking"] .lens  { filter: drop-shadow(0 0 24px rgba(245, 243, 239, .18)); }
.ring[data-state="speaking"] .lens  { filter: drop-shadow(0 0 28px rgba(95, 211, 160, .28)); }

.scale text { fill: var(--muted); font-size: 8px; font-weight: 400; text-anchor: middle; dominant-baseline: middle; letter-spacing: .04em; }
.ticks line { stroke: #4a4f57; stroke-width: .6; }
.ticks line.major { stroke: #f5f3ef; stroke-width: .9; opacity: .8; }
.housing { fill: var(--body); stroke: #33373d; stroke-width: 1.2; }
.rim { fill: none; stroke: #050506; stroke-width: 3; }
.index { fill: var(--c); transition: fill .4s; }

/* glass behind the blades: the state colour lives here */
.g0 { stop-color: var(--c); stop-opacity: .95; transition: stop-color .4s; }
.g1 { stop-color: var(--c); stop-opacity: .25; transition: stop-color .4s; }
.g2 { stop-color: #000; stop-opacity: 1; }
.glass { transform-box: view-box; transform-origin: 0 0; }
.flare { fill: #fff; opacity: .18; }

/* blades: 8 overlapping plates; --open is the hole radius, --twist turns the whole iris */
.blades { transform-box: view-box; transform-origin: 0 0; transform: rotate(var(--twist)); }
.blade {
  transform-box: view-box; transform-origin: 0 0;
  transform: rotate(calc(var(--i) * 45deg + var(--open) * 1.2deg)) translateY(calc((var(--open) + var(--lvl) * 30) * -1px));
  transition: transform .09s linear;
}
.blade path { fill: #24272c; stroke: none; }
.blade:nth-child(odd) path { fill: #202328; }
.blade line { stroke: #3d424a; stroke-width: .8; }

/* states */
.ring[data-state="off"], .ring[data-state="loading"] { --open: 6; }
.ring[data-state="loading"] .blades { animation: turn 2.4s linear infinite; }
.ring[data-state="idle"]      { --open: 26; --c: #8a8f98; }
.ring[data-state="idle"] .glass { animation: breathe 6s ease-in-out infinite; }
.ring[data-state="recording"] { --open: 54; --twist: 18deg; --c: var(--listen); }
.ring[data-state="thinking"]  { --open: 18; --c: var(--think); }
.ring[data-state="thinking"] .blades { animation: turn 1.6s linear infinite; }
.ring[data-state="speaking"]  { --open: 44; --twist: 8deg; --c: var(--speak); }
.ring[data-state="speaking"] .glass { animation: talk .5s ease-in-out infinite alternate; }
.ring[data-state="error"]     { --open: 10; --c: var(--err); }

@keyframes turn { to { transform: rotate(calc(var(--twist) + 360deg)); } }
@keyframes breathe { 50% { opacity: .55; } }
@keyframes talk { from { transform: scale(.94); } to { transform: scale(1.04); } }

.status { margin: 0; font-size: clamp(1.05rem, 2.8vmin, 1.5rem); color: var(--muted); text-align: center; min-height: 1.5em; font-weight: 300; }

/* Conversation */
.talk { grid-area: talk; display: flex; flex-direction: column; min-height: 0; }
.heard { color: var(--muted); font-size: clamp(1rem, 2.5vmin, 1.25rem); margin: 0 0 .9em; min-height: 1.4em; font-weight: 300; }
.heard:not(:empty)::before { content: "You: "; color: var(--listen); }
.reply { font-size: clamp(1.25rem, 3.5vmin, 1.95rem); line-height: 1.45; margin: 0; max-width: 34ch; overflow-y: auto; flex: 1; min-height: 0; font-weight: 300; }
.ask { display: flex; gap: .5rem; margin-top: 1.5vh; }
.ask input { flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: .7em 1.1em; }
.ask input:focus-visible { outline: 2px solid var(--listen); outline-offset: 1px; }
.ask button, .settings button { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: .7em 1.2em; cursor: pointer; }
.ask button:hover, .settings button:hover { border-color: #4a4f57; }
button.primary { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 500; }

.gear { position: absolute; right: 2.5vw; bottom: 2.5vh; background: none; border: 0; color: var(--muted); padding: 10px; cursor: pointer; opacity: .6; }
.gear:hover { opacity: 1; }

/* Start overlay */
.start-layer { position: fixed; inset: 0; background: rgba(11, 11, 13, .72); backdrop-filter: blur(2px); display: grid; place-items: center; padding: 6vw; z-index: 5; }
.start-layer[hidden] { display: none; }
.start-card { max-width: 30rem; }
.start-card h1 { font-weight: 200; font-size: clamp(2.8rem, 10vmin, 5rem); margin: 0 0 .15em; letter-spacing: -0.02em; }
.start-card p { color: var(--muted); line-height: 1.55; font-weight: 300; }
.start-card .primary { font-size: 1.15rem; padding: .9em 1.7em; border: 0; border-radius: 999px; cursor: pointer; margin: 1em 0 .5em; }
.hint { font-size: .9rem; }

/* Settings */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 18px; width: min(34rem, 92vw); max-height: 90vh; padding: 0; }
dialog::backdrop { background: rgba(5, 6, 7, .75); }
.settings { display: flex; flex-direction: column; gap: 1rem; padding: 1.5rem; }
.settings h2 { font-weight: 300; margin: 0; font-size: 1.6rem; }
.settings h3 { font-weight: 400; margin: .5rem 0 0; }
.settings label { display: flex; flex-direction: column; gap: .4rem; color: var(--muted); }
.settings label.check { flex-direction: row; align-items: center; gap: .6rem; color: var(--text); }
.settings label.check input { width: 1.2rem; height: 1.2rem; accent-color: var(--listen); }
.settings input[type=url], .settings input[type=password], .settings select { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .6em; color: var(--text); }
.settings input[type=range] { accent-color: var(--listen); }
.qr:not(:empty) { background: #fff; border-radius: 12px; padding: 8px; width: min(240px, 100%); }
.qr svg { display: block; width: 100%; height: auto; }
.small { font-size: .85rem; color: var(--muted); margin: 0; }
.row { display: flex; gap: .5rem; justify-content: space-between; flex-wrap: wrap; }
.meter { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--listen); transition: width .08s linear; }
.meter span.level { background: var(--speak); }

@media (prefers-reduced-motion: reduce) {
  .ring, .blade, .blades, .glass, .atmos::after { animation: none !important; transition: none !important; }
}
