:root {
  color-scheme: dark;
  --bg: #080908;
  --panel: rgba(12, 22, 20, 0.88);
  --panel-strong: rgba(18, 28, 24, 0.96);
  --paper: #c8b995;
  --paper-dark: #514736;
  --ink: #efe9d2;
  --muted: #8a9c91;
  --teal: #65d3c2;
  --amber: #d5aa5f;
  --red: #d25b4b;
  --green: #8ecf7a;
  --line: rgba(126, 211, 194, 0.22);
  --shadow: rgba(0, 0, 0, 0.55);
  font-family:
    "Yu Gothic UI", "Meiryo", "Noto Sans JP", ui-monospace, SFMono-Regular, Consolas,
    monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    radial-gradient(circle at 25% 10%, rgba(101, 211, 194, 0.12), transparent 28rem),
    radial-gradient(circle at 80% 20%, rgba(210, 91, 75, 0.08), transparent 20rem),
    linear-gradient(135deg, #060706, #10120f 48%, #050605);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.crt-static,
.scanline {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 50;
}

.crt-static {
  opacity: 0.15;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 4px 4px, 7px 7px;
  mix-blend-mode: screen;
}

.scanline {
  opacity: 0.2;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 3px,
    rgba(101, 211, 194, 0.14) 4px,
    transparent 5px
  );
}

.shell {
  width: min(1720px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 16px 0 24px;
}

.topbar,
.status-strip,
.archive-panel,
.viewer-panel,
.notebook-panel,
.overlay__panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 60px var(--shadow), inset 0 0 24px rgba(101, 211, 194, 0.05);
  backdrop-filter: blur(8px);
}

.topbar {
  min-height: 92px;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 16px;
  align-items: stretch;
  padding: 14px;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.brand span,
.panel-heading,
.viewer-toolbar,
.status-strip,
.doc-intro span,
.archive-card small,
.query-box label,
.hypothesis-box span,
.ending-dock span {
  letter-spacing: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.brand strong {
  color: var(--ink);
  font-size: clamp(1.3rem, 2vw, 2.2rem);
  line-height: 1.1;
  text-shadow: 0 0 18px rgba(101, 211, 194, 0.18);
}

.topbar__meta {
  display: grid;
  gap: 7px;
  align-content: center;
  justify-items: end;
  color: var(--muted);
  font-size: 0.84rem;
}

#accessLevel {
  border: 1px solid rgba(213, 170, 95, 0.36);
  background: rgba(213, 170, 95, 0.08);
  color: var(--amber);
  padding: 2px 8px;
  cursor: pointer;
}

.status-strip {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 1px;
  background: rgba(101, 211, 194, 0.15);
}

.status-strip > div,
.status-strip > button {
  min-height: 48px;
  border: 0;
  background: rgba(8, 9, 8, 0.72);
  padding: 10px 12px;
}

.status-strip > div {
  display: grid;
  gap: 3px;
}

.status-strip b {
  color: var(--amber);
  font-size: 0.72rem;
}

.status-strip span {
  color: var(--teal);
}

.status-strip button {
  color: var(--red);
  cursor: pointer;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(240px, 310px) minmax(0, 1fr) minmax(260px, 360px);
  gap: 10px;
  margin-top: 10px;
  min-height: calc(100vh - 190px);
}

.archive-panel,
.viewer-panel,
.notebook-panel {
  min-height: 0;
}

.archive-panel,
.notebook-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  color: var(--teal);
}

.archive-list {
  display: grid;
  gap: 8px;
  padding: 10px;
  overflow: auto;
}

.archive-card {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 10px;
  align-items: stretch;
  min-height: 72px;
  border: 1px solid rgba(101, 211, 194, 0.2);
  background: rgba(4, 8, 7, 0.74);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    transform 160ms ease,
    background 160ms ease;
}

.archive-card:hover,
.archive-card.is-active {
  border-color: rgba(213, 170, 95, 0.72);
  background: rgba(35, 30, 18, 0.62);
  transform: translateX(2px);
}

.archive-card.is-seen .archive-card__thumb {
  color: var(--green);
}

.archive-card.is-locked {
  opacity: 0.42;
  cursor: not-allowed;
}

.archive-card__thumb {
  display: grid;
  place-items: center;
  border-right: 1px solid rgba(101, 211, 194, 0.18);
  color: var(--amber);
  font-size: 0.8rem;
  background: rgba(101, 211, 194, 0.06);
}

.archive-card__body {
  display: grid;
  align-content: center;
  gap: 6px;
  min-width: 0;
  padding: 10px 8px 10px 0;
}

.archive-card strong {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 0.95rem;
}

.viewer-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.viewer-toolbar {
  min-height: 62px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.viewer-toolbar div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.viewer-toolbar strong {
  color: var(--ink);
  overflow-wrap: anywhere;
}

#viewerBadge {
  color: var(--amber);
  text-align: right;
  max-width: 45%;
}

.viewer {
  position: relative;
  overflow: auto;
  padding: clamp(14px, 2vw, 24px);
}

.doc-intro {
  margin-bottom: 18px;
  border-left: 3px solid rgba(213, 170, 95, 0.8);
  padding-left: 14px;
}

.doc-intro h1 {
  margin: 7px 0;
  font-size: clamp(1.3rem, 2vw, 2rem);
  line-height: 1.15;
}

.doc-intro p {
  max-width: 76ch;
  margin: 0;
  color: #c4c8b8;
  line-height: 1.8;
}

.paper-doc {
  position: relative;
  color: #191611;
  background:
    linear-gradient(90deg, rgba(86, 64, 38, 0.12), transparent 24%, rgba(50, 32, 12, 0.1)),
    var(--paper);
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: clamp(16px, 2.2vw, 28px);
  box-shadow: inset 0 0 34px rgba(51, 35, 13, 0.25);
}

.paper-doc__stamp {
  position: absolute;
  right: 16px;
  top: 12px;
  color: rgba(133, 35, 24, 0.75);
  border: 2px solid rgba(133, 35, 24, 0.52);
  transform: rotate(-4deg);
  padding: 4px 10px;
  font-weight: 800;
}

.roster-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 22px;
  font-size: clamp(0.72rem, 1.4vw, 0.95rem);
}

