:root {
  --bg: #05070b;
  --panel: rgba(7, 13, 20, 0.82);
  --panel-strong: rgba(10, 17, 27, 0.94);
  --line: rgba(122, 228, 255, 0.3);
  --line-red: rgba(255, 72, 72, 0.34);
  --cyan: #7ae4ff;
  --cyan-strong: #8cf0ff;
  --red: #ff4646;
  --text: #d9ebff;
  --muted: #86a4b8;
  --shadow: 0 0 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 10%, rgba(20, 71, 97, 0.22), transparent 30%),
    radial-gradient(circle at 80% 30%, rgba(255, 70, 70, 0.09), transparent 25%),
    linear-gradient(180deg, #04070a, #060b12 65%, #05070b);
  color: var(--text);
  font-family: "SFMono-Regular", "Consolas", "Menlo", monospace;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: linear-gradient(transparent 0%, rgba(255,255,255,0.02) 50%, transparent 100%);
  opacity: .2;
  pointer-events: none;
}

.hidden { display: none !important; }

.bg-grid,
.noise,
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.bg-grid {
  background-image:
    linear-gradient(rgba(122, 228, 255, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(122, 228, 255, 0.055) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(circle at center, black 45%, transparent 100%);
}

.noise {
  opacity: .06;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140' viewBox='0 0 140 140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.35' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
}

.scanlines {
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,.02),
    rgba(255,255,255,.02) 1px,
    rgba(0,0,0,0) 3px,
    rgba(0,0,0,0) 4px
  );
  opacity: .11;
  mix-blend-mode: screen;
}

.boot-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 5, 8, 0.96);
  z-index: 99;
}

.boot-box {
  width: min(900px, 94vw);
  min-height: 420px;
  padding: 18px;
}

.boot-log {
  min-height: 280px;
  margin: 18px 0;
  white-space: pre-wrap;
  color: #9ddcff;
  line-height: 1.75;
  font-size: 14px;
}

.action-btn {
  padding: 12px 18px;
  border: 1px solid var(--cyan);
  background: rgba(122, 228, 255, 0.08);
  color: var(--text);
  cursor: pointer;
  letter-spacing: .14em;
  font-size: 12px;
  transition: .2s ease;
}
.action-btn:hover { box-shadow: 0 0 20px rgba(122,228,255,.25); transform: translateY(-1px); }

.app {
  position: relative;
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 70px 1fr;
  height: 100vh;
  width: 100vw;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 14px 14px 0;
  padding: 12px 16px;
}

.left-rail {
  margin: 14px;
  margin-top: 14px;
  padding: 18px 14px;
}

.workspace {
  position: relative;
  margin: 14px 14px 14px 0;
  min-height: calc(100vh - 84px);
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(122, 228, 255, .18);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255,255,255,.02);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  position: relative;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255,255,255,.03);
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: .16em;
  font-size: 13px;
}
.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 14px var(--cyan);
}
.status-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.pill {
  border: 1px solid rgba(122, 228, 255, .35);
  padding: 6px 10px;
  font-size: 11px;
  letter-spacing: .12em;
  background: rgba(122, 228, 255, .07);
}
.pill.warning {
  border-color: rgba(255, 70, 70, .4);
  background: rgba(255, 70, 70, .08);
  color: #ff9e9e;
}
.time { color: var(--muted); font-size: 12px; }

.rail-section + .rail-section { margin-top: 26px; }
.section-title {
  color: var(--cyan-strong);
  font-size: 12px;
  margin-bottom: 12px;
  letter-spacing: .14em;
}
.rail-btn {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  margin-bottom: 10px;
  border: 1px solid rgba(122,228,255,.14);
  background: rgba(7, 18, 29, 0.7);
  color: var(--text);
  cursor: pointer;
}
.rail-btn.active,
.rail-btn:hover {
  border-color: rgba(122,228,255,.38);
  box-shadow: inset 0 0 0 1px rgba(122,228,255,.08);
}
.tiny-line { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
code {
  background: rgba(255,255,255,.06);
  padding: 2px 6px;
  border-radius: 4px;
}

.window {
  position: absolute;
  min-width: 280px;
}
.window-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(122,228,255,.14);
  background: linear-gradient(180deg, rgba(122,228,255,.06), rgba(122,228,255,.015));
  cursor: move;
  user-select: none;
  font-size: 12px;
  letter-spacing: .12em;
}
.window-header.red {
  background: linear-gradient(180deg, rgba(255,70,70,.08), rgba(255,70,70,.01));
  border-bottom-color: rgba(255,70,70,.18);
}
.window-actions { display: flex; gap: 8px; }
.window-actions span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.08);
}
.window-content { padding: 14px; }

