:root {
  --bg: #07090d;
  --bg-soft: #0b0f16;
  --panel: #0d121b;
  --ink: #d7e2ee;
  --muted: #6a7b8f;
  --dim: #3a4758;
  --line: #1a2431;
  --green: #5ee7a8;
  --green-soft: #2f8f68;
  --amber: #ffc857;
  --red: #ff6b6b;
  --violet: #b58cff;
  --cyan: #6fd6ff;
  --mono: "SFMono-Regular", "JetBrains Mono", "IBM Plex Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1100px 600px at 50% -10%, rgba(43, 122, 91, 0.18), transparent 65%),
    radial-gradient(800px 500px at 100% 100%, rgba(70, 49, 120, 0.14), transparent 60%),
    var(--bg);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at 50% 30%, #000 20%, transparent 75%);
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: clamp(12px, 2vw, 28px) clamp(12px, 2.5vw, 34px) 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100dvh;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }

.sigil {
  color: var(--green);
  font-size: 22px;
  line-height: 1;
  text-shadow: 0 0 18px rgba(94, 231, 168, 0.8);
  animation: pulse 3.2s ease-in-out infinite;
}

.wordmark {
  font-size: clamp(16px, 2.2vw, 22px);
  letter-spacing: 0.34em;
  font-weight: 700;
}

.tag {
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.12em;
  white-space: nowrap;
}

.topstats { display: flex; align-items: center; gap: clamp(10px, 2vw, 24px); }

.stat { display: flex; align-items: baseline; gap: 6px; }
.stat b { color: var(--ink); font-size: 15px; font-variant-numeric: tabular-nums; }
.stat i {
  color: var(--dim);
  font-style: normal;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 7px;
  font-family: var(--mono);
  font-size: 14px;
  cursor: pointer;
  transition: 160ms ease;
}
.icon-btn:hover { color: var(--green); border-color: var(--green-soft); }
.icon-btn.off { color: var(--dim); text-decoration: line-through; }

/* ---------- stage ---------- */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 286px;
  min-width: 0;
  gap: 14px;
  align-items: start;
}

.canvas-wrap {
  position: relative;
  width: min(100%, calc((100dvh - 215px) * 1.6923));
  aspect-ratio: 968 / 572;
  max-height: calc(100dvh - 215px);
  margin-inline: auto;
  border: 1px solid #1b2a37;
  border-radius: 10px;
  overflow: hidden;
  background: #04070a;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.6),
    0 30px 80px -30px rgba(0, 0, 0, 0.9),
    inset 0 0 120px rgba(0, 0, 0, 0.9);
}

canvas { display: block; width: 100%; max-width: 100%; height: 100%; image-rendering: auto; touch-action: none; }

.vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 50%, transparent 38%, rgba(0, 0, 0, 0.62) 100%);
}

.scanlines {
  position: absolute; inset: 0; pointer-events: none; opacity: 0.18;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,0.05) 0 1px, transparent 1px 3px);
  mix-blend-mode: overlay;
}

/* ---------- overlay ---------- */
.overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 45%, rgba(4, 7, 10, 0.78), rgba(4, 7, 10, 0.93));
  backdrop-filter: blur(2px);
  transition: opacity 260ms ease, visibility 260ms ease;
  text-align: center;
}
.overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.overlay-card { max-width: 520px; }

.eyebrow {
  margin: 0 0 10px;
  color: var(--green);
  font-size: 10px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
}

.overlay h1 {
  margin: 0;
  font-size: clamp(30px, 6vw, 58px);
  letter-spacing: 0.16em;
  font-weight: 800;
  line-height: 1.05;
  text-shadow: 0 0 34px rgba(94, 231, 168, 0.28);
}

.overlay h1.dead { color: var(--red); text-shadow: 0 0 34px rgba(255, 107, 107, 0.3); }
.overlay h1.win { color: var(--amber); text-shadow: 0 0 34px rgba(255, 200, 87, 0.35); }

.blurb {
  margin: 14px auto 20px;
  max-width: 62ch;
  color: #9aabbe;
  font-size: 13px;
  line-height: 1.65;
}
.blurb code { color: var(--green); }

.keys {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 18px;
  margin: 0 auto 24px;
  max-width: 480px;
  color: var(--muted);
  font-size: 11.5px;
  text-align: left;
}
.keys span { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

kbd {
  display: inline-block;
  padding: 2px 6px;
  border: 1px solid #263140;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #101722;
  color: #a9b9cb;
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.5;
}

.start-btn {
  appearance: none;
  border: 1px solid var(--green);
  background: linear-gradient(180deg, rgba(94, 231, 168, 0.16), rgba(94, 231, 168, 0.05));
  color: var(--green);
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  padding: 13px 34px;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 0 26px -6px rgba(94, 231, 168, 0.5), inset 0 0 20px rgba(94, 231, 168, 0.08);
  transition: 150ms ease;
}
.start-btn:hover { background: rgba(94, 231, 168, 0.2); box-shadow: 0 0 34px -4px rgba(94, 231, 168, 0.65); }
.start-btn:active { transform: translateY(1px); }

.best { margin: 16px 0 0; color: var(--dim); font-size: 11px; letter-spacing: 0.08em; }

/* ---------- side panel ---------- */
.panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.card {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(16, 23, 33, 0.92), rgba(10, 15, 22, 0.92));
  border-radius: 9px;
  padding: 13px 14px;
}

