:root {
  --ink: #1b2140;
  --ink-2: #262e57;
  --panel: rgba(27, 33, 64, 0.9);
  --panel-soft: rgba(27, 33, 64, 0.72);
  --line: rgba(255, 255, 255, 0.14);
  --cream: #fff8ea;
  --muted: rgba(255, 248, 234, 0.68);
  --gold: #ffc93c;
  --gold-deep: #d9901a;
  --grass: #5ad07a;
  --grass-deep: #2f9a4e;
  --danger: #ff5d5d;
  --frost: #7fd8ff;
  --radius: 18px;
  --font-display: 'Lilita One', 'Nunito', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: dark;
}

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--cream);
  font-family: var(--font-body);
  font-weight: 600;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  /* clip: not even scripts or focus can scroll the game layer. */
  overflow: clip;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#damage-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(255, 40, 40, 0.55) 100%);
}

#damage-vignette.is-playing {
  animation: hurt 0.7s ease-out;
}

@keyframes hurt {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  border: none;
  background: none;
  padding: 0;
}

button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

button:disabled {
  cursor: default;
}

/* ---------------------------------------------------------------- buttons */

.btn {
  min-height: 54px;
  padding: 0 22px;
  border-radius: 16px;
  background: var(--ink-2);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.28), 0 2px 0 rgba(0, 0, 0, 0.2);
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: 0.03em;
  transition: transform 0.12s var(--ease-out), filter 0.2s ease;
}

.btn:active:not(:disabled) {
  transform: translateY(2px) scale(0.98);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.28);
}

