:root {
  --bg: #0e0a0c;
  --panel: rgba(20, 10, 14, 0.86);
  --panel-solid: #1b1015;
  --panel-2: #2a1820;
  --line: #4a2a35;
  --text: #f4e9ec;
  --muted: #b89ea6;
  --accent: #e5383b;
  --accent-2: #ff6b6b;
  --gold: #e0c060;
  --violet: #c77dff;
  --good: #5fd38a;
  --bad: #ff4d4d;
  --radius: 10px;
  --header-h: 48px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent-2);
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

kbd {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  font: 600 12px/18px ui-monospace, monospace;
  background: var(--panel-2);
}

.site-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.site-logo {
  font-weight: 800;
  font-size: 20px;
  text-decoration: none;
  color: var(--text);
  letter-spacing: 0.5px;
}

.site-logo span {
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.site-header nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

.page {
  padding: 8px 8px 40px;
}

/* ---------- Game layout ---------- */

.game-root {
  position: relative;
  margin: 0 auto;
  width: 100%;
  max-width: min(1280px, calc((100vh - var(--header-h) - 24px) * 1.7778));
  max-width: min(1280px, calc((100dvh - var(--header-h) - 24px) * 1.7778));
  min-width: min(100%, 300px);
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 320px;
}

.stage > canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

@media (orientation: portrait) and (max-width: 720px) {
  .game-root {
    max-width: none;
  }
  .stage {
    aspect-ratio: 3 / 4;
    max-height: calc(100dvh - var(--header-h) - 20px);
  }
}

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

.hud {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  pointer-events: none;
}

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

.hud-row > * {
  pointer-events: auto;
}

.hud .spacer {
  flex: 1;
  pointer-events: none;
}

.chip,
.bar-wrap,
.hbtn {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  font-weight: 700;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chip.blood {
  color: #ff8a8a;
}

.drop {
  width: 10px;
  height: 13px;
  background: var(--accent);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  transform: rotate(0deg);
  clip-path: polygon(50% 0, 100% 60%, 85% 95%, 50% 100%, 15% 95%, 0 60%);
}

.moon {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #e8e3d0;
  box-shadow: 0 0 8px rgba(232, 227, 208, 0.6);
}

.moon.blood-moon {
  background: #e5383b;
  box-shadow: 0 0 10px rgba(229, 56, 59, 0.9);
}

.bar-wrap .lbl {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.bar {
  position: relative;
  width: 110px;
  height: 10px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.bar .fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(90deg, #8a0b16, #e5383b);
  transition: width 0.15s linear;
}

.bar i {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, 0.4);
}

.hp .fill {
  background: linear-gradient(90deg, #6d1b7b, #c77dff);
}

.alarm .fill {
  background: linear-gradient(90deg, #d4a017, #ff4d4d);
}

.alarm.hot {
  animation: pulse 0.6s infinite alternate;
}

.alarm .pack {
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  color: #9fd49a;
}

.alarm .pack[data-tier='1'] {
  color: #e6d38a;
}

.alarm .pack[data-tier='2'] {
  color: #ff9a6b;
}

.alarm .pack[data-tier='3'] {
  color: #ff4d4d;
}

.crypt .fill {
  background: linear-gradient(90deg, #555, #b8b4c0);
}

.hp span {
  font-size: 12px;
  color: var(--muted);
}

@keyframes pulse {
  to {
    border-color: var(--bad);
    box-shadow: 0 0 10px rgba(255, 77, 77, 0.6);
  }
}

.hbtn {
  cursor: pointer;
}

.hbtn:hover {
  border-color: var(--accent);
}

.hbtn.toggle.drain {
  color: #ff8a8a;
}

.hbtn.toggle.turn {
  color: var(--violet);
}

.timer {
  position: relative;
  width: 170px;
  height: 22px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.timer .fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: linear-gradient(90deg, rgba(30, 30, 80, 0.9), rgba(255, 140, 80, 0.8));
}

.timer span {
  position: relative;
  white-space: nowrap;
}

/* ---------- Action buttons and touch stick ---------- */

.actions {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.act {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: rgba(20, 8, 12, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 11px;
  gap: 2px;
}

.act.big {
  width: 84px;
  height: 84px;
  border-color: var(--accent);
  font-size: 13px;
}

.act.ready {
  border-color: var(--accent-2);
  box-shadow: 0 0 12px rgba(229, 56, 59, 0.55);
}

.act.off {
  opacity: 0.55;
}

.act b {
  position: relative;
  z-index: 1;
  font-size: 10px;
  letter-spacing: -0.2px;
}

.act.big b {
  font-size: 14px;
}

.act kbd {
  position: relative;
  z-index: 1;
  font-size: 9px;
  line-height: 13px;
  padding: 0 3px;
}

.act .cd {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0;
  background: rgba(0, 0, 0, 0.65);
}

.stick {
  position: absolute;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.25);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(229, 56, 59, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.5);
}

.banner {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s;
  text-shadow: 0 2px 12px #000, 0 0 2px #000;
}

.banner.show {
  opacity: 1;
}

.banner h2 {
  margin: 0;
  font-size: clamp(28px, 6vw, 56px);
  letter-spacing: 3px;
  color: #ffd6db;
}

.banner p {
  margin: 4px 0 0;
  font-size: clamp(13px, 2vw, 18px);
  color: var(--muted);
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  max-width: 80%;
  text-align: center;
}

.toast.show {
  opacity: 1;
}

/* ---------- Overlays (menus, dusk, results) ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  overflow-y: auto;
  background: rgba(8, 3, 6, 0.55);
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.overlay.show {
  display: block;
}

.overlay.dim {
  background: rgba(8, 3, 6, 0.86);
}

.menu {
  max-width: 760px;
  margin: 0 auto;
  text-align: center;
}

.logo {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(36px, 8vw, 72px);
  font-weight: 700;
  letter-spacing: 4px;
  margin: 4px 0 0;
  color: #ffe3e6;
  text-shadow: 0 0 22px rgba(229, 56, 59, 0.8), 0 3px 0 #5a0710;
}

.tagline {
  color: var(--muted);
  margin: 4px 0 14px;
}

.menu h2 {
  font-family: Georgia, serif;
  margin: 4px 0 10px;
  font-size: 26px;
}

.menu-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin: 12px auto;
  max-width: 560px;
}

.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent-2);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn.primary {
  background: linear-gradient(180deg, #b3131f, #7a0b14);
  border-color: #e5383b;
}

.btn small {
  display: block;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.btn.primary small {
  color: #ffd6db;
}

.stat-line {
  color: var(--muted);
  font-size: 14px;
  margin: 6px 0;
}

.essence {
  color: #9ee7ff;
  font-weight: 800;
}

.goal {
  max-width: 420px;
  margin: 8px auto;
  font-size: 13px;
  color: var(--muted);
}

.goal .bar {
  width: 100%;
  margin-top: 4px;
}

.goal .bar .fill {
  background: linear-gradient(90deg, #2c6e8a, #9ee7ff);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
  text-align: left;
  margin: 10px 0;
}

.card {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

.card h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.card p {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.35;
}

.card .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card .lvl {
  font-size: 12px;
  color: var(--muted);
}

.card.done {
  opacity: 0.7;
}

.card.locked {
  opacity: 0.45;
}

.gifts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin: 8px 0 14px;
}

.gift {
  text-align: left;
  border-radius: 12px;
  padding: 12px;
  border: 2px solid var(--line);
  background: var(--panel-solid);
  cursor: pointer;
}

.gift:hover:not(:disabled) {
  transform: translateY(-2px);
}

.gift.common {
  border-color: #6b6b75;
}

.gift.rare {
  border-color: #3a86ff;
  box-shadow: 0 0 10px rgba(58, 134, 255, 0.35);
}

.gift.epic {
  border-color: #c77dff;
  box-shadow: 0 0 14px rgba(199, 125, 255, 0.5);
}

.gift .rar {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.gift.common .rar {
  color: #a0a0aa;
}

.gift.rare .rar {
  color: #7fb0ff;
}

.gift.epic .rar {
  color: #d9a8ff;
}

.gift h3 {
  margin: 4px 0;
  font-size: 16px;
}

.gift p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.gift.chosen {
  border-color: var(--gold);
  box-shadow: 0 0 16px rgba(224, 192, 96, 0.6);
}

.gift:disabled:not(.chosen) {
  opacity: 0.35;
  cursor: default;
}

.dusk-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  text-align: left;
}

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

.dusk-grid h3 {
  margin: 6px 0;
  font-size: 15px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
  margin-bottom: 6px;
}

.shop-item .info {
  flex: 1;
  min-width: 0;
}

.shop-item .info b {
  font-size: 14px;
}

.shop-item .info span {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.pips {
  display: inline-flex;
  gap: 2px;
  margin-left: 6px;
  vertical-align: middle;
}

.pips i {
  width: 5px;
  height: 5px;
  border-radius: 1px;
  background: #3a2530;
}

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

.price {
  min-width: 78px;
  padding: 6px 8px;
  font-size: 13px;
}

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

.unit {
  width: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
  padding: 4px 2px;
  text-align: center;
  font-size: 10px;
  cursor: pointer;
}

.unit.sel {
  border-color: var(--gold);
}

.unit canvas {
  width: 34px;
  height: 34px;
  display: block;
  margin: 0 auto;
}

.promo {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
  margin: 8px 0 12px;
}

.summary div {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  font-size: 12px;
  color: var(--muted);
}

.summary b {
  display: block;
  font-size: 20px;
  color: var(--text);
}

.results .big {
  font-family: Georgia, serif;
  font-size: clamp(34px, 7vw, 60px);
  margin: 6px 0;
  letter-spacing: 3px;
}

.results .big.win {
  color: var(--gold);
  text-shadow: 0 0 20px rgba(224, 192, 96, 0.6);
}

.results .big.lose {
  color: var(--accent-2);
  text-shadow: 0 0 20px rgba(229, 56, 59, 0.6);
}

.near {
  color: #ffd6db;
  font-weight: 600;
}

.unlocks {
  margin: 10px auto;
  max-width: 480px;
  text-align: left;
}

.unlocks div {
  background: var(--panel-solid);
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: 14px;
}

.eclipse-pick {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 8px 0;
}

.help {
  text-align: left;
  font-size: 14px;
  line-height: 1.5;
}

.help li {
  margin-bottom: 4px;
}

/* ---------- Below the game ---------- */

.ad-slot {
  max-width: 970px;
  margin: 12px auto 0;
  min-height: 0;
}

.ad-slot:empty {
  display: none;
}

.about {
  max-width: 820px;
  margin: 20px auto 0;
  padding: 0 8px;
  color: var(--muted);
  line-height: 1.55;
}

.about h1,
.about h2 {
  color: var(--text);
  font-family: Georgia, serif;
}

@media (max-width: 720px) {
  .bar {
    width: 64px;
  }
  .chip,
  .bar-wrap,
  .hbtn {
    height: 26px;
    font-size: 12px;
    padding: 0 6px;
  }
  .bar-wrap .lbl {
    display: none;
  }
  .hp span {
    display: none;
  }
  .timer {
    width: 130px;
    font-size: 11px;
  }
  /* Keep tips clear of the action buttons at the bottom. */
  .toast {
    bottom: auto;
    top: 112px;
    font-size: 13px;
    max-width: 92%;
  }
  .act {
    width: 56px;
    height: 56px;
  }
  .act b {
    font-size: 9px;
  }
  .act.big {
    width: 74px;
    height: 74px;
  }
  .act kbd {
    display: none;
  }
}

@media (max-height: 520px) {
  .hud {
    padding: 4px;
    gap: 3px;
  }
  .chip,
  .bar-wrap,
  .hbtn {
    height: 24px;
    font-size: 12px;
    padding: 0 5px;
    gap: 4px;
  }
  .bar {
    width: 56px;
  }
  .bar-wrap .lbl,
  .hp span {
    display: none;
  }
  .timer {
    height: 20px;
    width: 120px;
    font-size: 11px;
  }
  .act {
    width: 50px;
    height: 50px;
  }
  .act.big {
    width: 66px;
    height: 66px;
  }
  .stage {
    min-height: 260px;
  }
}

.game-root:fullscreen {
  max-width: none;
  border: 0;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-root:fullscreen .stage {
  width: min(100vw, 177.78vh);
  aspect-ratio: 16 / 9;
}

@media (hover: none) {
  .act kbd {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .alarm.hot {
    animation: none;
  }
}
