:root {
  --sky-top: #090e24;
  --sky-mid: #131d42;
  --sky-bottom: #1e2d5c;
  --snow-bank: #d8ebff;
  --snow-shadow: #9ec0e6;
  --panel-bg: #111834;
  --panel-border: #3a4f8a;
  --panel-highlight: #ffd166;
  --text-main: #f4f7ff;
  --text-muted: #9eb3d9;
  --accent-red: #e63946;
  --accent-green: #2dc653;
  --accent-gold: #ffd166;
  --accent-blue: #4ea8de;
  --accent-purple: #b56eff;
  --pixel-font: "Courier New", "PingFang SC", "Microsoft YaHei", monospace;
}

body[data-theme="aurora"] {
  --sky-top: #071925;
  --sky-mid: #0e3845;
  --sky-bottom: #1d4e66;
  --panel-border: #39c6a8;
}

body[data-theme="fireplace"] {
  --sky-top: #1d1018;
  --sky-mid: #341a22;
  --sky-bottom: #4f2828;
  --panel-border: #e09f3e;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  font-family: var(--pixel-font);
  color: var(--text-main);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 55%, var(--sky-bottom) 100%);
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

.snow-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.santa-sleigh {
  position: fixed;
  top: 13%;
  left: -20%;
  font-size: 2rem;
  z-index: 25;
  pointer-events: none;
  opacity: 0;
  filter: drop-shadow(0 0 8px rgba(255, 209, 102, 0.8));
}

.santa-sleigh.flying {
  animation: flySleigh 4.2s linear forwards;
}

@keyframes flySleigh {
  0% { transform: translateX(0) translateY(0); opacity: 1; }
  50% { transform: translateX(65vw) translateY(-28px); opacity: 1; }
  100% { transform: translateX(135vw) translateY(8px); opacity: 0; }
}

.top-hud {
  position: relative;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(9, 14, 36, 0.85), rgba(9, 14, 36, 0));
}

.hud-left {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.pixel-badge {
  display: inline-block;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 700;
  background: var(--accent-red);
  color: #fff;
  border: 2px solid #fff;
  box-shadow: 2px 2px 0 #090e24;
}

.tree-title {
  margin: 0;
  font-size: clamp(15px, 1.9vw, 20px);
  letter-spacing: 0.4px;
  color: var(--accent-gold);
  text-shadow: 2px 2px 0 #090e24;
}

.gift-count {
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(17, 24, 52, 0.72);
  padding: 2px 7px;
  border: 2px solid var(--panel-border);
}

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

.pixel-btn {
  appearance: none;
  font-family: var(--pixel-font);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  color: var(--text-main);
  background: #1b2852;
  border: 2px solid #7693d6;
  box-shadow: 3px 3px 0 #070b1a;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s ease;
}

.pixel-btn:hover {
  background: #25366c;
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 #070b1a;
}

.pixel-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #070b1a;
}

.pixel-btn:focus-visible {
  outline: 3px solid var(--accent-gold);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent-green);
  color: #07190e;
  border-color: #aef7c3;
}

.btn-primary:hover {
  background: #3be066;
}

.btn-gold {
  background: var(--accent-gold);
  color: #1f1404;
  border-color: #fff6cf;
}

.btn-gold:hover {
  background: #ffe08a;
}

.btn-ghost {
  background: rgba(17, 24, 52, 0.78);
  border-color: var(--panel-border);
}

.btn-icon {
  padding: 6px 9px;
}

.stage {
  position: relative;
  z-index: 5;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 12px;
}

.tree-stage {
  position: relative;
  width: min(720px, 100%);
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 6px;
}

.tree-stage::after {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 115px;
  background:
    radial-gradient(ellipse 65% 55px at 50% 18px, var(--snow-bank) 68%, transparent 70%),
    linear-gradient(180deg, var(--snow-bank) 0%, var(--snow-shadow) 100%);
  z-index: -1;
  pointer-events: none;
}

.pixel-moon {
  position: absolute;
  top: 10px;
  right: 8%;
  width: 48px;
  height: 48px;
  background: #fff3b0;
  box-shadow:
    0 0 24px rgba(255, 243, 176, 0.45),
    inset -10px -6px 0 #e9c46a;
  image-rendering: pixelated;
  pointer-events: none;
}

.tree-container {
  position: relative;
  width: min(440px, 88vw, 54dvh);
  aspect-ratio: 64 / 78;
  user-select: none;
}

