:root {
  --ink: #050507;
  --amber: #ffb84d;
  --blood: #b00020;
  --ghost: #c58cff;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #000; color: #e8e2d0;
  font-family: 'JetBrains Mono', monospace;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
#game-wrap { position: fixed; inset: 0; }
canvas { display: block; position: absolute; inset: 0; }

.hidden { display: none !important; }

/* ---------- OVERLAYS ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(10,5,15,0.92), rgba(0,0,0,0.98));
}

/* ---------- TITLE ---------- */
#title-screen { flex-direction: column; }
.title-inner { text-align: center; animation: fadeUp 1.4s ease; }
h1 {
  font-family: 'Cinzel', serif; font-weight: 900;
  font-size: clamp(2.4rem, 9vw, 6rem); letter-spacing: 0.14em;
  color: #ece4d0; text-shadow: 0 0 30px rgba(255,184,77,0.25), 0 0 4px #000;
  animation: flicker 5s infinite;
}
.subtitle {
  font-family: 'Cinzel', serif; font-weight: 400;
  letter-spacing: 0.5em; text-transform: uppercase;
  color: var(--ghost); font-size: clamp(0.7rem, 2.5vw, 1.1rem); margin-top: 0.4rem;
  opacity: 0.7;
}
.flavor { margin: 1.6rem 0 2rem; color: #8a8478; font-size: 0.85rem; letter-spacing: 0.05em; }
.title-inner button, .end-inner button {
  display: block; margin: 0.6rem auto; min-width: 240px;
  background: transparent; border: 1px solid #4a3f30;
  color: #ece4d0; font-family: 'Cinzel', serif; font-weight: 700;
  letter-spacing: 0.2em; padding: 0.8rem 1.4rem; cursor: pointer;
  transition: all 0.2s; font-size: 0.85rem;
}
.title-inner button:hover, .end-inner button:hover {
  border-color: var(--amber); color: var(--amber);
  box-shadow: 0 0 24px rgba(255,184,77,0.3); background: rgba(255,184,77,0.05);
}
.title-inner button:disabled { opacity: 0.4; cursor: default; }

#board-list { margin-top: 1.4rem; max-width: 340px; width: 90vw; }
.board-row {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: 0.4rem 0.6rem; border-bottom: 1px solid #2a2420;
  font-size: 0.78rem; color: #b8b0a0;
}

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
#hud-top-left { position: absolute; top: 14px; left: 14px; }
#zone-name {
  font-family: 'Cinzel', serif; font-weight: 700; letter-spacing: 0.1em;
  color: #d8cfbc; text-shadow: 0 0 8px #000; font-size: 0.9rem; margin-bottom: 6px;
}
#light-bar-wrap { display: flex; align-items: center; gap: 8px; }
#light-label { font-size: 0.6rem; letter-spacing: 0.15em; color: var(--amber); }
#light-bar { width: 120px; height: 6px; background: rgba(255,255,255,0.08); border: 1px solid #3a3228; }
#light-fill { height: 100%; background: linear-gradient(90deg, #ff8a3d, #ffdd88); width: 20%; transition: width 0.3s; }

#hud-top-right { position: absolute; top: 14px; right: 14px; text-align: right; }
#trinket-progress { display: flex; flex-wrap: wrap; gap: 5px; justify-content: flex-end; max-width: 200px; }
.tier-pip {
  font-size: 0.58rem; letter-spacing: 0.05em; padding: 3px 6px;
  border: 1px solid #3a3228; color: #9a9080; background: rgba(0,0,0,0.4);
}
.tier-pip.full { border-color: var(--amber); color: var(--amber); box-shadow: 0 0 10px rgba(255,184,77,0.3); }

#noise-wrap { position: absolute; top: 90px; left: 14px; display: flex; align-items: center; gap: 8px; }
#noise-wrap span { font-size: 0.6rem; letter-spacing: 0.15em; color: #ff6a6a; }
#noise-bar { width: 130px; height: 8px; background: rgba(255,255,255,0.06); border: 1px solid #4a2828; }
#noise-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #4dff9e, #ffdd44 55%, #ff3030); transition: width 0.1s; }

#hud-bottom-left { position: absolute; bottom: 14px; left: 14px; }
#material-inv { display: flex; flex-wrap: wrap; gap: 6px; max-width: 60vw; }
.mat-chip {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid #444; padding: 3px 8px; font-size: 0.72rem;
  background: rgba(0,0,0,0.5); color: #ddd6c8;
}
.mat-chip i { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 6px currentColor; }
.mat-chip.empty { color: #665e50; border-color: #2a2420; }

#prompt-line {
  position: absolute; bottom: 60px; left: 50%; transform: translateX(-50%);
  text-align: center; font-size: 0.8rem; color: #ece4d0;
  text-shadow: 0 0 8px #000; opacity: 0; transition: opacity 0.3s;
  max-width: 90vw; letter-spacing: 0.04em;
}

#pause-hint {
  position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%);
  font-size: 0.58rem; color: #4a4438; z-index: 5; white-space: nowrap;
  pointer-events: none;
}

