@import url("https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:wght@400;700&family=Chewy&display=swap");

:root {
  --ink: #332757;
  --paper: #fff9e9;
  --cream: #f5ebce;
  --stone: #d8c89f;
  --stone-light: #efe1bd;
  --purple: #62509a;
  --purple-dark: #493b7a;
  --mint: #77c9ae;
  --mint-dark: #318a74;
  --pink: #ee7188;
  --gold: #f5bd3c;
  --danger: #c74460;
  --line: #8b7e9d;
  font-family: "Atkinson Hyperlegible", system-ui, sans-serif;
  color: var(--ink);
  background: #b9dfd3;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,.28) 0 3px, transparent 4px),
    radial-gradient(circle at 85% 72%, rgba(51,39,87,.08) 0 2px, transparent 3px),
    #b9dfd3;
  background-size: 45px 45px, 38px 38px;
}

button, a, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: wait; }

.page-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 40px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.brand {
  display: inline-block;
  color: var(--ink);
  text-decoration: none;
  font: 2rem/1 "Chewy", cursive;
  transform: rotate(-2deg);
}

.brand-no {
  margin-left: 3px;
  color: var(--pink);
  text-shadow: 2px 2px 0 var(--paper);
}

.plain-button,
.primary-button {
  min-height: 44px;
  padding: 8px 15px;
  border: 2px solid var(--ink);
  border-radius: 13px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 3px 3px 0 rgba(51,39,87,.2);
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, filter .12s;
}

.plain-button:hover,
.primary-button:hover {
  transform: translateY(-2px) rotate(-.5deg);
  box-shadow: 4px 5px 0 rgba(51,39,87,.16);
}

.plain-button:focus-visible,
.primary-button:focus-visible,
.arrow-piece:focus-visible,
.text-link:focus-visible {
  outline: 4px solid white;
  outline-offset: 3px;
}

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  max-width: 1020px;
  margin: 0 auto 14px;
}

.eyebrow {
  margin: 0;
  color: var(--purple-dark);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1, h2 {
  font-family: "Chewy", cursive;
  letter-spacing: .02em;
}

h1 {
  margin: -2px 0 0;
  font-size: clamp(2.8rem, 7vw, 5.3rem);
  font-weight: 400;
  line-height: .92;
}

h1 span {
  color: var(--pink);
  text-shadow: 2px 2px 0 var(--paper);
}

.hero-copy {
  margin: 8px 0 0;
  font-weight: 700;
}

.daily-strip {
  display: flex;
  gap: 8px;
}

.daily-strip > div {
  min-width: 92px;
  padding: 9px 13px;
  border: 2px solid rgba(51,39,87,.45);
  border-radius: 13px 16px 12px 15px;
  background: rgba(255,249,233,.72);
  text-align: center;
}

small,
.label {
  display: block;
  color: #665d74;
  font-size: .67rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.daily-strip strong {
  display: block;
  margin-top: 2px;
}

.game-card {
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 24px 20px 27px 21px;
  background: var(--paper);
  box-shadow: 8px 9px 0 rgba(51,39,87,.18);
}

.puzzle-library-bar {
  display: grid;
  grid-template-columns: 44px minmax(220px, 340px) auto 44px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 2px solid var(--ink);
  color: white;
  background: var(--purple-dark);
}

.puzzle-choice small {
  margin: 0 0 3px 3px;
  color: #dcd4f6;
}

.puzzle-choice select {
  width: 100%;
  min-height: 44px;
  padding: 7px 36px 7px 11px;
  border: 2px solid var(--ink);
  border-radius: 11px;
  color: var(--ink);
  background: var(--paper);
  font-weight: 700;
  cursor: pointer;
}

.puzzle-step {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 12px;
  color: var(--ink);
  background: var(--gold);
  box-shadow: 2px 2px 0 #2b214b;
  font-size: 1.35rem;
  font-weight: 700;
  cursor: pointer;
}

.puzzle-step:hover { transform: translateY(-1px); }

.puzzle-step:focus-visible,
.puzzle-choice select:focus-visible {
  outline: 4px solid white;
  outline-offset: 2px;
}

.puzzle-difficulty {
  min-width: 155px;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-align: center;
  text-transform: capitalize;
}

.status-row {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  align-items: center;
  gap: 32px;
  padding: 13px 22px;
  border-bottom: 2px dashed #cabfca;
}

.siege-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mode-badge {
  flex: 0 0 auto;
  padding: 4px 9px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  color: white;
  background: var(--mint-dark);
  box-shadow: 2px 2px 0 rgba(51,39,87,.16);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  transform: rotate(-1deg);
}

#siege-status {
  font-size: 1rem;
}

.numbers {
  display: flex;
  gap: 24px;
  text-align: center;
}

.numbers strong {
  display: block;
  font-size: 1.1rem;
}

#rating-preview {
  color: #d18b00;
  letter-spacing: .04em;
}

.threat-hud {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 11px 22px 9px;
  background: #f5edda;
}

.threat-hud[data-count="1"] {
  grid-template-columns: minmax(0, 620px);
  justify-content: center;
}

.threat-hud[data-count="3"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.threat-card {
  position: relative;
  padding: 9px 11px 8px;
  border: 2px solid #9c8fa3;
  border-radius: 14px 11px 16px 12px;
  background: #fffdf6;
  box-shadow: 2px 3px 0 rgba(51,39,87,.11);
}

.threat-card:nth-child(2) {
  transform: rotate(.3deg);
}

.threat-heading {
  display: flex;
  align-items: center;
  gap: 7px;
}

.threat-heading strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.threat-letter {
  display: grid;
  flex: 0 0 25px;
  place-items: center;
  height: 25px;
  border: 2px solid var(--ink);
  border-radius: 50% 45% 55% 43%;
  color: var(--ink);
  background: var(--mint);
  font: 1rem/1 "Chewy", cursive;
}

.visual-patched .threat-letter {
  background: #fab1a3;
}

.visual-crowned .threat-letter {
  background: #b9c4ff;
}

.distance-word {
  margin-left: auto;
  padding: 3px 7px;
  border-radius: 999px;
  color: white;
  background: var(--purple);
  font-size: .69rem;
  font-weight: 700;
  white-space: nowrap;
}

.distance-word-1,
.distance-word-0 {
  background: var(--danger);
  animation: warning-pulse 1.1s ease-in-out infinite;
}

.threat-facts {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 7px;
  margin-top: 7px;
}

.threat-facts span {
  min-width: 0;
  padding-left: 7px;
  border-left: 1px dashed #c9bfca;
}

.threat-facts span:first-child { padding-left: 0; border-left: 0; }
.threat-facts b { display: block; overflow: hidden; font-size: .75rem; text-overflow: ellipsis; text-transform: capitalize; white-space: nowrap; }

.distance-track {
  display: flex;
  gap: 4px;
  margin-top: 7px;
}

.distance-track i {
  flex: 1;
  height: 7px;
  border: 1px solid var(--purple);
  border-radius: 999px;
  background: #e5dfe6;
}

.distance-track i.filled {
  background: var(--mint);
  box-shadow: inset 0 1px rgba(255,255,255,.55);
}

.mini-route {
  position: absolute;
  top: -10px;
  right: 9px;
  display: none;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--purple-dark);
  background: var(--paper);
  font-size: .68rem;
}

.mini-route span.current { color: var(--danger); font-weight: 700; }
.mini-route b { color: #998ba1; font-weight: 400; }

.wall-status {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  padding: 7px 22px 8px;
  border-top: 1px dashed #cbbfcb;
  background: #f5edda;
}

.wall-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  padding: 5px 7px;
  border: 2px solid #8d8193;
  border-radius: 9px 12px 8px 11px;
  background: #fffdf6;
  text-transform: capitalize;
}