.tree-art,
.pixel-tree-svg {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

.tree-star {
  filter: drop-shadow(0 0 6px rgba(255, 209, 102, 0.9));
}

@media (prefers-reduced-motion: no-preference) {
  .tree-light.l1 { animation: blinkLight 1.9s steps(2, end) infinite; }
  .tree-light.l2 { animation: blinkLight 2.4s steps(2, end) 0.5s infinite; }
  .tree-light.l3 { animation: blinkLight 2.1s steps(2, end) 1.1s infinite; }
}

@keyframes blinkLight {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.ornaments-layer {
  position: absolute;
  inset: 0;
}

.ornament-btn {
  position: absolute;
  left: calc(var(--orn-x, 50) * 1%);
  top: calc(var(--orn-y, 50) * 1%);
  transform: translate(-50%, -50%);
  width: clamp(36px, 8vw, 48px);
  height: clamp(36px, 8vw, 48px);
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.14s ease, filter 0.14s ease;
}

.ornament-btn:hover,
.ornament-btn:focus-visible {
  transform: translate(-50%, -56%) scale(1.22);
  z-index: 8;
  outline: none;
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.9));
}

.ornament-btn.rarity-legendary {
  filter: drop-shadow(0 0 8px rgba(255, 209, 102, 0.95));
}

.ornament-btn.rarity-legendary::after {
  content: "✦";
  position: absolute;
  top: -6px;
  right: -4px;
  font-size: 12px;
  color: var(--accent-gold);
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  .ornament-btn .pixel-sprite {
    transform-origin: 50% 8%;
    animation: gentleSway 3.4s ease-in-out var(--sway-delay, 0s) infinite;
  }

  .ornament-btn.just-hung {
    animation: popHang 0.55s cubic-bezier(0.2, 1.4, 0.4, 1);
  }
}

@keyframes gentleSway {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}

@keyframes popHang {
  0% { transform: translate(-50%, -140%) scale(0.4); opacity: 0; }
  70% { transform: translate(-50%, -44%) scale(1.25); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.pixel-sprite {
  image-rendering: pixelated;
  display: block;
}

.ground-actors {
  position: relative;
  width: min(560px, 96vw);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: -42px;
  z-index: 9;
  pointer-events: none;
}

.elf-corner,
.cocoa-trigger {
  pointer-events: auto;
}

.elf-trigger {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--text-main);
  font-family: var(--pixel-font);
}

.elf-bubble {
  max-width: 245px;
  text-align: left;
  font-size: 12px;
  line-height: 1.4;
  padding: 7px 10px;
  background: #fffdf5;
  color: #161320;
  border: 2px solid #161320;
  box-shadow: 3px 3px 0 rgba(9, 14, 36, 0.65);
}

.elf-sprite {
  display: inline-block;
  filter: drop-shadow(0 3px 0 rgba(9, 14, 36, 0.4));
}

@media (prefers-reduced-motion: no-preference) {
  .elf-sprite {
    animation: elfBob 2.2s ease-in-out infinite;
  }
}

@keyframes elfBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.cocoa-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17, 24, 52, 0.72);
  border: 2px solid var(--panel-border);
  padding: 4px 8px;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(9, 14, 36, 0.55);
}

.cocoa-trigger:hover {
  border-color: var(--accent-gold);
  transform: translateY(-2px);
}

.summon-bar {
  position: relative;
  z-index: 12;
  width: min(560px, 96vw);
  display: flex;
  justify-content: center;
  margin-top: 8px;
}

.summon-bar-btn {
  width: 100%;
  padding: 11px 16px;
  font-size: 14px;
  letter-spacing: 0.4px;
}

.pixel-toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  z-index: 40;
  padding: 8px 14px;
  background: #142048;
  color: var(--accent-gold);
  border: 2px solid var(--accent-gold);
  box-shadow: 4px 4px 0 #070b1a;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.pixel-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

dialog.pixel-dialog {
  padding: 0;
  border: 3px solid var(--accent-gold);
  background: var(--panel-bg);
  color: var(--text-main);
  box-shadow: 8px 8px 0 rgba(5, 8, 22, 0.85);
  max-width: min(680px, 94vw);
  width: 100%;
  max-height: 90dvh;
  overflow: auto;
  opacity: 0;
  transition-property: opacity, transform, display, overlay;
  transition-duration: 0.24s;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}

@media (prefers-reduced-motion: no-preference) {
  dialog.pixel-dialog {
    transform: scale(0.94);
  }
}

