:root {
  color-scheme: dark;
  --ink: #071111;
  --paper: #eef5eb;
  --muted: #9bb7ae;
  --cyan: #6ce7d4;
  --green: #b8ff63;
  --lavender: #c9b7ff;
  --amber: #ffd166;
  --line: rgba(238, 245, 235, 0.16);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--ink); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--paper);
  background:
    radial-gradient(circle at 80% 12%, rgba(108, 231, 212, 0.08), transparent 30rem),
    linear-gradient(145deg, #071111, #0d131a 62%, #0b1012);
}

button, a { font: inherit; }

.site-header {
  display: flex;
  width: min(1180px, calc(100% - 36px));
  margin: 0 auto;
  padding: 18px 0;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.labs-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--paper);
  font-weight: 800;
  text-decoration: none;
}

.labs-link img { width: 32px; height: 32px; }

.quiet-button {
  border: 1px solid var(--line);
  padding: 9px 13px;
  color: var(--muted);
  background: rgba(255,255,255,.03);
  cursor: pointer;
}

.quiet-button:hover, .quiet-button:focus-visible {
  color: var(--paper);
  border-color: var(--cyan);
}

main {
  display: grid;
  width: min(1180px, calc(100% - 36px));
  margin: 0 auto;
  grid-template-columns: minmax(250px, .72fr) minmax(480px, 1.5fr);
  gap: clamp(28px, 6vw, 80px);
  padding: clamp(48px, 8vw, 96px) 0;
}

.story-panel { align-self: start; }
.eyebrow {
  margin: 0 0 12px;
  color: var(--cyan);
  font: 800 .72rem/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: .15em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 32px;
  font-size: clamp(3.5rem, 8vw, 7rem);
  line-height: .84;
  letter-spacing: -.07em;
}

.chapter-title {
  margin-bottom: 12px;
  color: var(--lavender);
  font: 800 .86rem/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
  text-transform: uppercase;
}

.story-text {
  min-height: 8em;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.7;
}

.lesson {
  display: inline-flex;
  flex-direction: column;
  gap: 7px;
  padding: 15px 18px;
  border-left: 3px solid var(--green);
  background: rgba(184, 255, 99, .06);
}

.lesson span {
  color: var(--muted);
  font: 700 .65rem/1 ui-monospace, monospace;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.lesson strong {
  color: var(--green);
  font: 800 1rem/1.2 ui-monospace, monospace;
}

.game-shell {
  min-width: 0;
  border: 1px solid var(--line);
  background: rgba(2, 9, 10, .82);
  box-shadow: 18px 18px 0 rgba(0, 0, 0, .2);
}

.world-header {
  display: flex;
  min-height: 47px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.mode-cluster {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font: 700 .7rem/1 ui-monospace, monospace;
}

.mode-indicator {
  padding: 5px 7px;
  color: var(--ink);
  background: var(--green);
}

.mode-indicator.insert { background: var(--lavender); }
.mode-indicator.command { background: var(--amber); }

.progress-track {
  width: min(180px, 35%);
  height: 4px;
  background: rgba(255,255,255,.1);
}

#progress-fill {
  display: block;
  height: 100%;
  background: var(--cyan);
  transition: width .35s ease;
}

.editor {
  position: relative;
  display: grid;
  min-height: 360px;
  padding: 44px 28px;
  grid-template-columns: 34px minmax(0, 1fr);
  overflow: auto;
  outline: none;
  background:
    linear-gradient(rgba(108,231,212,.025) 1px, transparent 1px);
  background-size: 100% 25px;
}

.editor:focus { box-shadow: inset 0 0 0 2px rgba(108,231,212,.22); }

.gutter, #buffer {
  margin: 0;
  font: 600 clamp(.88rem, 1.6vw, 1.08rem)/1.75 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.gutter {
  color: rgba(155,183,174,.35);
  text-align: right;
  padding-right: 12px;
  user-select: none;
  white-space: pre;
}

#buffer {
  min-width: max-content;
  color: #c7d8d2;
  white-space: pre;
}

.char {
  position: relative;
  display: inline-block;
  min-width: .62em;
}

.char.caret {
  color: var(--ink);
  background: var(--green);
  box-shadow: 0 0 16px rgba(184,255,99,.35);
}

.char.beacon::after {
  position: absolute;
  content: "";
  width: 5px;
  height: 5px;
  left: 50%;
  top: -2px;
  border-radius: 50%;
  background: var(--lavender);
  box-shadow: 0 0 10px var(--lavender);
  transform: translate(-50%, -50%);
}

.char.corruption {
  color: #ff8c8c;
  text-decoration: wavy underline rgba(255, 80, 80, .8);
}

.command-line {
  display: flex;
  gap: 10px;
  min-height: 42px;
  align-items: center;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font: 700 .76rem/1.3 ui-monospace, monospace;
}

.command-prompt { color: var(--cyan); }

.mission-row {
  display: flex;
  min-height: 70px;
  padding: 15px 16px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.mission-row p { margin: 0; color: var(--muted); line-height: 1.45; }
#beacon-count { color: var(--lavender); font: 700 .75rem/1.2 ui-monospace, monospace; white-space: nowrap; }

.key-guide {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  color: var(--muted);
  font-size: .78rem;
}

.key-guide div { display: flex; align-items: center; gap: 7px; }
kbd {
  display: inline-block;
  min-width: 25px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  color: var(--paper);
  background: rgba(255,255,255,.05);
  font: 700 .72rem/1 ui-monospace, monospace;
  text-align: center;
}

.message {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: 32px;
  padding: 12px 17px;
  color: var(--ink);
  background: var(--green);
  box-shadow: 8px 8px 0 rgba(0,0,0,.35);
  font-weight: 800;
  transform: translateX(-50%);
}

.hidden { display: none; }

dialog {
  width: min(620px, calc(100% - 32px));
  border: 1px solid rgba(108,231,212,.45);
  padding: 28px;
  color: var(--paper);
  background: #0c1517;
  box-shadow: 24px 24px 0 rgba(0,0,0,.4);
}

dialog::backdrop { background: rgba(3,8,9,.78); backdrop-filter: blur(5px); }
.dialog-heading { display: flex; justify-content: space-between; gap: 20px; }
dialog h2 { font-size: clamp(1.8rem, 5vw, 3rem); line-height: 1; }
dialog p, dialog dd { color: var(--muted); line-height: 1.55; }
dialog dl { display: grid; gap: 8px; }
dialog dl div { display: grid; grid-template-columns: 155px 1fr; gap: 15px; }
dialog dt, dialog dd { margin: 0; }
.help-note { padding-top: 15px; border-top: 1px solid var(--line); font-size: .82rem; }
.ending-dialog blockquote { margin: 28px 0; color: var(--lavender); font: 700 1.2rem/1.5 ui-monospace, monospace; }
.ending-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.ending-actions button, .ending-actions a {
  padding: 11px 15px;
  border: 1px solid var(--cyan);
  color: var(--ink);
  background: var(--cyan);
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}
.ending-actions a { color: var(--paper); background: transparent; }

@media (max-width: 820px) {
  main { grid-template-columns: 1fr; }
  .story-text { min-height: auto; }
  .key-guide { grid-column: 1; }
  .editor { min-height: 320px; padding-inline: 14px; }
}

@media (max-width: 520px) {
  .labs-link span { display: none; }
  h1 { font-size: 4rem; }
  .editor { grid-template-columns: 25px minmax(0, 1fr); }
  dialog dl div { grid-template-columns: 1fr; }
}