.wall-chip b {
  overflow: hidden;
  font-size: .68rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wall-chip em {
  color: #61576b;
  font-size: .62rem;
  font-style: normal;
  font-weight: 700;
}

.wall-chip.is-damaged {
  border-color: #bd5f42;
  background: #ffe0c1;
}

.wall-chip.is-damaged em::before {
  content: "";
}

.wall-chip.is-broken {
  border-style: dashed;
  border-color: var(--danger);
  background: #ffd4d4;
}

.wall-chip.is-broken em::before {
  content: "✖ ";
}

.siege-stage {
  padding: 13px 12px 7px;
  background:
    radial-gradient(circle at 50% 50%, #fffdf7 0 38%, #f0e5cc 76%, #e8dcc2 100%);
}

.castle-arena {
  position: relative;
  width: min(100%, 750px);
  aspect-ratio: 1;
  margin: 0 auto;
}

.castle-shell {
  position: absolute;
  z-index: 2;
  inset: 16%;
  filter: drop-shadow(5px 7px 0 rgba(51,39,87,.18));
  transition: filter .2s;
}

.board {
  --grid-size: 5;
  position: absolute;
  z-index: 3;
  inset: 10%;
  display: grid;
  grid-template: repeat(var(--grid-size), 1fr) / repeat(var(--grid-size), 1fr);
  gap: 5px;
  padding: 7px;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 14px 11px 16px 12px;
  background-color: #eadcbb;
  background-image:
    linear-gradient(rgba(73,59,122,.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(73,59,122,.07) 1px, transparent 1px),
    radial-gradient(circle at 60% 25%, rgba(255,255,255,.45), transparent 38%);
  background-size:
    calc(100% / var(--grid-size)) calc(100% / var(--grid-size)),
    calc(100% / var(--grid-size)) calc(100% / var(--grid-size)),
    auto;
  box-shadow: inset 0 0 0 4px #f7ebc9;
}

.castle-wall {
  position: absolute;
  z-index: 5;
  border: 3px solid var(--ink);
  background:
    linear-gradient(90deg, transparent 47%, rgba(51,39,87,.12) 48% 52%, transparent 53%),
    linear-gradient(var(--stone-light), var(--stone));
  box-shadow: inset 0 3px rgba(255,255,255,.35);
}

.castle-wall::before {
  content: "";
  position: absolute;
  background: repeating-linear-gradient(90deg, var(--stone-light) 0 13%, transparent 13% 20%);
}

.castle-wall::after {
  content: "";
  position: absolute;
  z-index: 3;
  inset: 8%;
  pointer-events: none;
  opacity: 0;
}

.castle-wall.is-damaged::after {
  content: "⚡";
  display: grid;
  place-items: center;
  opacity: 1;
  color: var(--ink);
  font: clamp(1.35rem, 3vw, 2.2rem)/1 "Chewy", cursive;
  text-shadow: 3px 2px 0 #f6d2aa;
  background:
    linear-gradient(56deg, transparent 0 43%, var(--ink) 44% 49%, transparent 50%) 48% 20% / 42% 55% no-repeat,
    linear-gradient(124deg, transparent 0 45%, var(--ink) 46% 51%, transparent 52%) 60% 67% / 36% 46% no-repeat,
    radial-gradient(circle, #8b674e 0 32%, transparent 35%) 26% 92% / 12% 28% no-repeat,
    radial-gradient(circle, #b58761 0 34%, transparent 37%) 72% 94% / 15% 25% no-repeat;
}

.wall-top.is-damaged::after,
.wall-bottom.is-damaged::after {
  transform: translateX(-28%);
}

.castle-wall.is-broken {
  border-style: dashed;
  background:
    radial-gradient(ellipse at center, #352b44 0 22%, transparent 24%),
    linear-gradient(90deg, transparent 47%, rgba(51,39,87,.18) 48% 52%, transparent 53%),
    linear-gradient(#c29d79, #a57e63);
  box-shadow: inset 0 0 0 4px rgba(51,39,87,.16);
}

.castle-wall.is-broken::after {
  content: "";
  inset: -12%;
  opacity: 1;
  background:
    linear-gradient(135deg, transparent 0 32%, #352b44 33% 67%, transparent 68%) 50% 46% / 35% 75% no-repeat,
    radial-gradient(circle, #75553f 0 40%, transparent 43%) 28% 93% / 17% 38% no-repeat,
    radial-gradient(circle, #a77c5a 0 42%, transparent 45%) 57% 97% / 20% 34% no-repeat,
    radial-gradient(circle, #75553f 0 40%, transparent 43%) 75% 88% / 15% 29% no-repeat;
}

.wall-left.is-damaged::after,
.wall-right.is-damaged::after,
.wall-left.is-broken::after,
.wall-right.is-broken::after {
  transform: rotate(90deg) translateX(-28%);
}

.wall-top,
.wall-bottom {
  left: 5%;
  width: 90%;
  height: 11%;
}

.wall-left,
.wall-right {
  top: 5%;
  width: 11%;
  height: 90%;
}

.wall-top {
  top: 0;
  border-radius: 11px 11px 5px 5px;
  transform: rotate(-.5deg);
}

.wall-top::before {
  left: 3%;
  right: 3%;
  bottom: 100%;
  height: 34%;
}

.wall-right {
  right: 0;
  border-radius: 5px 11px 11px 5px;
  transform: rotate(.4deg);
}

.wall-right::before {
  top: 3%;
  bottom: 3%;
  right: 100%;
  width: 34%;
  background: repeating-linear-gradient(var(--stone-light) 0 13%, transparent 13% 20%);
}

.wall-bottom {
  bottom: 0;
  border-radius: 5px 5px 11px 11px;
  transform: rotate(.4deg);
}

.wall-bottom::before {
  left: 3%;
  right: 3%;
  top: 100%;
  height: 34%;
}

.wall-left {
  left: 0;
  border-radius: 11px 5px 5px 11px;
  transform: rotate(-.4deg);
}

.wall-left::before {
  top: 3%;
  bottom: 3%;
  left: 100%;
  width: 34%;
  background: repeating-linear-gradient(var(--stone-light) 0 13%, transparent 13% 20%);
}

.firing-port {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 13px;
  height: 8px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--purple-dark);
  transform: translate(-50%, -50%);
}

.wall-left .firing-port,
.wall-right .firing-port {
  width: 8px;
  height: 13px;
}

.tower {
  position: absolute;
  z-index: 8;
  width: 18%;
  aspect-ratio: 1;
  border: 3px solid var(--ink);
  border-radius: 20% 20% 45% 42%;
  background:
    linear-gradient(90deg, transparent 46%, rgba(51,39,87,.13) 47% 53%, transparent 54%),
    var(--stone-light);
  box-shadow: inset 0 4px rgba(255,255,255,.4), 2px 3px 0 rgba(51,39,87,.14);
}

.tower::before {
  content: "";
  position: absolute;
  left: -3px;
  right: -3px;
  top: -15%;
  height: 28%;
  border: 3px solid var(--ink);
  border-bottom-width: 2px;
  border-radius: 8px 8px 2px 2px;
  background: repeating-linear-gradient(90deg, var(--stone-light) 0 20%, var(--purple-dark) 20% 29%);
}

.tower-nw { top: -3%; left: -3%; transform: rotate(-2deg); }
.tower-ne { top: -3%; right: -3%; transform: rotate(2deg); }
.tower-se { right: -3%; bottom: -3%; transform: rotate(-1deg); }
.tower-sw { bottom: -3%; left: -3%; transform: rotate(1deg); }

.castle-flag {
  position: absolute;
  z-index: 10;
  top: -13%;
  display: grid;
  place-items: center;
  width: 9%;
  aspect-ratio: .8;
  border: 2px solid var(--ink);
  border-radius: 3px 9px 9px 3px;
  color: #fff7c4;
  background: var(--pink);
  box-shadow: -3px 0 0 -1px var(--ink);
  font-size: clamp(.55rem, 1.6vw, 1.1rem);
  transform-origin: bottom left;
}

.flag-left { left: 6%; transform: rotate(-5deg); }
.flag-right { right: 6%; transform: rotate(5deg); }

.arrow-piece {
  position: relative;
  z-index: 3;
  width: 100%;
  height: 100%;
  min-width: 42px;
  min-height: 42px;
  padding: 0;
  border: 2px solid #51476b;
  border-radius: 12px 9px 13px 10px;
  color: white;
  background: var(--purple);
  box-shadow: inset 2px 2px 0 rgba(255,255,255,.24), 2px 3px 0 #403667;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  transition: transform .15s, filter .15s;
}

.arrow-piece > * {
  pointer-events: none;
}

.arrow-piece:nth-child(3n) { transform: rotate(1deg); }
.arrow-piece:nth-child(4n) { transform: rotate(-1.5deg); }

.arrow-piece:hover {
  z-index: 6;
  filter: brightness(1.1);
  transform: translateY(-2px) rotate(-1deg);
}

.arrow-glyph {
  display: block;
  font: 700 clamp(1.4rem, 3.5vw, 2.35rem)/1 system-ui, sans-serif;
  text-shadow: 1px 2px 0 rgba(0,0,0,.2);
}

.arrow-piece.golden {
  border: 3px double #774f00;
  color: var(--ink);
  background: var(--gold);
  box-shadow: inset 2px 2px 0 #fff2a8, 2px 3px 0 #a76800;
}

.gold-shine {
  position: absolute;
  right: 3px;
  top: 0;
  color: #fff9d5;
  font-size: .9rem;
  text-shadow: 0 1px 0 #9b5d00;
}

.arrow-piece.is-blocked {
  z-index: 20;
  animation: blocked-collision .72s ease-in-out;
}

.arrow-piece.is-leaving {
  z-index: 20;
  pointer-events: none;
  animation: leave .34s ease-in forwards;
}

.approach-zones {
  position: absolute;
  z-index: 0;
  display: flex;
  gap: 3px;
}

.approach-zones i {
  display: grid;
  flex: 1;
  min-width: 0;
  min-height: 0;
  place-content: center;
  border: 1px solid rgba(73,59,122,.32);
  border-radius: 7px;
  color: rgba(73,59,122,.72);
  background: rgba(255,249,233,.72);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.38);
  font-style: normal;
  line-height: 1;
  text-align: center;
}

.approach-zones i:nth-child(2) {
  border-color: rgba(73,59,122,.42);
  background: rgba(239,225,189,.82);
}

.approach-zones i:nth-child(3) {
  border-color: rgba(199,68,96,.48);
  color: rgba(122,45,66,.82);
  background: rgba(255,220,205,.78);
}

.approach-zones b {
  display: block;
  font: .74rem/1 "Chewy", cursive;
}

.approach-zones span {
  display: block;
  margin-top: 2px;
  font-size: .42rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.zones-top,
.zones-bottom {
  left: 35%;
  width: 30%;
  height: 20%;
  flex-direction: column;
}

.zones-left,
.zones-right {
  top: 35%;
  width: 20%;
  height: 30%;
}

.zones-top { top: 0; }
.zones-right { right: 0; flex-direction: row-reverse; }
.zones-bottom { bottom: 0; flex-direction: column-reverse; }
.zones-left { left: 0; }

.threat-layer {
  position: absolute;
  z-index: 12;
  inset: 0;
  pointer-events: none;
}

.siege-threat {
  --tx: 0%;
  --ty: 0%;
  --lane-shift: 0px;
  position: absolute;
  width: 66px;
  height: 70px;
  filter: drop-shadow(2px 4px 0 rgba(51,39,87,.2));
  transform: translate(var(--tx), var(--ty));
  transition: left .27s ease, right .27s ease, top .27s ease, bottom .27s ease, transform .27s ease;
}

.siege-threat strong {
  position: absolute;
  top: 54px;
  left: 50%;
  width: 23px;
  height: 23px;
  padding: 2px;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 999px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 1px 2px 0 rgba(51,39,87,.15);
  font-size: 0;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
  transform: translateX(-50%);
}

.siege-threat strong::after {
  font: .76rem/1 "Chewy", cursive;
}

.siege-threat.visual-horned strong::after { content: "A"; }
.siege-threat.visual-patched strong::after { content: "B"; }
.siege-threat.visual-crowned strong::after { content: "C"; }

.threat-body {
  position: absolute;
  inset: 9px 4px 9px;
  border: 3px solid var(--ink);
  border-radius: 46% 54% 42% 57%;
  background: var(--mint);
}

.threat-accessory::before,
.threat-accessory::after {
  content: "";
  position: absolute;
  z-index: -1;
  top: 1px;
  width: 17px;
  height: 22px;
  border: 3px solid var(--ink);
  border-radius: 80% 10%;
  background: var(--pink);
  transform: rotate(-22deg);
}

.threat-accessory::before { left: 5px; }
.threat-accessory::after { right: 5px; transform: scaleX(-1) rotate(-22deg); }

.threat-eye {
  position: absolute;
  top: 14px;
  width: 8px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink);
}

.eye-a { left: 13px; }
.eye-b { right: 13px; }

.threat-eye::before,
.threat-eye::after {
  content: "";
  position: absolute;
  left: 3px;
  top: -2px;
  width: 3px;
  height: 14px;
  border-radius: 3px;
  background: var(--ink);
  opacity: 0;
}

.threat-mouth {
  position: absolute;
  left: 50%;
  bottom: 7px;
  width: 17px;
  height: 8px;
  border-bottom: 3px solid var(--ink);
  border-radius: 50%;
  transform: translateX(-50%);
}

.threat-feet::before,
.threat-feet::after {
  content: "";
  position: absolute;
  z-index: -1;
  bottom: 7px;
  width: 21px;
  height: 10px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--mint);
}

.threat-feet::before { left: 8px; }
.threat-feet::after { right: 8px; }

.visual-patched .threat-body,
.visual-patched .threat-feet::before,
.visual-patched .threat-feet::after {
  background: #fab1a3;
}

.visual-crowned .threat-body,
.visual-crowned .threat-feet::before,
.visual-crowned .threat-feet::after {
  background: #aebcff;
}

.visual-patched .threat-accessory::before {
  top: 4px;
  left: 2px;
  width: 24px;
  height: 14px;
  border-radius: 50% 50% 10% 10%;
  background: var(--gold);
  transform: rotate(-12deg);
}

.visual-patched .threat-accessory::after {
  top: 2px;
  right: 6px;
  width: 13px;
  height: 19px;
  background: var(--purple);
  transform: rotate(28deg);
}

.visual-crowned .threat-accessory::before,
.visual-crowned .threat-accessory::after {
  top: 0;
  width: 21px;
  height: 18px;
  border-radius: 7px 7px 2px 2px;
  background: var(--gold);
}

.visual-crowned .threat-accessory::before {
  left: 11px;
  transform: rotate(-13deg);
}

.visual-crowned .threat-accessory::after {
  right: 11px;
  transform: rotate(13deg);
}

.threat-patch { display: none; }

.visual-patched .threat-patch {
  position: absolute;
  right: 9px;
  top: 10px;
  display: block;
  width: 15px;
  height: 13px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--purple-dark);
  transform: rotate(12deg);
}

.visual-patched .eye-b { opacity: 0; }

/* Threat position: distance three is farthest; zero touches the castle. */
.siege-threat.side-top {
  left: 50%;
  top: var(--side-position);
  --tx: calc(-50% + var(--lane-shift));
}

.siege-threat.side-bottom {
  left: 50%;
  bottom: var(--side-position);
  --tx: calc(-50% + var(--lane-shift));
}

.siege-threat.side-left {
  left: var(--side-position);
  top: 50%;
  --ty: calc(-50% + var(--lane-shift));
}

.siege-threat.side-right {
  right: var(--side-position);
  top: 50%;
  --ty: calc(-50% + var(--lane-shift));
}

.siege-threat.distance-3 { --side-position: 2.5%; }
.siege-threat.distance-2 { --side-position: 9%; }
.siege-threat.distance-1 { --side-position: 15.5%; }
.siege-threat.distance-0 { --side-position: 22%; }
.siege-threat.lane-a { --lane-shift: -33px; }
.siege-threat.lane-b { --lane-shift: 33px; }

.siege-threat.side-left .threat-body { transform: rotate(4deg); }
.siege-threat.side-right .threat-body { transform: rotate(-4deg); }
.siege-threat.side-bottom .threat-body { transform: rotate(2deg); }

.siege-threat.is-hit,
.siege-threat.is-golden-hit {
  z-index: 30;
}

.siege-threat.is-hit { animation: threat-hit 1.12s ease-in-out; }
.siege-threat.is-golden-hit { animation: threat-golden-hit 1.18s ease-in-out; }
.siege-threat.is-relocating { animation: threat-relocate .44s ease-out; }
.siege-threat.is-advancing { animation: threat-advance .34s ease-out; }
.siege-threat.is-wall-impact { z-index: 34; animation: threat-wall-impact .52s ease-in-out; }
.siege-threat.is-bouncing { z-index: 34; animation: threat-bounce .28s ease-out; }
.siege-threat.is-breaching { z-index: 35; animation: threat-breach .52s ease-in forwards; }

.siege-threat.is-hit .threat-eye,
.siege-threat.is-golden-hit .threat-eye {
  top: 13px;
  width: 11px;
  height: 12px;
  border-radius: 0;
  background: transparent;
}

.siege-threat.is-hit .threat-eye::before,
.siege-threat.is-hit .threat-eye::after,
.siege-threat.is-golden-hit .threat-eye::before,
.siege-threat.is-golden-hit .threat-eye::after {
  opacity: 1;
}

.siege-threat.is-hit .threat-eye::before,
.siege-threat.is-golden-hit .threat-eye::before { transform: rotate(45deg); }
.siege-threat.is-hit .threat-eye::after,
.siege-threat.is-golden-hit .threat-eye::after { transform: rotate(-45deg); }

.siege-threat.is-hit .threat-mouth,
.siege-threat.is-golden-hit .threat-mouth {
  bottom: 4px;
  width: 15px;
  height: 17px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: #ffd8cb;
}

.siege-threat.is-breached {
  filter: saturate(.55) drop-shadow(2px 4px 0 rgba(51,39,87,.2));
}

.gold-tip {
  width: fit-content;
  max-width: calc(100% - 20px);
  margin: -3px auto 5px;
  padding: 7px 12px;
  border: 2px solid #b3821d;
  border-radius: 13px 10px 14px 11px;
  background: #fff2b8;
  box-shadow: 2px 3px 0 rgba(106,76,13,.13);
  font-size: .83rem;
  text-align: center;
  transform: rotate(-.3deg);
}

.gold-tip > span {
  color: #d68f00;
  font-size: 1.2rem;
}

.castle-shell.is-firing .castle-flag { animation: flag-fire .35s ease-out; }
.castle-shell.fire-top .wall-top,
.castle-shell.fire-right .wall-right,
.castle-shell.fire-bottom .wall-bottom,
.castle-shell.fire-left .wall-left {
  animation: wall-fire .35s ease-out;
}

.castle-wall.is-impacting {
  animation: wall-impact .52s ease-in-out;
}

.castle-wall.is-breaking {
  animation: wall-break .72s ease-in forwards;
}

.castle-shell.is-threatened .castle-wall {
  border-color: #6a3153;
}

.castle-shell.is-threatened {
  animation: castle-worry 1.4s ease-in-out infinite;
}

.castle-shell.is-breached {
  animation: castle-breach .52s ease-in forwards;
  filter: drop-shadow(7px 9px 0 rgba(139,39,58,.28));
}

.castle-shell.is-victorious .castle-flag {
  animation: victory-flag .5s ease-in-out infinite alternate;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 22px;
  border-top: 2px dashed #cabfca;
}

.controls p {
  margin: 0;
  color: var(--purple);
  font-weight: 700;
  text-align: center;
}

.paper-dialog {
  position: relative;
  width: min(540px, calc(100% - 30px));
  max-height: calc(100dvh - 28px);
  padding: 27px;
  overflow: auto;
  border: 3px solid var(--ink);
  border-radius: 22px 17px 25px 19px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 9px 10px 0 rgba(51,39,87,.25);
}

.paper-dialog::backdrop {
  background: rgba(39,31,62,.68);
  backdrop-filter: blur(2px);
}

.paper-dialog h2 {
  margin: 2px 0 16px;
  font-size: 2.35rem;
}

.dialog-close {
  position: absolute;
  top: 9px;
  right: 11px;
  width: 44px;
  height: 44px;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-size: 2rem;
  cursor: pointer;
}

.paper-dialog ol {
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

.paper-dialog li {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 9px 0;
}

.paper-dialog li span {
  display: grid;
  flex: 0 0 31px;
  place-items: center;
  height: 31px;
  border-radius: 10px;
  color: white;
  background: var(--purple);
  font-weight: 700;
  transform: rotate(-2deg);
}

.rule-notes {
  display: grid;
  gap: 7px;
  margin: 15px 0;
}

.rule-notes p {
  margin: 0;
  padding: 8px 10px;
  border-radius: 11px;
  background: #f2e8d3;
  font-size: .88rem;
}

.rule-notes p:first-child { background: #fff0b7; }

.primary-button {
  width: 100%;
  color: white;
  background: var(--purple);
}

.result-dialog { text-align: center; }

.result-castle {
  display: inline-grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 3px solid var(--ink);
  border-radius: 50% 45% 52% 44%;
  background: var(--mint);
  font-size: 2rem;
  transform: rotate(-5deg);
}

.result-dialog .eyebrow { margin-top: 13px; }

.result-stars {
  color: #d99200;
  font-size: 2.7rem;
  letter-spacing: .08em;
  animation: stars-in .5s both;
}

.result-verdict {
  margin: 4px 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.result-grid,
.failure-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 15px 0;
}

.result-grid div,
.failure-grid div {
  padding: 9px;
  border: 2px solid #d2c5ce;
  border-radius: 11px;
}

.result-grid dt,
.failure-grid dt {
  color: #6f657b;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.result-grid dd,
.failure-grid dd {
  margin: 3px 0 0;
  font-weight: 700;
}

.result-actions {
  display: grid;
  gap: 9px;
}

.text-link {
  display: grid;
  min-height: 44px;
  place-items: center;
  color: var(--ink);
  font-weight: 700;
}

.failure-dialog {
  border-color: #732d4d;
  text-align: center;
}

.breach-mark {
  display: inline-block;
  padding: 8px 13px;
  border: 3px solid var(--ink);
  border-radius: 50% 45% 52% 44%;
  color: white;
  background: var(--danger);
  box-shadow: 3px 4px 0 rgba(51,39,87,.18);
  font: 1rem/1 "Chewy", cursive;
  transform: rotate(-7deg);
}

.failure-dialog h2 { color: #8c294b; }

.debug-panel {
  margin-top: 16px;
  padding: 15px;
  border: 2px dashed var(--ink);
  background: var(--paper);
}

.debug-panel > * { margin-right: 8px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  border: 0;
  white-space: nowrap;
  clip: rect(0,0,0,0);
}

[hidden] { display: none !important; }

body.menu-open { overflow: hidden; }

.opening-menu {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 22px;
  background:
    radial-gradient(circle at 16% 22%, rgba(255,255,255,.18) 0 3px, transparent 4px),
    radial-gradient(circle at 82% 75%, rgba(245,189,60,.22) 0 2px, transparent 3px),
    linear-gradient(145deg, #30264f 0%, #544486 52%, #342955 100%);
  background-size: 48px 48px, 37px 37px, auto;
  animation: menu-arrive .28s ease-out both;
}

.opening-menu::before,
.opening-menu::after {
  content: "";
  position: fixed;
  width: 270px;
  height: 270px;
  border: 3px dashed rgba(255,255,255,.1);
  border-radius: 50%;
  pointer-events: none;
}

.opening-menu::before { top: -145px; left: -95px; }
.opening-menu::after { right: -125px; bottom: -170px; }

.opening-panel {
  position: relative;
  width: min(900px, 100%);
  min-height: min(650px, calc(100dvh - 44px));
  padding: 18px 28px 27px;
  overflow: hidden;
  border: 4px solid var(--ink);
  border-radius: 31px 24px 34px 26px;
  background:
    linear-gradient(rgba(255,249,233,.93), rgba(247,234,203,.97)),
    var(--paper);
  box-shadow: 12px 14px 0 rgba(18,12,38,.32);
}

.opening-panel::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 2px dashed rgba(98,80,154,.16);
  border-radius: 22px 18px 25px 19px;
  pointer-events: none;
}

.opening-topline {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
}

.opening-brand {
  color: var(--ink);
  font: 1.8rem/1 "Chewy", cursive;
  text-decoration: none;
  transform: rotate(-2deg);
}

.opening-brand span:last-child {
  margin-left: 3px;
  color: var(--pink);
  text-shadow: 2px 2px 0 white;
}

.opening-tag {
  padding: 5px 9px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  color: white;
  background: var(--purple);
  font-size: .66rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  transform: rotate(1deg);
}

.opening-screen {
  position: relative;
  z-index: 2;
  min-height: 550px;
}

.opening-title-screen {
  display: grid;
  grid-template-columns: minmax(280px, .9fr) minmax(360px, 1.1fr);
  grid-template-rows: 1fr auto;
  align-items: center;
  gap: 10px 35px;
  padding: 18px 24px 3px;
}

.opening-copy h2 {
  margin: 3px 0 12px;
  font-size: clamp(4rem, 8vw, 6.4rem);
  font-weight: 400;
  line-height: .82;
  transform: rotate(-1deg);
}

.opening-copy h2 span {
  display: block;
  color: var(--pink);
  text-shadow: 3px 3px 0 white;
}

.opening-copy > p:last-child {
  max-width: 410px;
  margin: 0;
  font-size: 1.04rem;
  font-weight: 700;
  line-height: 1.45;
}

.opening-scene {
  position: relative;
  width: 100%;
  aspect-ratio: 1.12;
  max-height: 405px;
  border: 3px solid var(--ink);
  border-radius: 45% 46% 16% 18%;
  background:
    radial-gradient(circle at 77% 18%, rgba(255,255,255,.7) 0 2px, transparent 3px),
    radial-gradient(circle at 20% 30%, rgba(255,255,255,.5) 0 2px, transparent 3px),
    linear-gradient(#8b7bc1 0 58%, #8ed0b7 58% 100%);
  box-shadow: inset 0 -7px rgba(51,39,87,.12), 5px 7px 0 rgba(51,39,87,.15);
  overflow: hidden;
}

.opening-scene::after {
  content: "";
  position: absolute;
  left: -5%;
  right: -5%;
  bottom: -12%;
  height: 37%;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 35%, rgba(51,39,87,.13) 0 3px, transparent 4px),
    #6eb79c;
  background-size: 34px 27px;
}

.opening-moon {
  position: absolute;
  top: 10%;
  right: 12%;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  color: #b67800;
  background: #fff1a8;
  box-shadow: 3px 4px 0 rgba(51,39,87,.16);
  font-size: 1.8rem;
  transform: rotate(8deg);
}

.opening-fort {
  position: absolute;
  z-index: 3;
  left: 24%;
  right: 24%;
  bottom: 17%;
  height: 35%;
  border: 3px solid var(--ink);
  border-radius: 8px 8px 15px 15px;
  background:
    linear-gradient(90deg, transparent 47%, rgba(51,39,87,.13) 48% 52%, transparent 53%),
    var(--stone-light);
  box-shadow: inset 0 5px rgba(255,255,255,.3), 4px 5px 0 rgba(51,39,87,.16);
}

.opening-fort::before {
  content: "";
  position: absolute;
  left: -3px;
  right: -3px;
  bottom: 100%;
  height: 25%;
  border: 3px solid var(--ink);
  border-bottom-width: 2px;
  background: repeating-linear-gradient(90deg, var(--stone-light) 0 15%, transparent 15% 23%);
}

.opening-tower {
  position: absolute;
  bottom: -3px;
  width: 33%;
  height: 130%;
  border: 3px solid var(--ink);
  border-radius: 8px 8px 22px 22px;
  background: var(--stone-light);
  box-shadow: inset 0 5px rgba(255,255,255,.32);
}

.opening-tower::before {
  content: "";
  position: absolute;
  left: -3px;
  right: -3px;
  bottom: 100%;
  height: 17%;
  border: 3px solid var(--ink);
  background: repeating-linear-gradient(90deg, var(--stone-light) 0 24%, var(--purple-dark) 24% 33%);
}

.opening-tower-left { left: -25%; transform: rotate(-1deg); }
.opening-tower-right { right: -25%; transform: rotate(1deg); }

.opening-gate {
  position: absolute;
  left: 50%;
  bottom: -3px;
  width: 30%;
  height: 48%;
  border: 3px solid var(--ink);
  border-bottom: 0;
  border-radius: 50% 50% 0 0;
  background: var(--purple-dark);
  transform: translateX(-50%);
}

.opening-flag {
  position: absolute;
  z-index: 5;
  top: -114%;
  display: grid;
  place-items: center;
  width: 36px;
  height: 43px;
  border: 2px solid var(--ink);
  border-radius: 3px 9px 9px 3px;
  color: #fff7c4;
  background: var(--pink);
  box-shadow: -3px 0 0 -1px var(--ink);
  font-style: normal;
  animation: opening-flag-wave .8s ease-in-out infinite alternate;
}

.opening-flag.flag-a { left: -12%; }
.opening-flag.flag-b { right: -12%; animation-delay: -.35s; }

.opening-threat {
  position: absolute;
  z-index: 6;
  width: 68px;
  height: 67px;
  filter: drop-shadow(2px 4px 0 rgba(51,39,87,.2));
}

.opening-threat-a {
  left: 5%;
  bottom: 13%;
  transform: rotate(-7deg);
  animation: opening-monster-a 1.5s ease-in-out infinite alternate;
}

.opening-threat-b {
  right: 5%;
  bottom: 13%;
  transform: rotate(6deg);
  animation: opening-monster-b 1.6s ease-in-out infinite alternate;
}

.opening-shot {
  position: absolute;
  z-index: 8;
  color: #fff9dd;
  font-size: 2.3rem;
  font-weight: 700;
  text-shadow: 2px 2px 0 var(--ink);
}

.shot-one {
  left: 13%;
  top: 43%;
  transform: rotate(-8deg);
  animation: opening-shot-right 1.8s ease-in-out infinite;
}

.shot-two {
  right: 13%;
  top: 35%;
  transform: rotate(7deg);
  animation: opening-shot-left 2s .4s ease-in-out infinite;
}

.opening-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding-top: 5px;
}

.menu-play-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(320px, 100%);
  min-height: 67px;
  padding: 10px 13px 10px 27px;
  border: 3px solid var(--ink);
  border-radius: 19px 15px 21px 16px;
  color: var(--ink);
  background: var(--gold);
  box-shadow: 5px 6px 0 rgba(51,39,87,.22), inset 0 4px rgba(255,255,255,.32);
  font: 2rem/1 "Chewy", cursive;
  cursor: pointer;
  transform: rotate(-.7deg);
  transition: transform .14s, box-shadow .14s;
}

.menu-play-button b {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  color: white;
  background: var(--purple);
  font: 1.5rem/1 system-ui, sans-serif;
}

.menu-play-button:hover {
  transform: translateY(-3px) rotate(.3deg);
  box-shadow: 7px 8px 0 rgba(51,39,87,.18);
}

.menu-play-button:focus-visible,
.menu-text-button:focus-visible,
.difficulty-card:focus-visible,
.difficulty-back:focus-visible {
  outline: 4px solid var(--pink);
  outline-offset: 4px;
}

.menu-text-button,
.difficulty-back {
  min-height: 44px;
  border: 0;
  color: var(--purple-dark);
  background: transparent;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

.difficulty-screen {
  padding: 5px 22px 4px;
  animation: difficulty-arrive .24s ease-out both;
}

.difficulty-back {
  position: absolute;
  left: 12px;
  top: 4px;
  text-decoration: none;
}

.difficulty-heading {
  max-width: 620px;
  margin: 13px auto 22px;
  text-align: center;
}

.difficulty-heading h2 {
  margin: 1px 0 5px;
  font-size: clamp(2.8rem, 6vw, 4.5rem);
  font-weight: 400;
}

.difficulty-heading > p:last-child {
  margin: 0;
  font-weight: 700;
}

.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.difficulty-card {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 330px;
  flex-direction: column;
  align-items: stretch;
  padding: 20px 17px 16px;
  border: 3px solid var(--ink);
  border-radius: 21px 16px 23px 18px;
  color: var(--ink);
  background: #fffdf6;
  box-shadow: 4px 5px 0 rgba(51,39,87,.17);
  text-align: left;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, filter .15s;
}

.difficulty-card:hover {
  z-index: 2;
  filter: brightness(1.02);
  transform: translateY(-6px) rotate(-.4deg);
  box-shadow: 7px 9px 0 rgba(51,39,87,.14);
}

.difficulty-medium { transform: rotate(1deg); }
.difficulty-hard { transform: rotate(-.8deg); }

.difficulty-card::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 2px dashed rgba(51,39,87,.12);
  border-radius: 14px 11px 16px 12px;
  pointer-events: none;
}

.difficulty-easy { background: #e3f4ec; }
.difficulty-medium { background: #fff2bd; }
.difficulty-hard { background: #f8d7d5; }

.difficulty-icon {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 67px;
  height: 67px;
  margin: 0 auto 16px;
  border: 3px solid var(--ink);
  border-radius: 48% 42% 53% 45%;
  color: white;
  background: var(--mint-dark);
  box-shadow: 3px 4px 0 rgba(51,39,87,.16);
  font: 2rem/1 "Chewy", cursive;
  transform: rotate(-4deg);
}

.difficulty-medium .difficulty-icon {
  color: var(--ink);
  background: var(--gold);
  transform: rotate(4deg);
}

.difficulty-hard .difficulty-icon {
  background: var(--pink);
}

.difficulty-copy {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 1;
  flex-direction: column;
}

.difficulty-copy small {
  color: var(--purple-dark);
  text-align: center;
}

.difficulty-copy strong {
  display: block;
  margin: 2px 0 11px;
  font: 2.1rem/1 "Chewy", cursive;
  text-align: center;
}

.difficulty-copy > span:last-child {
  font-size: .88rem;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
}

.difficulty-meta {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 5px;
  margin-top: 18px;
  padding-top: 11px;
  border-top: 2px dashed rgba(51,39,87,.22);
  font-size: .72rem;
}

.difficulty-meta em {
  color: var(--purple-dark);
  font-style: normal;
}

.failure-menu-button {
  width: 100%;
  margin-top: 9px;
}

@keyframes blocked-collision {
  0% { transform: translate(0, 0); opacity: 1; }
  34% { transform: translate(var(--collision-x, 0), var(--collision-y, 0)); opacity: 1; }
  40% { transform: translate(var(--collision-x, 0), var(--collision-y, 0)); opacity: .12; }
  46% { transform: translate(var(--collision-x, 0), var(--collision-y, 0)); opacity: 1; }
  52% { transform: translate(var(--collision-x, 0), var(--collision-y, 0)); opacity: .12; }
  58% { transform: translate(var(--collision-x, 0), var(--collision-y, 0)); opacity: 1; }
  64% { transform: translate(var(--collision-x, 0), var(--collision-y, 0)); opacity: .12; }
  70% { transform: translate(var(--collision-x, 0), var(--collision-y, 0)); opacity: 1; }
  100% { transform: translate(0, 0); opacity: 1; }
}

@keyframes leave {
  to { transform: translate(var(--exit-x), var(--exit-y)) rotate(7deg); opacity: 0; }
}

@keyframes threat-hit {
  0% { transform: translate(var(--tx), var(--ty)) scale(1); opacity: 1; }
  18% { transform: translate(var(--tx), var(--ty)) scale(.83) rotate(-7deg); filter: brightness(1.45); }
  31% { transform: translate(var(--tx), var(--ty)) scale(1.12) rotate(6deg); }
  39% { transform: translate(var(--tx), var(--ty)) scale(1.08); opacity: .1; }
  47% { transform: translate(var(--tx), var(--ty)) scale(1.08); opacity: 1; }
  55% { transform: translate(var(--tx), var(--ty)) scale(1.08); opacity: .1; }
  63% { transform: translate(var(--tx), var(--ty)) scale(1.08); opacity: 1; }
  71% { transform: translate(var(--tx), var(--ty)) scale(1.08); opacity: .1; }
  79% { transform: translate(var(--tx), var(--ty)) scale(1.08); opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) scale(1); opacity: 1; }
}

@keyframes threat-golden-hit {
  0% { transform: translate(var(--tx), var(--ty)) scale(1); opacity: 1; }
  18% { transform: translate(var(--tx), var(--ty)) scale(.7) rotate(-12deg); filter: brightness(1.7) drop-shadow(0 0 8px var(--gold)); }
  31% { transform: translate(var(--tx), var(--ty)) scale(1.2) rotate(8deg); }
  39% { transform: translate(var(--tx), var(--ty)) scale(1.14); opacity: .08; }
  47% { transform: translate(var(--tx), var(--ty)) scale(1.14); opacity: 1; }
  55% { transform: translate(var(--tx), var(--ty)) scale(1.14); opacity: .08; }
  63% { transform: translate(var(--tx), var(--ty)) scale(1.14); opacity: 1; }
  71% { transform: translate(var(--tx), var(--ty)) scale(1.14); opacity: .08; }
  79% { transform: translate(var(--tx), var(--ty)) scale(1.14); opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) scale(1); opacity: 1; }
}

@keyframes threat-relocate {
  0% { transform: translate(var(--tx), var(--ty)) rotate(-10deg) scale(.78); opacity: .12; }
  52% { transform: translate(var(--tx), var(--ty)) rotate(8deg) scale(1.08); opacity: .72; }
  100% { transform: translate(var(--tx), var(--ty)) rotate(0) scale(1); opacity: 1; }
}

@keyframes threat-advance {
  0% { filter: brightness(1.25) drop-shadow(2px 4px 0 rgba(51,39,87,.2)); }
  65% { transform: translate(var(--tx), var(--ty)) scale(1.14); }
  100% { transform: translate(var(--tx), var(--ty)) scale(1); }
}

@keyframes threat-breach {
  0% { transform: translate(var(--tx), var(--ty)) scale(1); }
  45% { transform: translate(var(--tx), var(--ty)) scale(1.25) rotate(-9deg); }
  100% { transform: translate(var(--tx), var(--ty)) scale(1.08) rotate(8deg); }
}

@keyframes threat-wall-impact {
  0% { transform: translate(var(--tx), var(--ty)) scale(1); }
  35% { transform: translate(var(--tx), var(--ty)) scale(1.18, .82) rotate(-7deg); }
  48%, 68% { opacity: .2; }
  58%, 78%, 100% { opacity: 1; }
}

@keyframes threat-bounce {
  0% { transform: translate(var(--tx), var(--ty)) scale(1.2, .8); }
  70% { transform: translate(var(--tx), var(--ty)) scale(.9, 1.12); }
  100% { transform: translate(var(--tx), var(--ty)) scale(1); }
}

@keyframes wall-fire {
  40% { filter: brightness(1.45); transform: scale(1.025); }
}

@keyframes wall-impact {
  0%, 100% { filter: none; }
  28% { filter: brightness(1.65); transform: scale(1.035); }
  42% { transform: translateX(-2px); }
  56% { transform: translateX(2px); }
}

@keyframes wall-break {
  0% { filter: none; }
  35% { filter: brightness(1.8); transform: scale(1.05); }
  60% { transform: rotate(-2deg) translateY(3px); }
  100% { filter: saturate(.65); transform: rotate(1deg) translateY(5px); }
}

@keyframes flag-fire {
  50% { transform: rotate(-13deg) scaleX(.82); }
}

@keyframes castle-worry {
  0%, 92%, 100% { transform: translateX(0); }
  94% { transform: translateX(-1px); }
  96% { transform: translateX(1px); }
  98% { transform: translateX(-1px); }
}

@keyframes castle-breach {
  0% { transform: translate(0) rotate(0); }
  25% { transform: translate(-5px, 2px) rotate(-1deg); }
  50% { transform: translate(5px, -2px) rotate(1deg); }
  75% { transform: translate(-4px, 2px) rotate(-.8deg); }
  100% { transform: translate(2px, 4px) rotate(.4deg); }
}

@keyframes victory-flag {
  from { transform: rotate(-7deg) skewY(-5deg); }
  to { transform: rotate(8deg) skewY(5deg); }
}

@keyframes warning-pulse {
  50% { filter: brightness(1.22); transform: scale(1.03); }
}

@keyframes stars-in {
  from { opacity: 0; transform: scale(.4) rotate(-10deg); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes menu-arrive {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes difficulty-arrive {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes opening-flag-wave {
  from { transform: rotate(-6deg) skewY(-4deg); }
  to { transform: rotate(7deg) skewY(4deg); }
}

@keyframes opening-monster-a {
  from { transform: translateY(0) rotate(-7deg); }
  to { transform: translateY(-7px) rotate(-2deg); }
}

@keyframes opening-monster-b {
  from { transform: translateY(-3px) rotate(6deg); }
  to { transform: translateY(5px) rotate(1deg); }
}

@keyframes opening-shot-right {
  0%, 20% { opacity: 0; transform: translateX(-15px) rotate(-8deg); }
  35%, 75% { opacity: 1; }
  90%, 100% { opacity: 0; transform: translateX(47px) rotate(-8deg); }
}

@keyframes opening-shot-left {
  0%, 20% { opacity: 0; transform: translateX(15px) rotate(7deg); }
  35%, 75% { opacity: 1; }
  90%, 100% { opacity: 0; transform: translateX(-47px) rotate(7deg); }
}

@media (min-width: 860px) {
  .mini-route { display: flex; }
}

@media (max-width: 680px) {
  .opening-menu {
    display: block;
    padding: 8px;
  }

  .opening-panel {
    min-height: calc(100dvh - 16px);
    padding: 12px 14px 20px;
    border-radius: 22px 18px 24px 19px;
  }

  .opening-brand { font-size: 1.45rem; }
  .opening-tag { font-size: .56rem; }
  .opening-screen { min-height: auto; }

  .opening-title-screen {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    gap: 12px;
    padding: 20px 12px 4px;
    text-align: center;
  }

  .opening-copy h2 {
    margin: 3px 0 9px;
    font-size: clamp(3.4rem, 17vw, 5rem);
    line-height: .84;
  }

  .opening-copy h2 span { display: inline; }
  .opening-copy > p:last-child { margin-inline: auto; font-size: .9rem; }

  .opening-scene {
    width: min(360px, 100%);
    margin: 0 auto;
    max-height: none;
  }

  .opening-actions {
    flex-direction: column;
    gap: 5px;
  }

  .menu-play-button {
    min-height: 57px;
    font-size: 1.7rem;
  }

  .difficulty-screen { padding: 6px 9px 3px; }
  .difficulty-back { position: static; display: block; width: fit-content; }
  .difficulty-heading { margin: 1px auto 15px; }
  .difficulty-heading h2 { font-size: 2.8rem; }
  .difficulty-heading > p:last-child { font-size: .82rem; }

  .difficulty-grid {
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .difficulty-card,
  .difficulty-medium,
  .difficulty-hard {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    grid-template-rows: 1fr auto;
    gap: 3px 12px;
    min-height: 142px;
    padding: 13px 14px;
    transform: none;
  }

  .difficulty-icon {
    grid-row: 1 / -1;
    width: 55px;
    height: 55px;
    margin: 6px 0 0;
    font-size: 1.65rem;
  }

  .difficulty-copy {
    display: block;
  }

  .difficulty-copy small,
  .difficulty-copy strong,
  .difficulty-copy > span:last-child {
    text-align: left;
  }

  .difficulty-copy strong {
    margin: 1px 0 5px;
    font-size: 1.65rem;
  }

  .difficulty-copy > span:last-child { font-size: .76rem; }

  .difficulty-meta {
    grid-column: 2;
    margin-top: 4px;
    padding-top: 7px;
  }

  .page-shell {
    width: min(100% - 14px, 600px);
    padding-top: 9px;
  }

  .site-header { margin-bottom: 10px; }
  .brand { font-size: 1.6rem; }

  .hero {
    align-items: stretch;
    flex-direction: column;
    gap: 11px;
  }

  h1 { font-size: 3.2rem; }
  .hero-copy { font-size: .88rem; }

  .daily-strip { width: 100%; }
  .daily-strip > div {
    flex: 1;
    min-width: 0;
    padding: 7px 4px;
    font-size: .88rem;
  }

  .game-card { border-radius: 18px; }

  .puzzle-library-bar {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    gap: 7px;
    padding: 9px;
  }

  .puzzle-difficulty {
    grid-column: 1 / -1;
    grid-row: 2;
    min-width: 0;
  }

  .status-row {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 11px;
  }

  .siege-title { justify-content: center; }
  .numbers { justify-content: space-around; gap: 7px; }

  .threat-hud {
    gap: 6px;
    padding: 8px;
  }

  .wall-status {
    gap: 4px;
    padding: 6px 8px;
  }

  .wall-chip {
    gap: 3px;
    padding: 4px;
  }

  .wall-chip b { font-size: .61rem; }
  .wall-chip em { font-size: .56rem; }

  .threat-hud[data-count="3"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .threat-hud[data-count="3"] .threat-card:last-child {
    grid-column: 1 / -1;
  }

  .threat-card {
    padding: 7px;
  }

  .threat-heading { gap: 5px; }
  .threat-letter { flex-basis: 22px; height: 22px; font-size: .86rem; }
  .threat-heading strong { font-size: .78rem; }
  .distance-word { padding: 2px 5px; font-size: .6rem; }

  .threat-facts {
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }

  .distance-fact {
    grid-column: 1 / -1;
    padding-top: 3px;
  }

  .threat-facts b { font-size: .68rem; }
  .threat-facts small { font-size: .56rem; }

  .siege-stage { padding: 7px 2px 5px; }
  .castle-arena { width: min(100%, 560px); }

  .castle-shell { inset: 15%; }
  .board { gap: 3px; padding: 5px; }
  .arrow-piece { min-width: 0; min-height: 42px; border-radius: 9px; }
  .arrow-glyph { font-size: clamp(1.3rem, 6vw, 2rem); }

  .siege-threat {
    width: 51px;
    height: 57px;
  }

  .siege-threat strong {
    top: 43px;
    width: 19px;
    height: 19px;
    padding: 1px;
  }

  .siege-threat strong::after { font-size: .65rem; }

  .threat-body { inset: 8px 3px 8px; border-width: 2px; }
  .threat-accessory::before,
  .threat-accessory::after { width: 13px; height: 18px; border-width: 2px; }
  .threat-eye { top: 11px; width: 6px; height: 8px; }
  .eye-a { left: 10px; }
  .eye-b { right: 10px; }
  .threat-mouth { bottom: 6px; width: 13px; }
  .threat-feet::before,
  .threat-feet::after { bottom: 6px; width: 16px; height: 8px; border-width: 2px; }
  .threat-feet::before { left: 6px; }
  .threat-feet::after { right: 6px; }
  .visual-patched .threat-patch { right: 6px; top: 8px; width: 12px; height: 10px; border-width: 1px; }

  .siege-threat.lane-a { --lane-shift: -25px; }
  .siege-threat.lane-b { --lane-shift: 25px; }

  .gold-tip {
    font-size: .72rem;
  }

  .controls {
    flex-wrap: wrap;
    padding: 10px;
  }

  .controls p {
    order: -1;
    width: 100%;
    font-size: .84rem;
  }

  .controls button { flex: 1; }
}

@media (max-width: 430px) {
  .opening-panel { min-height: calc(100dvh - 16px); }
  .opening-topline { min-height: 38px; }
  .opening-title-screen { padding-top: 13px; }
  .opening-copy h2 { font-size: 3.45rem; }
  .opening-scene { width: min(285px, 100%); }
  .opening-moon { width: 44px; height: 44px; font-size: 1.35rem; }
  .opening-threat { width: 57px; height: 59px; }
  .opening-threat .threat-body { inset: 8px 3px 8px; }
  .difficulty-heading h2 { font-size: 2.45rem; }

  .site-header .plain-button { padding-inline: 10px; }
  .threat-hud,
  .threat-hud[data-count="1"],
  .threat-hud[data-count="3"] {
    grid-template-columns: 1fr;
  }
  .threat-hud[data-count="3"] .threat-card:last-child { grid-column: auto; }
  .wall-status { grid-template-columns: 1fr 1fr; }
  .wall-chip { justify-content: space-between; padding-inline: 8px; }
  .threat-facts { grid-template-columns: 1fr 1fr 1.2fr; }
  .distance-fact { grid-column: auto; padding-top: 0; }
  .castle-arena { min-height: 350px; }
  .castle-shell { inset: 14%; }
  .board { gap: 2px; padding: 4px; }
  .arrow-piece { min-height: 34px; }
  .arrow-glyph { font-size: 1.28rem; }
  .result-grid,
  .failure-grid { grid-template-columns: 1fr 1fr; }
}

/* Keep the active siege, including its full HUD, inside a single viewport. */
body:not(.menu-open) {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

body:not(.menu-open) .page-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 5px;
  height: 100dvh;
  padding: 7px 0 8px;
}

body:not(.menu-open) .site-header {
  min-height: 34px;
  margin: 0;
}

body:not(.menu-open) .brand {
  font-size: 1.65rem;
}

body:not(.menu-open) .site-header .plain-button {
  min-height: 34px;
  padding: 4px 11px;
}

body:not(.menu-open) main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 5px;
  min-height: 0;
}

body:not(.menu-open) .hero {
  align-items: center;
  width: 100%;
  max-width: none;
  min-height: 0;
  margin: 0;
}

body:not(.menu-open) .eyebrow,
body:not(.menu-open) .hero-copy {
  display: none;
}

body:not(.menu-open) h1 {
  margin: 0;
  font-size: clamp(1.9rem, 4.2vh, 2.65rem);
  line-height: .88;
}

body:not(.menu-open) .daily-strip > div {
  min-width: 78px;
  padding: 3px 8px;
}

body:not(.menu-open) .daily-strip strong {
  margin-top: 0;
  font-size: .85rem;
}

body:not(.menu-open) .game-card {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
  min-height: 0;
}

body:not(.menu-open) .puzzle-library-bar {
  grid-template-columns: 34px minmax(190px, 320px) auto 34px;
  gap: 7px;
  padding: 4px 12px;
}

body:not(.menu-open) .puzzle-choice small {
  display: none;
}

body:not(.menu-open) .puzzle-choice select {
  min-height: 34px;
  padding-block: 3px;
}

body:not(.menu-open) .puzzle-step {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  font-size: 1.05rem;
}

body:not(.menu-open) .status-row {
  gap: 14px;
  padding: 5px 14px;
}

body:not(.menu-open) .siege-title {
  gap: 8px;
}

body:not(.menu-open) #siege-status {
  font-size: .86rem;
}

body:not(.menu-open) .numbers {
  gap: 14px;
}

body:not(.menu-open) .numbers strong {
  font-size: .92rem;
  line-height: 1;
}

body:not(.menu-open) .threat-hud {
  gap: 6px;
  padding: 5px 14px;
}

body:not(.menu-open) .threat-card {
  padding: 5px 8px;
  border-width: 1px;
  border-radius: 10px;
}

body:not(.menu-open) .threat-letter {
  flex-basis: 20px;
  width: 20px;
  height: 20px;
  border-width: 1px;
  font-size: .78rem;
}

body:not(.menu-open) .threat-heading {
  gap: 5px;
}

body:not(.menu-open) .threat-heading strong {
  font-size: .76rem;
}

body:not(.menu-open) .distance-word {
  padding: 2px 5px;
  font-size: .58rem;
}

body:not(.menu-open) .threat-facts {
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 4px;
  margin-top: 4px;
}

body:not(.menu-open) .threat-facts span {
  padding-left: 4px;
}

body:not(.menu-open) .threat-facts b {
  font-size: .66rem;
}

body:not(.menu-open) .threat-facts small {
  font-size: .51rem;
}

body:not(.menu-open) .distance-fact {
  grid-column: auto;
  padding-top: 0;
}

body:not(.menu-open) .distance-track {
  gap: 3px;
  margin-top: 4px;
}

body:not(.menu-open) .distance-track i {
  height: 4px;
}

body:not(.menu-open) .wall-status {
  gap: 5px;
  padding: 3px 14px 4px;
}

body:not(.menu-open) .wall-chip {
  padding: 3px 5px;
  border-width: 1px;
}

body:not(.menu-open) .siege-stage {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  padding: 4px 7px 2px;
  overflow: hidden;
}

body:not(.menu-open) .castle-arena {
  width: auto;
  max-width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 750px;
  aspect-ratio: 1;
}

body:not(.menu-open) .gold-tip {
  margin: -2px auto 2px;
  padding: 3px 9px;
  border-width: 1px;
  font-size: .7rem;
  line-height: 1;
}

body:not(.menu-open) .gold-tip > span {
  font-size: .85rem;
}

body:not(.menu-open) .controls {
  flex-wrap: nowrap;
  gap: 10px;
  padding: 4px 14px 5px;
}

body:not(.menu-open) .controls .plain-button {
  min-height: 34px;
  padding: 4px 11px;
}

body:not(.menu-open) .controls p {
  order: initial;
  width: auto;
  font-size: .78rem;
}

@media (max-width: 680px) {
  body:not(.menu-open) .page-shell {
    width: min(100% - 10px, 600px);
    gap: 3px;
    padding: 4px 0 5px;
  }

  body:not(.menu-open) main {
    gap: 3px;
  }

  body:not(.menu-open) .hero {
    flex-direction: row;
    gap: 8px;
  }

  body:not(.menu-open) h1 {
    font-size: 1.7rem;
    white-space: nowrap;
  }

  body:not(.menu-open) .daily-strip {
    flex: 1;
    gap: 4px;
  }

  body:not(.menu-open) .daily-strip > div {
    min-width: 0;
    padding: 2px 3px;
    font-size: .72rem;
  }

  body:not(.menu-open) .daily-strip small {
    font-size: .5rem;
  }

  body:not(.menu-open) .puzzle-library-bar {
    grid-template-columns: 34px minmax(0, 1fr) 34px;
    grid-template-rows: 34px;
    padding: 3px 6px;
  }

  body:not(.menu-open) .puzzle-difficulty {
    display: none;
  }

  body:not(.menu-open) .status-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
    padding: 4px 7px;
  }

  body:not(.menu-open) .siege-title {
    justify-content: flex-start;
    min-width: 0;
  }

  body:not(.menu-open) #siege-status {
    overflow: hidden;
    font-size: .7rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body:not(.menu-open) .numbers {
    gap: 7px;
  }

  body:not(.menu-open) .numbers small {
    font-size: .49rem;
  }

  body:not(.menu-open) .numbers strong {
    font-size: .76rem;
  }

  body:not(.menu-open) .threat-hud,
  body:not(.menu-open) .threat-hud[data-count="3"] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3px;
    padding: 4px 6px;
  }

  body:not(.menu-open) .threat-hud[data-count="1"] {
    grid-template-columns: minmax(0, 1fr);
  }

  body:not(.menu-open) .threat-hud[data-count="3"] .threat-card:last-child {
    grid-column: auto;
  }

  body:not(.menu-open) .threat-card {
    min-width: 0;
    padding: 3px 4px;
  }

  body:not(.menu-open) .threat-heading strong {
    font-size: .64rem;
  }

  body:not(.menu-open) .distance-word {
    font-size: .5rem;
  }

  body:not(.menu-open) .threat-facts {
    gap: 2px;
    margin-top: 2px;
  }

  body:not(.menu-open) .threat-facts span {
    padding-left: 2px;
  }

  body:not(.menu-open) .threat-facts b {
    font-size: .56rem;
  }

  body:not(.menu-open) .threat-facts small {
    font-size: .43rem;
  }

  body:not(.menu-open) .distance-track {
    margin-top: 2px;
  }

  body:not(.menu-open) .wall-status {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3px;
    padding: 3px 6px;
  }

  body:not(.menu-open) .wall-chip {
    justify-content: center;
    padding: 2px 3px;
  }

  body:not(.menu-open) .wall-chip b {
    font-size: .55rem;
  }

  body:not(.menu-open) .wall-chip em {
    font-size: .5rem;
  }

  body:not(.menu-open) .siege-stage {
    padding: 3px 2px 1px;
  }

  body:not(.menu-open) .castle-arena {
    width: auto;
    min-height: 0;
  }

  body:not(.menu-open) .castle-shell {
    inset: 16%;
  }

  body:not(.menu-open) .board {
    gap: 2px;
    padding: 4px;
  }

  body:not(.menu-open) .arrow-piece {
    min-width: 0;
    min-height: 0;
  }

  body:not(.menu-open) .approach-zones {
    gap: 2px;
  }

  body:not(.menu-open) .approach-zones span {
    display: none;
  }

  body:not(.menu-open) .approach-zones b {
    font-size: .62rem;
  }

  body:not(.menu-open) .gold-tip {
    max-width: calc(100% - 8px);
    padding: 2px 5px;
    font-size: .61rem;
  }

  body:not(.menu-open) .controls {
    gap: 6px;
    padding: 3px 6px;
  }

  body:not(.menu-open) .controls .plain-button {
    flex: 0 0 auto;
    min-height: 32px;
    padding: 3px 9px;
    font-size: .76rem;
  }

  body:not(.menu-open) .controls p {
    flex: 1;
    min-width: 0;
    font-size: .68rem;
  }
}

@media (max-width: 430px) {
  body:not(.menu-open) .brand {
    font-size: 1.38rem;
  }

  body:not(.menu-open) .site-header .plain-button {
    padding-inline: 7px;
    font-size: .73rem;
  }

  body:not(.menu-open) .hero > div:first-child {
    display: none;
  }

  body:not(.menu-open) .daily-strip {
    width: 100%;
  }

  body:not(.menu-open) .mode-badge {
    padding: 2px 5px;
    border-width: 1px;
    font-size: .54rem;
  }

  body:not(.menu-open) #siege-status {
    display: none;
  }

  body:not(.menu-open) .threat-heading strong,
  body:not(.menu-open) .distance-word {
    display: none;
  }

  body:not(.menu-open) .threat-letter {
    flex-basis: 18px;
    width: 18px;
    height: 18px;
  }

  body:not(.menu-open) .threat-facts b {
    font-size: .52rem;
  }

  body:not(.menu-open) .wall-chip {
    padding-inline: 2px;
  }

  body:not(.menu-open) .wall-chip b {
    font-size: .49rem;
  }

  body:not(.menu-open) .wall-chip em {
    font-size: .45rem;
  }

  body:not(.menu-open) .arrow-glyph {
    font-size: clamp(.95rem, 5vw, 1.28rem);
  }
}

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

/* --------------------------------------------------------------------------
   Jellykid illustrated art pack
   -------------------------------------------------------------------------- */

body {
  background-color: #b9dfd3;
  background-image:
    linear-gradient(rgba(223,244,236,.68), rgba(185,223,211,.76)),
    url("../assets/art/game/siege-background.png");
  background-position: center;
  background-size: cover;
  background-attachment: fixed;
}

.opening-menu {
  background:
    linear-gradient(145deg, rgba(48,38,79,.9), rgba(84,68,134,.82) 52%, rgba(52,41,85,.92)),
    url("../assets/art/game/siege-background.png") center / cover;
}

.opening-scene {
  background:
    linear-gradient(rgba(139,123,193,.58) 0 57%, rgba(142,208,183,.48) 57% 100%),
    url("../assets/art/game/siege-background.png") center / cover;
}

.opening-scene.opening-castle-approach {
  aspect-ratio: 3 / 2;
  max-height: 405px;
  border-radius: 26px 22px 30px 24px;
  background:
    linear-gradient(rgba(255,255,255,.02), rgba(51,39,87,.08)),
    url("../assets/art/game/castle-approach.png") center / cover no-repeat;
  box-shadow:
    inset 0 0 0 2px rgba(255,255,255,.24),
    inset 0 -18px 34px rgba(51,39,87,.14),
    5px 7px 0 rgba(51,39,87,.15);
}

.opening-scene.opening-castle-approach::after {
  display: none;
}

.opening-fort {
  left: 23%;
  right: auto;
  bottom: 5%;
  width: 54%;
  height: auto;
  aspect-ratio: 1;
  border: 0;
  border-radius: 0;
  background: url("../assets/art/game/castle-frame.png") center / contain no-repeat;
  box-shadow: none;
}

.opening-fort::before,
.opening-fort > * {
  display: none;
}

.siege-stage {
  background:
    linear-gradient(rgba(255,253,247,.56), rgba(240,229,204,.64)),
    url("../assets/art/game/siege-background.png") center / cover;
}

.castle-shell {
  inset: 7%;
  isolation: isolate;
  filter: drop-shadow(5px 7px 0 rgba(51,39,87,.18));
}

.castle-shell::before {
  display: none;
}

.board {
  z-index: 3;
  inset: 20%;
  background-color: #eadcbb;
  background-image:
    linear-gradient(rgba(73,59,122,.11) 1px, transparent 1px),
    linear-gradient(90deg, rgba(73,59,122,.11) 1px, transparent 1px),
    linear-gradient(rgba(255,249,233,.08), rgba(255,249,233,.08)),
    url("../assets/art/game/courtyard-floor.png");
  background-position: 0 0, 0 0, center, center;
  background-size:
    calc(100% / var(--grid-size)) calc(100% / var(--grid-size)),
    calc(100% / var(--grid-size)) calc(100% / var(--grid-size)),
    auto,
    cover;
}

/* Each wall is its own illustrated asset so damage can swap one side without
   changing the other three sides of the castle. */
.castle-wall {
  z-index: 5;
  pointer-events: none;
  border: 0;
  background-color: transparent;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  box-shadow: none;
}

.castle-wall::before,
.castle-wall::after,
.firing-port,
.tower,
.castle-flag {
  display: none;
}

.castle-wall.is-damaged::after,
.castle-wall.is-broken::after {
  display: none;
  content: none;
  background: none;
}

.wall-top,
.wall-bottom {
  left: 0;
  width: 100%;
  height: 25%;
  transform: none;
}

.wall-left,
.wall-right {
  top: 0;
  width: 25%;
  height: 100%;
  transform: none;
}

.wall-top { top: -8%; }
.wall-right { right: -8%; }
.wall-bottom { bottom: -8%; }
.wall-left { left: -8%; }

.wall-top.is-intact {
  background-image: url("../assets/art/game/walls/castle-wall-top-intact.png?v=20260730-gates-fit");
}

.wall-right.is-intact {
  background-image: url("../assets/art/game/walls/castle-wall-right-intact.png?v=20260730-gates-fit");
}

.wall-bottom.is-intact {
  background-image: url("../assets/art/game/walls/castle-wall-bottom-intact.png?v=20260730-gates-fit");
}

.wall-left.is-intact {
  background-image: url("../assets/art/game/walls/castle-wall-left-intact.png?v=20260730-gates-fit");
}

.wall-top.is-damaged,
.wall-top.is-broken {
  background-image: url("../assets/art/game/walls/castle-wall-top-damaged.png?v=20260730-gates-fit");
}

.wall-right.is-damaged,
.wall-right.is-broken {
  background-image: url("../assets/art/game/walls/castle-wall-right-damaged.png?v=20260730-gates-fit");
}

.wall-bottom.is-damaged,
.wall-bottom.is-broken {
  background-image: url("../assets/art/game/walls/castle-wall-bottom-damaged.png?v=20260730-gates-fit");
}

.wall-left.is-damaged,
.wall-left.is-broken {
  background-image: url("../assets/art/game/walls/castle-wall-left-damaged.png?v=20260730-gates-fit");
}

.castle-wall.is-broken {
  border: 0;
  opacity: .82;
  filter: brightness(.72) saturate(.7);
  background-color: transparent;
  box-shadow: none;
}

.castle-shell.is-victorious .castle-wall {
  animation: illustrated-castle-victory .65s ease-out;
}

.visual-horned {
  --monster-art: url("../assets/art/game/monster-horned.png");
  --monster-face: #74d4b2;
}

.visual-patched {
  --monster-art: url("../assets/art/game/monster-patched.png");
  --monster-face: #f39786;
}

.visual-crowned {
  --monster-art: url("../assets/art/game/monster-crowned.png");
  --monster-face: #9da9f4;
}

.siege-threat::before,
.opening-threat::before {
  content: "";
  position: absolute;
  z-index: 1;
  inset: -7px;
  pointer-events: none;
  background: var(--monster-art) center / contain no-repeat;
}

.siege-threat > .threat-accessory,
.siege-threat > .threat-body,
.siege-threat > .threat-feet,
.opening-threat > .threat-accessory,
.opening-threat > .threat-body,
.opening-threat > .threat-feet {
  display: none;
}

.siege-threat strong {
  z-index: 4;
}

.siege-threat.is-hit::before,
.siege-threat.is-golden-hit::before {
  filter: brightness(1.12) saturate(.78);
}

.siege-threat.is-hit::after,
.siege-threat.is-golden-hit::after {
  content: "×  ×\A O";
  position: absolute;
  z-index: 3;
  top: 25%;
  left: 50%;
  display: block;
  width: 34px;
  height: 30px;
  padding-top: 2px;
  border-radius: 46% 52% 48% 45%;
  color: var(--ink);
  background: var(--monster-face);
  box-shadow: 0 0 0 2px var(--monster-face);
  font: 900 .82rem/.82 system-ui, sans-serif;
  text-align: center;
  white-space: pre;
  transform: translateX(-50%) rotate(-2deg);
}

@keyframes illustrated-castle-fire {
  0%, 100% { filter: none; transform: scale(1); }
  45% { filter: brightness(1.22) saturate(1.12); transform: scale(1.012); }
}

@keyframes illustrated-castle-victory {
  0%, 100% { filter: none; transform: translateY(0); }
  45% { filter: brightness(1.12) saturate(1.12); transform: translateY(-2%); }
}

@media (max-width: 680px) {
  .castle-shell,
  body:not(.menu-open) .castle-shell {
    inset: 7%;
  }

  .board,
  body:not(.menu-open) .board {
    inset: 20%;
  }

  .siege-threat::before,
  .opening-threat::before {
    inset: -5px;
  }

  .siege-threat.is-hit::after,
  .siege-threat.is-golden-hit::after {
    top: 23%;
    width: 28px;
    height: 25px;
    font-size: .7rem;
  }
}

/* Pull the complete monster route away from the illustrated walls. The arena
   scale creates a safe outer gutter for the new far zone on every side. */
.castle-arena {
  overflow: visible;
  transform: scale(.88);
  transform-origin: center;
}

.castle-shell,
body:not(.menu-open) .castle-shell {
  inset: 12%;
}

.board,
body:not(.menu-open) .board {
  inset: 13%;
}

.zones-top { top: -6.5%; }
.zones-right { right: -6.5%; }
.zones-bottom { bottom: -6.5%; }
.zones-left { left: -6.5%; }

.approach-zones {
  gap: 4px;
}

.approach-zones i {
  border: 2px solid rgba(73,59,122,.48);
  color: var(--ink);
  background: rgba(255,249,233,.9);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.72),
    1px 2px 0 rgba(51,39,87,.1);
}

.approach-zones i:nth-child(2) {
  border-color: rgba(142,102,38,.58);
  background: rgba(250,230,178,.92);
}

.approach-zones i:nth-child(3) {
  border-color: rgba(165,51,82,.68);
  color: #6f2944;
  background: rgba(255,206,194,.94);
}

.approach-zones b {
  font-size: .86rem;
}

.approach-zones span {
  font-size: .47rem;
}

/* Zone one now occupies the former zone-two position, zone two occupies the
   former far position, and zone three sits in the new outer gutter. */
.siege-threat.distance-3 { --side-position: -4%; }
.siege-threat.distance-2 { --side-position: 2.5%; }
.siege-threat.distance-1 { --side-position: 9%; }
.siege-threat.distance-0 { --side-position: 15.5%; }

.threat-next-marker {
  --tx: 0%;
  --ty: 0%;
  --lane-shift: 0px;
  --side-position: 2.5%;
  position: absolute;
  z-index: 2;
  width: 48px;
  height: 51px;
  border: 2px dashed rgba(73,59,122,.62);
  border-radius: 48% 52% 45% 55%;
  background: rgba(255,249,233,.56);
  box-shadow: 0 0 0 3px rgba(255,249,233,.35);
  opacity: .58;
  transform: translate(var(--tx), var(--ty));
  transition:
    left .27s ease,
    right .27s ease,
    top .27s ease,
    bottom .27s ease,
    transform .27s ease;
}

.threat-next-marker::before {
  content: "";
  position: absolute;
  inset: 3px;
  background: var(--monster-art) center / contain no-repeat;
  filter: grayscale(.18) saturate(.75);
}

.threat-next-marker::after {
  content: attr(data-threat-letter) " NEXT SIDE";
  position: absolute;
  left: 50%;
  bottom: -17px;
  min-width: max-content;
  padding: 2px 5px;
  border: 1px solid rgba(51,39,87,.65);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255,249,233,.94);
  box-shadow: 1px 1px 0 rgba(51,39,87,.12);
  font: 700 .48rem/1 system-ui, sans-serif;
  letter-spacing: .04em;
  text-transform: uppercase;
  transform: translateX(-50%);
}

.threat-next-marker.side-top {
  left: 50%;
  top: var(--side-position);
  --tx: calc(-50% + var(--lane-shift));
}

.threat-next-marker.side-bottom {
  left: 50%;
  bottom: var(--side-position);
  --tx: calc(-50% + var(--lane-shift));
}

.threat-next-marker.side-left {
  left: var(--side-position);
  top: 50%;
  --ty: calc(-50% + var(--lane-shift));
}

.threat-next-marker.side-right {
  right: var(--side-position);
  top: 50%;
  --ty: calc(-50% + var(--lane-shift));
}

.threat-next-marker.lane-a { --lane-shift: -27px; }
.threat-next-marker.lane-b { --lane-shift: 27px; }
.threat-next-marker.is-hidden { display: none; }

@media (max-width: 680px) {
  .castle-arena {
    transform: scale(.86);
  }

  .threat-next-marker {
    width: 38px;
    height: 41px;
  }

  .threat-next-marker::after {
    bottom: -14px;
    padding: 2px 4px;
    font-size: .4rem;
  }

  .threat-next-marker.lane-a { --lane-shift: -21px; }
  .threat-next-marker.lane-b { --lane-shift: 21px; }

  .approach-zones b {
    font-size: .68rem;
  }
}

/* Compact square road stops make each monster step read as a real position
   while the illustrated dirt tiles connect into a path toward the castle. */
.castle-arena {
  /* Keep both axes tied to the viewport width. A percentage here resolves
     against different arena dimensions, which can stretch a square tile. */
  --approach-zone-size: clamp(38px, 3.75vw, 48px);
  --approach-half-zone: calc(var(--approach-zone-size) / 2);
  --approach-monster-half: 28px;
  --approach-route-offset: calc(
    9% + var(--approach-monster-half)
    - var(--approach-zone-size)
    - var(--approach-zone-size)
    - var(--approach-half-zone)
    + 4px
  );
}

.zones-top,
.zones-bottom {
  left: 50%;
  width: var(--approach-zone-size);
  height: calc(
    var(--approach-zone-size)
    + var(--approach-zone-size)
    + var(--approach-zone-size)
    + 2px
  );
  transform: translateX(-50%);
}

.zones-left,
.zones-right {
  top: 50%;
  width: calc(
    var(--approach-zone-size)
    + var(--approach-zone-size)
    + var(--approach-zone-size)
    + 2px
  );
  height: var(--approach-zone-size);
  transform: translateY(-50%);
}

.zones-top { top: var(--approach-route-offset); }
.zones-right { right: var(--approach-route-offset); }
.zones-bottom { bottom: var(--approach-route-offset); }
.zones-left { left: var(--approach-route-offset); }

.approach-zones {
  gap: 1px;
}

.approach-zones i,
.approach-zones i:nth-child(2),
.approach-zones i:nth-child(3) {
  position: relative;
  isolation: isolate;
  overflow: visible;
  border: 0;
  border-radius: 24%;
  color: var(--ink);
  background: transparent;
  box-shadow: none;
}

.zones-top i,
.zones-bottom i {
  flex: 0 0 var(--approach-zone-size);
  width: 100%;
  height: var(--approach-zone-size);
}

.zones-left i,
.zones-right i {
  flex: 0 0 var(--approach-zone-size);
  width: var(--approach-zone-size);
  height: 100%;
}

.approach-zones i::before {
  content: "";
  position: absolute;
  z-index: 0;
  inset: -18%;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  filter: drop-shadow(1px 2px 0 rgba(51,39,87,.2));
}

.approach-zones i:nth-child(1)::before {
  background-image: url("../assets/art/game/monster-road-far.png");
}

.approach-zones i:nth-child(2)::before {
  background-image: url("../assets/art/game/monster-road-near.png");
}

.approach-zones i:nth-child(3)::before {
  background-image: url("../assets/art/game/monster-road-wall.png");
}

.zones-left i::before,
.zones-right i::before {
  transform: rotate(90deg);
}

.approach-zones b,
.approach-zones span {
  position: relative;
  z-index: 1;
}

.approach-zones b {
  width: 1.55em;
  height: 1.55em;
  margin: 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid rgba(51,39,87,.62);
  border-radius: 50%;
  color: var(--ink);
  background: rgba(255,249,233,.94);
  box-shadow: 1px 1px 0 rgba(51,39,87,.16);
  font-size: clamp(.62rem, 1.55vw, .86rem);
}

.approach-zones span {
  width: max-content;
  max-width: 100%;
  margin: 2px auto 0;
  padding: 1px 3px;
  border-radius: 999px;
  color: #533a29;
  background: rgba(255,249,233,.9);
  box-shadow: 0 1px 0 rgba(51,39,87,.15);
  font-size: clamp(.34rem, .82vw, .48rem);
  line-height: 1.05;
}

.siege-threat.distance-3 {
  --side-position: calc(
    9% - var(--approach-zone-size) - var(--approach-zone-size) + 6px
  );
}

.siege-threat.distance-2 {
  --side-position: calc(9% - var(--approach-zone-size) + 3px);
}

.siege-threat.distance-1 { --side-position: 9%; }
.siege-threat.distance-0 { --side-position: calc(9% + var(--approach-zone-size) + 1px); }

.threat-next-marker {
  --side-position: calc(9% - var(--approach-zone-size) - 1px);
}

.siege-threat {
  width: 56px;
  height: 61px;
}

.siege-threat::before {
  inset: -5px;
}

.siege-threat strong {
  top: 46px;
  width: 21px;
  height: 21px;
}

@media (max-width: 680px) {
  .castle-arena,
  body:not(.menu-open) .castle-arena {
    --approach-monster-half: 22px;
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    height: auto;
    min-height: 0;
    flex: 0 0 auto;
  }

  .siege-threat {
    width: 45px;
    height: 51px;
  }

  .siege-threat::before {
    inset: -4px;
  }

  .siege-threat strong {
    top: 39px;
    width: 18px;
    height: 18px;
  }

  .approach-zones {
    gap: 0;
  }

  .zones-top,
  .zones-bottom {
    height: calc(
      var(--approach-zone-size)
      + var(--approach-zone-size)
      + var(--approach-zone-size)
    );
  }

  .zones-left,
  .zones-right {
    width: calc(
      var(--approach-zone-size)
      + var(--approach-zone-size)
      + var(--approach-zone-size)
    );
  }

  .approach-zones i::before {
    inset: -20%;
  }

  .approach-zones b {
    font-size: clamp(.48rem, 2.2vw, .66rem);
  }

  .approach-zones span {
    display: none;
  }
}