/* ---------- CRAFT PANEL ---------- */
#craft-panel { background: rgba(2,2,5,0.96); animation: fadeUp 0.25s ease; }
.panel-inner {
  width: min(720px, 94vw); max-height: 88vh; overflow-y: auto;
  border: 1px solid #4a3f30; background: rgba(12,10,16,0.9);
  padding: 1.4rem; box-shadow: 0 0 40px rgba(0,0,0,0.8);
}
.panel-inner h2 {
  font-family: 'Cinzel', serif; letter-spacing: 0.15em; color: var(--amber);
  margin-bottom: 1rem; font-size: 1.1rem;
}
#tier-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 1rem; }
.tier-tab {
  background: transparent; border: 1px solid #3a3228; color: #9a9080;
  padding: 6px 12px; font-family: 'JetBrains Mono'; font-size: 0.7rem;
  letter-spacing: 0.1em; cursor: pointer; transition: all 0.15s;
}
.tier-tab.active, .tier-tab:hover { border-color: var(--amber); color: var(--amber); }
#recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.recipe {
  border: 1px solid #2e2820; background: rgba(0,0,0,0.4); padding: 10px;
  display: flex; flex-direction: column; gap: 6px;
}
.recipe.ready { border-color: #5a7a3a; }
.recipe.owned { border-color: var(--amber); background: rgba(255,184,77,0.06); }
.r-name { font-family: 'Cinzel', serif; font-weight: 700; font-size: 0.85rem; color: #ece4d0; }
.r-desc { font-size: 0.68rem; color: #b0a894; line-height: 1.3; flex: 1; }
.r-cost { font-size: 0.62rem; color: #7a7264; }
.r-craft {
  margin-top: 4px; background: transparent; border: 1px solid #4a3f30;
  color: #ddd6c8; padding: 6px; font-family: 'JetBrains Mono'; font-size: 0.66rem;
  letter-spacing: 0.1em; cursor: pointer; transition: all 0.15s;
}
.r-craft:hover:not(:disabled) { border-color: var(--amber); color: var(--amber); background: rgba(255,184,77,0.08); }
.r-craft:disabled { opacity: 0.5; cursor: default; color: var(--amber); border-color: var(--amber); }
#craft-close {
  margin-top: 1.2rem; width: 100%; background: transparent; border: 1px solid #4a3f30;
  color: #ece4d0; padding: 0.7rem; font-family: 'Cinzel', serif; letter-spacing: 0.15em;
  cursor: pointer;
}
#craft-close:hover { border-color: var(--blood); color: #ff6a6a; }

/* ---------- JUMPSCARE ---------- */
#jumpscare { z-index: 40; background: #000; }
.scare-anim { animation: scareShake 0.7s ease; }
@keyframes scareShake {
  0% { opacity: 0; transform: scale(1.4); }
  15% { opacity: 1; transform: scale(1); }
  20%,40%,60% { transform: scale(1.05) translate(6px, -6px); }
  30%,50%,70% { transform: scale(1.05) translate(-6px, 6px); }
  100% { opacity: 1; transform: scale(1); }
}

/* ---------- END SCREENS ---------- */
.end-inner { text-align: center; }
.death-title {
  font-family: 'Cinzel', serif; font-weight: 900; color: var(--blood);
  font-size: clamp(1.6rem, 6vw, 3rem); letter-spacing: 0.1em;
  text-shadow: 0 0 30px rgba(176,0,32,0.5); margin-bottom: 1rem;
}
.win-title {
  font-family: 'Cinzel', serif; font-weight: 900; color: #ffe08a;
  font-size: clamp(1.6rem, 6vw, 3rem); letter-spacing: 0.1em;
  text-shadow: 0 0 40px rgba(255,224,138,0.6); margin-bottom: 1rem;
}
.end-inner p { color: #b0a894; margin-bottom: 1.4rem; font-size: 0.85rem; }
#win-name {
  display: block; margin: 0 auto 1rem; width: 260px; max-width: 80vw;
  background: rgba(0,0,0,0.5); border: 1px solid #4a3f30; color: #ece4d0;
  padding: 0.7rem; font-family: 'JetBrains Mono'; text-align: center;
}
#win-name:focus { outline: none; border-color: var(--amber); }

/* ---------- TOUCH ---------- */
#touch-controls {
  position: absolute; inset: 0; z-index: 15; pointer-events: none;
}
.pad-left { position: absolute; bottom: 20px; left: 16px; display: flex; gap: 10px; }
.pad-right { position: absolute; bottom: 20px; right: 16px; display: flex; gap: 10px; align-items: flex-end; }
.tbtn {
  pointer-events: auto; width: 64px; height: 64px; border-radius: 50%;
  background: rgba(20,16,24,0.6); border: 1px solid #4a3f30; color: #ddd6c8;
  font-family: 'JetBrains Mono'; font-size: 0.62rem; font-weight: 700;
  letter-spacing: 0.05em; touch-action: none; -webkit-tap-highlight-color: transparent;
}
.tbtn:active { background: rgba(255,184,77,0.2); border-color: var(--amber); }

/* ---------- REMIX LINK ---------- */
#remix {
  position: absolute; bottom: 6px; right: 10px; z-index: 30;
  font-size: 0.62rem; color: #4a4438; text-decoration: none;
  letter-spacing: 0.05em;
}
#remix:hover { color: var(--amber); }

/* ---------- ANIMATIONS ---------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes flicker {
  0%,100% { opacity: 1; } 92% { opacity: 1; } 93% { opacity: 0.4; }
  94% { opacity: 1; } 96% { opacity: 0.6; } 97% { opacity: 1; }
}

@media (max-width: 640px) {
  #pause-hint { display: none; }
  #trinket-progress { max-width: 130px; }
}