:root {
  --gold: #e6bf62;
  --bright-gold: #ffe5a0;
  --parchment: #f0d7a1;
  --ink: #21160f;
  --blue-fire: #37c7ff;
  --shadow: #08090d;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--parchment);
  background: #050609;
  font-family: "IM Fell English", Georgia, serif;
}

button,
input {
  font: inherit;
}

.game-shell {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(3, 4, 8, 0.72), rgba(5, 8, 14, 0.22), rgba(3, 4, 8, 0.76)),
    url("assets/far-earth-menu-bg.png") center / cover no-repeat fixed;
}

.game-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 15%, rgba(50, 190, 255, 0.2), transparent 25%),
    repeating-linear-gradient(115deg, transparent 0 26px, rgba(88, 202, 255, 0.035) 27px 29px);
  mix-blend-mode: screen;
  pointer-events: none;
  animation: runeDrift 16s linear infinite;
}

.mist {
  position: absolute;
  inset: auto -20% 0;
  height: 35vh;
  background: linear-gradient(90deg, transparent, rgba(175, 205, 220, 0.12), transparent);
  filter: blur(22px);
  opacity: 0.8;
  pointer-events: none;
  animation: mistMove 22s ease-in-out infinite alternate;
}

.mist-b {
  bottom: 12%;
  animation-duration: 30s;
  animation-delay: -8s;
}

.blue-fire {
  position: absolute;
  bottom: 9%;
  width: 9rem;
  height: 13rem;
  border-radius: 48% 52% 50% 50%;
  background: radial-gradient(circle at 50% 78%, rgba(255, 255, 255, 0.9), rgba(70, 223, 255, 0.8) 18%, rgba(16, 81, 255, 0.32) 48%, transparent 70%);
  filter: blur(3px);
  opacity: 0.72;
  pointer-events: none;
  animation: flamePulse 1.6s ease-in-out infinite alternate;
}

.left-flame {
  left: 3%;
}

.right-flame {
  right: 4%;
  animation-delay: -0.7s;
}

.screen-stack {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 1.25rem;
  padding: clamp(1rem, 3vw, 2.5rem);
  opacity: 0;
  transform: translateY(18px) scale(0.985);
  pointer-events: none;
  transition: opacity 360ms ease, transform 360ms ease;
}

.screen.is-active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.title-wrap {
  text-align: center;
  text-shadow: 0 0 16px rgba(25, 183, 255, 0.45), 0 5px 0 rgba(0, 0, 0, 0.75);
}

.kicker {
  margin: 0 0 0.45rem;
  color: #9eeaff;
  font-family: Cinzel, serif;
  font-size: clamp(0.72rem, 1.7vw, 0.95rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: Cinzel, serif;
  color: var(--bright-gold);
}

h1 {
  max-width: 11ch;
  font-size: clamp(3.4rem, 10vw, 8.9rem);
  line-height: 0.84;
  text-transform: uppercase;
}

h1 span {
  display: block;
  color: var(--gold);
  font-size: 0.42em;
  line-height: 1.12;
}

h2 {
  font-size: clamp(2rem, 4vw, 4rem);
  line-height: 1;
  text-shadow: 0 3px 0 #251606, 0 0 18px rgba(65, 201, 255, 0.32);
}

.main-actions {
  display: grid;
  gap: 0.85rem;
  width: min(92vw, 24rem);
}

.rune-button,
.icon-button,
.small-button {
  min-height: 3.1rem;
  border: 1px solid rgba(255, 220, 135, 0.78);
  color: var(--bright-gold);
  background:
    linear-gradient(180deg, rgba(58, 37, 18, 0.92), rgba(14, 14, 19, 0.96)),
    linear-gradient(90deg, rgba(0, 183, 255, 0.14), transparent, rgba(0, 183, 255, 0.14));
  box-shadow: inset 0 0 20px rgba(255, 227, 142, 0.08), 0 0 26px rgba(45, 198, 255, 0.12);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.rune-button {
  position: relative;
  padding: 0.8rem 1.2rem;
  font-family: Cinzel, serif;
  font-weight: 700;
}

.rune-button:hover,
.rune-button:focus-visible,
.icon-button:hover,
.icon-button:focus-visible,
.small-button:hover,
.small-button:focus-visible {
  border-color: #6be3ff;
  box-shadow: inset 0 0 22px rgba(82, 209, 255, 0.16), 0 0 32px rgba(48, 205, 255, 0.35);
  transform: translateY(-2px);
  outline: none;
}

.book-screen {
  align-content: start;
  justify-items: stretch;
  background:
    linear-gradient(rgba(5, 7, 12, 0.5), rgba(5, 7, 12, 0.72)),
    url("assets/true-lore-book.png") center / cover no-repeat;
}

.panel-header {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 1rem;
  width: min(74rem, 100%);
  margin: 0 auto;
  padding-top: clamp(0.25rem, 2vw, 1.5rem);
}

.icon-button,
.small-button {
  min-height: 2.7rem;
  padding: 0.55rem 0.9rem;
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
  gap: 1rem;
  width: min(74rem, 100%);
  max-height: calc(100vh - 9.5rem);
  margin: 1.4rem auto 0;
  padding: 0.25rem 0.25rem 2rem;
  overflow-y: auto;
  scrollbar-color: var(--gold) rgba(0, 0, 0, 0.45);
}

.chapter-card {
  position: relative;
  min-height: 15rem;
  display: grid;
  align-content: end;
  gap: 0.55rem;
  padding: 1.2rem;
  border: 1px solid rgba(255, 227, 145, 0.5);
  color: #fff3cf;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  background: var(--theme), url("assets/chapter-card-frame.png") center / cover no-repeat;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.42);
  transition: transform 170ms ease, box-shadow 170ms ease, border-color 170ms ease;
}

.chapter-card::before {
  content: attr(data-mark);
  position: absolute;
  top: 0.65rem;
  right: 0.85rem;
  color: rgba(255, 236, 176, 0.35);
  font-size: 3.4rem;
  line-height: 1;
}

.chapter-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 18%, rgba(0, 0, 0, 0.3) 52%, rgba(0, 0, 0, 0.76));
  pointer-events: none;
}

