:root {
  --ink: #0d0f14;
  --ink-2: #12151d;
  --ink-3: #191d28;
  --stone: #2a2f3d;
  --ash: #6c7385;
  --bone: #c9c6ba;
  --parchment: #e9e2cf;
  --amber: #e6a648;
  --amber-soft: #f0c489;
  --amber-deep: #b06f22;
  --blood: #c0503f;
  --cool: #7fb0c4;
  --shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.8);
  --serif: "Cormorant Garamond", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  background:
    radial-gradient(120% 90% at 50% -10%, #171b26 0%, var(--ink) 55%, #08090d 100%);
  color: var(--bone);
  font-family: var(--serif);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  touch-action: manipulation;
}

/* fixed grain overlay for atmosphere */
.grain {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.stage {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.6rem, 2vh, 1.4rem);
  padding: clamp(0.8rem, 3vh, 2rem);
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 4vw, 2.6rem);
  width: min(720px, 96vw);
  padding: 0 0.2rem;
}
.hud[hidden] {
  display: none;
}
.hud__group {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.hud__label {
  font-family: var(--mono);
  font-size: 0.58rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ash);
}
.hud__value {
  font-family: var(--mono);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--parchment);
  line-height: 1;
}
.hud__sub {
  color: var(--ash);
  font-weight: 400;
  font-size: 0.85rem;
}
.hud__codex {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--amber);
  background: transparent;
  border: 1px solid rgba(230, 166, 72, 0.35);
  border-radius: 2px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.hud__codex:hover {
  background: rgba(230, 166, 72, 0.12);
  border-color: var(--amber);
  color: var(--amber-soft);
}

/* ---------- Canvas frame ---------- */
.frame {
  position: relative;
  border-radius: 4px;
  padding: clamp(8px, 1.4vw, 16px);
  background: linear-gradient(180deg, #14161f, #0b0c11);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(230, 166, 72, 0.08);
}
.frame::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(201, 198, 186, 0.08);
  border-radius: 3px;
  pointer-events: none;
}
#game {
  display: block;
  width: min(720px, 92vw);
  height: auto;
  aspect-ratio: 720 / 528;
  image-rendering: optimizeQuality;
  border-radius: 2px;
  background: #06070a;
}
.frame__hint {
  margin-top: 0.7rem;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ash);
  transition: opacity 0.4s;
}

/* ---------- Screens (overlays) ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 2rem;
  background: radial-gradient(80% 80% at 50% 40%, rgba(8, 9, 13, 0.82), rgba(6, 7, 10, 0.97));
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s ease, visibility 0.5s;
}
.screen.is-open {
  opacity: 1;
  visibility: visible;
}
.screen__inner {
  max-width: 30rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
}
.screen.is-open .screen__inner > * {
  animation: rise 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}
.screen.is-open .screen__inner > *:nth-child(2) { animation-delay: 0.08s; }
.screen.is-open .screen__inner > *:nth-child(3) { animation-delay: 0.16s; }
.screen.is-open .screen__inner > *:nth-child(4) { animation-delay: 0.24s; }
.screen.is-open .screen__inner > *:nth-child(5) { animation-delay: 0.32s; }
.screen.is-open .screen__inner > *:nth-child(6) { animation-delay: 0.4s; }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.eyebrow {
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--amber);
}
.eyebrow--warn {
  color: var(--blood);
}
.title {
  font-size: clamp(3rem, 10vw, 5.4rem);
  font-weight: 600;
  line-height: 0.94;
  letter-spacing: -0.01em;
  color: var(--parchment);
  text-shadow: 0 0 42px rgba(230, 166, 72, 0.16);
}
.title--small {
  font-size: clamp(2.2rem, 7vw, 3.4rem);
}
.lede {
  font-size: 1.18rem;
  line-height: 1.5;
  color: var(--bone);
  max-width: 28rem;
}
.lede em {
  color: var(--amber-soft);
  font-style: italic;
}
.lede--muted {
  color: var(--ash);
  font-size: 1.02rem;
}
.continued {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  color: var(--ash);
  text-transform: uppercase;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding: 0.95rem 1.9rem;
  border-radius: 2px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.15s, box-shadow 0.25s, background 0.25s;
  margin-top: 0.5rem;
}
.btn--primary {
  color: #1a1204;
  background: linear-gradient(180deg, var(--amber-soft), var(--amber));
  box-shadow: 0 10px 30px -10px rgba(230, 166, 72, 0.6);
  font-weight: 700;
}
.btn--primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 40px -12px rgba(230, 166, 72, 0.75);
  background: linear-gradient(180deg, #f6d3a2, var(--amber-soft));
}
.btn--primary:active {
  transform: translateY(0);
}

/* ---------- Death screen ---------- */
.death-sigil {
  width: 96px;
  height: 96px;
  filter: drop-shadow(0 0 24px currentColor);
}
.death-sigil canvas {
  display: block;
  width: 96px;
  height: 96px;
}
.death-name {
  font-size: clamp(2.4rem, 8vw, 3.6rem);
  font-weight: 600;
  color: var(--parchment);
  line-height: 1;
}
.death-lesson {
  font-size: 1.18rem;
  line-height: 1.5;
  color: var(--bone);
  font-style: italic;
}
.death-reveal {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  line-height: 1.7;
  color: var(--amber-soft);
  border-top: 1px solid rgba(230, 166, 72, 0.2);
  border-bottom: 1px solid rgba(230, 166, 72, 0.2);
  padding: 0.8rem 0;
  max-width: 26rem;
}

