:root {
  --ink: #07090d;
  --paper: #e8e2d6;
  --blood: #8b2e2e;
  --blood-hot: #c44b3c;
  --moon: #c5d4e8;
  --moss: #6a8f6a;
  --bone: #d9cbb3;
  --fog: rgba(180, 200, 220, 0.12);
  --line: rgba(232, 226, 214, 0.14);
  --font-display: "Cormorant Garamond", "Times New Roman", serif;
  --font-body: "Manrope", "Segoe UI", sans-serif;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--paper);
  font-family: var(--font-body);
  background: var(--ink);
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 60% 45% at 20% 0%, rgba(140, 170, 210, 0.22), transparent 55%),
    radial-gradient(ellipse 50% 40% at 90% 80%, rgba(139, 46, 46, 0.18), transparent 50%),
    linear-gradient(165deg, #05070b 0%, #10161f 45%, #080a0e 100%);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding:
    max(0.85rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    0.75rem
    max(1rem, env(safe-area-inset-left));
}

.back, .ghost {
  color: rgba(232, 226, 214, 0.65);
  text-decoration: none;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.back:hover, .ghost:hover { color: var(--paper); border-color: rgba(232, 226, 214, 0.35); }

.brand {
  font-family: var(--font-display);
  letter-spacing: 0.18em;
  font-size: 1.25rem;
  font-weight: 700;
}

.screen {
  width: min(1100px, 100% - 2rem);
  margin: 0 auto 1.5rem;
  animation: rise 0.55s ease both;
}

#screen-play { width: min(960px, 100% - 2rem); }

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

.menu-layout {
  display: grid;
  grid-template-columns: minmax(16rem, 22rem) 1fr;
  gap: clamp(1rem, 3vw, 2rem);
  align-items: center;
  padding: clamp(1rem, 3vw, 2rem) 0;
}

.menu-block { padding: 0; max-width: 28rem; }

.eyebrow {
  margin: 0 0 0.4rem;
  font-size: 0.75rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(197, 212, 232, 0.55);
}

.menu-block h1 {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: clamp(3.2rem, 10vw, 4.8rem);
  line-height: 0.95;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--bone);
  text-shadow: 0 0 40px rgba(140, 170, 210, 0.25);
}

.lead {
  margin: 0 0 1.5rem;
  color: rgba(232, 226, 214, 0.72);
  line-height: 1.55;
  font-size: 1.05rem;
}

.options,
.levels {
  margin: 0 0 1.25rem;
  padding: 0.9rem 1rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(8, 10, 14, 0.55);
  display: grid;
  gap: 0.7rem;
}

.options legend,
.levels legend {
  padding: 0 0.35rem;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(197, 212, 232, 0.55);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.45rem;
}

.level-btn {
  appearance: none;
  border: 1px solid rgba(197, 212, 232, 0.18);
  border-radius: 10px;
  background: rgba(12, 14, 20, 0.85);
  color: rgba(232, 226, 214, 0.78);
  font: inherit;
  padding: 0.55rem 0.25rem 0.6rem;
  cursor: pointer;
  display: grid;
  gap: 0.15rem;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.level-btn:hover:not(:disabled) {
  border-color: rgba(197, 212, 232, 0.4);
  transform: translateY(-1px);
}

.level-btn[aria-selected="true"] {
  border-color: rgba(196, 75, 60, 0.75);
  background: rgba(40, 16, 14, 0.85);
  color: var(--bone);
  box-shadow: inset 0 0 0 1px rgba(196, 75, 60, 0.25);
}

.level-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.level-btn .lv-num {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(197, 212, 232, 0.45);
}

.level-btn .lv-name {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.15;
}

.level-btn .lv-meta {
  font-size: 0.68rem;
  color: rgba(232, 226, 214, 0.42);
}

.level-blurb {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: rgba(232, 226, 214, 0.55);
}

.end-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.stat-stage b {
  font-size: 1.15rem;
  letter-spacing: 0.03em;
}

.opt {
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: rgba(232, 226, 214, 0.75);
}

.opt select,
.opt-inline select {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(12, 14, 20, 0.9);
  color: var(--paper);
  font: inherit;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
}

.opt-check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
}

.opt-check input {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--blood-hot);
}

.opt-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: rgba(232, 226, 214, 0.55);
}

.opt-inline select {
  padding: 0.4rem 0.5rem;
  font-size: 0.82rem;
}

.tips {
  margin: 1.5rem 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.55rem;
  color: rgba(232, 226, 214, 0.5);
  font-size: 0.92rem;
}

.tips li {
  padding-left: 1rem;
  border-left: 2px solid rgba(139, 46, 46, 0.65);
}

.btn,
.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: 10px;
  padding: 0.85rem 1.35rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--paper);
  background: linear-gradient(135deg, #a3453a, var(--blood));
  box-shadow: 0 8px 28px rgba(139, 46, 46, 0.35);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.btn:hover { transform: translateY(-1px); filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.ghost-btn,
.link-btn {
  color: var(--paper);
  background: transparent;
  border: 1px solid var(--line);
  box-shadow: none;
  margin-left: 0.5rem;
}

.ghost-btn[aria-pressed="true"] {
  border-color: var(--moon);
  color: var(--moon);
}

.hud {
  display: grid;
  grid-template-columns: 1.35fr repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.55rem 0.7rem;
  background: rgba(8, 10, 14, 0.65);
  backdrop-filter: blur(6px);
  display: grid;
  gap: 0.15rem;
}

.stat span {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(197, 212, 232, 0.5);
}

.stat b {
  font-family: var(--font-display);
  font-size: 1.55rem;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--bone);
}

.stage-wrap {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(197, 212, 232, 0.16);
  background: #0a0d12;
  touch-action: none;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

#game {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
  vertical-align: middle;
}

.boot {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-content: center;
  background: rgba(7, 9, 13, 0.72);
  color: var(--moon);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.85rem;
}

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

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.85rem;
}

.hint {
  margin: 0;
  flex: 1 1 12rem;
  font-size: 0.88rem;
  color: rgba(232, 226, 214, 0.5);
}

.end-block .btn { margin-right: 0.4rem; margin-bottom: 0.5rem; }

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 860px) {
  .menu-layout { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .hud { grid-template-columns: repeat(2, 1fr); }
  .ghost-btn { margin-left: 0; }
  .level-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-stage { grid-column: 1 / -1; }
}

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