.btn--primary {
  background: linear-gradient(180deg, #74e38f, var(--grass-deep));
  color: #0f2d17;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

.btn--gold {
  background: linear-gradient(180deg, #ffdd6b, var(--gold-deep));
  color: #3a2300;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}

.btn--ghost {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--line);
}

.btn--danger {
  background: linear-gradient(180deg, #ff8080, #d93a3a);
  color: #3a0000;
}

.btn:disabled {
  filter: grayscale(0.9) brightness(0.7);
}

.round-btn {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3);
  font-family: var(--font-display);
  font-size: 18px;
}

.round-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.round-btn[aria-pressed='true'] {
  background: linear-gradient(180deg, #ffdd6b, var(--gold-deep));
  color: #3a2300;
}

/* ---------------------------------------------------------------- HUD */

.hud {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 10px) calc(var(--safe-right) + 12px) 0 calc(var(--safe-left) + 12px);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-16px);
  transition: opacity 0.3s ease, transform 0.4s var(--ease-out);
}

.hud.is-visible {
  opacity: 1;
  transform: none;
}

.hud.is-visible button {
  pointer-events: auto;
}

.hud__stats {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.stat {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px 5px 7px;
  border-radius: 999px;
  background: var(--panel);
  font-family: var(--font-display);
  font-size: 19px;
  font-variant-numeric: tabular-nums;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3);
}

.stat svg {
  width: 20px;
  height: 20px;
}

.stat--lives svg {
  fill: var(--danger);
}

.stat--gold svg circle {
  fill: var(--gold);
}

.stat--gold .coin-mark {
  fill: none;
  stroke: var(--gold-deep);
  stroke-width: 1.8;
  stroke-linecap: round;
}

.stat.bump {
  animation: bump 0.3s var(--spring);
}

.stat.hurt {
  animation: shake 0.4s ease;
  color: var(--danger);
}

@keyframes bump {
  0% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.hud__wave {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 14px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3);
  line-height: 1.05;
}

.hud__wave span {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.hud__wave strong {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.hud__actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

/* ---------------------------------------------------------------- wave dock */

.dock {
  position: absolute;
  inset: auto 0 0 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 calc(var(--safe-right) + 12px) calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + 12px);
  pointer-events: none;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.3s ease, transform 0.4s var(--ease-out);
}

.dock.is-visible {
  opacity: 1;
  transform: none;
}

.dock.is-visible .wave-btn,
.dock.is-visible .spell {
  pointer-events: auto;
}

/* ---------------------------------------------------------------- spells */

.spells {
  width: min(100%, 440px);
  display: flex;
  gap: 10px;
}

.spell {
  position: relative;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 35%, var(--spell-light), var(--spell-dark));
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.3), 0 0 0 3px rgba(255, 255, 255, 0.85);
  transition: transform 0.15s var(--spring), box-shadow 0.2s ease;
}

.spell[data-spell='meteor'] { --spell-light: #ffb36b; --spell-dark: #d4461c; }
.spell[data-spell='blizzard'] { --spell-light: #c9f1ff; --spell-dark: #3a8fd6; }
.spell[data-spell='lightning'] { --spell-light: #fff39a; --spell-dark: #c98a12; }

.spell svg {
  position: relative;
  z-index: 1;
  width: 28px;
  height: 28px;
  fill: #fff;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.3));
}

.spell__cooldown {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: conic-gradient(rgba(12, 16, 36, 0.72) calc(var(--remaining, 0) * 1turn), transparent 0);
  pointer-events: none;
}

.spell__time {
  position: absolute;
  z-index: 3;
  font-family: var(--font-display);
  font-size: 18px;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}

.spell.is-ready {
  animation: spell-ready 2s ease-in-out infinite;
}

@keyframes spell-ready {
  0%, 100% { box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.3), 0 0 0 3px rgba(255, 255, 255, 0.85); }
  50% { box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.3), 0 0 22px var(--spell-light), 0 0 0 3px #fff; }
}

.spell.is-armed {
  transform: scale(1.15) translateY(-4px);
  box-shadow: 0 0 0 4px var(--gold), 0 0 28px var(--spell-light);
}

.spell:disabled svg {
  opacity: 0.6;
}

.spell-hint {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 170px);
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 16px;
  border-radius: 999px;
  background: var(--cream);
  color: var(--ink);
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 0.2s ease, transform 0.3s var(--spring);
}

.spell-hint.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.spell-hint button {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--cream);
  font-size: 13px;
}

/* Kingdom: objective column with the day's event under it. */
.hud__col {
  flex: 1;
  min-width: 0;
  max-width: 300px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.hud__col .objective {
  width: 100%;
}

.event-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #6a3fd0, #3a2a8a);
  color: var(--cream);
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
  animation: objective-new 0.5s var(--spring);
}

.event-chip[hidden] {
  display: none;
}

/* Boss health bar (motherships). */
.boss-bar {
  position: absolute;
  left: 50%;
  top: calc(var(--safe-top) + 200px);
  z-index: 3;
  width: min(calc(100% - 40px), 360px);
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
}

.boss-bar[hidden] {
  display: none;
}

.boss-bar__name {
  display: block;
  font-family: var(--font-display);
  font-size: 16px;
  color: #ffb0d8;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
}

.boss-bar__track {
  position: relative;
  display: block;
  height: 12px;
  margin-top: 3px;
  border-radius: 999px;
  background: rgba(20, 10, 30, 0.8);
  box-shadow: 0 0 0 2px rgba(255, 176, 216, 0.7);
  overflow: hidden;
}

.boss-bar__track i {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: linear-gradient(90deg, #ff3a8a, #ff9ad0);
  transition: width 0.2s linear;
}

.boss-bar__track .boss-bar__shield {
  background: rgba(120, 200, 255, 0.85);
  top: 55%;
}

/* Trades (market and merchant). */
.trades {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.trade {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
}

.trade.is-merchant {
  box-shadow: inset 0 0 0 2px rgba(180, 140, 255, 0.6);
}

.trade__deal {
  flex: 1;
  font-weight: 800;
  font-size: 15px;
}

.trade .btn {
  min-height: 40px;
  padding: 0 14px;
}

/* Blessing picker at dawn. */
.blessing-box {
  width: min(100%, 380px);
  text-align: center;
}

.blessing-box .report__kicker {
  color: var(--gold);
}

.blessing-box .report__title {
  color: var(--cream);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.blessings {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.blessing {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, #fff8ea, #f4e6c8);
  color: var(--ink);
  text-align: left;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35), inset 0 -4px 0 rgba(0, 0, 0, 0.08);
  opacity: 0;
  transform: translateY(20px) scale(0.95);
}

.screen.is-visible .blessing {
  animation: report-in 0.5s var(--spring) forwards;
}

.blessing span:first-child {
  font-size: 34px;
}

.blessing b {
  display: block;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 19px;
}

.blessing small {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: rgba(27, 33, 64, 0.7);
}

.blessing em {
  margin-left: auto;
  font-style: normal;
  font-weight: 800;
  font-size: 12px;
  color: #b07a2a;
}

/* Daily challenge card (menu). */
.realm-card.realm-card--daily {
  background: linear-gradient(110deg, #c0572a 0%, #8a2f6a 60%, #3a1f5c 100%);
}

.realm-card.realm-card--daily.is-done {
  background: linear-gradient(110deg, #3a8a5a 0%, #2a5c6a 60%, #2b2f5c 100%);
}

/* Bestiary screen. */
.bestiary-count {
  margin: -8px 0 0;
  font-weight: 800;
  color: var(--muted);
}

.bestiary {
  width: min(100%, 440px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.beast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3);
}

.beast img {
  width: 64px;
  height: 64px;
  flex: none;
}

.beast > div {
  flex: 1;
  min-width: 0;
}

.beast b {
  display: block;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 18px;
}

.beast span {
  display: block;
  font-size: 13px;
  color: var(--muted);
}

.beast dl {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  margin: 6px 0 0;
  font-size: 12px;
}

.beast dl div {
  display: flex;
  gap: 4px;
}

.beast dt {
  color: var(--muted);
}

.beast dd {
  margin: 0;
  font-weight: 800;
}

.beast em {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-style: normal;
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--gold);
}

.beast em small {
  font-family: var(--font-body);
  font-size: 10px;
  color: var(--muted);
}

.beast.is-unknown img {
  filter: brightness(0) opacity(0.45);
}

/* Kingdom HUD row: current objective and minimap. */
.hud__row {
  grid-column: 1 / -1;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.hud__row[hidden] {
  display: none;
}

.objective {
  position: relative;
  flex: 1;
  min-width: 0;
  max-width: 300px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px 9px 8px;
  overflow: hidden;
  border-radius: 14px;
  background: var(--panel);
  color: var(--cream);
  text-align: left;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3);
  pointer-events: auto;
}

.objective[hidden] {
  display: none;
}

.objective__icon {
  font-size: 18px;
}

.objective__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.objective__body b {
  overflow: hidden;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.objective__body small {
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
}

.objective__body small .costs span {
  color: var(--gold);
}

.objective__count {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--gold);
}

.objective__bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
}

.objective__bar i {
  display: block;
  height: 100%;
  background: var(--gold);
  transition: width 0.4s var(--ease-out);
}

.objective.is-done {
  background: linear-gradient(180deg, #ffd65c, #f0a92a);
  color: var(--ink);
}

.objective.is-done .objective__body small,
.objective.is-done .objective__count {
  color: var(--ink);
}

.objective.is-cheering {
  animation: objective-cheer 0.7s var(--spring);
}

.objective.is-new {
  animation: objective-new 0.5s var(--spring);
}

@keyframes objective-cheer {
  0% { transform: scale(1); }
  35% { transform: scale(1.08) rotate(-1.5deg); }
  70% { transform: scale(0.98) rotate(1deg); }
  100% { transform: none; }
}

@keyframes objective-new {
  from { transform: translateX(-30px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.minimap {
  position: relative;
  flex: none;
  margin-left: auto;
  pointer-events: auto;
}

.minimap canvas {
  display: block;
  width: 84px;
  height: 84px;
  border-radius: 14px;
  box-shadow: 0 0 0 2px rgba(255, 248, 234, 0.85), 0 4px 12px rgba(0, 0, 0, 0.35);
  touch-action: none;
}

.minimap__recenter {
  position: absolute;
  right: 0;
  bottom: -42px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--cream);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  animation: objective-new 0.3s var(--spring);
}

.minimap__rotate {
  position: absolute;
  left: 0;
  bottom: -42px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--cream);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}

.minimap__rotate svg {
  width: 22px;
  height: 22px;
}

.minimap__rotate .needle-n {
  fill: #e0463c;
}

.minimap__rotate .needle-s {
  fill: var(--ink);
  opacity: 0.55;
}

.minimap__recenter[hidden] {
  display: none;
}

.minimap__recenter svg {
  width: 20px;
  height: 20px;
  fill: var(--ink);
}

/* Arrows toward UFOs off screen. */
.arrows {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.edge-arrow {
  position: absolute;
  left: 0;
  top: 0;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  display: grid;
  place-items: center;
}

.edge-arrow[hidden] {
  display: none;
}

.edge-arrow svg {
  width: 30px;
  height: 30px;
  fill: #ff5d5d;
  filter: drop-shadow(0 0 6px rgba(255, 60, 60, 0.8));
  animation: edge-pulse 0.9s ease-in-out infinite;
}

.edge-arrow b {
  position: absolute;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 13px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

@keyframes edge-pulse {
  50% { opacity: 0.6; }
}

/* Dawn report after each night. */
.screen--report {
  justify-content: center;
  background: radial-gradient(circle at 50% 40%, rgba(255, 200, 120, 0.25), rgba(20, 24, 48, 0.6) 70%);
}

.screen--report.is-danger {
  background: radial-gradient(circle at 50% 40%, rgba(255, 90, 90, 0.25), rgba(20, 24, 48, 0.65) 70%);
}

.report {
  width: min(100%, 360px);
  padding: 22px 20px 18px;
  border-radius: 24px;
  background: linear-gradient(180deg, #fff8ea, #f4e6c8);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35), inset 0 -5px 0 rgba(0, 0, 0, 0.08);
  transform: translateY(24px) scale(0.92);
  opacity: 0;
}

.screen--report.is-visible .report {
  animation: report-in 0.55s var(--spring) forwards;
}

@keyframes report-in {
  to { transform: none; opacity: 1; }
}

.report__kicker {
  margin: 0;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #b07a2a;
}

.report__title {
  margin: 2px 0 6px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 30px;
  line-height: 1.1;
}

.is-danger .report__title {
  color: #c0392b;
}

.report__stars {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
}

.report__stars i {
  width: 38px;
  height: 38px;
  transform: scale(0);
}

.report__stars i:nth-child(2) {
  width: 46px;
  height: 46px;
  margin-top: -6px;
}

.screen--report.is-visible .report__stars i {
  animation: star-pop 0.45s var(--spring) forwards;
}

@keyframes star-pop {
  to { transform: scale(1); }
}

.report__stars svg {
  width: 100%;
  height: 100%;
  fill: rgba(27, 33, 64, 0.14);
}

.report__stars i.on svg {
  fill: var(--gold);
  filter: drop-shadow(0 2px 0 var(--gold-deep));
}

.report__stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 10px;
}

.report__stats div {
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(27, 33, 64, 0.07);
  opacity: 0;
  transform: translateY(8px);
}

.screen--report.is-visible .report__stats div {
  animation: report-row 0.4s var(--ease-out) forwards;
}

@keyframes report-row {
  to { opacity: 1; transform: none; }
}

.report__stats dt {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(27, 33, 64, 0.55);
}

.report__stats dd {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}

.report__stats .good dd {
  color: #2f9a4e;
}

.report__stats .bad dd {
  color: #c0392b;
}

.report__stats .gold dd {
  color: #c07f0c;
}

.report__best {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: 16px;
  background: rgba(255, 201, 60, 0.22);
  text-align: left;
}

.report__best[hidden] {
  display: none;
}

.report__best img {
  width: 56px;
  height: 56px;
}

.report__best small {
  display: block;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #b07a2a;
}

.report__best b {
  display: block;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 19px;
}

.report__best span {
  font-size: 13px;
  font-weight: 700;
  color: rgba(27, 33, 64, 0.65);
}

.report__note {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 700;
  color: rgba(27, 33, 64, 0.7);
}

.report__note:empty {
  display: none;
}

.report__actions {
  display: flex;
  gap: 8px;
}

.report__actions .btn {
  flex: 1;
}

.report__actions .btn[hidden] {
  display: none;
}

.report__actions .btn--ghost {
  color: var(--ink);
  box-shadow: inset 0 0 0 2px rgba(27, 33, 64, 0.18);
}

/* The knight: portrait with level and health, and his power next to it. */
.hero-group {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.spell--hero {
  --spell-light: #ffe08a;
  --spell-dark: #b8741a;
}

.hero-btn {
  position: relative;
  width: 56px;
  height: 56px;
  padding: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #3a4478, #1b2140);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.3), 0 0 0 3px var(--gold);
  pointer-events: auto;
}

.hero-btn img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.hero-btn b {
  position: absolute;
  right: -4px;
  top: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 13px;
  line-height: 20px;
}

.hero-btn__hp {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 4px;
  height: 5px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.hero-btn__hp i {
  display: block;
  height: 100%;
  background: #ffd65c;
}

.hero-btn.is-down {
  filter: grayscale(1) brightness(0.6);
}

.hero-btn.is-selected {
  box-shadow: 0 0 0 4px #fff, 0 0 22px var(--gold);
}

.spells--compact .hero-btn {
  width: 48px;
  height: 48px;
}

.spells--tight {
  gap: 6px;
}

.spells--tight .spell,
.spells--tight .hero-btn {
  width: 40px;
  height: 40px;
}

.spells--tight .spell svg {
  width: 20px;
  height: 20px;
}

.spells--tight .hero-group {
  gap: 6px;
}

/* Tower specializations: two choice cards at the last level. */
.branches {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 2px 0 10px;
}

.branches[hidden] {
  display: none;
}

.branches__title {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gold);
}

.branch {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 201, 60, 0.18), rgba(255, 201, 60, 0.06));
  box-shadow: inset 0 0 0 2px rgba(255, 201, 60, 0.45);
  color: var(--cream);
  text-align: left;
}

.branch b {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 16px;
}

.branch span {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--muted);
}

.branch em {
  margin-top: auto;
  font-style: normal;
  font-weight: 800;
  font-size: 13px;
}

.branch:disabled {
  opacity: 0.55;
}

/* Undo toast after placing a construction site. */
.undo {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 170px);
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 16px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(20, 18, 34, 0.92);
  color: var(--cream);
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px) scale(0.96);
  transition: opacity 0.2s ease, transform 0.3s var(--spring);
}

.undo.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0) scale(1);
}

.undo button {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--ink);
  font-size: 13px;
}

.undo__timer {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: var(--gold);
  transform-origin: left;
}

.undo__timer.is-running {
  animation: undo-timer linear forwards;
}

@keyframes undo-timer {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* Construction progress in the info sheet. */
.work {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 2px 0 10px;
  font-weight: 800;
  font-size: 13px;
  color: var(--ink-soft, #5a5670);
}

.work[hidden] {
  display: none;
}

.work__bar {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

.work__bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffb730, #ffd966);
  transition: width 0.3s ease;
}

.sheet__actions .btn[hidden] {
  display: none;
}

#screen-flash {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 50%, rgba(255, 240, 200, 0.9), rgba(255, 150, 60, 0.25) 60%, transparent 90%);
}

#screen-flash.is-playing {
  animation: hurt 0.5s ease-out;
}

#screen-flash[data-variant='frost'] {
  background: radial-gradient(circle at 50% 50%, rgba(220, 250, 255, 0.85), rgba(120, 200, 255, 0.25) 60%, transparent 90%);
}