.roster-table th,
.roster-table td {
  border: 1px solid rgba(41, 31, 18, 0.42);
  padding: 8px;
  text-align: left;
}

.roster-table th {
  background: rgba(48, 34, 18, 0.14);
}

.roster-table .is-player {
  background: rgba(171, 30, 24, 0.16);
  font-weight: 800;
}

.roster-table .is-linked {
  color: #772117;
  font-weight: 700;
}

.red-note {
  color: #8d2119;
  font-weight: 800;
}

.map-doc,
.audio-doc,
.system-ui-doc,
.pod-doc {
  border: 1px solid rgba(101, 211, 194, 0.22);
  background: rgba(3, 8, 7, 0.52);
  padding: clamp(14px, 2vw, 22px);
}

.map-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(180px, 260px);
  gap: 18px;
  align-items: center;
}

.map-ring {
  position: relative;
  min-height: 470px;
  border: 1px solid rgba(213, 170, 95, 0.32);
  background:
    linear-gradient(rgba(213, 170, 95, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(213, 170, 95, 0.08) 1px, transparent 1px);
  background-size: 28px 28px;
  overflow: hidden;
}

.map-ring::before,
.map-ring::after,
.map-core {
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(239, 233, 210, 0.36);
  content: "";
}

.map-ring::before {
  inset: 8%;
}

.map-ring::after {
  inset: 20%;
  border-color: rgba(101, 211, 194, 0.26);
}

.map-core {
  width: 118px;
  height: 118px;
  left: 50%;
  top: 50%;
  display: grid;
  place-items: center;
  color: var(--teal);
  background: rgba(101, 211, 194, 0.08);
  transform: translate(-50%, -50%);
  z-index: 1;
  font-weight: 800;
}

.map-label,
.forbidden {
  position: absolute;
  color: var(--ink);
  border: 1px solid rgba(239, 233, 210, 0.18);
  background: rgba(8, 9, 8, 0.72);
  padding: 5px 9px;
}

.label-a {
  left: 10%;
  top: 26%;
}

.label-b {
  right: 9%;
  top: 22%;
}

.label-c {
  right: 13%;
  bottom: 24%;
}

.label-d {
  left: 14%;
  bottom: 28%;
}

.forbidden {
  left: 50%;
  top: 10%;
  color: var(--red);
  border-color: rgba(210, 91, 75, 0.45);
  transform: rotate(-12deg);
}

.map-index {
  margin: 0;
  padding-left: 24px;
  color: #c8d1c8;
  line-height: 2;
}

.map-index li::marker {
  color: var(--amber);
}

.map-caption {
  color: var(--muted);
}

.route-button,
.decode-button,
.ending-actions button,
.ending-dock button,
.query-row button {
  border: 1px solid rgba(213, 170, 95, 0.52);
  background: rgba(213, 170, 95, 0.12);
  color: var(--amber);
  min-height: 40px;
  padding: 9px 12px;
  cursor: pointer;
}

.route-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.route-button.ghost {
  border-color: rgba(101, 211, 194, 0.34);
  color: var(--teal);
  background: rgba(101, 211, 194, 0.07);
}

.terminal-log {
  display: grid;
  gap: 10px;
}

.terminal-log.compact {
  gap: 6px;
}

.log-line {
  display: grid;
  grid-template-columns: minmax(84px, 130px) minmax(0, 1fr);
  gap: 12px;
  border: 1px solid rgba(101, 211, 194, 0.18);
  background: rgba(4, 8, 7, 0.7);
  padding: 10px;
}

.log-line span {
  color: var(--amber);
}

.log-line p {
  margin: 0;
  color: #d8dfd4;
  line-height: 1.7;
}

.log-line.is-ai {
  border-color: rgba(101, 211, 194, 0.3);
}

.log-line.is-ai p {
  color: #baf3e9;
}

.surveillance-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(101, 211, 194, 0.26);
  background: #050605;
}

