@font-face {
  font-family: "DungGeunMo";
  src: url("font-src/DungGeunMo.woff2") format("woff2"),
       url("font-src/DungGeunMo.woff") format("woff");
  font-display: swap;
}

:root {
  --navy: #071426;
  --midnight: #102542;
  --panel: #1d2f4a;
  --steel: #7f8b99;
  --dark-steel: #465160;
  --ink: #eef6ff;
  --muted: #9fb2c5;
  --yellow: #ffd34d;
  --red: #e94141;
  --blue: #4aa7ff;
  --green: #55d66b;
  --purple: #a76bff;
  --white: #f4f4ee;
  --black: #05080f;
  --pixel-shadow: 0 0 0 3px var(--black), 6px 6px 0 0 rgba(0,0,0,.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    var(--navy);
  background-size: 16px 16px;
  color: var(--ink);
  font-family: "DungGeunMo", "Courier New", monospace;
  image-rendering: pixelated;
}

button,
input {
  font: inherit;
}

.game-shell {
  width: 100vw;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 31vw, 460px);
  gap: 14px;
  padding: 14px;
}

.playfield {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
}

.pixel-panel {
  border: 4px solid var(--black);
  box-shadow: var(--pixel-shadow);
  background: var(--midnight);
}

.hud,
.mission-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
}

.hud {
  min-height: 76px;
}

.hud > div,
.mission-bar > div:first-child {
  min-width: 0;
}

.hud-label {
  display: block;
  color: var(--muted);
  font-size: clamp(10px, 1vw, 13px);
  margin-bottom: 4px;
}

.hud strong,
.mission-bar strong {
  color: var(--white);
  font-size: clamp(14px, 1.6vw, 22px);
  letter-spacing: 0;
}

.timer-block strong,
.digital-timer {
  color: var(--red);
  text-shadow: 3px 0 0 #530909;
}

.bomb {
  position: relative;
  min-height: 0;
  width: min(100%, 980px);
  justify-self: center;
  padding: clamp(12px, 2vw, 22px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 12px;
  background:
    linear-gradient(90deg, transparent 0 18px, rgba(0,0,0,.14) 18px 22px, transparent 22px 44px),
    #596676;
}

.bomb::before,
.bomb::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  background: var(--dark-steel);
  border: 3px solid var(--black);
  top: 12px;
}

.bomb::before {
  left: 12px;
}

.bomb::after {
  right: 12px;
}

.bomb-top,
.warning-strip,
.circuit-board {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bomb-top {
  justify-content: space-between;
}

.battery-pack {
  display: flex;
  gap: 5px;
  padding: 8px;
  background: #242c34;
  border: 3px solid var(--black);
}

.battery-pack span {
  display: block;
  width: 18px;
  height: 34px;
  background: linear-gradient(#f2d65a 0 18%, #34302a 18% 28%, #71c565 28%);
  border: 2px solid var(--black);
}

.digital-timer {
  min-width: 108px;
  padding: 8px 14px;
  text-align: center;
  font-size: clamp(28px, 5vw, 56px);
  background: #12090b;
  border: 4px solid var(--black);
}

.status-led {
  width: 34px;
  height: 34px;
  border: 4px solid var(--black);
  background: var(--red);
  animation: ledBlink 1s steps(2, end) infinite;
}

.warning-strip {
  justify-content: space-between;
  padding: 8px 10px;
  background: #1c2430;
  border: 3px solid var(--black);
  color: var(--yellow);
  font-size: clamp(11px, 1.25vw, 16px);
}

.module-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
}

.module {
  position: relative;
  min-height: 144px;
  padding: 10px;
  background: #26384e;
  border: 4px solid var(--black);
  box-shadow: inset -5px -5px 0 rgba(0,0,0,.18), inset 5px 5px 0 rgba(255,255,255,.06);
}

.module.active {
  outline: 4px solid var(--yellow);
}

.module.solved {
  background: #224632;
}

.module h3 {
  margin: 0 0 8px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--yellow);
  font-size: clamp(13px, 1.4vw, 18px);
}

.module-light {
  width: 14px;
  height: 14px;
  display: inline-block;
  background: var(--red);
  border: 2px solid var(--black);
}

.solved .module-light {
  background: var(--green);
}

.wires {
  display: grid;
  gap: 7px;
}

.wire {
  height: 16px;
  border: 3px solid var(--black);
  cursor: pointer;
  position: relative;
}

.wire.cut {
  opacity: .35;
}

.wire.cut::after {
  content: "절단";
  position: absolute;
  left: 50%;
  top: -6px;
  transform: translateX(-50%);
  color: var(--white);
  background: var(--black);
  padding: 1px 4px;
}

.red { background: var(--red); }
.blue { background: var(--blue); }
.yellow { background: var(--yellow); color: var(--black); }
.green { background: var(--green); color: var(--black); }
.purple { background: var(--purple); }
.white { background: var(--white); color: var(--black); }

