@font-face {
  font-family: "DungGeunMo";
  src:
    url("../assets/fonts/DungGeunMo.woff2") format("woff2"),
    url("../assets/fonts/DungGeunMo.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --navy: #07101f;
  --midnight: #101b32;
  --panel: #17233a;
  --panel-dark: #0c1426;
  --line: #5f6c82;
  --white: #f7f3d7;
  --muted: #abb4c4;
  --yellow: #ffd34f;
  --red: #e84b45;
  --blue: #3d8cff;
  --green: #38d86f;
  --purple: #a66cff;
  --cyan: #40e0d0;
  --orange: #ff9f43;
  --shadow: #02050b;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 24px),
    repeating-linear-gradient(0deg, transparent 0 10px, rgba(255, 255, 255, 0.025) 10px 11px),
    var(--navy);
  color: var(--white);
  font-family: "DungGeunMo", "Courier New", monospace;
  letter-spacing: 0;
}

button,
a {
  font: inherit;
}

canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.game-shell {
  min-height: 100vh;
  padding: 22px;
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
  background:
    radial-gradient(circle at 20% 18%, rgba(61, 140, 255, 0.16), transparent 25%),
    linear-gradient(135deg, rgba(16, 27, 50, 0.92), rgba(7, 16, 31, 0.98));
}

.game-shell::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 16px 16px;
  opacity: 0.35;
}

.mission-header,
.mission-grid,
.reward-card,
.opening-panel {
  position: relative;
  z-index: 1;
}

.mission-header {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 16px;
  padding: 14px;
  border: 4px solid var(--line);
  background: var(--panel-dark);
  box-shadow: 0 8px 0 var(--shadow);
}

.eyebrow,
.timer-label {
  margin: 0 0 5px;
  color: var(--yellow);
  font-size: 13px;
  text-transform: uppercase;
}

.mission-header h2 {
  margin: 0;
  font-size: clamp(22px, 3vw, 40px);
  line-height: 1;
}

.stage-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.stage-meta span {
  padding: 6px 8px;
  border: 3px solid #334058;
  background: #10182a;
  color: var(--muted);
  font-size: 13px;
}

.stage-meta span.is-urgent {
  color: var(--yellow);
  border-color: var(--yellow);
}

.timer-card {
  min-width: 154px;
  padding: 10px 14px;
  text-align: center;
  border: 4px solid #334058;
  background: #070b12;
}

.timer-card strong {
  display: block;
  color: var(--red);
  font-size: clamp(38px, 6vw, 68px);
  line-height: 0.9;
  text-shadow: 4px 0 #5a1217;
}

.timer-card.is-danger strong {
  color: var(--yellow);
  text-shadow: 4px 0 #7a130d;
}

.timer-card.is-critical strong {
  color: var(--white);
  background: var(--red);
  text-shadow: none;
}

.mission-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(420px, 1.6fr) minmax(240px, 0.9fr);
  gap: 18px;
  align-items: stretch;
}

.mission-log,
.status-panel {
  min-height: 0;
  padding: 16px;
  border: 4px solid var(--line);
  background: rgba(12, 20, 38, 0.95);
  box-shadow: 0 8px 0 var(--shadow);
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 9px;
  border-bottom: 3px solid #324056;
  padding-bottom: 12px;
}

.panel-title span {
  width: 12px;
  height: 12px;
  background: var(--red);
  box-shadow: 16px 0 var(--yellow), 32px 0 var(--green);
}

.panel-title h3 {
  margin: 0;
  font-size: 18px;
}

.mission-log ol {
  margin: 18px 0;
  padding-left: 32px;
  font-size: clamp(16px, 1.25vw, 21px);
  line-height: 1.48;
  max-height: min(48vh, 390px);
  overflow: auto;
}

.mission-log li.is-done {
  color: var(--green);
  text-decoration: line-through;
}

.mission-log li.is-current {
  color: var(--yellow);
}

