:root {
  --ink: #0c0a08;
  --paper: #f3ebe0;
  --muted: rgba(243, 235, 224, 0.62);
  --amber: #e09a45;
  --amber-hot: #f0b45a;
  --blood: #a33a2c;
  --line: rgba(243, 235, 224, 0.14);
  --font-display: "Cinzel", "Times New Roman", serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--paper);
  font-family: var(--font-body);
  background: var(--ink);
  overflow-x: clip;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 70% 45% at 20% 0%, rgba(224, 154, 69, 0.22), transparent 55%),
    radial-gradient(ellipse 50% 40% at 90% 80%, rgba(163, 58, 44, 0.18), transparent 50%),
    linear-gradient(165deg, #0a0806, #16110d 50%, #0c0a08);
  transition: opacity 0.45s ease, background-image 0.45s ease;
  animation: bg-breathe 14s ease-in-out infinite alternate;
}

.bg.has-image {
  background-size: cover;
  background-position: center;
  will-change: transform;
  animation: bg-ken 22s ease-in-out infinite alternate;
}

@keyframes bg-breathe {
  from { filter: saturate(1); }
  to { filter: saturate(1.08) brightness(1.04); }
}

@keyframes bg-ken {
  from { transform: scale(1.02); background-position: 48% 45%; }
  to { transform: scale(1.08); background-position: 52% 50%; }
}

.bg.has-image::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(12, 10, 8, 0.55) 0%, rgba(12, 10, 8, 0.35) 40%, rgba(12, 10, 8, 0.92) 100%),
    linear-gradient(90deg, rgba(12, 10, 8, 0.55), transparent 50%);
}

.fx-flash {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  opacity: 0;
  background: rgba(243, 235, 224, 0.35);
}

.fx-flash.hit {
  background: rgba(224, 154, 69, 0.35);
  animation: flash 0.35s ease;
}

.fx-flash.hurt {
  background: rgba(163, 58, 44, 0.4);
  animation: flash 0.4s ease;
}

.fx-flash.crit {
  background: rgba(240, 180, 90, 0.55);
  animation: flash 0.5s ease;
}

@keyframes flash {
  0% { opacity: 0.7; }
  100% { opacity: 0; }
}

.dice-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  gap: 0.75rem;
  background: rgba(12, 10, 8, 0.55);
  backdrop-filter: blur(4px);
}

.dice-overlay[hidden] { display: none; }

.dice {
  width: 5.5rem;
  height: 5.5rem;
  border-radius: 1rem;
  display: grid;
  place-content: center;
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--ink);
  background: linear-gradient(145deg, var(--amber-hot), var(--amber));
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  animation: dice-spin 0.55s ease;
}

.dice.crit {
  animation: dice-spin 0.55s ease, dice-glow 0.8s ease;
}

.dice-label {
  margin: 0;
  text-align: center;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--paper);
}

@keyframes dice-spin {
  0% { transform: scale(0.4) rotate(-40deg); opacity: 0; }
  60% { transform: scale(1.12) rotate(12deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes dice-glow {
  0%, 100% { box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45); }
  50% { box-shadow: 0 0 40px rgba(240, 180, 90, 0.85); }
}

.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));
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(10px);
  background: rgba(12, 10, 8, 0.55);
}

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