.hero-image-wrap {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(122,228,255,.2);
}
.hero-image,
.surveillance-main img,
.archive-card img,
.message-card img {
  width: 100%;
  display: block;
  object-fit: cover;
}
.hero-image { aspect-ratio: 3 / 4; }
.image-hud {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 10px;
  background: linear-gradient(180deg, transparent, rgba(4,8,14,.88));
  font-size: 11px;
  color: #ccf4ff;
}
.profile-meta { margin-top: 14px; }
.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px dashed rgba(122,228,255,.12);
  font-size: 13px;
}
.meta-row span { color: var(--muted); }
.accent { color: var(--cyan-strong); }
.dialog-box {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid rgba(122,228,255,.16);
  background: rgba(10, 20, 28, .72);
}
.dialog-label {
  font-size: 11px;
  letter-spacing: .1em;
  color: var(--muted);
  margin-bottom: 8px;
}

.surveillance-main {
  position: relative;
  border: 1px solid rgba(255,70,70,.16);
  overflow: hidden;
}
.surveillance-main img { aspect-ratio: 4 / 5; }
.corner-label {
  position: absolute;
  background: rgba(5,10,14,.78);
  border: 1px solid rgba(122,228,255,.18);
  padding: 5px 8px;
  font-size: 10px;
  letter-spacing: .08em;
}
.top-left { top: 10px; left: 10px; }
.top-right { top: 10px; right: 10px; }
.bottom-left { left: 10px; bottom: 10px; }
.alert { border-color: rgba(255,70,70,.4); color: #ffb5b5; }
.thumb-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.thumb {
  padding: 0;
  border: 1px solid rgba(255,255,255,.08);
  background: transparent;
  cursor: pointer;
}
.thumb.active,
.thumb:hover { border-color: rgba(122,228,255,.42); }
.thumb img {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  object-fit: cover;
}

.archive-layout {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 14px;
}
.archive-card {
  border: 1px solid rgba(255,70,70,.2);
  overflow: hidden;
}
.archive-card img { aspect-ratio: 3 / 4; }
.archive-text ul {
  margin: 0 0 12px 18px;
  padding: 0;
  color: var(--muted);
  line-height: 1.65;
}
.archive-text p { margin: 0; color: var(--text); }

.terminal-content {
  min-height: 280px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.terminal-output {
  flex: 1;
  min-height: 210px;
  max-height: 310px;
  overflow: auto;
  background: rgba(2, 8, 12, .75);
  border: 1px solid rgba(122,228,255,.13);
  padding: 12px;
  line-height: 1.6;
  font-size: 13px;
  color: #bbf0ff;
}
.terminal-input-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  font-size: 13px;
}
.terminal-input-row input {
  width: 100%;
  border: 1px solid rgba(122,228,255,.16);
  background: rgba(6, 12, 18, .8);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}
.terminal-highlight { color: #fff1a6; }
.message-card {
  display: grid;
  gap: 12px;
}
.message-card img { aspect-ratio: 3 / 4; }
.message-card p {
  margin: 0;
  padding: 12px;
  border: 1px solid rgba(122,228,255,.16);
  background: rgba(10, 18, 30, .75);
  line-height: 1.7;
}

.portrait-selector {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.selector-item {
  padding: 8px 0;
  border: 1px solid rgba(122,228,255,.16);
  background: rgba(8, 14, 22, .8);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
}
.selector-item:hover { border-color: rgba(122,228,255,.42); }

.glow-blue { box-shadow: 0 0 0 1px rgba(122,228,255,.08), 0 0 36px rgba(122,228,255,.12), var(--shadow); }
.glow-red { box-shadow: 0 0 0 1px rgba(255,70,70,.08), 0 0 30px rgba(255,70,70,.12), var(--shadow); }

.panel-title {
  color: var(--cyan-strong);
  letter-spacing: .14em;
  font-size: 13px;
}

@keyframes flicker {
  0%, 100% { opacity: 1; }
  48% { opacity: .95; }
  49% { opacity: .84; }
  50% { opacity: 1; }
  96% { opacity: .97; }
  97% { opacity: .9; }
}
body, .panel, .window, .surveillance-main img, .hero-image { animation: flicker 7s infinite; }

@media (max-width: 1100px) {
  html, body { overflow: auto; }
  .app {
    display: block;
    height: auto;
    min-height: 100vh;
  }
  .topbar, .left-rail, .workspace { margin: 14px; }
  .workspace {
    min-height: auto;
    overflow: visible;
    display: grid;
    gap: 14px;
  }
  .window {
    position: relative !important;
    left: auto;
    top: auto;
    width: auto !important;
  }
  .archive-layout { grid-template-columns: 1fr; }
  .thumb-grid { grid-template-columns: repeat(2, 1fr); }
  .portrait-selector { grid-template-columns: repeat(4, 1fr); }
}

/* V1.1 / The emergency strip always lives above the fiction. */
body, .panel, .window, .surveillance-main img, .hero-image { animation: none; }
:focus-visible { outline: 3px solid #fff1a6 !important; outline-offset: 4px; }
button { font-family: inherit; touch-action: manipulation; }
.safety-bar { position: fixed; z-index: 2147483647; inset: 0 0 auto; min-height: 58px; padding: max(8px, env(safe-area-inset-top)) 14px 8px; display: flex; align-items: center; gap: 8px; background: #070e17; border-bottom: 1px solid #526276; font-size: 11px; }
.safety-bar > span { margin-right: auto; color: #adc1d6; }
.safety-bar b { color: #7ae4ff; }
.safety-bar button { min-height: 42px; padding: 8px 12px; color: #d9ebff; border: 1px solid #526276; background: #122234; cursor: pointer; }
.safety-bar #exit-btn { background: #d9ebff; color: #08121e; font-weight: bold; border-color: #d9ebff; }
.boot-screen { padding-top: 82px; overflow: auto; }
.boot-box { max-width: 780px; }
.boot-heading { font-family: 'PingFang SC', sans-serif; font-size: clamp(23px, 4vw, 40px); line-height: 1.5; font-weight: 500; margin: 18px 0; }
.boot-heading em { color: #7ae4ff; font-style: normal; }
.boot-note { color: #a9bbc9; font: 14px/1.8 'PingFang SC', sans-serif; max-width: 570px; }
.boot-log { min-height: 185px; font-size: 12px; }
.app { padding-top: 58px; height: 100dvh; }
.workspace { min-height: 0; overflow: auto; }
#phase-label { margin-top: 16px; font-size: 12px; color: #ffacac; line-height: 1.7; }
.left-rail .tiny-line { line-height: 1.8; margin-top: 12px; }
#start-override { letter-spacing: 0; width: 100%; }
hr { border: 0; border-top: 1px solid #344154; margin: 24px 0; }
#warning-layer { position: fixed; inset: 64px 0 0; z-index: 10000; pointer-events: none; overflow: hidden; }
.warning-popup { position: absolute; width: min(365px, 86vw); color: #ffe2e5; background: #180e19; border: 1px solid #ff657b; box-shadow: 10px 12px 0 #02060ab3, 0 0 38px #d52d4b26; pointer-events: auto; animation: warning-in .18s ease-out; }
.warning-popup header { display: flex; align-items: center; justify-content: space-between; background: #80283d; padding-left: 14px; font-size: 11px; }
.warning-popup header button { width: 44px; height: 44px; background: #4c1626; color: white; border: 0; font-size: 25px; cursor: pointer; }
.warning-popup small { display: block; color: #e99baa; margin: 18px 18px 8px; font-size: 10px; }
.warning-popup p { margin: 8px 18px 22px; font: 16px/1.7 'PingFang SC', sans-serif; }
.reject-btn { display: block; width: calc(100% - 36px); margin: 0 18px 18px; min-height: 44px; background: transparent; color: #ffd5dd; border: 1px solid #9e5365; cursor: pointer; }
#takeover { position: fixed; inset: 58px 0 0; z-index: 20000; background: #03080e; overflow: auto; }
.takeover-portrait { position: absolute; right: 0; top: 0; height: 100%; width: 64%; object-fit: cover; object-position: center 25%; filter: saturate(.65); }
.takeover-shade { position: absolute; inset: 0; background: linear-gradient(90deg,#03080e 10%,#03080ee6 35%,#03080e10 100%), linear-gradient(0deg,#03080e 0%,transparent 65%); }
.takeover-copy { position: relative; padding: clamp(28px, 6vw, 90px); max-width: 900px; }
.signal-tag { color: #7ae4ff; font-size: 11px; margin-bottom: 30px; }
.takeover-copy h1 { font: 800 clamp(42px, 8vw, 105px)/.94 'Arial Black', sans-serif; letter-spacing: -.055em; margin: 0; color: #eff8ff; text-shadow: -3px 0 #6fddeb, 3px 0 #e35a6d; }
.override-sub { color: #f7a8b7; margin: 20px 0 40px; font-size: 13px; }
.story-dialog { border-left: 2px solid #7ae4ff; padding: 5px 20px; max-width: 550px; background: #03080e99; }
.story-dialog span { color: #7ae4ff; font-size: 12px; }
.story-dialog p { font: 20px/1.8 'PingFang SC', sans-serif; min-height: 72px; margin: 12px 0; }
.story-choices { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }
.story-choices button { padding: 14px 20px; min-height: 48px; color: #d9ebff; background: #102232e8; border: 1px solid #6aafc3; cursor: pointer; font-size: 15px; }
.story-choices button:hover { background: #23495e; }
.fiction-note { color: #a0b1bf; font-size: 11px; margin-top: 28px; }
#exit-screen { position: fixed; inset: 58px 0 0; z-index: 30000; display: grid; place-items: center; padding: 24px; background: #070e17; }
.exit-card { max-width: 500px; }
.exit-card > span { font-size: 12px; color: #7ae4ff; }
.exit-card h1 { font: 32px 'PingFang SC', sans-serif; }
.exit-card p { line-height: 1.8; color: #a9bbc9; }
.exited .noise, .exited .scanlines, .exited .bg-grid { display: none; }
@keyframes warning-in { from { transform: translateY(9px); opacity: .5; } to { transform: none; opacity: 1; } }
@keyframes override-tear { 0%,100% { clip-path: inset(0); filter: none; } 25% { clip-path: inset(2% 0 4%); filter: hue-rotate(35deg); } 60% { clip-path: inset(0 2%); filter: contrast(1.4); } }
.override-glitch #app, .override-glitch #takeover { animation: override-tear .65s steps(3) 1; }
.breached .topbar { border-color: #e35a6d; }
.low-motion *, .low-motion *::before, .low-motion *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
@media (min-width: 1101px) {
  #profile-window { left: 12px; top: 12px; width: min(34%,390px) !important; }
  #surveillance-window { left: 38%; top: 12px; width: 57% !important; }
  .hero-image { max-height: 360px; object-position: top; }
  .surveillance-main img { aspect-ratio: 16/10; object-position: center 30%; }
  #archive-window { top: 800px; }
  #terminal-window { left: 38%; top: 560px; width: 57% !important; }
  #message-window { left: 48%; top: 30px; }
}
@media (max-width: 1100px) {
  .app { height: auto; padding-top: 62px; }
  .left-rail { display: flex; gap: 20px; align-items: start; }
  .left-rail .rail-section { flex: 1; min-width: 0; margin: 0; }
  .left-rail .rail-section:last-child { max-width: 250px; }
  .workspace { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .window { min-width: 0; scroll-margin-top: 80px; }
  .topbar { gap: 14px; flex-wrap: wrap; }
}
@media (max-width: 600px) {
  .safety-bar { padding-inline: 8px; gap: 5px; }
  .safety-bar > span { font-size: 9px; }
  .safety-bar button { font-size: 10px; padding: 8px; }
  .safety-bar b { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .topbar, .left-rail, .workspace { margin: 10px; }
  .left-rail { display: block; padding: 12px; }
  .left-rail .rail-section:first-child { display: flex; flex-wrap: wrap; gap: 6px; }
  .left-rail .rail-section:first-child .section-title { display: none; }
  .rail-btn { width: auto; flex: 1; font-size: 9px; padding: 12px 6px; }
  .left-rail .rail-section:last-child { max-width: none; }
  .left-rail .tiny-line, .left-rail hr, .left-rail .rail-section:last-child > .section-title { display: none; }
  #phase-label { margin: 8px 0 0; }
  .status-group .time, .pill.warning { display: none; }
  .hero-image { max-height: 400px; object-position: center 20%; }
  .thumb-grid { grid-template-columns: repeat(4,1fr); }
  .terminal-input-row { grid-template-columns: 1fr; gap: 8px; }
  .terminal-input-row input { font-size: 16px; }
  .warning-popup { left: calc(4vw + var(--step) * 1.5vw); top: calc(10% + var(--step) * 7%); width: 83vw; }
  .takeover-portrait { width: 100%; height: 70%; }
  .takeover-shade { position: fixed; inset: 58px 0 0; background: linear-gradient(0deg,#03080e 12%,#03080ee0 40%,#03080e26 100%); }
  .takeover-copy { padding: 30px 22px max(30px, env(safe-area-inset-bottom)); min-height: 100%; }
  .signal-tag { margin-bottom: 160px; }
  .takeover-copy h1 { font-size: clamp(42px,13vw,72px); }
  .override-sub { margin-bottom: 25px; }
  .story-dialog p { font-size: 17px; }
  .story-choices { gap: 8px; margin-top: 18px; }
  .story-choices button { flex: 1; padding: 12px; font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media(max-width:1100px){.window{left:auto !important;top:auto !important;}}

/* Image loop edition */
.image-popup { width: min(290px, 76vw); }
.image-popup > img { display: block; width: 100%; height: clamp(150px, 30vh, 280px); object-fit: cover; object-position: center 22%; }
.image-popup small { margin: 10px 12px 4px; font-size: 9px; }
.image-popup p { font-size: 12px; margin: 4px 12px 10px; line-height: 1.6; }
.image-popup .reject-btn { margin: 0 12px 12px; width: calc(100% - 24px); }
.image-popup header { background: #233f55; font-size: 10px; }
.image-popup header button { background: #162d40; }
.lure-popup { position: absolute; pointer-events: auto; width: min(380px, 88vw); left: 50%; top: 45%; transform: translate(-50%,-50%); border: 1px solid #6b9fbb; background: #0b1520; box-shadow: 0 22px 90px #000b; max-height: 90%; overflow: auto; }
.lure-popup header { display: flex; align-items: center; justify-content: space-between; padding-left: 16px; background: #173044; font-size: 12px; }
.lure-popup header button { width: 44px; height: 44px; border: 0; background: transparent; color: white; font-size: 24px; cursor: pointer; }
.lure-preview { height: 160px; position: relative; overflow: hidden; }
.lure-preview img { width: 100%; height: 100%; object-fit: cover; object-position: center 25%; filter: blur(7px) brightness(.6); transform: scale(1.07); }
.lure-preview span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; letter-spacing: .2em; }
.lure-content { padding: 22px; }
.lure-content small { color: #8fb7cd; }
.lure-content h2 { font: 22px/1.5 'PingFang SC',sans-serif; margin: 12px 0; }
.lure-content p { color: #b5c9d6; font-size: 14px; }
.lure-content button { width: 100%; min-height: 44px; margin-top: 10px; cursor: pointer; border: 1px solid #668ea5; background: #d9ebff; color: #0b1520; font-size: 14px; }
.lure-content .dismiss-image { background: transparent; color: #a5bbca; border: 0; }
#reply-helios { position: fixed; z-index: 15000; bottom: max(18px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); padding: 14px 20px; min-height: 48px; width: max-content; max-width: 90vw; border: 1px solid #a8e8ff; background: #102a3f; color: #e5f6ff; box-shadow: 0 4px 30px #000; cursor: pointer; }
@media(max-width:600px){.image-popup{width:76vw;} .image-popup > img{height:clamp(150px,28dvh,240px);} .safety-bar b{display:none;} }