.objective,
.status-message {
  min-height: 56px;
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.bomb-stage {
  min-height: min(68vh, 720px);
  display: grid;
  place-items: center;
}

.stage-backdrop {
  width: min(100%, 820px);
  aspect-ratio: 320 / 224;
  position: relative;
  border: 4px solid #5c6880;
  background: #0a1223;
  box-shadow: 0 10px 0 var(--shadow), inset 0 0 0 4px #121c31;
}

#bombCanvas,
#fxCanvas,
.wire-hotspots {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#fxCanvas,
.wire-hotspots {
  pointer-events: none;
}

.wire-hotspots button {
  position: absolute;
  border: 0;
  background: transparent;
  cursor: crosshair;
  pointer-events: auto;
}

.wire-hotspots button:hover,
.wire-hotspots button:focus-visible {
  outline: 4px solid rgba(255, 255, 255, 0.65);
  outline-offset: -4px;
}

.wire-hotspots button.is-cut {
  pointer-events: none;
}

.progress-track {
  height: 26px;
  margin: 18px 0;
  padding: 4px;
  border: 3px solid #4a5870;
  background: #050910;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--green);
  transition: width 160ms steps(4);
}

.wire-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 16px 0;
}

.wire-chip {
  min-height: 34px;
  padding: 7px 6px;
  border: 3px solid #3f4c64;
  background: #10182a;
  color: var(--white);
  text-align: center;
  font-size: 14px;
}

.wire-chip.is-cut {
  color: #07101f;
  background: var(--green);
}

.pixel-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 46px;
  padding: 10px 16px;
  border: 0;
  color: #07101f;
  background: var(--yellow);
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 5px 0 #8f6a11, inset 0 0 0 4px rgba(255, 255, 255, 0.22);
}

.pixel-button:hover,
.pixel-button:focus-visible {
  transform: translateY(1px);
  box-shadow: 0 4px 0 #8f6a11, inset 0 0 0 4px rgba(255, 255, 255, 0.32);
}

.restart-button {
  width: 100%;
  margin-top: 4px;
}

.opening-screen,
.reward-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(4, 8, 16, 0.92);
}

.opening-panel,
.reward-card {
  width: min(620px, 100%);
  border: 4px solid var(--line);
  background: #0d1729;
  padding: clamp(22px, 5vw, 44px);
  box-shadow: 0 10px 0 #000;
  text-align: center;
}

.opening-panel h1,
.reward-card h2 {
  margin: 0 0 16px;
  font-size: clamp(34px, 7vw, 72px);
  line-height: 0.95;
}

.opening-panel p {
  margin: 10px 0;
  color: var(--muted);
  line-height: 1.45;
}

.start-button {
  min-width: 210px;
  margin-top: 18px;
}

.reward-card canvas {
  width: 100%;
  max-width: 560px;
  margin: 18px auto;
  border: 4px solid #53627d;
  background: #09111f;
}

.result-stats {
  display: grid;
  gap: 6px;
  width: min(360px, 100%);
  margin: 0 auto 12px;
  padding: 12px;
  border: 4px solid var(--green);
  background: #07101f;
}

.result-stats strong {
  color: var(--green);
  font-size: clamp(22px, 4vw, 38px);
  line-height: 1;
}

.result-stats span {
  color: var(--muted);
  font-size: 15px;
}

.reward-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

[hidden] {
  display: none !important;
}

.game-shell[data-outcome="fail"] {
  animation: shake 260ms steps(4) 2;
}

.game-shell[data-outcome="fail"]::after,
.game-shell[data-outcome="success"]::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  opacity: 0;
}

.game-shell[data-outcome="fail"]::after {
  background: rgba(232, 75, 69, 0.34);
  animation: flash 420ms steps(2);
}

.game-shell[data-outcome="success"]::after {
  background: rgba(56, 216, 111, 0.24);
  animation: flash 520ms steps(2);
}

@keyframes shake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(8px, -4px);
  }
  50% {
    transform: translate(-7px, 5px);
  }
  75% {
    transform: translate(4px, 7px);
  }
}

@keyframes flash {
  0%,
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@media (max-width: 980px) {
  .game-shell {
    padding: 14px;
  }

  .mission-grid {
    grid-template-columns: 1fr;
  }

  .bomb-stage {
    min-height: auto;
  }

  .mission-header {
    flex-direction: column;
  }

  .timer-card {
    width: 100%;
  }
}

@media (max-width: 540px) {
  .mission-log,
  .status-panel,
  .mission-header {
    border-width: 3px;
  }

  .wire-list {
    grid-template-columns: 1fr;
  }
}