.surveillance-frame img,
.image-doc img {
  display: block;
  width: 100%;
  height: auto;
}

.surveillance-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(to bottom, transparent 0, transparent 6px, rgba(255, 255, 255, 0.08) 7px),
    linear-gradient(90deg, rgba(101, 211, 194, 0.12), transparent 30%, rgba(210, 91, 75, 0.08));
  mix-blend-mode: screen;
}

.cam-overlay {
  position: absolute;
  inset: 12px 14px auto 14px;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #eaf8f3;
  text-shadow: 0 0 8px #000;
  font-size: clamp(0.72rem, 1.5vw, 1rem);
}

.rec-dot {
  color: var(--red);
}

.signal-warning {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 12px;
  z-index: 1;
  color: var(--red);
  border: 1px solid rgba(210, 91, 75, 0.34);
  background: rgba(0, 0, 0, 0.58);
  padding: 8px;
}

.cassette {
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
  gap: 12px;
  border: 1px solid rgba(239, 233, 210, 0.18);
  background: #161411;
  padding: 18px;
}

.reel {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 12px solid #2b2922;
  background: radial-gradient(circle, #0a0a08 0 18%, #4b473e 19% 23%, #111 24%);
}

.cassette-label {
  min-height: 54px;
  display: grid;
  place-items: center;
  background: #d0c1a0;
  color: #201910;
  text-align: center;
}

.waveform {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 120px;
  margin: 16px 0;
  border: 1px solid rgba(101, 211, 194, 0.2);
  padding: 12px;
  background: rgba(101, 211, 194, 0.04);
}

.waveform span {
  flex: 1;
  height: var(--h);
  background: linear-gradient(to top, var(--teal), rgba(239, 233, 210, 0.8));
  opacity: 0.8;
}

.transcript {
  margin-top: 14px;
  color: #d9e4dc;
  line-height: 1.8;
}

.note-doc {
  font-family: "Yu Mincho", "Yu Gothic UI", serif;
  font-size: 1.05rem;
  line-height: 1.9;
}

.note-date {
  text-align: right;
  color: var(--paper-dark);
  font-size: 0.88rem;
}

.sketch-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 20px;
}

