:root {
  --bg: #070a14;
  --panel: rgba(17, 23, 41, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --text: #e8ecff;
  --muted: #8d96b8;
  --accent: #22d3ee;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
}

/* ---- HUD ---- */

.back {
  position: fixed;
  top: 10px;
  left: 10px;
  color: #fff;
  text-decoration: none;
  font-size: 13px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
}
.back:hover { background: rgba(0, 0, 0, 0.65); }

.hearts {
  position: fixed;
  top: 44px;
  left: 12px;
  display: flex;
  gap: 3px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}
.heart {
  width: 18px;
  height: 18px;
  background: #ef4444;
  clip-path: polygon(50% 100%, 6% 55%, 6% 25%, 22% 8%, 40% 8%, 50% 22%, 60% 8%, 78% 8%, 94% 25%, 94% 55%);
}
.heart.empty { background: rgba(0, 0, 0, 0.55); }

.clock {
  position: fixed;
  top: 10px;
  right: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 13px;
}

.hint {
  position: fixed;
  left: 12px;
  bottom: 84px;
  max-width: min(420px, calc(100vw - 24px));
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.5);
  color: #e5e7eb;
  font-size: 13px;
}
.hint:empty { display: none; }

.toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  pointer-events: none;
}

/* ---- slots ---- */

.hotbar {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 5px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.5);
}

.slot {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  border: 2px solid transparent;
  display: grid;
  place-items: center;
}
.slot.sel { border-color: #fff; background: rgba(255, 255, 255, 0.18); }
.slot.pick { border-color: var(--accent); }
.slot img { width: 34px; height: 34px; image-rendering: pixelated; pointer-events: none; }
.slot .n {
  position: absolute;
  right: 4px;
  bottom: 1px;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 0 1px 2px #000, 0 0 3px #000;
  pointer-events: none;
}
.slot .k {
  position: absolute;
  left: 4px;
  top: 1px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.55);
  pointer-events: none;
}

/* ---- overlays ---- */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(3, 5, 12, 0.6);
}

.card {
  width: min(760px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.card-head, .card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}
.card-head { border-bottom: 1px solid var(--line); }
.card-foot { border-top: 1px solid var(--line); }
.card h2, .card h3, .card h1 { margin: 0; }
.card h3 { font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }

.card-body {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 20px;
  padding: 16px;
  overflow: auto;
}
@media (max-width: 720px) { .card-body { grid-template-columns: 1fr; } }

.inv-grid {
  display: grid;
  grid-template-columns: repeat(9, 48px);
  gap: 4px;
}
@media (max-width: 560px) { .inv-grid { grid-template-columns: repeat(6, 48px); } }

.note { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.recipes {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 46vh;
  overflow: auto;
}
.recipe {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
}
.recipe.locked { opacity: 0.45; }
.recipe img { width: 32px; height: 32px; image-rendering: pixelated; }
.recipe .name { font-weight: 600; }
.recipe .cost { font-size: 12px; color: var(--muted); }
.recipe .cost .miss { color: #f87171; }
.recipe .tag { font-size: 11px; color: var(--accent); }

/* ---- buttons / intro ---- */

.btn {
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.16); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #04222a; border-color: transparent; font-weight: 700; padding: 10px 28px; }
.btn-primary:hover { background: #67e8f9 !important; }
.btn-danger { color: #fca5a5; }

.intro { padding: 28px; text-align: center; align-items: center; }
.intro h1 { font-size: 40px; letter-spacing: 0.04em; }
.intro p { color: var(--muted); max-width: 46ch; }
.controls { display: grid; gap: 4px; margin: 14px 0 20px; text-align: left; min-width: min(360px, 100%); }
.controls div { display: flex; justify-content: space-between; gap: 20px; }
.controls dt { color: var(--text); }
.controls dd { margin: 0; color: var(--muted); }
kbd {
  font: 12px ui-monospace, Menlo, monospace;
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--line);
}

/* ---- first-person overlays ---- */

.crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  mix-blend-mode: difference;
}
.crosshair::before, .crosshair::after {
  content: "";
  position: absolute;
  background: #fff;
}
.crosshair::before { left: 8px; top: 0; width: 2px; height: 18px; }
.crosshair::after { top: 8px; left: 0; height: 2px; width: 18px; }

.flash {
  position: fixed;
  inset: 0;
  background: rgba(220, 38, 38, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease-out;
}
.flash.on { opacity: 1; transition: none; }

.held {
  position: fixed;
  right: 5vw;
  bottom: -12px;
  width: 150px;
  height: 150px;
  pointer-events: none;
  transform-origin: 80% 100%;
  transform: rotate(-12deg);
  filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.45));
}
.held img { width: 100%; height: 100%; image-rendering: pixelated; }
.held.empty { display: none; }
.held.swing { animation: swing 0.38s ease-in-out infinite; }
@keyframes swing {
  0%, 100% { transform: rotate(-12deg); }
  50% { transform: rotate(-52deg) translate(-14px, 8px); }
}