.chapter-card:hover,
.chapter-card:focus-visible {
  transform: translateY(-4px);
  border-color: #68ddff;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.58), 0 0 28px rgba(58, 211, 255, 0.24);
  outline: none;
}

.chapter-card > * {
  position: relative;
  z-index: 1;
}

.chapter-number {
  color: #8eeaff;
  font-family: Cinzel, serif;
  font-size: 0.8rem;
  text-transform: uppercase;
}

.chapter-card h3 {
  font-size: 1.08rem;
  line-height: 1.12;
}

.chapter-card p {
  margin: 0;
  color: #f9e6b8;
  font-size: 1rem;
  line-height: 1.25;
}

.detail-panel,
.text-panel {
  width: min(54rem, 100%);
  margin: 1.5rem auto 0;
  padding: clamp(1rem, 3vw, 2rem);
  color: var(--ink);
  background: rgba(246, 219, 164, 0.9);
  border: 1px solid rgba(94, 48, 16, 0.5);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.story-copy,
.text-panel p {
  margin: 0 0 1rem;
  font-size: clamp(1.1rem, 2vw, 1.35rem);
  line-height: 1.45;
}

.lore-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin: 1.25rem 0;
}

.lore-facts div {
  padding: 1rem;
  background: rgba(38, 20, 8, 0.08);
  border: 1px solid rgba(78, 42, 10, 0.3);
}

dt {
  color: #64400e;
  font-family: Cinzel, serif;
  font-size: 0.75rem;
  text-transform: uppercase;
}

dd {
  margin: 0.25rem 0 0;
  font-size: 1.18rem;
}

.begin-button {
  width: min(100%, 21rem);
}

.audio-panel {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 221, 138, 0.28);
}

.volume-label {
  color: var(--bright-gold);
  font-family: Cinzel, serif;
  font-size: 0.8rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  z-index: 3;
  width: min(30rem, calc(100vw - 2rem));
  padding: 1rem 1.2rem;
  color: #fff2bf;
  text-align: center;
  background: rgba(8, 10, 16, 0.94);
  border: 1px solid rgba(97, 221, 255, 0.65);
  box-shadow: 0 0 35px rgba(49, 207, 255, 0.35);
  opacity: 0;
  transform: translate(-50%, 1rem);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes runeDrift {
  from { background-position: 0 0, 0 0; }
  to { background-position: 0 0, 120px 160px; }
}

@keyframes mistMove {
  from { transform: translateX(-9%); }
  to { transform: translateX(9%); }
}

@keyframes flamePulse {
  from { transform: scaleY(0.88) scaleX(1.08); opacity: 0.56; }
  to { transform: scaleY(1.08) scaleX(0.94); opacity: 0.84; }
}

@media (max-width: 720px) {
  .screen {
    padding: 0.85rem;
  }

  h1 {
    font-size: clamp(3rem, 18vw, 5.2rem);
  }

  .book-screen {
    background-position: center;
  }

  .panel-header {
    grid-template-columns: 1fr;
    gap: 0.65rem;
  }

  .panel-header .icon-button {
    justify-self: start;
  }

  .chapter-grid {
    max-height: calc(100vh - 10rem);
  }

  .chapter-card {
    min-height: 13.5rem;
  }

  .lore-facts {
    grid-template-columns: 1fr;
  }

  .blue-fire {
    width: 5.5rem;
    height: 8rem;
    bottom: 4%;
  }
}

.chapter1-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  color: #f4d995;
  background: #050609;
  font-family: "IM Fell English", Georgia, serif;
}

#chapter1-canvas,
#c2-canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
  background: #050609;
}

.chapter1-hud {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  right: 0.75rem;
  z-index: 11;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.55rem;
  color: #ffe5a0;
  background: rgba(5, 6, 9, 0.78);
  border: 1px solid rgba(88, 205, 255, 0.45);
  box-shadow: 0 0 24px rgba(22, 167, 255, 0.18);
}

