:root {
  --ink: #050505;
  --panel: rgba(24, 24, 24, 0.82);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f5f5f7;
  --muted: #a1a1a6;
  --red: #ff5a5f;
  --blue: #55aaff;
  --aqua: #40d9c6;
  --yellow: #f6c653;
  --violet: #b58cff;
}

* { box-sizing: border-box; }

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

body {
  overflow: hidden;
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", sans-serif;
  background:
    radial-gradient(circle at 50% 48%, #252525 0, #101010 32%, var(--ink) 72%),
    var(--ink);
}

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

.watch-shell {
  position: relative;
  min-height: 100dvh;
  overflow: hidden;
}

.auth-locked body { overflow: hidden; }
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 35%, rgba(93,176,151,0.22), transparent 28%),
    rgba(0,0,0,0.86);
  backdrop-filter: blur(24px);
}
.auth-gate.is-hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease;
}
.auth-card {
  width: min(430px, 100%);
  padding: 30px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 30px;
  background: linear-gradient(180deg, rgba(42,42,42,0.78), rgba(10,10,10,0.94));
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}
.auth-eyebrow {
  margin: 0 0 10px;
  color: #9ee1bc;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.auth-card h1 {
  margin: 0;
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  letter-spacing: -0.06em;
}
.auth-copy {
  margin: 10px 0 22px;
  color: var(--muted);
  line-height: 1.45;
}
.auth-card button {
  width: 100%;
  border: 0;
  border-radius: 999px;
  padding: 13px 18px;
  color: #050505;
  background: #f5f5f7;
  font-weight: 900;
  cursor: pointer;
}
.auth-status {
  min-height: 1.2em;
  margin: 14px 0 0;
  color: #f5d57a;
  font-size: 0.82rem;
}

.watch-shell::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.34;
  background-image: radial-gradient(rgba(255,255,255,0.45) 0.55px, transparent 0.7px);
  background-size: 22px 22px;
  mask-image: radial-gradient(ellipse at center, black, transparent 76%);
}

.topbar {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: max(22px, env(safe-area-inset-top)) 28px 0;
  pointer-events: none;
}

.brand { font-size: 0.9rem; font-weight: 800; letter-spacing: -0.02em; }
.system-status { margin: 0; color: var(--muted); font-size: 0.72rem; text-align: center; }
.topbar-actions { justify-self: end; display: flex; gap: 12px; align-items: center; pointer-events: auto; }
.library-link, .reset-button { border: 0; color: var(--muted); background: none; cursor: pointer; font-size: 0.72rem; text-decoration: none; }
.library-link { color: #9ee1bc; }

.constellation {
  position: absolute;
  inset: 0;
  min-height: 570px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.constellation::-webkit-scrollbar { display: none; }

.constellation::before, .constellation::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.06);
  pointer-events: none;
}
.constellation::before { width: min(78vw, 760px); aspect-ratio: 1; top: 50%; left: 50%; transform: translate(-50%, -50%); }
.constellation::after { width: min(52vw, 500px); aspect-ratio: 1; top: 50%; left: 50%; transform: translate(-50%, -50%); border-color: rgba(255,255,255,0.08); }

.sector {
  position: absolute;
  width: 55vw;
  height: 55vw;
  max-width: 700px;
  max-height: 700px;
  border-radius: 50%;
  opacity: 0.2;
  filter: blur(8px);
  pointer-events: none;
}
.sector span { position: absolute; color: rgba(255,255,255,0.68); font-size: 0.66rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; filter: blur(0); }
.sector-mechanics { top: -28%; right: -17%; background: radial-gradient(circle, rgba(255,75,80,0.26), transparent 67%); }
.sector-mechanics span { left: 23%; bottom: 20%; }
.sector-livestock { top: -22%; left: -19%; background: radial-gradient(circle, rgba(55,148,255,0.24), transparent 67%); }
.sector-livestock span { right: 21%; bottom: 17%; }
.sector-slurry { bottom: -34%; left: -9%; background: radial-gradient(circle, rgba(47,221,187,0.21), transparent 66%); }
.sector-slurry span { right: 28%; top: 20%; }
.sector-health { bottom: -35%; right: 2%; background: radial-gradient(circle, rgba(255,193,73,0.2), transparent 67%); }
.sector-health span { left: 28%; top: 20%; }
.sector-power { top: 32%; right: -34%; background: radial-gradient(circle, rgba(181,140,255,0.18), transparent 67%); }
.sector-power span { left: 21%; top: 48%; }

