:root {
  color-scheme: dark;
  --ink: #090d13;
  --midnight: #101722;
  --slate: #334352;
  --oxblood: #6f1723;
  --gold: #d0a84f;
  --gold-light: #f1dfad;
  --ember: #e67b22;
  --blue: #3aa3e8;
  --green: #43b968;
  --danger: #dc3545;
  --panel: rgba(13, 20, 30, 0.92);
  --panel-border: rgba(208, 168, 79, 0.42);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  --board-size: min(calc(62vh - 66px), 690px, calc(100vw - 460px));
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--ink);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: #f7edd3;
  font-family: "Songti SC", "STSong", "Noto Serif SC", Georgia, serif;
  background:
    radial-gradient(circle at 50% 10%, rgba(68, 88, 108, 0.22), transparent 38%),
    linear-gradient(180deg, #111926, #080c12);
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 3px solid #fff2ad;
  outline-offset: 3px;
}

.is-hidden {
  display: none !important;
}

.app-shell,
.screen {
  min-height: 100vh;
}

.screen {
  position: relative;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  text-align: center;
  background: #0b1018;
}

.loading-screen p {
  margin: 18px 0 0;
  color: #cbbd98;
  letter-spacing: 0.18em;
}

.loading-crown {
  font-size: 4rem;
  color: var(--gold);
  animation: crown-pulse 1.4s ease-in-out infinite;
}

@keyframes crown-pulse {
  50% {
    transform: translateY(-8px);
    filter: drop-shadow(0 0 18px rgba(236, 190, 75, 0.75));
  }
}

.title-screen {
  isolation: isolate;
  display: grid;
  align-items: center;
  padding: clamp(28px, 6vw, 96px);
}

.title-art,
.title-vignette {
  position: absolute;
  inset: 0;
  z-index: -2;
}

.title-art {
  background:
    url("assets/story/chapter-01/opening-cell-v1.webp") center / cover no-repeat,
    #101722;
}

.title-vignette {
  z-index: -1;
  background:
    linear-gradient(90deg, rgba(4, 7, 11, 0.95) 4%, rgba(4, 7, 11, 0.54) 48%, rgba(4, 7, 11, 0.12)),
    linear-gradient(0deg, rgba(3, 5, 8, 0.8), transparent 45%);
}

.title-content {
  width: min(660px, 90vw);
  padding: clamp(26px, 4vw, 52px);
  border-left: 2px solid rgba(208, 168, 79, 0.62);
  background: linear-gradient(90deg, rgba(7, 12, 19, 0.74), transparent);
  text-shadow: 0 3px 16px #000;
}

