:root {
  color-scheme: dark;
  --bg: #11120f;
  --stone: #24251f;
  --ink: #f1ead9;
  --muted: #b2aa97;
  --gold: #c99d4d;
  --red: #a73632;
  --green: #5e9f6d;
  --blue: #6d8cae;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: auto;
  background:
    radial-gradient(circle at 20% 10%, rgba(201, 157, 77, 0.15), transparent 30%),
    linear-gradient(135deg, #11120f 0%, #1b1a16 48%, #080908 100%);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
}

.game-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 205px;
  gap: 10px;
  width: min(1080px, calc(100vw - 20px));
  height: min(640px, calc(100vh - 20px));
  min-height: 520px;
  margin: 10px auto;
  padding: 0;
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(241, 234, 217, 0.16);
  background: #070807;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.hud {
  position: absolute;
  inset: 8px 8px auto 8px;
  display: grid;
  grid-template-columns: 160px 160px minmax(170px, 1fr);
  gap: 6px;
  pointer-events: none;
}

.meter,
.boss-meter {
  padding: 6px;
  border: 1px solid rgba(241, 234, 217, 0.14);
  background: rgba(12, 13, 11, 0.72);
  backdrop-filter: blur(8px);
}

.meter span,
.boss-meter span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.bar {
  height: 9px;
  overflow: hidden;
  background: rgba(241, 234, 217, 0.12);
}

.bar i {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--red);
  transition: width 120ms ease;
}

.stamina .bar i {
  background: var(--green);
}

.boss-meter .bar i {
  background: var(--gold);
}

.message {
  position: absolute;
  left: 50%;
  bottom: 16px;
  display: grid;
  gap: 6px;
  min-width: min(360px, calc(100% - 32px));
  padding: 8px 12px;
  transform: translateX(-50%);
  border: 1px solid rgba(241, 234, 217, 0.18);
  background: rgba(12, 13, 11, 0.8);
  text-align: center;
  transition: opacity 200ms ease;
}

.message strong {
  font-size: 16px;
}

.message span {
  color: var(--muted);
  font-size: 11px;
}

.message.hidden {
  opacity: 0;
}

.cutscene {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(rgba(5, 6, 5, 0.35), rgba(5, 6, 5, 0.82)),
    radial-gradient(circle at 50% 34%, rgba(201, 157, 77, 0.2), transparent 34%),
    #080908;
  z-index: 4;
  overflow: hidden;
}

.main-menu {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(rgba(4, 5, 4, 0.2), rgba(4, 5, 4, 0.82)),
    radial-gradient(circle at 50% 28%, rgba(201, 157, 77, 0.24), transparent 38%),
    #070807;
}

.main-menu.hidden {
  display: none;
}

.menu-panel {
  display: grid;
  gap: 12px;
  width: min(430px, 100%);
  padding: 18px;
  border: 1px solid rgba(241, 234, 217, 0.2);
  background: rgba(12, 13, 11, 0.86);
}

.menu-panel span {
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.menu-panel h2 {
  margin: 0;
  color: var(--ink);
  font-size: 23px;
}

.menu-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.menu-actions,
.build-row,
.weapon-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.menu-actions button,
.build-row button,
.weapon-row button {
  padding: 8px 10px;
  border: 1px solid rgba(241, 234, 217, 0.2);
  background: rgba(241, 234, 217, 0.08);
  color: var(--ink);
  font: 700 12px "Segoe UI", system-ui, sans-serif;
  cursor: pointer;
}

.menu-actions button:hover,
.build-row button:hover,
.weapon-row button:hover,
.weapon-row button.active {
  background: rgba(201, 157, 77, 0.24);
}

.cutscene.hidden {
  display: none;
}

.cutscene::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle, black 0%, transparent 72%);
  animation: ashGrid 9s linear infinite;
}

.cutscene-frame {
  position: relative;
  display: grid;
  gap: 10px;
  width: min(440px, 100%);
  padding: 16px;
  border: 1px solid rgba(241, 234, 217, 0.2);
  background: rgba(11, 12, 10, 0.82);
  animation: sceneIn 420ms ease both;
}

.cutscene-frame.switching {
  animation: sceneOut 180ms ease both;
}

