:root {
  color-scheme: dark;
  --ink: #edf4e8;
  --muted: #a8b8ad;
  --dim: #738279;
  --glass: rgba(5, 16, 14, 0.58);
  --line: rgba(210, 232, 214, 0.2);
  --line-strong: rgba(216, 239, 220, 0.42);
  --acid: #c8ef8f;
  --cyan: #8fd6d1;
  --amber: #f4c979;
  --danger: #e4876d;
  --panel: #091512;
  --mono: "DM Mono", Consolas, monospace;
  --sans: "Manrope", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: #07100e;
  color: var(--ink);
  font-family: var(--sans);
}

body {
  min-height: 100svh;
  overflow: hidden;
}

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

.world {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #07100e;
}

.world-image {
  position: absolute;
  inset: -2%;
  background: url("assets/kerns-world.png") center 48% / cover no-repeat;
  filter: saturate(0.82) contrast(1.06) brightness(0.8);
  transform: scale(1.04);
  transition: filter 900ms ease, transform 8s ease;
}

#atmosphere { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.7; }

.world-shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(2, 8, 7, 0.82) 0%, rgba(2, 9, 8, 0.38) 35%, rgba(3, 10, 9, 0.08) 61%, rgba(2, 8, 7, 0.66) 100%),
    linear-gradient(180deg, rgba(3, 9, 8, 0.7) 0%, transparent 25%, transparent 62%, rgba(2, 8, 7, 0.85) 100%);
}

.scanline {
  position: absolute;
  inset: 0;
  opacity: 0.05;
  pointer-events: none;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 3px, #d8ffe8 4px);
}

.shell {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  display: grid;
  grid-template-rows: 74px 1fr 112px;
  padding: 0 34px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

.brand strong {
  display: block;
  font: 500 12px/1.2 var(--mono);
  letter-spacing: 0.12em;
}

.brand small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font: 300 9px/1.2 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.brand-mark {
  position: relative;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line-strong);
  transform: rotate(45deg);
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid var(--acid);
}

.brand-mark::after { inset: 11px; background: var(--acid); }
.brand-mark i { position: absolute; width: 7px; height: 1px; background: var(--line-strong); }
.brand-mark i:nth-child(1) { left: -7px; top: 6px; }
.brand-mark i:nth-child(2) { right: -7px; top: 6px; }
.brand-mark i:nth-child(3) { left: -7px; bottom: 6px; }
.brand-mark i:nth-child(4) { right: -7px; bottom: 6px; }

.telemetry { display: flex; gap: 34px; }
.telemetry span { display: grid; justify-items: end; }
.telemetry b { font: 400 11px/1.1 var(--mono); letter-spacing: 0.08em; }
.telemetry small { margin-top: 5px; color: var(--dim); font: 400 8px/1 var(--mono); letter-spacing: 0.14em; }
.telemetry .signal b { color: var(--acid); }
.telemetry .signal b::before { content: ""; display: inline-block; width: 5px; height: 5px; margin-right: 7px; border-radius: 50%; background: var(--acid); box-shadow: 0 0 9px var(--acid); }

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(5, 15, 13, 0.42);
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease;
}

.icon-button:hover,
.icon-button.active { border-color: var(--line-strong); background: rgba(188, 230, 182, 0.12); color: var(--acid); }
.icon-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

.deck {
  min-height: 0;
  display: grid;
  grid-template-columns: 54px minmax(420px, 1fr) 274px;
  gap: 38px;
  align-items: center;
}

.rail {
  align-self: center;
  display: grid;
  gap: 9px;
  padding: 9px 7px;
  border: 1px solid var(--line);
  background: rgba(3, 12, 10, 0.32);
  backdrop-filter: blur(12px);
}

.rail-button {
  position: relative;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.rail-button::before {
  content: "";
  position: absolute;
  left: -8px;
  width: 2px;
  height: 0;
  background: var(--acid);
  transition: height 160ms ease;
}

.rail-button:hover,
.rail-button.active { color: var(--ink); background: rgba(210, 238, 216, 0.08); }
.rail-button.active::before { height: 22px; }
.rail-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }

