:root {
  --bg: #0b0f14;
  --bg2: #121821;
  --bg3: #1a2230;
  --fg: #e8eef4;
  --dim: #8b98a8;
  --accent: #ff4d3d;
  --ok: #3ddc84;
  --danger: #ff4d3d;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
}

.view {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg2);
  border-bottom: 1px solid #232c3a;
  flex: 0 0 auto;
}
.topbar h1 { font-size: 1.15rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; }

/* ---------- buttons ---------- */
.btn {
  min-height: 48px;
  min-width: 48px;
  padding: 12px 16px;
  border: 1px solid #2a3547;
  border-radius: 12px;
  background: var(--bg3);
  color: var(--fg);
  font-size: 1rem;
  cursor: pointer;
}
.btn:active { transform: scale(0.97); }
.btn.small { min-height: 40px; min-width: 40px; padding: 8px 12px; font-size: 0.9rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.mic { font-size: 1.3rem; }
.btn.mic.listening { background: var(--accent); border-color: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }

/* wake-word listening toggle */
.btn.listen { font-weight: 600; }
.btn.listen.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  animation: pulse 1.6s infinite;
}
.listen-note {
  margin: 0;
  padding: 6px 14px 0;
  color: var(--dim);
  font-size: 0.8rem;
}

/* ---------- HUD core centerpiece (CSS-only) ---------- */
.core-wrap {
  display: flex;
  justify-content: center;
  padding: 16px 0 4px;
  flex: 0 0 auto;
}
.hud-core {
  position: relative;
  width: 132px;
  height: 132px;
}
.hud-core .disc {
  position: absolute;
  inset: 18px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 77, 61, 0.8), rgba(255, 77, 61, 0.22) 46%, rgba(11, 15, 20, 0.9) 72%),
    radial-gradient(circle, #1a2230, #0b0f14);
  box-shadow:
    0 0 24px rgba(255, 77, 61, 0.35),
    0 0 60px rgba(255, 77, 61, 0.12),
    inset 0 0 18px rgba(0, 0, 0, 0.6);
  animation: corePulse 4s ease-in-out infinite;
}
.hud-core .ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 77, 61, 0.28);
  border-top-color: rgba(255, 77, 61, 0.9);
  border-right-color: transparent;
  animation: ringSpin 14s linear infinite;
}
.hud-core .ring2 {
  inset: 8px;
  border-color: rgba(139, 152, 168, 0.18);
  border-bottom-color: rgba(255, 77, 61, 0.55);
  border-top-color: transparent;
  animation: ringSpin 22s linear infinite reverse;
}
/* wake-listening: core brightens, ring spins faster (class toggled from JS) */
.hud-core.wake-on .disc {
  animation-duration: 1.8s;
  filter: brightness(1.3);
  box-shadow:
    0 0 34px rgba(255, 77, 61, 0.6),
    0 0 90px rgba(255, 77, 61, 0.25),
    inset 0 0 18px rgba(0, 0, 0, 0.5);
}
.hud-core.wake-on .ring { animation-duration: 3s; }
.hud-core.wake-on .ring2 { animation-duration: 5s; }
@keyframes corePulse {
  0%, 100% { transform: scale(1); opacity: 0.92; }
  50% { transform: scale(1.045); opacity: 1; }
}
@keyframes ringSpin { to { transform: rotate(360deg); } }

/* ---------- big circular mic under the core ---------- */
.home-mic-wrap {
  display: flex;
  justify-content: center;
  padding: 6px 0 12px;
  flex: 0 0 auto;
}
#home-mic {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  font-size: 1.9rem;
  padding: 0;
}
#home-mic.wake-on,
#mic-btn.wake-on {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 18px rgba(255, 77, 61, 0.35);
}
#mic-btn { border-radius: 50%; }

/* ---------- telemetry: scanline overlay + grid-line framing ---------- */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.015) 0 1px,
    transparent 1px 3px
  );
}
.tile, .panel, .gate-card {
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.02),
    0 0 14px rgba(255, 77, 61, 0.04);
}
.tile.has-new {
  box-shadow:
    0 0 16px -2px var(--tile-accent, var(--accent)),
    0 0 0 1px #232c3a,
    inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}
.listen-note, .topbar h1 {
  font-family: ui-monospace, Menlo, monospace;
  letter-spacing: 0.04em;
}

/* ---------- reduced motion: kill pulse/ring/scanline shimmer ---------- */
@media (prefers-reduced-motion: reduce) {
  .hud-core .disc, .hud-core .ring, .hud-core .ring2,
  .btn.listen.on, .btn.mic.listening {
    animation: none !important;
  }
}

/* ---------- token gate / modal ---------- */
.gate {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 10, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.gate-card {
  background: var(--bg2);
  border: 1px solid #2a3547;
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.gate-card h1, .gate-card h2 { margin: 0; }
.gate-card input {
  min-height: 52px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #2a3547;
  background: var(--bg);
  color: var(--fg);
  font-size: 1rem;
}
.gate-card .row { display: flex; gap: 10px; justify-content: flex-end; }
.error { color: var(--danger); margin: 0; }

/* ---------- tiles ---------- */
.tiles {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-content: start;
}
@media (min-width: 560px) { .tiles { grid-template-columns: 1fr 1fr; } }

.tile {
  position: relative;
  background: var(--bg2);
  border: 1px solid #232c3a;
  border-left: 5px solid var(--accent);
  border-radius: 14px;
  padding: 14px 16px;
  min-height: 76px;
  text-align: left;
  color: var(--fg);
  cursor: pointer;
  width: 100%;
}
.tile .name { font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.tile .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.tile .last {
  color: var(--dim);
  font-size: 0.85rem;
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: ui-monospace, Menlo, monospace;
}
.tile .badge {
  position: absolute;
  top: 10px;
  right: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 8px;
}
.tile .err { color: var(--danger); }

/* ---------- quick actions ---------- */
.quick { padding: 0 14px 10px; flex: 0 0 auto; }
.quick h2 { font-size: 0.95rem; color: var(--dim); margin: 6px 0; }
.quick-row { display: flex; gap: 10px; flex-wrap: wrap; }
.panel {
  margin-top: 10px;
  background: var(--bg2);
  border: 1px solid #232c3a;
  border-radius: 12px;
  padding: 12px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.8rem;
  white-space: pre-wrap;
  max-height: 40dvh;
  overflow-y: auto;
}
.foot { padding: 8px 14px 12px; color: var(--dim); font-size: 0.85rem; flex: 0 0 auto; }
.toggle { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.toggle input { width: 22px; height: 22px; }

/* ---------- session view ---------- */
.output {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 14px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg);
}
.output .new-line { color: var(--ok); }

.composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--bg2);
  border-top: 1px solid #232c3a;
  flex: 0 0 auto;
}
.composer input {
  flex: 1;
  min-height: 52px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #2a3547;
  background: var(--bg);
  color: var(--fg);
  font-size: 1rem;
}

.voice-preview {
  padding: 10px 12px;
  background: var(--bg3);
  border-top: 1px solid #2a3547;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 0 0 auto;
}
.voice-preview textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid #2a3547;
  background: var(--bg);
  color: var(--fg);
  padding: 10px;
  font-size: 1rem;
  resize: vertical;
}
.voice-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--bg3);
  border: 1px solid #2a3547;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.9rem;
  z-index: 60;
  max-width: 90vw;
}