#screen-flash[data-variant='lightning'] {
  background: rgba(230, 240, 255, 0.55);
}

/* ---------------------------------------------------------------- flying coins */

.coins {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.coin {
  position: absolute;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3b0, var(--gold) 45%, var(--gold-deep));
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
  opacity: 0;
}

.res-fly {
  position: absolute;
  margin: -11px 0 0 -11px;
  font-size: 20px;
  line-height: 22px;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
  opacity: 0;
}

.res-fly.is-flying {
  opacity: 1;
  transition: transform 0.62s cubic-bezier(0.5, -0.4, 0.75, 0.55);
}

.coin.is-flying {
  opacity: 1;
  transition: transform 0.65s cubic-bezier(0.55, -0.35, 0.8, 0.6);
}

.wave-btn {
  position: relative;
  width: min(100%, 440px);
  min-height: 70px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 18px;
  overflow: hidden;
  border-radius: 20px;
  text-align: left;
  background: linear-gradient(180deg, #ff8a5c, #e0482f);
  color: #fff;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.25), 0 6px 20px rgba(0, 0, 0, 0.25);
  transition: transform 0.12s var(--ease-out), filter 0.2s ease;
}

.wave-btn:active:not(:disabled) {
  transform: translateY(2px) scale(0.985);
}

.wave-btn:disabled {
  background: var(--panel);
}

.wave-btn.is-ready:not(:disabled) {
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.25), 0 6px 20px rgba(0, 0, 0, 0.25); }
  50% { box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.25), 0 6px 30px rgba(255, 110, 70, 0.7); }
}