.back,
.ghost {
  color: var(--muted);
  text-decoration: none;
  background: none;
  border: 0;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  padding: 0.4rem 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.back:hover,
.ghost:hover { color: var(--paper); }

.screen {
  width: min(52rem, 100%);
  margin: 0 auto;
  padding: 0.5rem max(1rem, env(safe-area-inset-right)) max(2rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

.screen.is-enter {
  animation: screen-in 0.45s ease both;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.hero-block {
  padding: 1.5rem 0 1.2rem;
  animation: rise 0.6s ease both;
}

.eyebrow {
  margin: 0 0 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.75rem;
  color: var(--amber);
  font-weight: 600;
}

.hero-block h1,
.end-block h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(3.2rem, 14vw, 5.5rem);
  line-height: 0.9;
  letter-spacing: 0.06em;
}

.lead {
  margin: 0.9rem 0 0;
  max-width: 32ch;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1.45;
}

.class-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-top: 1.2rem;
}

.class-card {
  border: 1px solid var(--line);
  background: rgba(12, 10, 8, 0.65);
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  color: inherit;
  font: inherit;
  text-align: left;
  padding: 0;
  transition: border-color 0.15s ease, transform 0.2s ease, box-shadow 0.2s ease;
  animation: rise 0.55s ease both;
}

.class-card:nth-child(1) { animation-delay: 0.05s; }
.class-card:nth-child(2) { animation-delay: 0.12s; }
.class-card:nth-child(3) { animation-delay: 0.2s; }

.class-card:hover,
.class-card:focus-visible {
  border-color: rgba(224, 154, 69, 0.65);
  transform: translateY(-4px) scale(1.01);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  outline: none;
}

.class-card img {
  display: block;
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.class-card:hover img {
  transform: scale(1.05);
}

.class-card .body {
  padding: 0.75rem 0.85rem 1rem;
  display: grid;
  gap: 0.3rem;
}

.class-card strong {
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: 0.04em;
}

.class-card span {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.class-card .stats {
  margin-top: 0.35rem;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--amber-hot);
}

.resume-wrap {
  margin: 1.2rem 0 0;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.9rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.hud b { color: var(--paper); font-weight: 600; }

.scene-art {
  margin: 0 0 1rem;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  aspect-ratio: 16/9;
  background: #1a1410;
  animation: art-in 0.55s ease both;
}

.scene-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  animation: art-ken 18s ease-in-out infinite alternate;
}

.scene-art.shake {
  animation: art-in 0.01s ease, shake 0.4s ease;
}

.scene-art.pulse-hit {
  animation: art-in 0.01s ease, pulse-hit 0.45s ease;
}

@keyframes art-in {
  from { opacity: 0; transform: scale(1.04); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes art-ken {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes pulse-hit {
  0% { filter: brightness(1); }
  40% { filter: brightness(1.35) saturate(1.2); }
  100% { filter: brightness(1); }
}

.scene-body h2,
.combat-body h2 {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4vw, 2rem);
  letter-spacing: 0.03em;
}

.scene-body p,
.combat-body p {
  margin: 0 0 1rem;
  color: var(--muted);
  line-height: 1.5;
  font-size: 1.05rem;
}

.hint {
  color: var(--amber) !important;
  font-size: 0.95rem !important;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.btn,
.choice-btn {
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  color: var(--ink);
  background: linear-gradient(160deg, var(--amber-hot), var(--amber));
  padding: 0.95rem 1.2rem;
  border-radius: 12px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.btn:hover:not(:disabled),
.choice-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.choice-btn,
.ghost-btn {
  width: 100%;
}

.choice-btn {
  animation: rise 0.4s ease both;
}

.choice-btn:nth-child(1) { animation-delay: 0.05s; }
.choice-btn:nth-child(2) { animation-delay: 0.12s; }
.choice-btn:nth-child(3) { animation-delay: 0.18s; }

.ghost-btn {
  background: rgba(12, 10, 8, 0.45);
  color: var(--paper);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
}

.btn:disabled,
.choice-btn:disabled {
  opacity: 0.45;
  cursor: wait;
}

.bars {
  display: grid;
  gap: 0.55rem;
  margin-bottom: 0.9rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 4.5rem 1fr 3.2rem;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.bar {
  height: 0.65rem;
  background: rgba(243, 235, 224, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--amber), var(--amber-hot));
  transform-origin: left center;
  transition: transform 0.25s ease;
}

.bar.enemy i {
  background: linear-gradient(90deg, var(--blood), #c45a3a);
}

.combat-log {
  min-height: 5.5rem;
  max-height: 9rem;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.9rem;
  background: rgba(12, 10, 8, 0.55);
  font-size: 0.92rem;
  color: var(--muted);
  line-height: 1.45;
}

.combat-log div + div { margin-top: 0.35rem; }
.combat-log .hit { color: var(--amber-hot); }
.combat-log .miss { color: rgba(243, 235, 224, 0.45); }
.combat-log .hurt { color: #e07a6a; }
.combat-log div {
  animation: rise 0.3s ease both;
}

.loot-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.loot-list li {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  background: rgba(12, 10, 8, 0.5);
  animation: loot-pop 0.45s ease both;
}

.loot-list li:nth-child(2) { animation-delay: 0.1s; }

@keyframes loot-pop {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.loot-list strong {
  display: block;
  font-family: var(--font-display);
  margin-bottom: 0.15rem;
}

.loot-list span { color: var(--muted); font-size: 0.92rem; }

.end-block {
  animation: end-in 0.7s ease both;
}

.end-block .choices {
  margin-top: 1.5rem;
  max-width: 22rem;
}

@keyframes end-in {
  from { opacity: 0; transform: scale(0.96) translateY(12px); filter: blur(2px); }
  to { opacity: 1; transform: scale(1) translateY(0); filter: blur(0); }
}

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

.scene-body.is-enter h2,
.combat-body.is-enter h2 {
  animation: rise 0.45s ease both;
}

.scene-body.is-enter p,
.combat-body.is-enter .bars {
  animation: rise 0.5s 0.08s ease both;
}

@media (max-width: 720px) {
  .class-grid {
    grid-template-columns: 1fr;
  }

  .class-card {
    display: grid;
    grid-template-columns: 7.5rem 1fr;
  }

  .class-card img {
    aspect-ratio: 3/4;
    height: 100%;
    min-height: 7.5rem;
  }

  .scene-art {
    aspect-ratio: 4/3;
    border-radius: 12px;
  }

  .bar-row {
    grid-template-columns: 3.5rem 1fr 2.8rem;
    font-size: 0.8rem;
  }
}

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