.brain-sketch,
.pod-sketch {
  min-height: 170px;
  border: 2px dashed rgba(42, 32, 19, 0.42);
  background:
    radial-gradient(circle at 50% 42%, transparent 0 20%, rgba(74, 48, 21, 0.18) 21% 24%, transparent 25%),
    linear-gradient(35deg, transparent 48%, rgba(112, 28, 18, 0.3) 49% 51%, transparent 52%);
}

.image-doc {
  margin: 0;
  border: 1px solid rgba(213, 170, 95, 0.32);
  background: rgba(0, 0, 0, 0.42);
}

.image-doc figcaption {
  padding: 10px 12px;
  color: var(--muted);
  border-top: 1px solid rgba(213, 170, 95, 0.22);
}

.system-ui-doc {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(240px, 1fr) minmax(220px, 320px);
  gap: 16px;
  align-items: center;
}

.status-column {
  display: grid;
  gap: 9px;
}

.status-column span {
  border: 1px solid rgba(101, 211, 194, 0.18);
  background: rgba(101, 211, 194, 0.06);
  padding: 10px;
  color: var(--green);
}

.radar {
  position: relative;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid rgba(101, 211, 194, 0.42);
  background:
    radial-gradient(circle, rgba(101, 211, 194, 0.18) 0 2px, transparent 3px),
    repeating-radial-gradient(circle, transparent 0 14%, rgba(101, 211, 194, 0.18) 15% 16%, transparent 17% 28%);
}

.radar::before {
  content: "";
  position: absolute;
  inset: 50% 0 49% 50%;
  background: linear-gradient(90deg, rgba(101, 211, 194, 0.9), transparent);
  transform-origin: left center;
  animation: sweep 5s linear infinite;
}

.radar span {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 18px var(--teal);
}

.radar span:nth-child(1) {
  left: 30%;
  top: 42%;
}

.radar span:nth-child(2) {
  left: 58%;
  top: 28%;
}

.radar span:nth-child(3) {
  left: 68%;
  top: 62%;
}

.radar span:nth-child(4) {
  left: 44%;
  top: 72%;
}

@keyframes sweep {
  to {
    transform: rotate(360deg);
  }
}

.pod-doc {
  color: #d9e4dc;
}

.pod-diagram {
  position: relative;
  min-height: 500px;
  border: 1px solid rgba(239, 233, 210, 0.18);
  background:
    linear-gradient(rgba(239, 233, 210, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(239, 233, 210, 0.06) 1px, transparent 1px);
  background-size: 30px 30px;
}

.pod-shell {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(42%, 260px);
  height: 78%;
  border: 3px solid rgba(213, 170, 95, 0.62);
  border-radius: 46% 46% 18% 18%;
  transform: translate(-50%, -50%);
  background: rgba(213, 170, 95, 0.06);
}

.pod-body {
  position: absolute;
  left: 50%;
  top: 15%;
  width: 42%;
  height: 66%;
  border: 2px solid rgba(239, 233, 210, 0.45);
  border-radius: 50% 50% 22% 22%;
  transform: translateX(-50%);
}

.pod-label {
  position: absolute;
  border: 1px solid rgba(101, 211, 194, 0.26);
  background: rgba(5, 8, 7, 0.82);
  padding: 7px 10px;
}

.p1 {
  left: 11%;
  top: 16%;
}

.p2 {
  right: 10%;
  top: 26%;
}

.p3 {
  left: 12%;
  bottom: 28%;
}

.p4 {
  right: 12%;
  bottom: 18%;
}

.core-actions,
.ending-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.notebook-panel {
  background:
    linear-gradient(180deg, rgba(18, 28, 24, 0.96), rgba(9, 13, 11, 0.94)),
    var(--panel-strong);
}

.notebook-meter {
  height: 9px;
  margin: 12px;
  border: 1px solid rgba(101, 211, 194, 0.22);
  background: rgba(0, 0, 0, 0.34);
}

.notebook-meter div {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--red), var(--amber), var(--teal));
  transition: width 220ms ease;
}

.discovery-list {
  margin: 0;
  padding: 0 12px 12px 34px;
  overflow: auto;
  display: grid;
  gap: 9px;
  max-height: 36vh;
}