.bubble-field {
  position: relative;
  z-index: 2;
  min-width: 100%;
  min-height: 100%;
  background:
    radial-gradient(circle at 50% 45%, rgba(255,255,255,0.055), transparent 17%),
    radial-gradient(circle at 50% 45%, rgba(255,255,255,0.025), transparent 48%),
    #050505;
}
.sector-dial {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.88;
}
.sector-path-label {
  font-size: 0.56rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.56;
  paint-order: stroke;
  stroke: rgba(0,0,0,0.68);
  stroke-width: 3px;
  stroke-linejoin: round;
  dominant-baseline: middle;
}
.bubble-field.is-ranked .sector-path-label,
.bubble-field.is-ranked .sector-dial { opacity: 0; }

.document-bubble {
  --size: clamp(58px, 8vw, 104px);
  --focus-scale: 1;
  --focus-opacity: 1;
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--size);
  height: var(--size);
  opacity: var(--focus-opacity);
  transform: translate(-50%, -50%) scale(var(--focus-scale));
  z-index: 2;
  display: grid;
  align-content: center;
  gap: 3px;
  padding: 10px;
  overflow: hidden;
  border: 1px solid currentColor;
  border-radius: 50%;
  color: #eee;
  background: rgba(32,32,32,0.74);
  box-shadow: inset 0 1px rgba(255,255,255,0.18), 0 14px 34px rgba(0,0,0,0.28), 0 0 28px color-mix(in srgb, currentColor 16%, transparent);
  cursor: pointer;
  transition: left 740ms cubic-bezier(.18,.9,.2,1), top 740ms cubic-bezier(.18,.9,.2,1), width 260ms ease, height 260ms ease, transform 180ms ease, opacity 180ms ease, background 220ms ease;
}
.document-bubble:hover { transform: translate(-50%, -50%) scale(calc(var(--focus-scale) * 1.12)); background-color: rgba(52,52,52,0.96); z-index: 3; }
.document-bubble span { display: block; font-size: clamp(0.62rem, 1.5vw, 0.82rem); font-weight: 800; line-height: 1; }
.document-bubble small { display: -webkit-box; overflow: hidden; -webkit-line-clamp: 2; -webkit-box-orient: vertical; color: rgba(255,255,255,0.68); font-size: 0.53rem; line-height: 1.16; }
.document-bubble.is-image-bubble,
.document-bubble.is-video-bubble { align-content: end; color: #fff; border-color: rgba(255,255,255,.68); background-color: #272727; background-position: center, center; background-repeat: no-repeat; background-size: 100% 100%, cover; box-shadow: inset 0 -25px 36px rgba(0,0,0,.48), 0 14px 34px rgba(0,0,0,.28), 0 0 28px rgba(158,225,188,.22); }
.document-bubble.is-image-bubble span,
.document-bubble.is-video-bubble span { font-size: .58rem; letter-spacing: .08em; text-shadow: 0 1px 4px #000; }
.document-bubble.is-image-bubble small,
.document-bubble.is-video-bubble small { color: rgba(255,255,255,.92); font-size: .56rem; font-weight: 900; line-height: 1.04; text-shadow: 0 1px 4px #000; }
.play-badge { position: absolute; top: 9px; left: 11px; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; color: #111; background: rgba(255,255,255,.88); font-size: .54rem; line-height: 1; box-shadow: 0 2px 9px rgba(0,0,0,.32); }
.document-bubble.is-relevant { animation: evidence-pulse 2.8s ease-in-out infinite; background-color: color-mix(in srgb, currentColor 13%, #171717); }
.match-order { position: absolute; top: 9px; right: 13px; color: rgba(255,255,255,0.82); font-size: 0.58rem; line-height: 1; }
.theme-mechanics { color: var(--red); }
.theme-livestock { color: var(--blue); }
.theme-slurry { color: var(--aqua); }
.theme-health { color: var(--yellow); }
.theme-power { color: var(--violet); }
.theme-general { color: #d9e0d9; }

.primary-bubble {
  position: absolute;
  z-index: 3;
  top: var(--y, 45%);
  left: var(--x, 50%);
  --focus-scale: 1;
  --focus-opacity: 1;
  width: clamp(104px, 11vw, 150px);
  height: clamp(104px, 11vw, 150px);
  opacity: var(--focus-opacity);
  transform: translate(-50%, -50%) scale(var(--focus-scale));
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 7px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.48);
  border-radius: 50%;
  color: white;
  background:
    radial-gradient(circle at 33% 25%, rgba(255,255,255,0.85), transparent 7%),
    radial-gradient(circle at 70% 78%, rgba(255,120,112,0.38), transparent 18%),
    conic-gradient(from 195deg, #234a42, #b15b4b, #244c91, #205d4f, #d08a4f, #234a42);
  box-shadow: inset 18px 14px 42px rgba(255,255,255,0.22), inset -30px -32px 54px rgba(0,0,0,0.58), 0 0 0 13px rgba(255,255,255,0.04), 0 0 90px rgba(84,173,145,0.34), 0 30px 55px rgba(0,0,0,0.42);
  cursor: pointer;
  animation: primary-pulse 5s ease-in-out infinite;
}
.primary-bubble[hidden] { display: none; }
.primary-ring { position: absolute; inset: 7%; border: 1px solid rgba(255,255,255,0.24); border-radius: inherit; }
.primary-code { position: relative; font-size: clamp(1.05rem, 1.85vw, 1.55rem); font-weight: 900; letter-spacing: 0; }
.primary-label { position: relative; width: 72%; font-size: clamp(0.78rem, 1.25vw, 1.05rem); font-weight: 900; line-height: 1.05; opacity: 0.92; }
.constellation-caption { position: absolute; z-index: 3; left: 50%; top: calc(45% + clamp(82px, 10vw, 118px)); transform: translateX(-50%); color: rgba(255,255,255,0.45); font-size: 0.67rem; white-space: nowrap; }

.conversation-panel {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  width: min(740px, calc(100vw - 32px));
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(31,31,31,0.72), rgba(12,12,12,0.92));
  box-shadow: 0 24px 70px rgba(0,0,0,0.38);
  backdrop-filter: blur(24px);
}
.chat-log { display: flex; flex-direction: column; gap: 9px; max-height: min(21dvh, 190px); overflow: auto; padding: 14px 16px 8px; scrollbar-width: none; }
.chat-log::-webkit-scrollbar { display: none; }
.message { max-width: 87%; padding: 10px 13px; border-radius: 16px; background: rgba(255,255,255,0.07); }
.message-user { align-self: flex-end; background: rgba(91,153,255,0.18); }
.message-label { margin: 0 0 4px; color: var(--muted); font-size: 0.59rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; }
.message-body { margin: 0; font-size: 0.77rem; line-height: 1.43; white-space: pre-wrap; }
.message-evidence { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 9px; }
.message-evidence button { border: 1px solid rgba(104,207,171,0.28); border-radius: 999px; padding: 4px 7px; color: #a6edcf; background: rgba(48,127,98,0.13); font-size: 0.6rem; cursor: pointer; }

.chat-form { display: grid; grid-template-columns: 1fr 40px auto; gap: 8px; align-items: center; padding: 9px; border-top: 1px solid var(--line); }
.chat-form textarea { width: 100%; max-height: 112px; resize: none; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 0.82rem; line-height: 1.35; }
.chat-form textarea::placeholder { color: #77777b; }
.voice-button, .send-button { height: 38px; border: 0; cursor: pointer; }
.voice-button { display: grid; place-items: center; border-radius: 50%; background: rgba(255,255,255,0.1); }
.voice-button span { width: 10px; height: 16px; border-radius: 999px; background: #fff; }
.voice-button.is-listening { background: var(--red); animation: listening 0.9s ease-in-out infinite; }
.send-button { padding: 0 15px; border-radius: 999px; color: #050505; background: #f5f5f7; font-size: 0.72rem; font-weight: 800; }
.send-button:disabled { opacity: 0.5; }

.document-drawer {
  position: fixed;
  z-index: 10;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: min(620px, calc(100vw - 24px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 13px;
  padding: 22px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 30px;
  color: var(--text);
  background: rgba(17,17,17,0.98);
  box-shadow: -22px 0 90px rgba(0,0,0,.48);
  transform: translateX(calc(100% + 26px));
  transition: transform 360ms cubic-bezier(.2,.8,.2,1);
}
.document-drawer.is-open { transform: translateX(0); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.drawer-category, .evidence-label { margin: 0; color: #8edfc4; font-size: 0.61rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.drawer-head h2 { margin: 5px 0 0; font-size: clamp(1.1rem, 2vw, 1.45rem); letter-spacing: -0.04em; line-height: 1.08; }
.close-drawer { flex: 0 0 auto; border: 1px solid var(--line); border-radius: 999px; padding: 7px 10px; color: var(--muted); background: transparent; cursor: pointer; font-size: 0.67rem; }
.evidence-card { padding: 14px; border: 1px solid rgba(255,214,100,0.22); border-radius: 17px; background: linear-gradient(135deg, rgba(255,195,55,0.14), rgba(33,83,70,0.12)); }
.evidence-card blockquote { max-height: 110px; margin: 8px 0; overflow: auto; color: #fff3c7; font-size: 0.76rem; line-height: 1.6; }
.evidence-card mark { padding: 0.08em 0.18em; color: #fff9df; background: linear-gradient(105deg, rgba(255,190,53,0.72), rgba(252,222,118,0.34)); box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.evidence-page { margin: 0; color: var(--muted); font-size: 0.65rem; }
.pdf-frame-wrap { min-height: 0; overflow: hidden; border: 1px solid rgba(255,255,255,0.12); border-radius: 22px; background: #252525; }
.pdf-frame-wrap iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.video-section { min-width: 0; }
.video-list { display: flex; gap: 10px; overflow-x: auto; margin-top: 8px; }
.video-list iframe { flex: 0 0 220px; aspect-ratio: 16/9; border: 0; border-radius: 12px; }
.asset-video-section { min-height: 0; overflow: auto; }
.asset-video-section video { display: block; width: min(100%, 980px); max-height: min(60dvh, 680px); margin: 0 auto; border-radius: 20px; background: #000; }
.asset-image-section { min-height: 0; overflow: auto; }
.asset-image-section img { display: block; width: min(100%, 980px); max-height: min(60dvh, 680px); margin: 0 auto; border-radius: 20px; object-fit: contain; background: #111; }
.transcript-panel { width: min(100%, 980px); margin: 14px auto 0; padding: 15px; border: 1px solid rgba(255,214,100,.22); border-radius: 16px; background: rgba(255,195,55,.08); }
.transcript-panel p:last-child { margin: 8px 0 0; color: #fff3c7; line-height: 1.5; }
.transcript-panel mark { padding: .05em .14em; color: #fff; background: rgba(255,179,46,.62); }

@keyframes evidence-pulse { 0%,100% { box-shadow: inset 0 1px rgba(255,255,255,0.18), 0 14px 34px rgba(0,0,0,0.28), 0 0 24px color-mix(in srgb, currentColor 18%, transparent); } 50% { box-shadow: inset 0 1px rgba(255,255,255,0.26), 0 14px 34px rgba(0,0,0,0.28), 0 0 46px color-mix(in srgb, currentColor 48%, transparent); } }
@keyframes primary-pulse { 0%,100% { box-shadow: inset 18px 14px 42px rgba(255,255,255,0.22), inset -30px -32px 54px rgba(0,0,0,0.58), 0 0 0 13px rgba(255,255,255,0.04), 0 0 70px rgba(84,173,145,0.25), 0 30px 55px rgba(0,0,0,0.42); } 50% { box-shadow: inset 18px 14px 42px rgba(255,255,255,0.28), inset -30px -32px 54px rgba(0,0,0,0.5), 0 0 0 18px rgba(255,255,255,0.05), 0 0 112px rgba(84,173,145,0.45), 0 30px 55px rgba(0,0,0,0.42); } }
@keyframes listening { 50% { transform: scale(1.14); } }

@media (max-width: 680px) {
  .topbar { padding: max(17px, env(safe-area-inset-top)) 18px 0; }
  .system-status { max-width: 130px; line-height: 1.2; }
  .constellation { min-height: 500px; }
  .primary-bubble { width: clamp(84px, 24vw, 104px); height: clamp(84px, 24vw, 104px); gap: 3px; }
  .primary-code { font-size: clamp(0.82rem, 4.9vw, 1.02rem); }
  .primary-label { font-size: clamp(0.6rem, 3.1vw, 0.74rem); }
  .constellation-caption { display: none; }
  .document-bubble { --size: clamp(48px, 14.5vw, 64px); padding: 7px; }
  .document-bubble small { display: none; }
  .conversation-panel { width: calc(100vw - 20px); bottom: max(10px, env(safe-area-inset-bottom)); border-radius: 24px; }
  .chat-log { max-height: 25dvh; }
  .document-drawer { top: auto; right: 0; bottom: 0; width: 100vw; height: min(82dvh, 720px); padding: 18px; border-radius: 28px 28px 0 0; transform: translateY(calc(100% + 18px)); }
  .document-drawer.is-open { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
