:root {
  color-scheme: dark;
  --bg: #11130f;
  --panel: rgba(23, 27, 24, 0.9);
  --panel-strong: #20251f;
  --ink: #f1f4ea;
  --muted: #aeb8aa;
  --line: rgba(241, 244, 234, 0.16);
  --line-strong: rgba(241, 244, 234, 0.28);
  --teal: #4fd2c8;
  --amber: #f3b65f;
  --green: #8de36f;
  --magenta: #ff5c9f;
  --red: #ff6961;
  --violet: #9b8cff;
  --tile: clamp(42px, 7vw, 50px);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(79, 210, 200, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(243, 182, 95, 0.09), transparent 30%),
    var(--bg);
  overflow-x: hidden;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  background-image:
    linear-gradient(rgba(241, 244, 234, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(241, 244, 234, 0.045) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, black 0%, transparent 88%);
}

button,
input {
  font: inherit;
}

button {
  min-width: 0;
  color: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

.game-shell {
  --layer-accent: var(--teal);
  --layer-soft: rgba(79, 210, 200, 0.14);
  --layer-border: rgba(79, 210, 200, 0.62);
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(1480px, 100%);
  min-height: 100vh;
  padding: 16px;
  margin: 0 auto;
}

.game-shell[data-layer="data"] {
  --layer-accent: var(--violet);
  --layer-soft: rgba(155, 140, 255, 0.14);
  --layer-border: rgba(155, 140, 255, 0.62);
}

.game-shell[data-layer="infrastructure"] {
  --layer-accent: var(--amber);
  --layer-soft: rgba(243, 182, 95, 0.14);
  --layer-border: rgba(243, 182, 95, 0.62);
}

.game-shell[data-layer="security"] {
  --layer-accent: var(--magenta);
  --layer-soft: rgba(255, 92, 159, 0.14);
  --layer-border: rgba(255, 92, 159, 0.62);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 0 0;
}

.eyebrow,
.layer-name {
  margin: 0 0 4px;
  color: var(--layer-accent);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  font-size: 3.35rem;
  max-width: 12ch;
}

h2 {
  font-size: 1.18rem;
}

.run-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}

.run-stats span {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.run-stats strong {
  color: var(--ink);
}

.layer-track {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.layer-track li {
  display: flex;
  min-width: 0;
  min-height: 54px;
  align-items: center;
  gap: 10px;
  padding: 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.layer-track span {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 34px;
  place-items: center;
  color: var(--bg);
  font-size: 0.78rem;
  font-weight: 900;
  background: var(--muted);
  border-radius: 5px;
}

.layer-track strong {
  overflow: hidden;
  font-size: 0.88rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-track .current {
  color: var(--ink);
  border-color: var(--layer-border);
  box-shadow: inset 0 0 0 1px var(--layer-soft);
}

.layer-track .current span {
  background: var(--layer-accent);
}

.layer-track .complete {
  color: var(--green);
  border-color: rgba(141, 227, 111, 0.44);
}

.layer-track .complete span {
  background: var(--green);
}

.arena {
  display: grid;
  grid-template-columns: minmax(286px, 0.95fr) minmax(386px, 1.1fr) minmax(260px, 0.75fr);
  gap: 12px;
  align-items: stretch;
  flex: 1;
}

.daemon-panel,
.console-panel,
.patch-rack,
.status-rack {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.25);
}

.daemon-panel,
.console-panel {
  padding: 14px;
}

.side-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.patch-rack,
.status-rack {
  padding: 14px;
}

.daemon-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 100%;
}

.daemon-stage {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #080a08;
}

.daemon {
  display: block;
  width: 100%;
  height: min(32vh, 300px);
  min-height: 220px;
}

.daemon {
  --daemon-accent: var(--teal);
  --daemon-second: var(--amber);
}

.daemon[data-layer="data"] {
  --daemon-accent: var(--violet);
  --daemon-second: var(--green);
}

.daemon[data-layer="infrastructure"] {
  --daemon-accent: var(--amber);
  --daemon-second: var(--teal);
}

.daemon[data-layer="security"] {
  --daemon-accent: var(--magenta);
  --daemon-second: var(--amber);
}

.daemon-bg {
  fill: #0b0f0d;
}

.daemon-grid {
  opacity: 0.36;
}

.grid-line {
  fill: none;
  stroke: rgba(241, 244, 234, 0.12);
  stroke-width: 1;
}

.trace {
  fill: none;
  stroke: var(--daemon-accent);
  stroke-linecap: round;
  stroke-width: 4;
  opacity: 0.45;
  stroke-dasharray: 18 16;
  animation: trace 2.9s linear infinite;
}

.trace-b {
  animation-duration: 3.7s;
}

.trace-c {
  stroke: var(--daemon-second);
  animation-duration: 4.2s;
}

.mantle,
.helmet {
  fill: #1e2521;
  stroke: var(--daemon-accent);
  stroke-width: 3;
}

.helmet {
  filter: drop-shadow(0 0 16px rgba(79, 210, 200, 0.2));
}

.face,
.jaw {
  fill: #101410;
  stroke: rgba(241, 244, 234, 0.42);
  stroke-width: 2;
}

.horn {
  fill: #171c18;
  stroke: var(--daemon-second);
  stroke-width: 3;
}

.eye {
  fill: var(--daemon-second);
  transform-box: fill-box;
  transform-origin: center;
  animation: pulse 1.4s ease-in-out infinite alternate;
}

.right {
  animation-delay: 0.24s;
}

.mouth {
  fill: none;
  stroke: var(--red);
  stroke-linecap: round;
  stroke-width: 5;
}

.daemon[data-status="layerCleared"] .daemon-body,
.daemon[data-status="won"] .daemon-body {
  transform-box: fill-box;
  transform-origin: center;
  animation: daemon-clear 1.15s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.daemon[data-status="lost"] .daemon-body,
.daemon[data-status="lost"] .runes {
  filter: grayscale(1);
  opacity: 0.48;
}

.daemon[data-status="lost"] .trace {
  animation-play-state: paused;
  opacity: 0.14;
}

.rune-chip rect {
  fill: rgba(8, 12, 10, 0.86);
  stroke: var(--daemon-accent);
  stroke-width: 2;
  filter: drop-shadow(0 0 10px rgba(79, 210, 200, 0.12));
}

.rune-chip text {
  fill: var(--daemon-accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 18px;
  font-weight: 800;
  dominant-baseline: central;
  opacity: 0.9;
  text-anchor: middle;
}

.boss-readout {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sigil {
  display: grid;
  flex: 0 0 58px;
  width: 58px;
  height: 58px;
  place-items: center;
  margin: 0;
  color: #0a0d0b;
  font-size: 0.9rem;
  font-weight: 900;
  background: var(--layer-accent);
  border-radius: 8px;
  box-shadow: 0 0 0 4px var(--layer-soft);
}

.meter-group {
  display: grid;
  gap: 6px;
}

.meter-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

.meter-label strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.meter {
  height: 14px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.meter span {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--magenta), var(--amber));
  transition: width 220ms ease;
}

.meter.memory span {
  background: linear-gradient(90deg, var(--teal), var(--green));
}

.console-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.console-head {
  display: flex;
  width: 100%;
  min-height: 46px;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.encounter-action {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  color: #0d100e;
  font-weight: 800;
  background: var(--amber);
  border: 0;
  border-radius: 6px;
}

.encounter-action svg,
.guess-form button svg,
.keyboard svg,
.patch svg,
.tool-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.word-board {
  display: grid;
  gap: 6px;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(5, var(--tile));
  gap: 6px;
}

.tile {
  position: relative;
  display: grid;
  aspect-ratio: 1;
  place-items: center;
  color: var(--ink);
  font-size: 1.45rem;
  font-weight: 900;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: inset 0 -10px 22px rgba(0, 0, 0, 0.12);
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.board-row.active .tile {
  border-color: rgba(241, 244, 234, 0.34);
}

.tile.draft {
  background: var(--layer-soft);
  border-color: var(--layer-border);
  transform: translateY(-1px);
}

.tile.locked::after {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 6px;
  height: 6px;
  content: "";
  background: var(--amber);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(243, 182, 95, 0.72);
}

.tile.correct {
  color: #09100b;
  background: var(--green);
  border-color: transparent;
}

.tile.present {
  color: #14100a;
  background: var(--amber);
  border-color: transparent;
}

.tile.absent {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.1);
}

.tile.hint {
  color: var(--amber);
  border-color: rgba(243, 182, 95, 0.65);
  background: rgba(243, 182, 95, 0.1);
}

.guess-form {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  width: min(100%, 392px);
  align-items: center;
}

.guess-form label {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.guess-form input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 900;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

.guess-form button,
.patch {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  font-weight: 900;
  background: var(--layer-soft);
  border: 1px solid var(--layer-border);
  border-radius: 6px;
}

.guess-form button {
  color: var(--layer-accent);
}

.assist-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, 392px);
}

.tool-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 10px;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.tool-button.danger {
  color: #ffd9d6;
  border-color: rgba(255, 105, 97, 0.42);
}

.keyboard {
  display: grid;
  width: min(100%, 560px);
  gap: 6px;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.keyboard button {
  display: grid;
  flex: 1 1 0;
  max-width: 46px;
  min-width: 24px;
  height: 36px;
  place-items: center;
  padding: 0;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.keyboard .wide {
  flex-basis: 62px;
  max-width: 66px;
}

.keyboard .correct {
  color: #09100b;
  background: var(--green);
}

.keyboard .present {
  color: #14100a;
  background: var(--amber);
}

.keyboard .absent {
  color: #6f786e;
  background: rgba(255, 255, 255, 0.06);
}

.patches {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.patch {
  justify-content: space-between;
  width: 100%;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.055);
  border-color: var(--line);
}

.patch span {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: left;
}

.patch b {
  display: grid;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  place-items: center;
  color: #0b0e0c;
  background: var(--amber);
  border-radius: 50%;
}

.patch.armed {
  border-color: var(--green);
  box-shadow: inset 0 0 0 1px rgba(141, 227, 111, 0.24);
}

.status-message {
  min-height: 42px;
  margin: 10px 0;
  color: var(--ink);
  line-height: 1.4;
}

.run-summary {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px 12px;
  padding: 12px 0;
  margin: 2px 0 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.summary-grade {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  color: #0b0e0c;
  font-size: 1.75rem;
  font-weight: 950;
  background: var(--layer-accent);
  border-radius: 8px;
  box-shadow: 0 0 0 4px var(--layer-soft);
}

.game-shell[data-status="won"] .summary-grade {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(141, 227, 111, 0.14);
}

.game-shell[data-status="lost"] .summary-grade {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(255, 105, 97, 0.14);
}

.summary-copy {
  display: grid;
  align-content: center;
  gap: 3px;
  min-width: 0;
}

.summary-copy span {
  color: var(--layer-accent);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.game-shell[data-status="won"] .summary-copy span {
  color: var(--green);
}

.game-shell[data-status="lost"] .summary-copy span {
  color: var(--red);
}

.summary-copy strong {
  overflow-wrap: anywhere;
  font-size: 1.05rem;
}

.run-summary dl {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
}

.run-summary dl div {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 7px;
  background: rgba(255, 255, 255, 0.045);
  border-radius: 5px;
}

.run-summary dt {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.run-summary dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.combat-log {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  list-style: none;
  overflow: auto;
}

.combat-log li {
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.045);
  border-left: 3px solid var(--layer-accent);
  border-radius: 5px;
}

noscript {
  display: block;
  padding: 16px;
  color: #0b0e0c;
  background: var(--amber);
}

.audio-bank {
  display: none;
}

.effect-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
}

.effect-layer.play {
  opacity: 1;
}

.effect-layer.play::before {
  position: absolute;
  inset: 0;
  content: "";
  background: rgba(79, 210, 200, 0.1);
  animation: effect-fade var(--effect-duration, 2600ms) ease both;
}

.effect-layer.win.play::before {
  background: rgba(141, 227, 111, 0.16);
}

.effect-layer.lose.play::before {
  background: rgba(255, 105, 97, 0.18);
  animation-name: lose-fade;
}

.effect-burst {
  position: absolute;
  width: 1px;
  height: 1px;
}

.effect-burst span {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--teal);
  border-radius: 2px;
  box-shadow: 0 0 18px currentColor;
  transform: rotate(var(--angle)) translateX(0);
  animation: burst var(--particle-duration, 2100ms) cubic-bezier(0.18, 0.82, 0.24, 1) both;
}

.effect-layer.win .effect-burst span {
  width: 12px;
  height: 12px;
  color: var(--green);
  background: var(--green);
  animation-duration: var(--particle-duration, 3900ms);
}

.effect-layer.lose .effect-burst span {
  width: 14px;
  height: 3px;
  color: var(--red);
  background: var(--red);
  animation-name: collapse;
}

.effect-card {
  position: relative;
  display: grid;
  gap: 6px;
  min-width: min(86vw, 360px);
  padding: 22px;
  text-align: center;
  background: rgba(17, 19, 15, 0.9);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.42);
  animation: card-pop var(--effect-duration, 2600ms) ease both;
}

.effect-card strong {
  color: var(--ink);
  font-size: 2rem;
  line-height: 1;
}

.effect-card span {
  color: var(--muted);
  font-weight: 800;
}

.effect-layer.win .effect-card {
  border-color: rgba(141, 227, 111, 0.72);
  box-shadow: 0 0 44px rgba(141, 227, 111, 0.24), 0 22px 60px rgba(0, 0, 0, 0.48);
}

.effect-layer.lose .effect-card {
  border-color: rgba(255, 105, 97, 0.72);
  box-shadow: 0 0 44px rgba(255, 105, 97, 0.18), 0 22px 60px rgba(0, 0, 0, 0.48);
}

@keyframes trace {
  to {
    stroke-dashoffset: -68;
  }
}

@keyframes pulse {
  from {
    opacity: 0.72;
    transform: scale(0.9);
  }

  to {
    opacity: 1;
    transform: scale(1.08);
  }
}

@keyframes daemon-clear {
  0% {
    opacity: 1;
    transform: scale(1);
  }

  55% {
    opacity: 0.88;
    transform: scale(1.04);
  }

  100% {
    opacity: 0.22;
    transform: scale(0.88);
  }
}

@keyframes burst {
  0% {
    opacity: 0;
    transform: rotate(var(--angle)) translateX(0) scale(0.2);
  }

  18% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: rotate(var(--angle)) translateX(var(--distance)) scale(1);
  }
}

@keyframes collapse {
  0% {
    opacity: 0;
    transform: rotate(var(--angle)) translateX(var(--distance)) scaleX(1.4);
  }

  25% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: rotate(var(--angle)) translateX(0) scaleX(0.2);
  }
}

@keyframes card-pop {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.94);
  }

  18%,
  76% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  100% {
    opacity: 0;
    transform: translateY(-10px) scale(0.98);
  }
}

@keyframes effect-fade {
  0%,
  100% {
    opacity: 0;
  }

  20%,
  72% {
    opacity: 1;
  }
}

@keyframes lose-fade {
  0%,
  100% {
    opacity: 0;
  }

  14%,
  82% {
    opacity: 1;
  }
}

@media (max-width: 1120px) {
  .arena {
    grid-template-columns: minmax(280px, 0.85fr) minmax(360px, 1.15fr);
  }

  .side-panel {
    grid-column: 1 / -1;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    grid-template-rows: auto;
  }
}

@media (max-width: 760px) {
  :root {
    --tile: clamp(40px, 16vw, 50px);
  }

  .game-shell {
    padding: 12px;
  }

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

  h1 {
    font-size: 2.5rem;
  }

  .run-stats {
    justify-content: start;
  }

  .layer-track {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .layer-track li {
    flex: 0 0 220px;
  }

  .arena,
  .side-panel {
    grid-template-columns: 1fr;
  }

  .console-head {
    flex-direction: column;
  }

  .encounter-action {
    width: 100%;
  }

  .guess-form {
    grid-template-columns: 1fr;
  }

  .assist-controls {
    grid-template-columns: 1fr;
  }

  .guess-form label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .guess-form button {
    width: 100%;
  }

  .keyboard button {
    height: 38px;
    font-size: 0.78rem;
  }

  .run-summary dl {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 2.25rem;
  }
}

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