.wave-btn__progress {
  position: absolute;
  inset: auto 0 0 0;
  height: 5px;
  background: rgba(255, 255, 255, 0.85);
  transform-origin: left;
  transform: scaleX(0);
}

.wave-btn__text {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.wave-btn__title {
  font-family: var(--font-display);
  font-size: 21px;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

.wave-btn__meta {
  font-size: 13px;
  opacity: 0.9;
}

.wave-btn__preview {
  display: flex;
  gap: 4px;
}

.enemy-chip {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.2);
}

.enemy-chip img {
  width: 100%;
  height: 100%;
}

.enemy-chip b {
  position: absolute;
  right: -3px;
  bottom: -3px;
  min-width: 20px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--ink);
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 13px;
  line-height: 20px;
  text-align: center;
}

/* ---------------------------------------------------------------- sheets */

.sheet {
  position: absolute;
  left: 50%;
  bottom: 0;
  z-index: 5;
  width: min(100%, 520px);
  padding: 14px calc(var(--safe-right) + 14px) calc(var(--safe-bottom) + 14px) calc(var(--safe-left) + 14px);
  border-radius: 24px 24px 0 0;
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.3);
  transform: translate(-50%, 105%);
  visibility: hidden;
  transition: transform 0.35s var(--ease-out), visibility 0s linear 0.35s;
  touch-action: pan-y;
}

