:root {
  --bg: #020812;
  --panel: rgba(5, 15, 28, .82);
  --panel-2: rgba(6, 24, 35, .78);
  --line: rgba(86, 255, 190, .28);
  --cyan: #3ae2ff;
  --green: #74f2a8;
  --yellow: #ffcd50;
  --purple: #b478ff;
  --red: #ff6a85;
  --text: #eafff4;
  --muted: rgba(234, 255, 244, .66);
  --shadow: 0 22px 80px rgba(0,0,0,.38);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; background: var(--bg); color: var(--text); overflow: hidden; }
body {
  background:
    radial-gradient(circle at 80% 16%, rgba(58,226,255,.14), transparent 28%),
    radial-gradient(circle at 10% 80%, rgba(116,242,168,.12), transparent 30%),
    linear-gradient(135deg, #020812, #041723 48%, #020812);
}

.app {
  min-height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.topbar, .footerbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: rgba(2, 8, 18, .76);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 260px; }
.brand img { width: 46px; height: 46px; object-fit: contain; filter: drop-shadow(0 0 14px rgba(116,242,168,.42)); }
.brand strong { display: block; font-size: 20px; letter-spacing: .4px; }
.brand span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }

.hud { margin-left: auto; display: grid; grid-template-columns: repeat(4, minmax(84px, auto)); gap: 8px; }
.hud div {
  padding: 8px 12px;
  border: 1px solid rgba(58,226,255,.22);
  background: rgba(0,0,0,.25);
  border-radius: 14px;
  min-width: 84px;
}
.hud small { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .8px; }
.hud b { display: block; color: var(--green); font-size: 18px; }

.desktop {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, .85fr) minmax(420px, 1.65fr) minmax(280px, 1fr);
  gap: 12px;
  padding: 12px;
  background-image: url('assets/backgrounds/bg-terminal-lab.png');
  background-size: cover;
  background-position: center;
  position: relative;
}

.desktop::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.025) 0 1px, transparent 1px 4px),
    radial-gradient(circle at 40% 20%, rgba(86,255,190,.10), transparent 30%),
    rgba(0,0,0,.16);
  pointer-events: none;
}

.window {
  position: relative;
  z-index: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(5,15,28,.86), rgba(2,8,18,.78));
  box-shadow: var(--shadow), inset 0 0 38px rgba(58,226,255,.035);
  overflow: hidden;
  backdrop-filter: blur(14px);
}

.win-title {
  height: 44px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(86,255,190,.18);
  background: rgba(0,0,0,.24);
  color: var(--text);
  font-weight: 900;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 1px;
}
.win-title span {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--green);
  box-shadow: 18px 0 0 var(--yellow), 36px 0 0 var(--red);
}
.win-title em {
  margin-left: auto;
  color: var(--cyan);
  font-style: normal;
  text-transform: none;
}

.mission-window { display: grid; grid-template-rows: auto auto 1fr auto; }
.mission-text, .objectives, .principle, .file-tree, .tool-list { padding: 16px; }
.mission-text { color: var(--text); line-height: 1.55; font-weight: 700; }
.objectives h3, .principle h3 { margin: 0 0 8px; color: var(--yellow); text-transform: uppercase; font-size: 12px; letter-spacing: 1px; }
.objectives ul { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.objectives li { color: var(--muted); line-height: 1.35; }
.objectives li.done { color: var(--green); text-decoration: line-through; }
.principle p { margin: 0; line-height: 1.45; color: var(--muted); }

.terminal-window { display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; }
.terminal-output {
  min-height: 0;
  overflow: auto;
  padding: 16px;
  font-family: "Cascadia Mono", "Fira Code", Consolas, monospace;
  font-size: 14px;
  line-height: 1.5;
  background:
    radial-gradient(circle at 20% 15%, rgba(58,226,255,.05), transparent 40%),
    rgba(0, 0, 0, .32);
}
.line { white-space: pre-wrap; word-break: break-word; margin: 0 0 8px; }
.line.cmd { color: var(--cyan); }
.line.ok { color: var(--green); }
.line.warn { color: var(--yellow); }
.line.bad { color: var(--red); }
.line.story { color: #fff; }
.line.dim { color: var(--muted); }
.line.ascii { color: var(--green); font-size: 12px; }

.terminal-input {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 12px;
  border-top: 1px solid rgba(86,255,190,.18);
  background: rgba(0,0,0,.36);
  font-family: "Cascadia Mono", "Fira Code", Consolas, monospace;
}
.terminal-input label { color: var(--green); white-space: nowrap; }
.terminal-input input {
  width: 100%;
  border: 1px solid rgba(58,226,255,.22);
  border-radius: 12px;
  background: rgba(2,8,18,.72);
  color: var(--text);
  outline: none;
  padding: 12px 12px;
  font: inherit;
}
.terminal-input input:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(58,226,255,.12); }
button {
  border: 1px solid rgba(116,242,168,.28);
  background: linear-gradient(180deg, rgba(116,242,168,.18), rgba(58,226,255,.08));
  color: var(--text);
  font-weight: 900;
  border-radius: 13px;
  padding: 10px 13px;
  cursor: pointer;
  box-shadow: inset 0 0 18px rgba(255,255,255,.03);
}
button:hover { border-color: var(--green); transform: translateY(-1px); }
button:active { transform: translateY(0); }

.command-help {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,.07);
  background: rgba(0,0,0,.18);
}
.command-help span { color: var(--muted); font-size: 12px; }
.command-help button { padding: 7px 9px; border-radius: 10px; color: var(--cyan); font-family: "Cascadia Mono", Consolas, monospace; }