.chapter1-hud div,
.chapter1-hud button,
.touch-pad button,
.battle-commands button,
.overlay-card button {
  min-height: 2.45rem;
  border: 1px solid rgba(230, 191, 98, 0.76);
  color: #ffe5a0;
  background: linear-gradient(180deg, rgba(53, 34, 17, 0.95), rgba(11, 13, 18, 0.95));
  font-family: Cinzel, serif;
}

.chapter1-hud div {
  display: grid;
  align-content: center;
  padding: 0.35rem 0.55rem;
}

.chapter1-hud button,
.touch-pad button,
.battle-commands button,
.overlay-card button {
  cursor: pointer;
}

.chapter1-log {
  position: fixed;
  left: 0.75rem;
  bottom: 0.75rem;
  z-index: 11;
  width: min(28rem, calc(100vw - 1.5rem));
  max-height: 10.5rem;
  overflow-y: auto;
  padding: 0.75rem;
  color: #ffe8af;
  background: rgba(5, 6, 9, 0.82);
  border: 1px solid rgba(88, 205, 255, 0.5);
  box-shadow: 0 0 24px rgba(22, 167, 255, 0.2);
}

.chapter1-log p,
.battle-messages p,
.overlay-card p {
  margin: 0 0 0.45rem;
  line-height: 1.28;
}

.touch-pad {
  position: fixed;
  right: 0.75rem;
  bottom: 0.75rem;
  z-index: 11;
  display: grid;
  grid-template-columns: repeat(3, 4.6rem);
  grid-template-areas:
    ". up ."
    "left interact right"
    ". down .";
  gap: 0.35rem;
}

.touch-pad [data-move="up"] { grid-area: up; }
.touch-pad [data-move="down"] { grid-area: down; }
.touch-pad [data-move="left"] { grid-area: left; }
.touch-pad [data-move="right"] { grid-area: right; }
.touch-pad [data-action="interact"] { grid-area: interact; }

.touch-pad button {
  min-height: 4.2rem;
  padding: 0.35rem;
}

.chapter-overlay {
  position: fixed;
  inset: 0;
  z-index: 13;
  display: none;
  place-items: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.78);
}

.chapter-overlay.is-visible {
  display: grid;
}

.overlay-card {
  width: min(42rem, 100%);
  max-height: 88vh;
  overflow: auto;
  padding: clamp(1rem, 3vw, 2rem);
  color: #24170c;
  background: rgba(240, 215, 161, 0.96);
  border: 2px solid rgba(230, 191, 98, 0.9);
  box-shadow: 0 0 55px rgba(62, 200, 255, 0.26);
}

.overlay-card h2 {
  margin-bottom: 1rem;
  color: #5a2a0f;
  text-shadow: none;
}

.overlay-card button {
  display: inline-block;
  margin: 0.35rem 0.35rem 0 0;
  padding: 0.55rem 0.8rem;
}

.overlay-card pre {
  overflow: auto;
  padding: 0.75rem;
  color: #9eeaff;
  background: #080a0f;
  line-height: 0.9;
  font-size: 0.72rem;
}

.chapter-character-art {
  display: block;
  width: min(14rem, 55vw);
  max-height: 18rem;
  object-fit: contain;
  margin: 0 0 1rem;
  background: #100d0b;
  border: 1px solid rgba(90, 42, 15, 0.4);
}

.battle-screen {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: grid;
  grid-template-rows: minmax(12rem, 1fr) auto auto auto;
  gap: 0.55rem;
  padding: 1rem;
  background: rgba(4, 5, 8, 0.96);
}

.battle-stage {
  position: relative;
  min-height: 15rem;
  overflow: hidden;
  border: 1px solid rgba(88, 205, 255, 0.45);
  background: #080a0e;
}

.battle-stage img:first-child {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
}

#battle-portrait,
#c2-bportrait {
  position: absolute;
  left: 50%;
  bottom: 12%;
  width: min(48vw, 22rem);
  max-height: 82%;
  object-fit: contain;
  transform: translateX(-50%);
  filter: drop-shadow(0 0 24px rgba(65, 213, 255, 0.28));
}

.battle-info,
.battle-messages,
.battle-commands {
  padding: 0.75rem;
  background: rgba(5, 6, 9, 0.86);
  border: 1px solid rgba(230, 191, 98, 0.5);
}

.battle-info {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.battle-messages {
  min-height: 5.5rem;
  max-height: 9rem;
  overflow: auto;
}

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

@media (max-width: 760px) {
  .chapter1-hud {
    font-size: 0.82rem;
  }

  .chapter1-log {
    bottom: 12.5rem;
    max-height: 7.5rem;
  }

  .touch-pad {
    left: 50%;
    right: auto;
    grid-template-columns: repeat(3, minmax(4.4rem, 1fr));
    width: min(22rem, calc(100vw - 1rem));
    transform: translateX(-50%);
  }

  .touch-pad button {
    min-height: 3.6rem;
  }

  .battle-screen {
    padding: 0.55rem;
  }

  .battle-commands {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