.sheet.is-open {
  transform: translate(-50%, 0);
  visibility: visible;
  transition: transform 0.35s var(--ease-out), visibility 0s;
}

.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.sheet h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 24px;
  letter-spacing: 0.02em;
}

.sheet__close {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 16px;
}

.sheet__hint {
  margin: 10px 2px 0;
  font-size: 13px;
  color: var(--muted);
}

.build-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.build-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px 8px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 0 0 2px transparent;
  transition: transform 0.15s var(--ease-out), box-shadow 0.15s ease, background 0.15s ease;
}

.build-card img {
  width: 100%;
  max-width: 72px;
  aspect-ratio: 1;
}

.build-card__name {
  font-size: 12px;
  line-height: 1.1;
  text-align: center;
}

.build-card__cost {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--gold);
}

.build-card__cost::before,
.gold-inline::before {
  content: '';
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: inset 0 -2px 0 var(--gold-deep);
}

.build-card.is-selected {
  background: rgba(90, 208, 122, 0.22);
  box-shadow: inset 0 0 0 2px var(--grass);
  transform: translateY(-4px);
}

.build-card.is-selected .build-card__cost {
  color: var(--cream);
}

.build-card.is-poor {
  opacity: 0.5;
}

.build-card.is-poor .build-card__cost {
  color: var(--danger);
}

.build-card.denied {
  animation: shake 0.35s ease;
}

.tower-id {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tower-id img {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
}

.pips {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.pips i {
  width: 22px;
  height: 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.16);
}

.pips i.on {
  background: var(--gold);
}

.tower-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 6px;
  margin: 0 0 12px;
}

.tower-stats div {
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
}

.tower-stats dt {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.tower-stats dd {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.tower-stats .up {
  margin-left: 4px;
  font-size: 14px;
  color: var(--grass);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  margin-bottom: 12px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.22);
}

.segmented[hidden] {
  display: none;
}

.segmented button {
  min-height: 36px;
  border-radius: 10px;
  font-size: 12px;
  color: var(--muted);
}

.segmented button[aria-pressed='true'] {
  background: var(--cream);
  color: var(--ink);
}

.sheet__actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 8px;
}

.sheet__actions.is-single {
  grid-template-columns: 1fr;
}

.sheet__actions .btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 18px;
  padding: 0 12px;
}

/* ---------------------------------------------------------------- banner, floaters, coach */

.banner {
  position: absolute;
  top: calc(var(--safe-top) + 84px);
  left: 50%;
  z-index: 4;
  padding: 10px 22px;
  border-radius: 16px;
  background: var(--panel);
  font-family: var(--font-display);
  font-size: 24px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -10px) scale(0.9);
}

.banner small {
  display: block;
  font-family: var(--font-body);
  font-size: 13px;
  text-align: center;
  color: var(--gold);
}

.banner.is-playing {
  animation: banner 2.2s var(--ease-out) forwards;
}

.banner[data-variant='danger'] {
  background: linear-gradient(180deg, #ff7a7a, #c93232);
}

@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -10px) scale(0.85); }
  12% { opacity: 1; transform: translate(-50%, 0) scale(1.05); }
  20% { transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -8px) scale(0.96); }
}

.floaters {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.floater {
  position: absolute;
  font-family: var(--font-display);
  font-size: 17px;
  white-space: nowrap;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translate(-50%, -50%);
}

.floater[data-variant='combo'] {
  color: #ffe45e;
  font-size: 20px;
  -webkit-text-stroke: 1px #7a3b00;
}

.floater[data-variant='heal'] {
  color: #7dffa8;
  font-size: 20px;
}

.floater[data-variant='danger'] {
  color: var(--danger);
  font-size: 22px;
}

.floater.is-playing {
  animation: floater 1s var(--ease-out) forwards;
}

@keyframes floater {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(1); }
}

.coach {
  position: absolute;
  left: 50%;
  top: calc(var(--safe-top) + 150px);
  z-index: 4;
  width: min(calc(100% - 32px), 360px);
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--cream);
  color: var(--ink);
  font-weight: 800;
  font-size: 15px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.3s ease, transform 0.4s var(--spring);
}

.is-realm .coach {
  top: calc(var(--safe-top) + 205px);
}

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

/* ---------------------------------------------------------------- screens */

.screen {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: calc(var(--safe-top) + 20px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 20px) calc(var(--safe-left) + 16px);
  background: rgba(20, 24, 48, 0.55);
  /* Centered when it fits, scrollable from the top when it doesn't. */
  justify-content: flex-start;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
  overflow-y: auto;
  touch-action: pan-y;
}

.screen > :first-child {
  margin-top: auto;
}

.screen > :last-child {
  margin-bottom: auto;
}

.screen.is-visible {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.35s ease, visibility 0s;
}

.screen--menu {
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(20, 24, 48, 0.55) 0%, rgba(20, 24, 48, 0) 30%, rgba(20, 24, 48, 0) 45%, rgba(20, 24, 48, 0.85) 75%);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.brand {
  text-align: center;
}

.brand__kicker,
.screen__kicker {
  margin: 0;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.brand__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(54px, 16vw, 96px);
  line-height: 0.95;
  letter-spacing: 0.02em;
  color: var(--cream);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink), 0 12px 24px rgba(0, 0, 0, 0.3);
}