.card h2 {
  margin: 0 0 10px;
  color: var(--dim);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

.bar-row {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 9px;
  margin-bottom: 9px;
}
.bar-row label { color: var(--dim); font-size: 9.5px; letter-spacing: 0.12em; }
.bar-row b { font-size: 11px; font-variant-numeric: tabular-nums; color: #b9c8d8; }

.bar {
  height: 7px;
  border-radius: 99px;
  background: #060a0f;
  border: 1px solid #1c2734;
  overflow: hidden;
}
.bar span {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 99px;
  transition: width 220ms ease;
}
.bar.hp span { background: linear-gradient(90deg, #b03a3a, var(--red)); box-shadow: 0 0 10px rgba(255, 107, 107, 0.5); }
.bar.xp span { background: linear-gradient(90deg, #2f7d8f, var(--cyan)); box-shadow: 0 0 10px rgba(111, 214, 255, 0.35); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
}
.stats-grid div { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.stats-grid i { color: var(--dim); font-style: normal; font-size: 8.5px; letter-spacing: 0.14em; }
.stats-grid b { font-size: 14px; color: var(--ink); font-variant-numeric: tabular-nums; }

.log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 128px;
  max-height: 184px;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.45;
}
.log li { color: #8fa1b5; animation: slidin 200ms ease both; }
.log li:last-child { color: #c6d4e3; }
.log li.good { color: var(--green); }
.log li.warn { color: var(--amber); }
.log li.bad { color: var(--red); }
.log li.dim { color: var(--dim); }

.legend ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  font-size: 10px;
  color: var(--dim);
}
.legend li { display: flex; align-items: center; gap: 7px; }
.g { font-size: 13px; width: 12px; text-align: center; }
.g.player { color: #fff; text-shadow: 0 0 8px rgba(255,255,255,0.6); }
.g.gold { color: var(--amber); }
.g.potion { color: var(--violet); }
.g.blade { color: var(--cyan); }
.g.stairs { color: var(--green); }
.g.enemy { color: var(--red); }

.hint p { margin: 0; color: var(--dim); font-size: 10.5px; line-height: 1.6; }

/* ---------- touch ---------- */
.touch { display: none; }

/* ---------- animation ---------- */
@keyframes pulse { 0%, 100% { opacity: 0.65; } 50% { opacity: 1; } }
@keyframes slidin { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* ---------- responsive ---------- */
@media (min-width: 981px) {
  .app { justify-content: center; }
}

@media (max-width: 980px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
  .canvas-wrap { max-height: none; max-width: 100%; }
  .panel { display: grid; grid-template-columns: 1fr 1fr; }
  .vitals { grid-column: 1; }
  .log-card { grid-column: 2; grid-row: 1 / span 2; }
  .legend, .hint { display: none; }
}

@media (max-width: 640px) {
  .app { padding: 10px 10px 18px; gap: 10px; }
  .topbar { gap: 8px; }
  .brand { gap: 7px; }
  .tag { display: none; }
  .topstats { gap: 10px; }
  .stat { flex-direction: column; align-items: flex-end; gap: 0; }
  .stat b { font-size: 13px; }
  .stat i { font-size: 8px; }
  .icon-btn { width: 28px; height: 28px; }
  .panel { grid-template-columns: 1fr; }
  .log-card { grid-column: 1; grid-row: auto; }
  .log { min-height: 76px; max-height: 108px; }
  .keys { grid-template-columns: 1fr; text-align: center; justify-items: center; }
  .overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    padding: 22px 18px;
    overflow-y: auto;
    background: radial-gradient(ellipse at 50% 40%, rgba(5, 9, 13, 0.97), #04070a 70%);
  }
  .overlay h1 { font-size: clamp(22px, 8vw, 40px); letter-spacing: 0.1em; }
  .blurb { font-size: 11.5px; margin-bottom: 14px; }
  .start-btn { padding: 11px 26px; }
  .touch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 6px 4px;
    user-select: none;
    -webkit-user-select: none;
  }
  .dpad {
    display: grid;
    grid-template-columns: repeat(3, 46px);
    grid-template-rows: repeat(3, 42px);
    gap: 4px;
  }
  .dpad button, .touch-actions button {
    appearance: none;
    border: 1px solid #253140;
    background: #0e1520;
    color: #9fb1c5;
    border-radius: 7px;
    font-family: var(--mono);
    font-size: 16px;
    padding: 0;
    touch-action: manipulation;
  }
  .dpad button:active, .touch-actions button:active { background: #182333; color: var(--green); }
  .touch-actions { display: flex; flex-direction: column; gap: 8px; }
  .touch-actions button {
    font-size: 10px;
    letter-spacing: 0.08em;
    padding: 12px 12px;
    min-width: 96px;
    text-transform: uppercase;
  }
}

@media (min-width: 641px) {
  .touch { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