.eyebrow,
.card-kicker {
  margin: 0 0 10px;
  color: var(--gold);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.title-content h1 {
  margin: 0;
  font-size: clamp(3.6rem, 8vw, 7.8rem);
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 0.98;
}

.title-subtitle {
  max-width: 520px;
  margin: 24px 0 34px;
  color: #e4d6b5;
  font-size: clamp(1rem, 2vw, 1.35rem);
  line-height: 1.8;
}

.title-actions,
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.button {
  min-height: 48px;
  padding: 12px 26px;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  cursor: pointer;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 800;
  letter-spacing: 0.06em;
  transition: transform 150ms ease, filter 150ms ease, background 150ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.button-primary {
  color: #211505;
  border-color: #f1d078;
  background: linear-gradient(180deg, #f3d779, #bd8624);
  box-shadow: 0 10px 34px rgba(208, 168, 79, 0.24);
}

.button-ghost {
  background: rgba(14, 22, 32, 0.72);
}

.title-hint {
  margin: 24px 0 0;
  color: #9fa9ad;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.82rem;
}

.game-overview {
  max-width: 620px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid rgba(208, 168, 79, 0.32);
  color: #b9c0c1;
  font: 0.78rem/1.55 ui-sans-serif, system-ui, sans-serif;
}

.game-overview h2 {
  margin: 0 0 8px;
  color: #ead9ad;
  font: 800 0.9rem/1.3 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.03em;
}

.game-overview p {
  margin: 0;
}

.game-overview ul {
  display: grid;
  margin: 10px 0 0;
  padding-left: 18px;
  gap: 4px;
}

.noscript-message {
  max-width: 720px;
  margin: 40px auto;
  padding: 28px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
}

.screen-header,
.game-header {
  position: relative;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 76px;
  padding: 12px clamp(16px, 4vw, 52px);
  border-bottom: 1px solid var(--panel-border);
  background: rgba(8, 13, 20, 0.94);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(16px);
}

.screen-header h2,
.game-header h2 {
  margin: 0;
}

.screen-header .eyebrow {
  margin-bottom: 2px;
}

.screen-header .icon-button:last-child,
.game-header .icon-button:last-child {
  margin-left: auto;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(208, 168, 79, 0.3);
  border-radius: 50%;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.04);
}

.icon-button:hover {
  background: rgba(208, 168, 79, 0.14);
}

.level-screen {
  padding-bottom: 60px;
}

.chapter-banner {
  display: flex;
  min-height: 260px;
  align-items: flex-end;
  padding: 38px clamp(18px, 7vw, 110px);
  background:
    linear-gradient(90deg, rgba(6, 10, 16, 0.85), transparent 70%),
    linear-gradient(0deg, #0b1018, transparent 58%),
    url("assets/ui/chapter-covers/chapter-01.webp") center 40% / cover no-repeat;
}

.chapter-banner p {
  margin: 0 0 8px;
  font-size: clamp(1.7rem, 4vw, 3rem);
}

.chapter-banner span {
  color: #c8c2b0;
}

.level-list {
  display: grid;
  width: min(1260px, calc(100% - 34px));
  margin: 34px auto 0;
  grid-template-columns: repeat(5, minmax(180px, 1fr));
  gap: 18px;
}

.level-card {
  position: relative;
  min-height: 300px;
  overflow: hidden;
  padding: 0;
  border: 1px solid rgba(208, 168, 79, 0.38);
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  background: #151d28;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.25);
  transition: transform 180ms ease, border-color 180ms ease;
}

.level-card:hover:not(:disabled) {
  z-index: 2;
  transform: translateY(-8px);
  border-color: #e2bd60;
}

.level-card:disabled {
  cursor: not-allowed;
  filter: grayscale(0.9) brightness(0.5);
}

.level-card-image {
  height: 170px;
  background-position: center;
  background-size: cover;
}

.level-card-body {
  display: block;
  padding: 18px;
}

.level-card-number,
.level-card-status {
  color: var(--gold);
  font: 800 0.68rem/1 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.16em;
}

.level-card h3 {
  margin: 10px 0 8px;
  font-size: 1.2rem;
}

.level-card p {
  margin: 0;
  color: #aeb5b8;
  font: 0.82rem/1.55 ui-sans-serif, system-ui, sans-serif;
}

.level-card-status {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 8px 10px;
  border-radius: 20px;
  color: #191103;
  background: #d4ad51;
}

.game-screen {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.game-header {
  min-height: 68px;
}

.level-heading {
  min-width: 220px;
}

.level-heading span {
  color: var(--gold);
  font: 800 0.64rem/1 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.14em;
}

.level-heading h2 {
  font-size: 1.15rem;
}

.header-metrics {
  display: flex;
  gap: 12px;
  margin-left: auto;
}

.header-metrics div {
  min-width: 78px;
  padding: 5px 12px;
  border-left: 1px solid rgba(208, 168, 79, 0.32);
}

.header-metrics span {
  display: block;
  color: #8f999d;
  font: 0.65rem/1.2 ui-sans-serif, system-ui, sans-serif;
}

.header-metrics strong {
  font: 800 1.12rem/1.3 ui-sans-serif, system-ui, sans-serif;
}

.game-layout {
  display: grid;
  min-height: 0;
  height: auto;
  grid-template-rows: minmax(0, 62fr) minmax(230px, 38fr);
}

.puzzle-zone {
  display: grid;
  min-height: 0;
  padding: 12px clamp(12px, 3vw, 38px);
  grid-template-columns: minmax(180px, 1fr) var(--board-size) minmax(180px, 1fr);
  align-items: center;
  gap: clamp(12px, 3vw, 42px);
  background:
    radial-gradient(circle at 50% 40%, rgba(50, 72, 90, 0.28), transparent 50%),
    #0d141e;
}

.objective-card,
.tactics-card {
  width: min(300px, 100%);
  padding: 18px;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.objective-card {
  justify-self: end;
}

.objective-list {
  display: grid;
  gap: 10px;
}

.objective-item {
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.objective-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font: 0.78rem/1.4 ui-sans-serif, system-ui, sans-serif;
}

.objective-row strong {
  color: var(--gold-light);
}

.progress-track {
  height: 5px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 8px;
  background: #252d35;
}

.progress-track i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #8d6322, #e6bf5c);
}

.legend {
  display: grid;
  margin-top: 16px;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  color: #929ca1;
  font: 0.67rem/1.2 ui-sans-serif, system-ui, sans-serif;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.legend-dot.blade { background: #e63843; }
.legend-dot.shield { background: #2f97e5; }
.legend-dot.heart { background: #42b763; }
.legend-dot.flame { background: #e99626; }

.board-frame {
  position: relative;
  width: var(--board-size);
  aspect-ratio: 1;
  padding: clamp(7px, 1vw, 12px);
  border: 1px solid #997437;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 30%),
    #0a1018;
  box-shadow:
    0 0 0 5px #17130e,
    0 0 0 6px #775b2d,
    0 30px 70px rgba(0, 0, 0, 0.48);
}

.board-frame::before,
.board-frame::after {
  position: absolute;
  z-index: 3;
  top: -8px;
  width: 28px;
  height: 28px;
  content: "";
  border: 2px solid #c39a49;
  transform: rotate(45deg);
  background: #19140d;
}

.board-frame::before { left: -8px; }
.board-frame::after { right: -8px; }

.board {
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  gap: 2px;
  background: #060a0f;
}

.gem-cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 2px;
  place-items: center;
  border: 1px solid rgba(176, 152, 101, 0.13);
  border-radius: 4px;
  cursor: pointer;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.045), transparent 50%),
    #111a24;
  transition: transform 110ms ease, background 110ms ease, box-shadow 110ms ease;
}

.gem-cell:hover:not(:disabled) {
  z-index: 2;
  transform: scale(1.05);
  background-color: #1c2934;
}

.gem-cell.is-selected {
  z-index: 4;
  transform: scale(1.08);
  border-color: #ffe99b;
  box-shadow: 0 0 0 2px #d09c37, 0 0 22px rgba(255, 214, 105, 0.68);
}

.gem-cell.is-blocked {
  cursor: not-allowed;
  background: #0b0d10;
}

.gem-cell.is-collapsed {
  opacity: 0.25;
  filter: grayscale(1);
}

.gem-icon {
  position: absolute;
  z-index: 1;
  inset: 8%;
  display: block;
  width: 84%;
  height: 84%;
  min-width: 0;
  min-height: 0;
  overflow: visible;
  filter: drop-shadow(0 5px 4px rgba(0, 0, 0, 0.45));
  pointer-events: none;
}

.gem-glow {
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  opacity: 0.2;
  filter: blur(8px);
}

.gem-cell[data-gem="blade"] .gem-glow { background: #f12f3f; }
.gem-cell[data-gem="shield"] .gem-glow { background: #29a4ff; }
.gem-cell[data-gem="flame"] .gem-glow { background: #ffad32; }
.gem-cell[data-gem="hourglass"] .gem-glow { background: #ae5cf2; }
.gem-cell[data-gem="wing"] .gem-glow { background: #ebf5ff; }
.gem-cell[data-gem="heart"] .gem-glow { background: #3bd367; }
.gem-cell[data-gem="crown"] .gem-glow { background: #ffdd55; opacity: 0.5; }

.obstacle-icon {
  position: absolute;
  z-index: 3;
  inset: 2%;
  width: 96%;
  height: 96%;
  pointer-events: none;
}

.gem-cell:not([data-obstacle]) .obstacle-icon {
  display: none;
}

.special-mark {
  position: absolute;
  z-index: 2;
  right: 5%;
  bottom: 4%;
  display: none;
  min-width: 18px;
  min-height: 18px;
  place-items: center;
  border: 1px solid #fff2b0;
  border-radius: 50%;
  color: #251a07;
  background: #d9b34f;
  font: 900 0.6rem/1 ui-sans-serif, system-ui, sans-serif;
}

.gem-cell[data-special] .special-mark {
  display: grid;
}

.combo-banner {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 42%;
  min-width: 180px;
  padding: 10px 18px;
  border: 1px solid #f2ce72;
  border-radius: 4px;
  opacity: 0;
  color: #fff1b8;
  text-align: center;
  transform: translate(-50%, -50%) scale(0.8);
  background: rgba(80, 22, 33, 0.92);
  pointer-events: none;
}

.combo-banner.is-active {
  animation: combo-pop 850ms ease both;
}

@keyframes combo-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.65); }
  25%, 70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -65%) scale(1.05); }
}

.intent-display {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid rgba(219, 63, 74, 0.35);
  background: rgba(94, 19, 29, 0.28);
}

.intent-display svg {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
}

.intent-display strong,
.intent-display span {
  display: block;
}

.intent-display strong {
  margin-bottom: 4px;
}

.intent-display span {
  color: #a7b0b4;
  font: 0.7rem/1.2 ui-sans-serif, system-ui, sans-serif;
}

.enemy-timer {
  margin-top: 10px;
}

.enemy-timer-copy {
  display: flex;
  margin-bottom: 5px;
  align-items: center;
  justify-content: space-between;
  color: #bbb4a5;
  font: 0.66rem/1 ui-sans-serif, system-ui, sans-serif;
}

.enemy-timer-copy strong {
  color: #ff9e78;
  font-variant-numeric: tabular-nums;
}

.enemy-timer-track {
  height: 7px;
  overflow: hidden;
  border: 1px solid rgba(219, 63, 74, 0.5);
  background: rgba(20, 10, 13, 0.9);
}

.enemy-timer-track i {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #8b1726, #ff784f);
  box-shadow: 0 0 12px rgba(255, 90, 68, 0.65);
  transition: width 100ms linear;
}

.ultimate-button {
  display: flex;
  width: 100%;
  margin-top: 14px;
  padding: 12px;
  align-items: center;
  gap: 12px;
  border: 1px solid rgba(208, 168, 79, 0.5);
  border-radius: 5px;
  cursor: pointer;
  text-align: left;
  background: linear-gradient(135deg, rgba(208, 168, 79, 0.2), rgba(81, 28, 42, 0.4));
}

.ultimate-button:disabled {
  cursor: not-allowed;
  opacity: 0.44;
}

.ultimate-button:not(:disabled) {
  animation: ultimate-ready 1.2s ease-in-out infinite alternate;
}

@keyframes ultimate-ready {
  to { box-shadow: 0 0 24px rgba(239, 196, 76, 0.45); }
}

.ultimate-icon {
  color: var(--gold);
  font-size: 2rem;
}

.ultimate-button strong,
.ultimate-button small {
  display: block;
}

.ultimate-button small {
  margin-top: 3px;
  color: #aab2b5;
}

.battle-zone {
  position: relative;
  isolation: isolate;
  display: grid;
  min-height: 230px;
  overflow: hidden;
  grid-template-columns: 1fr minmax(180px, 0.45fr) 1fr;
  border-top: 2px solid #80612e;
  background-position: center 78%;
  background-size: cover;
  box-shadow: inset 0 20px 60px rgba(0, 0, 0, 0.45);
}

.battle-zone::after {
  position: absolute;
  z-index: -1;
  inset: 0;
  content: "";
  background:
    linear-gradient(90deg, rgba(5, 8, 12, 0.55), transparent 30%, transparent 70%, rgba(5, 8, 12, 0.55)),
    linear-gradient(0deg, rgba(4, 7, 10, 0.45), transparent 52%);
}

.battle-light {
  position: absolute;
  left: 50%;
  top: -30%;
  width: 40%;
  height: 90%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse, rgba(255, 214, 139, 0.16), transparent 68%);
  pointer-events: none;
}

.combatant {
  position: relative;
  min-width: 0;
}

.sprite {
  position: absolute;
  bottom: 0;
  width: auto;
  height: calc(100% - 8px);
  max-height: 400px;
  aspect-ratio: 1;
  background-repeat: no-repeat;
  background-color: transparent;
  filter: drop-shadow(0 16px 14px rgba(0, 0, 0, 0.7));
  transition: filter 140ms ease;
}

.sprite-player {
  left: clamp(6px, 5vw, 120px);
  background-image: url("assets/atlases/princess-chapter-01.webp");
  background-position: 0% 0%;
  background-size: 400% 200%;
}

.sprite-enemy {
  right: clamp(6px, 5vw, 120px);
  background-image: url("assets/atlases/enemies-chapter-01.webp");
  background-position: 0% 0%;
  background-size: 400% 300%;
}

.sprite.is-attacking {
  animation: attack-lunge 480ms cubic-bezier(0.22, 0.75, 0.22, 1);
}

.sprite-enemy.is-attacking {
  animation-name: enemy-attack-lunge;
}

.sprite.is-hit {
  animation: hit-flash 380ms ease;
}

.sprite-player.is-ultimate {
  animation: ultimate-flare 950ms ease;
}

@keyframes attack-lunge {
  45% { transform: translateX(8%); }
}

@keyframes enemy-attack-lunge {
  45% { transform: translateX(-8%); }
}

@keyframes hit-flash {
  25% { filter: brightness(2.4) saturate(0.2) drop-shadow(0 0 18px #fff); }
  55% { transform: translateX(3%); }
}

@keyframes ultimate-flare {
  45% { filter: brightness(1.6) drop-shadow(0 0 36px #efc750); transform: translateY(-2%); }
}

.combat-hud {
  position: absolute;
  z-index: 4;
  top: 16px;
  width: min(310px, 72%);
  font-family: ui-sans-serif, system-ui, sans-serif;
}

.player-hud { left: 24px; }
.enemy-hud { right: 24px; text-align: right; }

.combat-hud strong {
  display: block;
  margin-bottom: 5px;
  font-size: 0.82rem;
}

.combat-hud > span {
  color: #d8d3c6;
  font-size: 0.66rem;
}

.bar {
  height: 8px;
  overflow: hidden;
  border: 1px solid #8b723e;
  background: #171b20;
}

.bar i {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #741725, #e14b55);
  transition: width 350ms ease;
}

.enemy-bar i {
  margin-left: auto;
}

.shield-value,
.armor-value {
  margin-left: 8px;
  color: #76caff !important;
}

.battle-center {
  position: relative;
  z-index: 5;
  display: grid;
  place-items: center;
}

.battle-message {
  align-self: end;
  max-width: 340px;
  margin-bottom: 20px;
  padding: 8px 13px;
  border: 1px solid rgba(208, 168, 79, 0.28);
  border-radius: 3px;
  color: #d9d2c0;
  text-align: center;
  background: rgba(7, 11, 17, 0.76);
  font: 0.72rem/1.4 ui-sans-serif, system-ui, sans-serif;
}

.damage-number {
  position: absolute;
  top: 34%;
  opacity: 0;
  color: #fff2b0;
  font: 900 clamp(1.6rem, 4vw, 3rem)/1 ui-sans-serif, system-ui, sans-serif;
  text-shadow: 0 3px 0 #6a111d, 0 0 20px #e74b4b;
  pointer-events: none;
}

.damage-number.is-active {
  animation: damage-float 700ms ease-out;
}

@keyframes damage-float {
  0% { opacity: 0; transform: translateY(20px) scale(0.6); }
  25% { opacity: 1; transform: translateY(0) scale(1.15); }
  100% { opacity: 0; transform: translateY(-45px) scale(1); }
}

.dialog-backdrop {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  padding: 22px;
  place-items: center;
  background: rgba(3, 6, 10, 0.82);
  backdrop-filter: blur(10px);
}

.dialog {
  width: min(920px, 94vw);
  overflow: hidden;
  border: 1px solid #9e7c39;
  border-radius: 8px;
  background: #111923;
  box-shadow: var(--shadow);
}

.story-dialog {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
}

.story-visual {
  min-height: 500px;
  background: url("assets/story/chapter-01/opening-cell-v1.webp") 35% center / cover no-repeat;
}

.story-copy {
  display: flex;
  padding: clamp(28px, 5vw, 58px);
  flex-direction: column;
  justify-content: center;
}

.story-copy h2,
.result-dialog h2 {
  margin: 0 0 20px;
  font-size: clamp(2rem, 5vw, 3.5rem);
}

.story-copy p:not(.eyebrow),
.result-dialog > p:not(.eyebrow) {
  color: #bbb6aa;
  line-height: 1.8;
}

.story-copy .button {
  align-self: flex-start;
  margin-top: 18px;
}

.result-dialog {
  max-width: 660px;
  padding: clamp(28px, 6vw, 60px);
  text-align: center;
}

.result-emblem {
  margin-bottom: 10px;
  color: var(--gold);
  font-size: 4rem;
}

.result-stats {
  display: grid;
  margin: 28px 0;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: rgba(208, 168, 79, 0.18);
}

.result-stats div {
  padding: 18px 8px;
  background: #0e151e;
}

.result-stats span,
.result-stats strong {
  display: block;
  font-family: ui-sans-serif, system-ui, sans-serif;
}

.result-stats span {
  color: #949da1;
  font-size: 0.7rem;
}

.result-stats strong {
  margin-top: 6px;
  font-size: 1.3rem;
}

.result-dialog .dialog-actions {
  justify-content: center;
}

.screen-shake {
  animation: screen-shake 280ms ease;
}

@keyframes screen-shake {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

@media (max-width: 1050px) {
  :root {
    --board-size: min(calc(62vh - 66px), 620px, calc(100vw - 330px));
  }

  .puzzle-zone {
    grid-template-columns: 145px var(--board-size) 145px;
    gap: 12px;
  }

  .objective-card,
  .tactics-card {
    padding: 12px;
  }

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

  .level-list {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 760px) {
  :root {
    --board-size: min(calc(100vw - 20px), 58vh);
  }

  .title-screen {
    align-items: end;
    padding: 18px;
  }

  .title-art {
    background-position: 48% center;
  }

  .title-vignette {
    background: linear-gradient(0deg, rgba(3, 5, 8, 0.97) 12%, rgba(3, 5, 8, 0.45) 80%);
  }

  .title-content {
    width: 100%;
    padding: 26px 18px;
    border-left: 0;
    border-top: 1px solid rgba(208, 168, 79, 0.55);
    background: linear-gradient(0deg, rgba(7, 12, 19, 0.86), transparent);
  }

  .game-overview {
    font-size: 0.74rem;
  }

  .title-content h1 {
    font-size: clamp(3.2rem, 17vw, 5.2rem);
  }

  .level-list {
    grid-template-columns: 1fr;
  }

  .level-card {
    display: grid;
    min-height: 156px;
    grid-template-columns: 42% 1fr;
  }

  .level-card-image {
    height: 100%;
  }

  .game-screen {
    grid-template-rows: auto auto;
    min-height: 100vh;
    height: auto;
    overflow: visible;
  }

  .game-header {
    position: sticky;
    top: 0;
  }

  .level-heading {
    min-width: 0;
  }

  .header-metrics div {
    min-width: 52px;
    padding: 4px 7px;
  }

  .game-layout {
    height: auto;
    min-height: calc(100vh - 68px);
    grid-template-rows: auto 260px;
  }

  .puzzle-zone {
    padding: 10px;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 8px;
  }

  .board-frame {
    grid-column: 1 / -1;
    grid-row: 1;
    justify-self: center;
  }

  .objective-card,
  .tactics-card {
    width: 100%;
    height: 128px;
    overflow: auto;
  }

  .objective-card {
    grid-column: 1;
    grid-row: 2;
  }

  .tactics-card {
    grid-column: 2;
    grid-row: 2;
  }

  .legend {
    display: none;
  }

  .intent-display {
    padding: 7px;
  }

  .intent-display svg {
    width: 34px;
    height: 34px;
  }

  .ultimate-button {
    margin-top: 7px;
    padding: 7px;
  }

  .battle-zone {
    min-height: 260px;
    grid-template-columns: 1fr 0.25fr 1fr;
  }

  .sprite-player { left: 4px; }
  .sprite-enemy { right: 4px; }

  .combat-hud {
    width: 76%;
  }

  .player-hud { left: 8px; }
  .enemy-hud { right: 8px; }

  .battle-message {
    display: none;
  }

  .story-dialog {
    grid-template-columns: 1fr;
  }

  .story-visual {
    min-height: 240px;
  }
}

@media (max-width: 430px) {
  .game-header {
    gap: 8px;
    padding-inline: 8px;
  }

  .game-header .icon-button:last-child {
    display: none;
  }

  .level-heading h2 {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .header-metrics {
    gap: 2px;
  }

  .header-metrics div {
    border-left: 0;
  }

  .board {
    gap: 1px;
  }

  .gem-cell {
    border-radius: 2px;
  }

  .objective-row {
    font-size: 0.7rem;
  }

  .result-stats {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