.brand__tagline {
  margin: 8px 0 0;
  font-weight: 800;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}

.menu-bar {
  width: min(100%, 440px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.star-total,
.perks-balance {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px 6px 8px;
  border-radius: 999px;
  background: var(--panel);
  font-family: var(--font-display);
  font-size: 20px;
}

.star-total svg,
.perks-balance svg {
  width: 24px;
  height: 24px;
  fill: var(--gold);
  filter: drop-shadow(0 1px 0 var(--gold-deep));
}

.btn--small {
  min-height: 44px;
  padding: 0 16px;
  font-size: 17px;
}

.badge {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-left: 4px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 13px;
  text-shadow: none;
}

.badge[hidden] {
  display: none;
}

.levels {
  width: min(100%, 440px);
  display: grid;
  gap: 8px;
}

.level-card {
  position: relative;
}

.level-card__play {
  width: 100%;
}

.level-card__heroic {
  position: absolute;
  right: 12px;
  bottom: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 201, 60, 0.18);
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
}

.level-card__heroic.is-done {
  background: var(--gold);
  color: #3a2300;
}

.level-card--survival .level-card__play {
  background: linear-gradient(100deg, rgba(90, 60, 160, 0.95), rgba(27, 33, 64, 0.92));
}

.perks-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.screen__title--small {
  font-size: clamp(36px, 10vw, 52px);
}

.perks {
  width: min(100%, 440px);
  display: grid;
  gap: 8px;
}

.perk {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3);
}

.perk__icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 24px;
}

.perk__name {
  display: block;
  font-family: var(--font-display);
  font-size: 18px;
}