.discovery-list li {
  border-bottom: 1px solid rgba(101, 211, 194, 0.12);
  padding-bottom: 9px;
}

.discovery-list li::marker {
  color: var(--amber);
}

.discovery-list strong {
  display: block;
  color: var(--teal);
  font-size: 0.92rem;
}

.discovery-list span {
  display: block;
  margin-top: 4px;
  color: #c4c8b8;
  font-size: 0.82rem;
  line-height: 1.55;
}

.discovery-list .empty {
  color: var(--muted);
}

.query-box,
.hypothesis-box,
.ending-dock {
  margin: 0 12px 12px;
  border: 1px solid rgba(101, 211, 194, 0.18);
  background: rgba(5, 8, 7, 0.58);
  padding: 12px;
}

.query-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 8px;
}

.query-row input {
  min-width: 0;
  border: 1px solid rgba(101, 211, 194, 0.28);
  background: rgba(0, 0, 0, 0.42);
  color: var(--ink);
  padding: 9px 10px;
}

.query-result,
.hypothesis-box p {
  color: #c4c8b8;
  line-height: 1.65;
  margin: 10px 0 0;
  font-size: 0.86rem;
}

.ending-dock {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.ending-dock button.is-cleared {
  border-color: rgba(101, 211, 194, 0.58);
  color: var(--teal);
}

.ending-screen {
  min-height: 62vh;
  display: grid;
  align-content: center;
  gap: 14px;
  border: 1px solid rgba(213, 170, 95, 0.34);
  padding: clamp(22px, 5vw, 70px);
  background:
    linear-gradient(rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.8)),
    url("../assets/generated/machine-chapel.png") center / cover;
}

.ending-screen.surface {
  background:
    linear-gradient(rgba(0, 0, 0, 0.48), rgba(0, 0, 0, 0.82)),
    url("../assets/generated/surveillance-corridor.png") center / cover;
}

.ending-screen.hidden {
  background:
    linear-gradient(rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0.84)),
    url("../assets/reference/reference_lun-a12_moodboard.png") center / cover;
}

.ending-screen > span {
  color: var(--amber);
}

.ending-screen h1 {
  margin: 0;
  font-size: clamp(1.7rem, 4vw, 3.4rem);
}

.ending-screen p {
  max-width: 70ch;
  margin: 0;
  color: #ecf2e8;
  line-height: 1.9;
  text-shadow: 0 1px 8px #000;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.7);
  padding: 18px;
}

.overlay[aria-hidden="true"] {
  display: none;
}

.overlay__panel {
  width: min(680px, 100%);
  padding: clamp(22px, 5vw, 42px);
}

.overlay__panel span {
  color: var(--red);
}

.overlay__panel h2 {
  margin: 10px 0;
  font-size: clamp(1.4rem, 3vw, 2.4rem);
}

.overlay__panel p {
  line-height: 1.9;
  color: #d8dfd4;
}

.overlay__panel button {
  border: 1px solid rgba(101, 211, 194, 0.5);
  background: rgba(101, 211, 194, 0.1);
  color: var(--teal);
  min-height: 42px;
  padding: 10px 14px;
  cursor: pointer;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .notebook-panel {
    grid-column: 1 / -1;
    min-height: 360px;
  }

  .system-ui-doc {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100vw - 12px, 1720px);
    padding-top: 6px;
  }

  .topbar,
  .status-strip,
  .workspace,
  .map-grid {
    grid-template-columns: 1fr;
  }

  .topbar__meta {
    justify-items: start;
  }

  .status-strip {
    gap: 0;
  }

  .workspace {
    min-height: 0;
  }

  .archive-panel {
    max-height: 340px;
  }

  .viewer {
    padding: 12px;
  }

  #viewerBadge {
    max-width: none;
  }

  .viewer-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .map-ring,
  .pod-diagram {
    min-height: 360px;
  }

  .cam-overlay {
    flex-direction: column;
  }

  .log-line {
    grid-template-columns: 1fr;
  }

  .cassette {
    grid-template-columns: 44px 1fr 44px;
    padding: 12px;
  }
}