.primary { max-width: 700px; }

.eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--acid);
  font: 400 9px/1 var(--mono);
  letter-spacing: 0.13em;
}

.pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--acid);
  box-shadow: 0 0 12px var(--acid);
  animation: pulse 2.4s infinite;
}

.coordinates { color: var(--dim); margin-left: 8px; }

.hero-copy { margin: clamp(28px, 5vh, 62px) 0 42px; }
.kicker { margin: 0 0 10px; color: var(--muted); font: 300 12px/1.4 var(--mono); }

h1 {
  margin: 0;
  max-width: 700px;
  font-size: clamp(52px, 6.5vw, 104px);
  font-weight: 500;
  line-height: 0.87;
  letter-spacing: 0;
  text-shadow: 0 8px 40px rgba(0, 0, 0, 0.42);
}

.hero-copy > p:last-child {
  max-width: 530px;
  margin: 25px 0 0;
  color: #c2cec5;
  font-size: 14px;
  line-height: 1.7;
}

.perspective-switch {
  width: min(650px, 100%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(5, 15, 13, 0.3);
  backdrop-filter: blur(10px);
}

.perspective {
  min-width: 0;
  height: 68px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 16px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.perspective:last-child { border-right: 0; }
.perspective:hover { background: rgba(210, 238, 216, 0.06); }
.perspective.active { background: rgba(200, 239, 143, 0.1); }
.perspective-icon { color: var(--acid); font: 400 20px/1 var(--mono); }
.perspective b { display: block; font-size: 11px; font-weight: 600; }
.perspective small { display: block; overflow: hidden; margin-top: 4px; color: var(--muted); font: 300 8px/1.2 var(--mono); white-space: nowrap; text-overflow: ellipsis; }

.readout {
  align-self: center;
  padding: 19px;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(15px);
}

.readout-head {
  display: flex;
  justify-content: space-between;
  padding-bottom: 15px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font: 400 8px/1 var(--mono);
  letter-spacing: 0.12em;
}

.planet-glyph { position: relative; width: 150px; height: 150px; margin: 22px auto; }
.planet-core {
  position: absolute;
  inset: 38px;
  border: 1px solid rgba(200, 239, 143, 0.8);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, rgba(200, 239, 143, 0.25), rgba(15, 42, 32, 0.2) 55%, rgba(3, 10, 8, 0.7));
  box-shadow: inset -8px -5px 18px rgba(0, 0, 0, 0.6), 0 0 24px rgba(143, 214, 209, 0.12);
}
.planet-core::before, .planet-core::after { content: ""; position: absolute; border: 1px dotted rgba(200, 239, 143, 0.27); border-radius: 50%; }
.planet-core::before { inset: 11px -4px; transform: rotate(20deg); }
.planet-core::after { inset: -3px 16px; transform: rotate(-20deg); }
.orbit { position: absolute; border: 1px solid rgba(205, 230, 211, 0.2); border-radius: 50%; }
.orbit-a { inset: 17px 3px; transform: rotate(-18deg); }
.orbit-b { inset: 2px 24px; transform: rotate(42deg); }
.satellite { position: absolute; top: 27px; right: 26px; width: 5px; height: 5px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 8px var(--amber); animation: satellite 8s linear infinite; transform-origin: -50px 49px; }

dl { margin: 0; border-top: 1px solid var(--line); }
dl div { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
dt { color: var(--muted); font: 300 9px/1 var(--mono); }
dd { margin: 0; font: 400 9px/1 var(--mono); }

.text-command {
  width: 100%;
  display: flex;
  justify-content: space-between;
  margin-top: 17px;
  padding: 12px 0 0;
  border: 0;
  background: transparent;
  color: var(--acid);
  font: 500 9px/1 var(--mono);
  letter-spacing: 0.08em;
  cursor: pointer;
}

.timeline {
  display: grid;
  grid-template-columns: 175px 1fr 230px;
  gap: 25px;
  align-items: center;
  border-top: 1px solid var(--line);
}

.timeline-label span { display: block; color: var(--dim); font: 400 8px/1 var(--mono); letter-spacing: 0.11em; }
.timeline-label strong { display: block; margin-top: 9px; font: 400 11px/1 var(--mono); color: var(--acid); }
.timeline-control { position: relative; min-width: 0; padding-top: 3px; }

input[type="range"] {
  width: 100%;
  height: 20px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: linear-gradient(90deg, var(--acid) var(--range, 0%), var(--line-strong) var(--range, 0%)); }
input[type="range"]::-webkit-slider-thumb { width: 14px; height: 14px; margin-top: -6px; appearance: none; border: 3px solid #0a1713; border-radius: 50%; background: var(--acid); box-shadow: 0 0 0 1px var(--acid), 0 0 12px rgba(200, 239, 143, 0.4); }
input[type="range"]::-moz-range-track { height: 2px; background: var(--line-strong); }
input[type="range"]::-moz-range-progress { height: 2px; background: var(--acid); }
input[type="range"]::-moz-range-thumb { width: 9px; height: 9px; border: 3px solid #0a1713; border-radius: 50%; background: var(--acid); box-shadow: 0 0 0 1px var(--acid); }

.ticks { display: flex; justify-content: space-between; color: var(--dim); font: 400 8px/1 var(--mono); }
.session-button {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: rgba(7, 20, 16, 0.65);
  text-align: left;
  cursor: pointer;
}
.session-button:hover { background: rgba(200, 239, 143, 0.12); border-color: var(--acid); }
.session-button.running { color: var(--acid); }
.session-button svg { width: 18px; fill: currentColor; stroke: none; }
.session-button b, .session-button small { display: block; }
.session-button b { font-size: 11px; font-weight: 600; }
.session-button small { margin-top: 4px; color: var(--muted); font: 300 8px/1 var(--mono); }

.panel {
  position: fixed;
  z-index: 10;
  inset: 0;
  visibility: hidden;
  pointer-events: none;
}
.panel.open { visibility: visible; pointer-events: auto; }
.panel-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(1, 6, 5, 0.58);
  opacity: 0;
  transition: opacity 280ms ease;
  backdrop-filter: blur(3px);
}
.panel.open .panel-backdrop { opacity: 1; }
.panel-sheet {
  position: absolute;
  top: 0;
  right: 0;
  width: min(620px, 92vw);
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 30px 34px;
  background: rgba(7, 18, 15, 0.97);
  border-left: 1px solid var(--line-strong);
  transform: translateX(100%);
  transition: transform 360ms cubic-bezier(.2,.8,.2,1);
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.45);
}
.panel.open .panel-sheet { transform: translateX(0); }
.compact-sheet { width: min(500px, 92vw); }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.panel-kicker { color: var(--acid); font: 400 8px/1 var(--mono); letter-spacing: 0.14em; }
.panel h2 { margin: 8px 0 0; font-size: 26px; font-weight: 500; }
.close-button { background: transparent; }

.spoiler-control { padding: 24px 0 20px; border-bottom: 1px solid var(--line); }
.spoiler-control label { display: flex; justify-content: space-between; font: 400 10px/1 var(--mono); }
.spoiler-control label span { color: var(--muted); }
.spoiler-control input { margin-top: 14px; --range: 0%; }
.spoiler-control p { margin: 8px 0 0; color: var(--dim); font: 300 9px/1.5 var(--mono); }
.capsule-list { min-height: 0; overflow-y: auto; padding: 12px 8px 50px 0; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.epoch-heading { margin: 21px 0 8px; color: var(--cyan); font: 400 9px/1 var(--mono); letter-spacing: 0.11em; }
.capsule {
  position: relative;
  padding: 17px 16px;
  border-top: 1px solid var(--line);
}
.capsule:last-child { border-bottom: 1px solid var(--line); }
.capsule-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.capsule-id { color: var(--acid); font: 400 9px/1 var(--mono); }
.chapter-map {
  width: 110px;
  padding: 4px 6px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  outline: 0;
  background: rgba(255,255,255,0.03);
  font: 300 8px/1 var(--mono);
}
.capsule h3 { margin: 10px 0 7px; font-size: 14px; font-weight: 600; }
.capsule p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.58; }
.capsule textarea {
  width: 100%;
  min-height: 52px;
  margin-top: 12px;
  padding: 9px;
  resize: vertical;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 3px;
  outline: 0;
  background: rgba(255,255,255,0.025);
  font: 300 10px/1.5 var(--mono);
}
.capsule textarea:focus, .chapter-map:focus { border-color: var(--acid); }
.capsule.locked { min-height: 84px; overflow: hidden; }
.capsule.locked > * { filter: blur(6px); opacity: 0.26; user-select: none; pointer-events: none; }
.capsule-lock {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 16px;
  color: var(--dim);
  background: rgba(7, 18, 15, 0.62);
  filter: none !important;
  opacity: 1 !important;
  font: 400 9px/1 var(--mono);
  letter-spacing: 0.08em;
}
.capsule-lock::before { content: ""; width: 7px; height: 7px; border: 1px solid var(--dim); transform: rotate(45deg); }

.atlas-map { position: relative; flex: 1; margin-top: 24px; min-height: 430px; border: 1px solid var(--line); background: radial-gradient(circle at center, rgba(120, 181, 160, 0.1), transparent 55%); overflow: hidden; }
.atlas-map::before { content: ""; position: absolute; inset: 0; opacity: 0.18; background-image: radial-gradient(#d9f2df 0.8px, transparent 0.8px); background-size: 31px 31px; }
.world-node { position: absolute; z-index: 2; display: grid; justify-items: start; padding: 0; border: 0; background: none; cursor: pointer; text-align: left; }
.world-node:nth-child(1) { left: 15%; top: 19%; }
.world-node:nth-child(2) { right: 11%; top: 49%; }
.world-node:nth-child(3) { left: 22%; bottom: 14%; }
.world-node i { width: 16px; height: 16px; margin-bottom: 9px; border: 1px solid var(--line-strong); border-radius: 50%; background: #12271f; box-shadow: 0 0 0 7px rgba(200,239,143,0.04); }
.world-node.active i { background: var(--acid); box-shadow: 0 0 18px rgba(200,239,143,0.7); }
.world-node b { font: 400 10px/1 var(--mono); }
.world-node span { margin-top: 5px; color: var(--dim); font: 300 8px/1 var(--mono); }
.map-lines { position: absolute; left: 23%; top: 29%; width: 55%; height: 45%; border: 1px dashed rgba(200,239,143,0.18); transform: rotate(16deg) skew(-14deg); }

.journal-prompts { display: flex; flex-wrap: wrap; gap: 7px; margin: 24px 0 14px; }
.prompt-chip { padding: 7px 9px; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; background: transparent; font: 300 8px/1.2 var(--mono); cursor: pointer; }
.prompt-chip:hover { color: var(--acid); border-color: var(--line-strong); }
#journalText { flex: 1; width: 100%; min-height: 300px; padding: 18px; resize: none; color: var(--ink); border: 1px solid var(--line); border-radius: 3px; outline: 0; background: rgba(255,255,255,0.02); font: 300 13px/1.8 var(--mono); }
#journalText:focus { border-color: var(--line-strong); }
.save-status { padding-top: 12px; color: var(--dim); font: 300 8px/1 var(--mono); text-align: right; }

.toast { position: fixed; z-index: 30; left: 50%; bottom: 24px; padding: 10px 14px; border: 1px solid var(--line-strong); border-radius: 3px; background: #0c1b17; font: 400 9px/1 var(--mono); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: opacity 180ms ease, transform 180ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

body[data-perspective="portiid"] .world-image { filter: saturate(1.05) contrast(1.08) brightness(0.72) hue-rotate(-10deg); transform: scale(1.07); }
body[data-perspective="portiid"] { --acid: #f1d878; --cyan: #b2e49a; }
body[data-perspective="ark"] .world-image { filter: saturate(0.42) contrast(1.17) brightness(0.58) hue-rotate(24deg); transform: scale(1.02); }
body[data-perspective="ark"] { --acid: #8fd6d1; --cyan: #a8cce8; }

@keyframes pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }
@keyframes satellite { to { transform: rotate(360deg); } }

@media (max-width: 980px) {
  .shell { padding: 0 20px; grid-template-rows: 66px 1fr 106px; }
  .deck { grid-template-columns: 48px 1fr; gap: 24px; }
  .readout { display: none; }
  .telemetry span:first-child { display: none; }
  .primary { max-width: 680px; }
}

@media (max-width: 680px) {
  body { overflow: auto; }
  .world-shade { background: linear-gradient(180deg, rgba(3,9,8,.78) 0%, rgba(2,8,7,.18) 34%, rgba(2,8,7,.9) 82%); }
  .world-image { background-position: 52% 46%; }
  .shell { min-height: 100svh; height: auto; grid-template-rows: 58px 1fr auto; padding: 0 15px; }
  .topbar { position: relative; }
  .brand-mark { width: 24px; height: 24px; }
  .brand strong { font-size: 10px; }
  .brand small { display: none; }
  .telemetry { margin-left: auto; margin-right: 10px; gap: 12px; }
  .telemetry span:nth-child(2) { display: none; }
  .topbar > .icon-button { width: 34px; height: 34px; }
  .deck { display: block; padding: 28px 0 22px; }
  .rail { position: fixed; z-index: 5; left: 50%; bottom: 12px; width: calc(100% - 30px); display: flex; justify-content: space-around; padding: 5px 10px; transform: translateX(-50%); background: rgba(5,16,14,.9); }
  .rail-button::before { left: 50%; bottom: -6px; width: 0; height: 2px; transform: translateX(-50%); transition: width 160ms ease; }
  .rail-button.active::before { width: 21px; height: 2px; }
  .eyebrow { font-size: 8px; }
  .coordinates { display: none; }
  .hero-copy { margin: 22px 0 28px; }
  h1 { font-size: clamp(48px, 15vw, 70px); line-height: 0.9; }
  .hero-copy > p:last-child { margin-top: 18px; font-size: 12px; line-height: 1.58; }
  .perspective-switch { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .perspective { height: 58px; justify-content: center; padding: 0 6px; text-align: center; }
  .perspective-icon { display: none; }
  .perspective small { display: none; }
  .perspective b { font-size: 9px; }
  .timeline { grid-template-columns: 1fr; gap: 11px; padding: 15px 0 85px; }
  .timeline-label { display: flex; align-items: center; justify-content: space-between; }
  .timeline-label strong { margin: 0; }
  .session-button { height: 50px; }
  .ticks { margin-top: 2px; }
  .panel-sheet { width: 100%; padding: 24px 18px 90px; border-left: 0; }
  .panel h2 { font-size: 23px; }
  .atlas-map { min-height: 380px; }
}

@media (max-height: 720px) and (min-width: 681px) {
  .shell { grid-template-rows: 62px 1fr 90px; }
  .hero-copy { margin: 22px 0 26px; }
  h1 { font-size: clamp(48px, 6vw, 78px); }
  .hero-copy > p:last-child { margin-top: 17px; line-height: 1.5; }
  .perspective { height: 58px; }
  .planet-glyph { width: 120px; height: 120px; margin: 13px auto; transform: scale(.82); }
  .readout { padding: 14px 17px; }
  dl div { padding: 8px 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