.perk__effect {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.perk .pips {
  margin-top: 4px;
}

.perk__buy {
  min-height: 42px;
  padding: 0 12px;
  font-size: 16px;
}

.perks-note {
  width: min(100%, 440px);
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.end-reward {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.end-reward:empty {
  display: none;
}

.level-card__play {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px 14px 8px 8px;
  border-radius: var(--radius);
  background: var(--panel);
  text-align: left;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.3);
  transition: transform 0.15s var(--ease-out);
}

.level-card__play:active:not(:disabled) {
  transform: scale(0.98);
}

.level-card__play canvas {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  image-rendering: pixelated;
}

.level-card__name {
  display: block;
  font-family: var(--font-display);
  font-size: 21px;
  line-height: 1.1;
}

.level-card__info {
  display: block;
  font-size: 13px;
  color: var(--muted);
}

.stars {
  display: flex;
  gap: 2px;
}

.stars svg {
  width: 20px;
  height: 20px;
  fill: rgba(255, 255, 255, 0.16);
}

.stars svg.on {
  fill: var(--gold);
  filter: drop-shadow(0 1px 0 var(--gold-deep));
}

.level-card__play:disabled {
  opacity: 0.55;
}

.level-card__lock {
  font-size: 22px;
}

.settings {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.chip {
  min-height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--panel-soft);
  font-size: 13px;
  color: var(--muted);
}

.chip[hidden] {
  display: none;
}

.chip__value {
  margin-left: 3px;
  color: var(--cream);
  font-weight: 800;
}

.chip[aria-pressed='false'] .chip__value {
  color: rgba(255, 248, 234, 0.4);
}

.credits {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.screen__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(48px, 14vw, 72px);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
}

.panel {
  width: min(100%, 340px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.end-stars {
  display: flex;
  gap: 8px;
}

.end-stars[hidden] {
  display: none;
}

.end-stars svg {
  width: 64px;
  height: 64px;
  fill: rgba(255, 255, 255, 0.18);
  transform: scale(0);
}

.end-stars svg.pop {
  animation: star-pop 0.5s var(--spring) forwards;
}

.end-stars svg.on {
  fill: var(--gold);
  filter: drop-shadow(0 3px 0 var(--gold-deep));
}

.end-stars svg:nth-child(2) {
  transform-origin: center;
  margin-top: -14px;
}

@keyframes star-pop {
  0% { transform: scale(0) rotate(-40deg); }
  100% { transform: scale(1) rotate(0); }
}

.end-stats {
  width: min(100%, 340px);
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.end-stats div {
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--panel);
}

.end-stats dt {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.end-stats dd {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- overlays */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  background: radial-gradient(circle at 50% 40%, #33407a, var(--ink) 70%);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0s linear 0.4s;
}

.overlay.is-visible {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.4s ease, visibility 0s;
}

.overlay--dim {
  background: rgba(20, 24, 48, 0.85);
}

.overlay p {
  margin: 0;
  max-width: 320px;
  color: var(--muted);
}

.overlay .overlay__brand {
  font-family: var(--font-display);
  font-size: 52px;
  color: var(--cream);
}

.progress {
  width: min(70vw, 260px);
  height: 12px;
  padding: 2px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--grass), var(--gold));
  transition: width 0.2s ease;
}

/* ---------------------------------------------------------------- responsive */

@media (max-height: 760px) {
  .brand__tagline,
  .credits {
    display: none;
  }
  .level-card__info {
    display: none;
  }
}

@media (max-height: 620px) {
  .brand__title {
    font-size: 56px;
  }
  .level-card__play {
    grid-template-columns: 48px 1fr auto;
    padding: 6px 12px 6px 6px;
  }
  .level-card__play canvas {
    width: 48px;
    height: 48px;
  }
}

@media (max-width: 360px) {
  .build-card__name {
    display: none;
  }
  .wave-btn__preview .enemy-chip {
    width: 34px;
    height: 34px;
  }
}

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

/* ---------------------------------------------------------------- shop, gems, achievements, resume */

.spell[hidden] {
  display: none;
}

.spell[data-spell='quake'] { --spell-light: #d9b48a; --spell-dark: #7a4e2a; }
.spell[data-spell='repair'] { --spell-light: #a8ffb8; --spell-dark: #2f9a4e; }
.spell[data-spell='goldrain'] { --spell-light: #fff0a0; --spell-dark: #d9901a; }

.spells--compact .spell {
  width: 48px;
  height: 48px;
}

.spells--compact .spell svg {
  width: 24px;
  height: 24px;
}

.wallet,
.menu-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.menu-bar {
  flex-wrap: wrap;
}

.gem {
  display: inline-block;
  width: 18px;
  height: 18px;
  background: linear-gradient(135deg, #b8f4ff, #4fb4ff 45%, #3a4fd6);
  clip-path: polygon(50% 0, 100% 38%, 50% 100%, 0 38%);
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.3));
}

.gem-total {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px 6px 10px;
  border-radius: 999px;
  background: var(--panel);
  font-family: var(--font-display);
  font-size: 20px;
}

.gem-total--big {
  margin: 0;
}

.btn--gem {
  background: linear-gradient(180deg, #8fe2ff, #3a7fd6);
  color: #06224a;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}

.badge--soft {
  width: auto;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  color: var(--cream);
}

.resume-card {
  width: min(100%, 440px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  text-align: left;
  background: linear-gradient(100deg, #74e38f, var(--grass-deep));
  color: #0f2d17;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25), 0 6px 18px rgba(0, 0, 0, 0.25);
  animation: pulse-green 2s ease-in-out infinite;
}

.resume-card[hidden] {
  display: none;
}

.resume-card b {
  display: block;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 20px;
}

.resume-card__icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  font-size: 16px;
}

@keyframes pulse-green {
  0%, 100% { box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25), 0 6px 18px rgba(0, 0, 0, 0.25); }
  50% { box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25), 0 6px 26px rgba(90, 208, 122, 0.7); }
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  width: min(100%, 440px);
  padding: 4px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.3);
}

.tab {
  min-height: 40px;
  border-radius: 10px;
  font-family: var(--font-display);
  font-size: 17px;
  color: var(--muted);
}

.tab[aria-selected='true'] {
  background: var(--cream);
  color: var(--ink);
}

.shop,
.achievements {
  width: min(100%, 440px);
  display: grid;
  gap: 8px;
}

.shop-item {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3);
}

.shop-item__art {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.07);
}

.shop-item__art img {
  width: 100%;
  height: 100%;
}

.shop-item__art .spell {
  pointer-events: none;
  animation: none;
}

.shop-item__name {
  display: block;
  font-family: var(--font-display);
  font-size: 19px;
}

.shop-item__blurb {
  display: block;
  font-size: 13px;
  color: var(--muted);
}

.shop-item__stats {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--frost);
}

.shop-item__footer {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.shop-item__buy {
  min-height: 42px;
  padding: 0 16px;
  font-size: 17px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.shop-item.is-owned .shop-item__buy {
  background: rgba(90, 208, 122, 0.2);
  color: var(--grass);
  box-shadow: none;
  filter: none;
}

.achievement {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--panel);
  opacity: 0.7;
}

.achievement.is-done {
  opacity: 1;
  box-shadow: inset 0 0 0 2px rgba(255, 201, 60, 0.6);
}

.achievement__icon {
  font-size: 24px;
  text-align: center;
}

.achievement__name {
  display: block;
  font-family: var(--font-display);
  font-size: 17px;
}

.achievement__text {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.achievement__reward {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-display);
  font-size: 16px;
}

.build-grid--wide {
  grid-template-columns: repeat(4, 1fr);
}

/* ---------------------------------------------------------------- Kingdom */

.hud__res {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  gap: 6px;
}

.hud__res[hidden] {
  display: none;
}

.res {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  padding: 3px 9px 3px 6px;
  border-radius: 999px;
  background: var(--panel);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3);
  font-variant-numeric: tabular-nums;
}

.res i {
  font-style: normal;
  font-size: 14px;
}

.res b {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 17px;
}

.res small {
  font-size: 11px;
  color: var(--muted);
}

.res.is-full b {
  color: var(--gold);
}

.res.bump {
  animation: bump 0.3s var(--spring);
}

.realm-bar {
  width: min(100%, 440px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.realm-bar[hidden] {
  display: none;
}

.dock.is-visible .realm-bar__btn {
  pointer-events: auto;
}

.realm-bar__btn {
  min-height: 40px;
  padding: 0 12px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3);
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.realm-bar__btn.is-alert {
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3), inset 0 0 0 2px var(--gold);
  color: var(--gold);
}

.realm-bar__btn:disabled {
  opacity: 0.55;
}

.tabs--sheet {
  width: 100%;
  margin-bottom: 10px;
}

.tabs--four {
  grid-template-columns: repeat(4, 1fr);
}

.tabs--four .tab {
  font-size: 14px;
}

/* Kingdom build menu: one row of cards that scrolls sideways, so the map stays visible. */
.build-grid--realm {
  display: flex;
  gap: 8px;
  margin: 0 calc(-14px - var(--safe-right)) 0 calc(-14px - var(--safe-left));
  padding: 4px calc(14px + var(--safe-right)) 6px calc(14px + var(--safe-left));
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  touch-action: pan-x;
  overscroll-behavior-x: contain;
}

.build-grid--realm::-webkit-scrollbar {
  display: none;
}

.build-grid--realm .build-card {
  flex: none;
  width: 86px;
  scroll-snap-align: start;
}

.build-grid--realm .build-card img {
  max-width: 62px;
}

#sheet-realm-build .sheet__head {
  margin-bottom: 4px;
}

#sheet-realm-build .sheet__hint {
  margin-top: 4px;
  min-height: 2.6em;
}

/* Kingdom: toasts sit above the taller dock, banners below the taller HUD. */
.is-realm .undo {
  bottom: calc(var(--safe-bottom) + 212px);
}

.is-realm .spell-hint {
  bottom: calc(var(--safe-bottom) + 262px);
}

.is-realm .banner {
  top: calc(var(--safe-top) + 285px);
}

.build-card__costs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 5px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.3;
}

.build-card__costs .poor,
.costs .poor {
  color: var(--danger);
}

.build-card.is-locked {
  opacity: 0.45;
}

.build-card__lock {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 14px;
}

.costs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0 6px;
  font-weight: 800;
}

