:root {
  color-scheme: dark;
  font-family: "Courier New", Courier, monospace;
  background: #080a0c;
  color: #f3f5f7;
  --panel: rgba(13, 16, 20, 0.96);
  --line: rgba(255, 255, 255, 0.18);
  --accent: #e9f2ff;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #080a0c;
}

button, kbd { font: inherit; }
button { color: inherit; }

#game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  background: #06080a;
  overflow: hidden;
  user-select: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#game-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(255,255,255,0.018) 0,
      rgba(255,255,255,0.018) 1px,
      transparent 1px,
      transparent 4px
    ),
    radial-gradient(circle at center, transparent 45%, rgba(0,0,0,0.42) 100%);
  mix-blend-mode: screen, normal;
}

.hud {
  position: absolute;
  z-index: 4;
  top: 18px;
  left: 18px;
  right: 18px;
  padding: 10px 13px;
  border: 1px solid rgba(255,255,255,0.24);
  background: rgba(0,0,0,0.54);
  backdrop-filter: blur(6px);
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}

.hud__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.hud__progress {
  margin-top: 7px;
  justify-content: flex-start;
  flex-wrap: wrap;
  color: rgba(255,255,255,0.78);
  font-size: 0.76rem;
}

.hud__progress span { margin-right: 14px; }
.hud__progress span.completed { color: #fff; }

.hud__exit {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid rgba(126, 255, 161, 0.38);
  color: #a9ffbd;
}

.hud__exit[hidden] { display: none !important; }

.hud__exit-arrow {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 1px solid rgba(126, 255, 161, 0.58);
  background: rgba(75, 181, 105, 0.14);
  font-size: 1.4rem;
  line-height: 1;
}

.hud__exit-copy {
  display: grid;
  gap: 2px;
}

.hud__exit-copy b {
  font-size: 0.79rem;
  letter-spacing: 0.08em;
}

.hud__exit-copy small {
  color: rgba(215, 255, 225, 0.72);
  font-size: 0.67rem;
  letter-spacing: 0.04em;
}

.hud__exit--pulse {
  animation: exit-guide-pulse 0.72s steps(2, end) 4;
}

@keyframes exit-guide-pulse {
  50% {
    color: #fff;
    border-top-color: #fff;
    filter: brightness(1.6);
  }
}

.interaction-prompt {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 76px;
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid rgba(255,255,255,0.38);
  background: rgba(0,0,0,0.74);
  white-space: nowrap;
  font-size: 0.82rem;
  letter-spacing: 0.05em;
}

.crosshair {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  transform: translate(-50%, -50%);
  opacity: 0.55;
  pointer-events: none;
}
.crosshair::before,
.crosshair::after {
  content: "";
  position: absolute;
  background: #fff;
}
.crosshair::before { left: 4px; top: 0; width: 2px; height: 10px; }
.crosshair::after { left: 0; top: 4px; width: 10px; height: 2px; }

.overlay {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0,0,0,0.78);
  backdrop-filter: blur(8px);
}

.overlay--visible { display: flex; }

.panel {
  width: min(540px, 100%);
  padding: 27px;
  border: 1px solid rgba(255,255,255,0.24);
  background: var(--panel);
  box-shadow: 0 22px 80px rgba(0,0,0,0.55);
}

.panel--wide { width: min(680px, 100%); }

.eyebrow {
  margin: 0 0 7px;
  color: rgba(255,255,255,0.58);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
}

h1, h2 {
  margin: 0 0 16px;
  line-height: 1;
  letter-spacing: 0.04em;
}
h1 { font-size: clamp(1.85rem, 4vw, 3.2rem); }
h2 { font-size: clamp(1.45rem, 3vw, 2.2rem); }

p { line-height: 1.55; }

.controls-help {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin: 22px 0;
  padding: 15px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.035);
  font-size: 0.85rem;
}

kbd {
  display: inline-block;
  min-width: 28px;
  margin: 0 2px;
  padding: 3px 6px;
  border: 1px solid rgba(255,255,255,0.3);
  border-bottom-width: 3px;
  border-radius: 3px;
  background: rgba(255,255,255,0.08);
  text-align: center;
  font-size: 0.78rem;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid rgba(255,255,255,0.32);
  cursor: pointer;
  letter-spacing: 0.04em;
}

.primary-button {
  background: #f4f6f8;
  color: #090b0e;
  font-weight: 700;
}
.primary-button:hover { background: #fff; }

.secondary-button { background: transparent; }
.secondary-button:hover { background: rgba(255,255,255,0.08); }

.small-note {
  margin: 14px 0 0;
  color: rgba(255,255,255,0.5);
  font-size: 0.76rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.password-list {
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}
.password-list li {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.password-list code {
  overflow-wrap: anywhere;
  color: #fff;
}

.debug-panel {
  position: absolute;
  z-index: 12;
  right: 18px;
  bottom: 18px;
  width: 230px;
  padding: 8px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(0,0,0,0.78);
}
.debug-panel canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}
.debug-panel p {
  margin: 7px 2px 1px;
  color: rgba(255,255,255,0.6);
  font-size: 0.62rem;
}

.touch-controls {
  display: none;
  position: absolute;
  z-index: 8;
  right: 18px;
  bottom: 18px;
  grid-template-columns: 54px;
  gap: 4px;
  justify-items: center;
}
.touch-controls div { display: flex; gap: 4px; }
.touch-controls button {
  width: 54px;
  height: 48px;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.62);
  touch-action: none;
}

@media (pointer: coarse), (max-width: 760px) {
  .touch-controls { display: grid; }
  .interaction-prompt { bottom: 134px; }
  .hud { top: 10px; left: 10px; right: 10px; }
  .hud__progress b { display: none; }
  .panel { padding: 21px; }
  .debug-panel { display: none !important; }
}

/* Minigiochi */
.minigame-overlay {
  z-index: 30;
  padding: 16px;
  background: rgba(0,0,0,.9);
  backdrop-filter: blur(5px);
}

.panel--minigame {
  width: min(940px, 100%);
  padding: 18px;
}

.minigame-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

.minigame-header h2,
.minigame-header p { margin: 0; }

.minigame-symbol {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 1px solid rgba(255,255,255,.28);
  background: rgba(255,255,255,.04);
  font-size: 2.2rem;
}

.minigame-exit {
  min-height: 38px;
  padding: 7px 12px;
}

#minigame-canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid rgba(255,255,255,.26);
  background: #071017;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.minigame-controls {
  display: none;
  grid-template-columns: repeat(5, 54px);
  justify-content: center;
  gap: 5px;
  margin-top: 12px;
}

.minigame-controls button {
  height: 46px;
  border: 1px solid rgba(255,255,255,.32);
  background: rgba(255,255,255,.035);
  color: #fff;
  touch-action: none;
}

@media (pointer: coarse), (max-width: 760px) {
  .minigame-overlay { padding: 7px; }
  .panel--minigame { padding: 10px; }
  .minigame-header { grid-template-columns: auto 1fr; gap: 10px; }
  .minigame-header h2 { font-size: 1.15rem; }
  .minigame-exit { grid-column: 1 / -1; width: 100%; }
  .minigame-symbol { width: 44px; height: 44px; font-size: 1.6rem; }
  .minigame-controls { display: grid; }
}