.right-stack {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(180px, .92fr) minmax(150px, .74fr) minmax(130px, .62fr);
  gap: 12px;
}

.network-map {
  position: relative;
  min-height: 180px;
  height: 100%;
  padding: 14px;
  background-image: url('assets/backgrounds/bg-network-map.png');
  background-size: cover;
  background-position: center;
}
.node {
  position: absolute;
  width: 72px;
  height: 72px;
  border-radius: 22px;
  border: 2px solid rgba(58,226,255,.45);
  background: rgba(0,0,0,.45);
  display: grid;
  place-items: center;
  color: var(--text);
  font-size: 10px;
  text-align: center;
  font-weight: 900;
  box-shadow: 0 0 30px rgba(58,226,255,.12);
  transition: .2s ease;
}
.node.unlocked { border-color: var(--green); box-shadow: 0 0 25px rgba(116,242,168,.26); }
.node.connected { border-color: var(--yellow); box-shadow: 0 0 30px rgba(255,205,80,.36); transform: scale(1.05); }
.node.rooted { border-color: var(--purple); box-shadow: 0 0 38px rgba(180,120,255,.42); }
.node.locked { opacity: .45; filter: grayscale(.8); }

.file-tree code, .tool-list code {
  display: block;
  padding: 7px 9px;
  margin-bottom: 7px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(0,0,0,.20);
  color: var(--muted);
  font-family: "Cascadia Mono", Consolas, monospace;
}
.tool-list code.ready { color: var(--green); border-color: rgba(116,242,168,.28); }
.tool-list code.locked { color: rgba(255,255,255,.38); }

.footerbar {
  border-top: 1px solid var(--line);
  border-bottom: none;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.footerbar button { min-height: 42px; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 70% 20%, rgba(58,226,255,.16), transparent 35%),
    rgba(0,0,0,.72);
  backdrop-filter: blur(12px);
}
.overlay.active { display: grid; }
.overlay-card {
  width: min(760px, 100%);
  padding: 28px;
  border-radius: 28px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(5,15,28,.96), rgba(2,8,18,.94));
  box-shadow: var(--shadow);
  text-align: center;
}
.overlay-card img { width: 130px; height: 130px; object-fit: contain; filter: drop-shadow(0 0 24px rgba(116,242,168,.35)); }
.overlay-card h1 { margin: 8px 0 0; font-size: clamp(34px, 7vw, 72px); letter-spacing: 1px; }
.overlay-card h2 { color: var(--green); margin: 0 0 14px; }
.overlay-card p { color: var(--muted); line-height: 1.55; max-width: 620px; margin: 0 auto 18px; }
.pill-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 16px 0 22px; }
.pill-row span {
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid rgba(116,242,168,.22);
  background: rgba(116,242,168,.10);
  color: var(--text);
  font-weight: 800;
}

@keyframes pulseNode {
  0%, 100% { box-shadow: 0 0 18px rgba(58,226,255,.16); }
  50% { box-shadow: 0 0 42px rgba(116,242,168,.34); }
}
.node.connected, .node.rooted { animation: pulseNode 1.4s ease-in-out infinite; }

@media (max-width: 1160px) {
  html, body { overflow: auto; }
  .app { max-height: none; min-height: 100dvh; }
  .desktop { grid-template-columns: 1fr; overflow: visible; }
  .right-stack { grid-template-rows: auto auto auto; }
  .network-map { height: 300px; }
  .mission-window { min-height: 250px; }
  .topbar { flex-wrap: wrap; }
  .hud { width: 100%; grid-template-columns: repeat(4, 1fr); margin-left: 0; }
}

@media (max-width: 680px) {
  .topbar { padding: 10px; }
  .brand { min-width: 0; width: 100%; }
  .brand strong { font-size: 17px; }
  .hud { grid-template-columns: repeat(2, 1fr); }
  .desktop { padding: 8px; gap: 8px; }
  .window { border-radius: 18px; }
  .terminal-output { font-size: 12px; padding: 12px; min-height: 340px; }
  .terminal-input { grid-template-columns: 1fr; }
  .terminal-input label { font-size: 12px; }
  .footerbar { display: grid; grid-template-columns: 1fr 1fr; padding: 8px; }
  .footerbar button { width: 100%; }
  .network-map { height: 260px; }
  .node { width: 58px; height: 58px; font-size: 9px; }
}