.jobs {
  display: grid;
  gap: 8px;
}

.job {
  display: grid;
  grid-template-columns: 34px 1fr auto auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
}

.job__icon {
  font-size: 24px;
  text-align: center;
}

.job__name {
  display: block;
  font-family: var(--font-display);
  font-size: 18px;
}

.job__info {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.job__count {
  min-width: 28px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 22px;
}

.job__btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 22px;
  font-weight: 800;
}

.job__btn:disabled {
  opacity: 0.35;
}

.job--idle {
  grid-template-columns: 34px 1fr auto;
  background: rgba(255, 201, 60, 0.12);
}

.realm-card {
  position: relative;
  width: min(100%, 440px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  text-align: left;
  background: linear-gradient(110deg, #3f8f5a 0%, #2a5c8a 55%, #2b1f5c 100%);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.3);
}

.realm-card b {
  display: block;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 24px;
}

.realm-card span span,
#realm-detail {
  display: block;
  font-size: 13px;
  color: rgba(255, 248, 234, 0.85);
}

.realm-card__icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 26px;
}

.realm-card__tag {
  position: absolute;
  top: -8px;
  right: 12px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--gold);
  color: #3a2300;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.realm-card__tag[hidden] {
  display: none;
}

.research-wallet {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 10px;
  margin: 4px 0 0;
  font-size: 15px;
  font-weight: 800;
}

.research-item .shop-item__art {
  font-size: 30px;
}

.research-item.is-maxed .shop-item__buy {
  background: rgba(90, 208, 122, 0.2);
  color: var(--grass);
  box-shadow: none;
}

.research-item .pips i {
  width: 16px;
}

.btn--danger-soft {
  background: rgba(255, 93, 93, 0.18);
  color: #ffb0b0;
}

.btn--danger-soft[hidden] {
  display: none;
}

.floater[data-variant='res'] {
  color: #fff;
  font-size: 15px;
}

.floater[data-variant='night'] {
  color: #c9b8ff;
  font-size: 20px;
}

/* ---------------------------------------------------------------- heroes */

.realm-card.realm-card--hero {
  background: linear-gradient(110deg, #b8862a 0%, #8a3a2a 55%, #3a1f4c 100%);
}

.realm-card__portrait {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: radial-gradient(circle at 50% 40%, rgba(255, 240, 200, 0.35), rgba(0, 0, 0, 0.15));
}

.hero-pick {
  width: min(100%, 440px);
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 14px;
  align-items: start;
}

.hero-pick__stage {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 20px;
  overflow: hidden;
  background: linear-gradient(180deg, #2b2f5c, #151833);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.15), 0 10px 30px rgba(0, 0, 0, 0.35);
}

.hero-pick__stage::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 38%, var(--hero-glow, #ffc93c) 0%, transparent 68%);
  opacity: 0.45;
}

.hero-pick__portrait {
  position: absolute;
  inset: 8% 0 12%;
  width: 100%;
  height: 80%;
  object-fit: contain;
  animation: hero-in 0.4s var(--spring);
}

@keyframes hero-in {
  from {
    transform: translateY(12px) scale(0.9);
    opacity: 0;
  }
}

.hero-pick__role {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  padding: 4px 6px;
  border-radius: 10px;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.45);
}

.hero-pick__info h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 30px;
  line-height: 1;
}

.hero-pick__blurb {
  margin: 6px 0 8px;
  font-size: 14px;
  color: var(--muted);
}

.hero-pick__info {
  min-width: 0;
}

.hero-pick__stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px 10px;
  margin: 0 0 8px;
}

.hero-pick__stats div {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font-size: 13px;
}

.hero-pick__stats dt {
  color: var(--muted);
}

.hero-pick__stats dd {
  margin: 0;
  font-weight: 800;
}

.hero-pick__power,
.hero-pick__aura {
  margin: 0 0 6px;
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.08);
}

.hero-pick__aura[hidden] {
  display: none;
}

.hero-roster {
  width: min(100%, 440px);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.hero-chip {
  position: relative;
  aspect-ratio: 1;
  border-radius: 16px;
  padding: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #34396a, #1c1f3d);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12);
  transition: transform 0.15s ease;
}

.hero-chip img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.hero-chip.is-locked img {
  filter: grayscale(0.9) brightness(0.55);
}

.hero-chip.is-active {
  transform: translateY(-3px);
  box-shadow: inset 0 0 0 3px var(--hero-glow, #ffc93c), 0 6px 16px rgba(0, 0, 0, 0.35);
}

.hero-chip__badge {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 1px 5px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 800;
  background: rgba(0, 0, 0, 0.55);
}

@media (max-width: 360px) {
  .hero-pick {
    grid-template-columns: 110px 1fr;
  }
}