.button-pad {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.bomb-button,
.key,
.symbol-key,
.stop-button,
.pixel-button {
  border: 3px solid var(--black);
  color: var(--white);
  background: var(--panel);
  box-shadow: inset -4px -4px 0 rgba(0,0,0,.25), inset 4px 4px 0 rgba(255,255,255,.08);
  cursor: pointer;
  image-rendering: pixelated;
}

.bomb-button {
  min-height: 48px;
  display: grid;
  place-items: center;
  gap: 2px;
}

.button-ko {
  display: block;
  font-size: 17px;
}

.button-en {
  display: block;
  font-size: 10px;
  opacity: .82;
}

.bomb-button:active,
.bomb-button.holding,
.key:active,
.symbol-key:active,
.stop-button:active,
.pixel-button:active {
  transform: translate(3px, 3px);
  box-shadow: inset 3px 3px 0 rgba(0,0,0,.35);
}

.keypad-display {
  min-height: 28px;
  margin-bottom: 8px;
  padding: 5px;
  color: var(--green);
  background: #07100b;
  border: 3px solid var(--black);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.key {
  min-height: 34px;
}

.symbol-pad {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.symbol-key {
  min-height: 44px;
  font-size: 22px;
}

.meter-track {
  position: relative;
  height: 42px;
  margin: 16px 0 12px;
  background: #101722;
  border: 3px solid var(--black);
}

.safe-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--green);
}

.safe-zone.yellow-zone {
  background: var(--yellow);
}

.meter-needle {
  position: absolute;
  top: -8px;
  width: 8px;
  height: 54px;
  background: var(--red);
  border: 2px solid var(--black);
}

.stop-button {
  width: 100%;
  min-height: 38px;
}

.circuit-board {
  min-height: 34px;
  padding: 7px;
  background: #173b34;
  border: 3px solid var(--black);
}

.circuit-board i {
  height: 6px;
  flex: 1;
  background: var(--green);
  border: 1px solid #08231d;
}

.effect-layer {
  pointer-events: none;
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.spark,
.confetti,
.boom-cell {
  position: absolute;
  width: 10px;
  height: 10px;
}

.spark {
  background: var(--yellow);
  animation: pop .38s steps(3, end) forwards;
}

.confetti {
  background: var(--green);
  animation: fall .9s steps(6, end) forwards;
}

.boom-cell {
  background: var(--red);
  animation: boom .8s steps(5, end) forwards;
}

.mission-bar {
  min-height: 80px;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.pixel-button {
  min-height: 36px;
  padding: 6px 10px;
}

.pixel-button.danger {
  background: #672532;
}

.icon-button {
  min-width: 38px;
}

.hidden {
  display: none !important;
}

.manual {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  padding: 12px;
  background: #e7dfbd;
  color: #18202b;
}

.manual-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 4px solid #18202b;
  padding-bottom: 10px;
}

.manual-header p,
.manual-header h1 {
  margin: 0;
}

.manual-header p {
  color: #536071;
  font-size: 12px;
}

.manual-header h1 {
  font-size: clamp(22px, 2.6vw, 34px);
}

.stamp {
  color: var(--red);
  border: 4px solid var(--red);
  padding: 6px;
  transform: rotate(4deg);
}

.manual-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 12px 0;
}

.manual-tab {
  min-height: 34px;
  border: 3px solid #18202b;
  background: #c9c09d;
  color: #18202b;
  cursor: pointer;
}

.manual-tab.active {
  background: var(--yellow);
}

.manual-tab.locked {
  opacity: .45;
}

.manual-page {
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.manual-page h2 {
  margin: 0 0 12px;
  font-size: 22px;
}

.manual-section {
  border-top: 3px solid #18202b;
  padding: 10px 0;
}

.manual-section h3 {
  margin: 0 0 7px;
  color: #334666;
}

.manual-section ul {
  margin: 0;
  padding-left: 18px;
}

.manual-section li {
  margin-bottom: 8px;
}

.manual-section p {
  margin: 0;
  line-height: 1.35;
}

.manual-section dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 10px;
  margin: 0;
}

.manual-section dt {
  color: #536071;
}

.manual-section dd {
  margin: 0;
}

.debug-panel pre {
  white-space: pre-wrap;
  margin: 0;
  max-height: 220px;
  overflow: auto;
  font-size: 12px;
}

.shake {
  animation: shake .28s steps(2, end);
}

.red-alert {
  animation: redAlert .28s steps(2, end);
}

@keyframes ledBlink {
  50% { filter: brightness(.45); }
}

@keyframes pop {
  to { transform: translateY(-30px) scale(0); opacity: 0; }
}

@keyframes fall {
  to { transform: translateY(100px); opacity: 0; }
}

@keyframes boom {
  to { transform: scale(4); opacity: 0; }
}

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

@keyframes redAlert {
  50% { box-shadow: var(--pixel-shadow), inset 0 0 0 999px rgba(233,65,65,.28); }
}

@media (max-width: 900px) {
  .game-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 58fr) minmax(210px, 42fr);
    gap: 10px;
    padding: 10px;
  }

  .hud,
  .mission-bar {
    min-height: 0;
    padding: 8px;
  }

  .hud {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
  }

  .bomb {
    width: 100%;
    padding: 10px;
  }

  .module-grid {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
    gap: 8px;
  }

  .module {
    min-height: 120px;
    padding: 8px;
  }

  .manual {
    padding: 10px;
  }

  .manual-tabs {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media (max-width: 620px) {
  body {
    overflow: auto;
  }

  .game-shell {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .hud {
    grid-template-columns: repeat(2, 1fr);
  }

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

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

  .control-row {
    justify-content: flex-start;
  }

  .manual-tabs {
    grid-template-columns: repeat(3, 1fr);
  }
}