/* ---------- Codex ---------- */
.codex {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 60;
  height: 100%;
  width: min(420px, 90vw);
  background: linear-gradient(180deg, #17130c, #0f0c07);
  border-left: 1px solid rgba(230, 166, 72, 0.2);
  box-shadow: -30px 0 60px -20px rgba(0, 0, 0, 0.8);
  padding: 1.8rem 1.6rem;
  overflow-y: auto;
  transform: translateX(102%);
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.codex.is-open {
  transform: none;
}
.codex__scrim {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(4, 5, 8, 0.6);
  backdrop-filter: blur(2px);
}
.codex__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid rgba(201, 198, 186, 0.12);
  padding-bottom: 0.8rem;
}
.codex__head h2 {
  font-size: 1.7rem;
  font-weight: 600;
  color: var(--parchment);
}
.codex__close {
  background: none;
  border: none;
  color: var(--ash);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s;
}
.codex__close:hover {
  color: var(--amber);
}
.codex__meta {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ash);
  margin: 0.9rem 0 1.4rem;
  line-height: 1.9;
}
.codex__sub {
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--amber);
  margin: 1.4rem 0 0.8rem;
}
.codex__sigils {
  list-style: none;
  display: grid;
  gap: 0.7rem;
}
.codex__sigil {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid rgba(201, 198, 186, 0.08);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.015);
}
.codex__sigil canvas,
.codex__sigil svg {
  flex: 0 0 auto;
}
.codex__sigil canvas {
  width: 38px;
  height: 38px;
}
.codex__sigil--locked {
  opacity: 0.4;
}
.codex__sigil-name {
  font-size: 1.25rem;
  color: var(--parchment);
  line-height: 1.1;
}
.codex__sigil-desc {
  font-size: 0.98rem;
  color: var(--ash);
  line-height: 1.3;
}
.codex__sigil--locked .codex__sigil-name {
  font-family: var(--mono);
  font-size: 0.82rem;
  letter-spacing: 0.2em;
  color: var(--ash);
}
.codex__notes {
  list-style: none;
  display: grid;
  gap: 1rem;
  padding-bottom: 2rem;
}
.codex__note {
  font-size: 1.08rem;
  line-height: 1.5;
  color: var(--bone);
  padding-left: 1rem;
  border-left: 2px solid var(--amber-deep);
  font-style: italic;
}
.codex__empty {
  font-size: 1rem;
  color: var(--ash);
  font-style: italic;
}

/* ---------- Touch d-pad ---------- */
.dpad {
  position: fixed;
  bottom: 1.2rem;
  right: 1.2rem;
  z-index: 45;
  display: grid;
  grid-template-columns: repeat(3, 3.1rem);
  grid-template-rows: repeat(3, 3.1rem);
  gap: 0.3rem;
}
.dpad button {
  background: rgba(25, 29, 40, 0.85);
  border: 1px solid rgba(230, 166, 72, 0.25);
  color: var(--amber-soft);
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
}
.dpad button:active {
  background: rgba(230, 166, 72, 0.2);
}
.dpad [data-dir="up"] { grid-area: 1 / 2; }
.dpad [data-dir="left"] { grid-area: 2 / 1; }
.dpad [data-dir="down"] { grid-area: 3 / 2; }
.dpad [data-dir="right"] { grid-area: 2 / 3; }

@media (max-width: 640px) {
  .hud { gap: 1.1rem; }
  .frame__hint { display: none; }
}