:is(dialog.pixel-dialog[open]):where(:not([data-closing])) {
  opacity: 1;

  @starting-style {
    opacity: 0;
  }

  @media (prefers-reduced-motion: no-preference) {
    transform: scale(1);

    @starting-style {
      transform: scale(0.94);
    }
  }

  &::backdrop {
    background-color: rgba(5, 8, 22, 0.74);

    @starting-style {
      background-color: rgba(5, 8, 22, 0);
    }
  }
}

dialog.pixel-dialog::backdrop {
  background-color: rgba(5, 8, 22, 0);
  backdrop-filter: blur(2px);
  transition-property: background-color, display, overlay;
  transition-duration: 0.24s;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}

@media (prefers-reduced-motion: reduce) {
  dialog.pixel-dialog {
    transition-duration: 0.1s;
  }
}

.item-dialog {
  max-width: min(440px, 92vw);
}

.countries-dialog {
  max-width: min(520px, 92vw);
}

.dialog-inner {
  padding: 18px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 2px dashed var(--panel-border);
}

.dialog-header h2 {
  margin: 0;
  font-size: 17px;
  color: var(--accent-gold);
}

.pixel-close {
  font-family: var(--pixel-font);
  font-size: 16px;
  font-weight: 700;
  width: 32px;
  height: 32px;
  background: #231838;
  color: #fff;
  border: 2px solid #7693d6;
  cursor: pointer;
}

.pixel-close:hover {
  background: var(--accent-red);
}

.dialog-desc {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
}

.rule-list {
  margin: 0 0 12px;
  padding: 10px 14px 10px 26px;
  background: #0b1128;
  border: 2px solid var(--panel-border);
  font-size: 12px;
  line-height: 1.65;
}

.prompt-box {
  margin: 0 0 14px;
  padding: 12px;
  max-height: 270px;
  overflow: auto;
  background: #070b1c;
  border: 2px dashed var(--accent-gold);
  color: #d7f5e2;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.prompt-box:focus-visible {
  outline: 2px solid var(--accent-gold);
}

.summon-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.waiting-live {
  font-size: 12px;
  color: var(--accent-green);
}

.countries-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
}

.country-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  font-family: var(--pixel-font);
  font-size: 13px;
  color: var(--text-main);
  background: #0b1128;
  border: 2px solid var(--panel-border);
  cursor: pointer;
  text-align: left;
}

.country-row:hover {
  border-color: var(--accent-gold);
  background: #16224a;
}

.country-row.active {
  border-color: var(--accent-gold);
  background: rgba(255, 209, 102, 0.14);
}

.country-rank {
  min-width: 28px;
  font-weight: 700;
  color: var(--accent-gold);
}

.country-name {
  flex: 1;
  font-weight: 700;
}

.country-metrics {
  font-size: 12px;
  color: var(--text-muted);
}

.sprite-frame {
  width: 74px;
  height: 74px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: #070b1c;
  border: 3px solid var(--accent-blue);
}

.sprite-frame-lg {
  width: 96px;
  height: 96px;
  margin: 0 auto 10px;
}

.sprite-frame.rarity-common { border-color: #9eb3d9; }
.sprite-frame.rarity-rare { border-color: var(--accent-blue); }
.sprite-frame.rarity-epic { border-color: var(--accent-purple); }
.sprite-frame.rarity-legendary {
  border-color: var(--accent-gold);
  box-shadow: 0 0 14px rgba(255, 209, 102, 0.55);
}

.rarity-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border: 1px solid currentColor;
}

.rarity-tag.rarity-common { color: #cbd8e8; }
.rarity-tag.rarity-rare { color: var(--accent-blue); }
.rarity-tag.rarity-epic { color: var(--accent-purple); }
.rarity-tag.rarity-legendary { color: var(--accent-gold); background: rgba(255, 209, 102, 0.14); }

.item-hero {
  text-align: center;
  margin-bottom: 14px;
}

.item-title {
  margin: 0 0 6px;
  font-size: 18px;
  color: #fff;
}

.item-stats {
  margin: 0;
  font-size: 12px;
  color: var(--accent-green);
}

.item-blessing {
  margin: 0 0 12px;
  padding: 12px;
  background: #0b1128;
  border: 2px solid var(--panel-border);
  font-size: 14px;
  line-height: 1.55;
}

.item-footer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.pixel-link {
  color: var(--accent-gold);
  text-decoration: underline;
}

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

.item-actions .pixel-btn {
  flex: 1;
}