.cutscene-frame span {
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.cutscene-frame h2 {
  margin: 0;
  color: var(--ink);
  font-size: 20px;
}

.speaker {
  min-height: 18px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.cutscene-frame p {
  min-height: 68px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.cutscene-frame p::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 1em;
  margin-left: 3px;
  transform: translateY(2px);
  background: var(--gold);
  animation: caretBlink 820ms steps(1) infinite;
}

.cutscene-frame button {
  width: fit-content;
  padding: 8px 13px;
  border: 1px solid rgba(241, 234, 217, 0.22);
  background: rgba(201, 157, 77, 0.18);
  color: var(--ink);
  font: 700 13px "Segoe UI", system-ui, sans-serif;
  cursor: pointer;
}

.cutscene-frame button:hover {
  background: rgba(201, 157, 77, 0.3);
}

.cutscene-frame button:disabled {
  cursor: default;
  opacity: 0.55;
}

.cutscene-visual {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.moon {
  position: absolute;
  left: 50%;
  top: 16%;
  width: 84px;
  height: 84px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle at 45% 42%, rgba(241, 234, 217, 0.92), rgba(201, 157, 77, 0.18) 58%, transparent 68%);
  filter: blur(0.4px);
  opacity: 0.42;
  animation: moonPulse 4s ease-in-out infinite;
}

.bell {
  position: absolute;
  left: calc(50% - 31px);
  top: 23%;
  width: 62px;
  height: 68px;
  border: 4px solid rgba(201, 157, 77, 0.42);
  border-top-left-radius: 42px 54px;
  border-top-right-radius: 42px 54px;
  border-bottom: 12px solid rgba(201, 157, 77, 0.48);
  transform-origin: 50% 0;
  animation: bellSway 3.8s ease-in-out infinite;
}

.bell::before {
  content: "";
  position: absolute;
  left: 21px;
  top: -17px;
  width: 14px;
  height: 18px;
  border: 3px solid rgba(201, 157, 77, 0.42);
  border-bottom: 0;
}

.bell::after {
  content: "";
  position: absolute;
  left: 24px;
  bottom: -22px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(241, 208, 132, 0.66);
  box-shadow: 0 0 18px rgba(241, 208, 132, 0.5);
}

.ember {
  position: absolute;
  bottom: -24px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f1d084;
  box-shadow: 0 0 16px #c99d4d;
  opacity: 0;
}

.ember-a {
  left: 20%;
  animation: emberRise 6s linear infinite;
}

.ember-b {
  left: 54%;
  animation: emberRise 7.5s 1.4s linear infinite;
}

.ember-c {
  left: 78%;
  animation: emberRise 5.8s 0.6s linear infinite;
}

@keyframes sceneIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes sceneOut {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-10px) scale(0.99);
  }
}

@keyframes ashGrid {
  from {
    background-position: 0 0, 0 0;
  }
  to {
    background-position: 42px 84px, 0 42px;
  }
}

@keyframes caretBlink {
  0%,
  45% {
    opacity: 1;
  }
  46%,
  100% {
    opacity: 0;
  }
}

@keyframes moonPulse {
  0%,
  100% {
    opacity: 0.32;
    transform: translateX(-50%) scale(0.96);
  }
  50% {
    opacity: 0.5;
    transform: translateX(-50%) scale(1.04);
  }
}

@keyframes bellSway {
  0%,
  100% {
    transform: rotate(-2deg);
  }
  50% {
    transform: rotate(2deg);
  }
}

@keyframes emberRise {
  0% {
    opacity: 0;
    transform: translateY(0) translateX(0) scale(0.7);
  }
  18% {
    opacity: 0.85;
  }
  100% {
    opacity: 0;
    transform: translateY(-78vh) translateX(46px) scale(1.4);
  }
}

.panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 9px;
  padding: 10px;
  border: 1px solid rgba(241, 234, 217, 0.14);
  background: rgba(20, 21, 18, 0.78);
}

h1 {
  margin: 0;
  color: var(--gold);
  font-size: 19px;
  font-weight: 700;
}

.stats {
  display: grid;
  gap: 6px;
}

.lore {
  display: grid;
  gap: 6px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(241, 234, 217, 0.12);
}

.lore h2 {
  margin: 0;
  color: var(--ink);
  font-size: 12px;
}

.lore p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.stats p,
.controls p {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  margin: 0;
  color: var(--muted);
}

.stats #oath {
  max-width: 104px;
  color: var(--gold);
  font-size: 12px;
  text-align: right;
}

.stats #weapon {
  color: var(--blue);
  font-size: 12px;
}

.build-panel {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(241, 234, 217, 0.12);
}

.build-panel h2 {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
}

.stats b {
  color: var(--ink);
  font-size: 13px;
}

.controls {
  display: grid;
  gap: 4px;
  margin-top: auto;
}

kbd {
  min-width: 48px;
  padding: 2px 5px;
  border: 1px solid rgba(241, 234, 217, 0.18);
  background: rgba(241, 234, 217, 0.08);
  color: var(--ink);
  font: 600 10px ui-monospace, SFMono-Regular, Consolas, monospace;
  text-align: center;
}

.stats #status {
  color: var(--blue);
  font-size: 12px;
  text-align: right;
}

@media (max-width: 820px) {
  .game-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    width: min(620px, calc(100vw - 16px));
    margin: 8px auto;
  }

  .stage {
    aspect-ratio: 16 / 9;
  }

  .hud {
    grid-template-columns: 1fr 1fr;
  }

  .boss-meter {
    grid-column: 1 / -1;
  }

  .panel {
    min-height: auto;
    max-height: none;
  }
}

@media (max-height: 680px) {
  .game-shell {
    height: min(560px, calc(100vh - 16px));
    min-height: 480px;
  }

  .panel {
    gap: 8px;
    padding: 10px;
  }

  .lore p {
    max-height: 68px;
    overflow: hidden;
  }

  .controls {
    gap: 4px;
  }

  .cutscene-frame {
    width: min(460px, 100%);
    padding: 16px;
  }

  .cutscene-frame h2 {
    font-size: 21px;
  }

  .cutscene-frame p {
    min-height: 62px;
    font-size: 13px;
  }
}
