:root {
  --ink: #f4ead8;
  --muted: #b8a993;
  --gold: #ffcf6b;
  --gold-deep: #d9822b;
  --ember: #ff8a3a;
  --panel: rgba(22, 16, 30, 0.82);
  --panel-solid: #1b1426;
  --line: rgba(255, 207, 107, 0.22);
  --danger: #ff5a5a;
  --good: #7ee07a;
  --common: #c9c2b4;
  --rare: #5fb8ff;
  --epic: #c07aff;
  --legendary: #ffb93a;
  --radius: 14px;
  --title: 'Palatino Linotype', 'Book Antiqua', Palatino, Georgia, serif;
  --body: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0d0a14;
  color: var(--ink);
  font-family: var(--body);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
[hidden] { display: none !important; }
canvas#world { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
canvas#overlay { position: fixed; inset: 0; pointer-events: none; z-index: 2; }

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }
a { color: var(--gold); }

.primary, .ghost, .danger {
  border: 0;
  border-radius: 999px;
  padding: 10px 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.2s ease;
}
.primary {
  background: linear-gradient(180deg, #ffd98a, #e8912f);
  color: #2a1606;
  box-shadow: 0 4px 0 #8a4a14, 0 10px 30px rgba(255, 150, 50, 0.35);
}
.primary:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.06); }
.primary:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #8a4a14; }
.primary.big { font-size: 1.25rem; padding: 14px 34px; font-family: var(--title); }
.ghost {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  color: var(--ink);
}
.ghost:hover:not(:disabled) { background: rgba(255, 207, 107, 0.12); }
.ghost.active { background: rgba(255, 90, 90, 0.25); border-color: var(--danger); }
.danger { background: rgba(255, 80, 80, 0.15); border: 1px solid rgba(255, 90, 90, 0.5); color: #ffb0b0; }
.small { padding: 6px 14px; font-size: 0.85rem; }
.icon-btn {
  width: 40px; height: 40px;
  display: inline-grid; place-items: center;
  border-radius: 12px;
  background: rgba(20, 14, 28, 0.6);
  border: 1px solid var(--line);
  text-decoration: none;
  font-size: 1.1rem;
  backdrop-filter: blur(6px);
}
.icon-btn:hover { background: rgba(255, 207, 107, 0.15); }
kbd {
  font-family: var(--body);
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--muted);
}

/* --- Loading and title ------------------------------------------------- */
#loading {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 60%, #2a1a10, #0d0a14 70%);
}
.loading-card { text-align: center; }
.logo {
  font-family: var(--title);
  font-size: clamp(3rem, 9vw, 6.5rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff3d6;
  text-shadow: 0 0 24px rgba(255, 170, 70, 0.75), 0 0 60px rgba(255, 120, 40, 0.45), 0 4px 0 #6a3410;
  line-height: 1;
}
.logo span { color: var(--gold); }
.logo.small { font-size: 2.4rem; }
.flame {
  width: 26px; height: 40px; margin: 22px auto;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: radial-gradient(circle at 50% 70%, #fff6c8, #ffb03a 45%, #e84a1a 80%, transparent 82%);
  filter: drop-shadow(0 0 16px #ff8a3a);
  animation: flicker 0.18s infinite alternate;
}
@keyframes flicker { from { transform: scale(1, 1) rotate(-2deg); } to { transform: scale(0.94, 1.06) rotate(2deg); } }
#loading-text { color: var(--muted); }

.screen { position: fixed; inset: 0; z-index: 10; }
#title {
  display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% 45%, rgba(10, 6, 16, 0.15), rgba(10, 6, 16, 0.75));
}
.title-card {
  text-align: center;
  max-width: 640px;
  padding: 24px;
  animation: rise 1s ease both;
}
.tagline { font-size: 1.12rem; line-height: 1.55; color: #eadfcb; margin: 18px auto 30px; text-shadow: 0 2px 8px #000; max-width: 34em; }
.lang { display: flex; gap: 10px; justify-content: center; align-items: center; margin-top: 22px; color: var(--muted); }
select {
  font: inherit; color: var(--ink);
  background: rgba(20, 14, 28, 0.85);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
}
.foot { color: var(--muted); font-size: 0.85rem; margin-top: 18px; text-shadow: 0 1px 4px #000; }
.home-link { font-size: 0.9rem; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

/* --- The Hearth --------------------------------------------------------- */
#hearth {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: linear-gradient(90deg, rgba(10, 6, 16, 0.92) 0%, rgba(10, 6, 16, 0.78) 48%, rgba(10, 6, 16, 0.05) 75%);
  animation: rise 0.5s ease both;
}
.hearth-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; max-width: 760px; }
.hearth-top h1 { font-family: var(--title); margin: 0; font-size: 2.2rem; color: #fff1d0; text-shadow: 0 0 20px rgba(255, 150, 60, 0.5); }
.hearth-top p { margin: 4px 0 0; color: var(--muted); max-width: 34em; }
.hearth-actions { display: flex; gap: 8px; align-items: center; }
.embers {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(40, 20, 10, 0.75);
  border: 1px solid rgba(255, 150, 60, 0.45);
  font-size: 1.1rem;
  box-shadow: 0 0 18px rgba(255, 120, 40, 0.25);
}
.embers b { color: var(--gold); }
#hearth-tabs { display: flex; gap: 6px; flex-wrap: wrap; max-width: 760px; }
#hearth-tabs button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 999px;
  padding: 7px 16px;
  font-weight: 700;
  color: var(--muted);
}
#hearth-tabs button.active { background: linear-gradient(180deg, rgba(255, 207, 107, 0.28), rgba(217, 130, 43, 0.25)); color: #fff1d0; border-color: rgba(255, 207, 107, 0.6); }
#hearth-tabs button.locked { opacity: 0.55; }
#hearth-panel {
  overflow-y: auto;
  max-width: 760px;
  padding: 4px 6px 12px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 207, 107, 0.3) transparent;
  touch-action: pan-y;
}
.hearth-foot { display: flex; align-items: center; gap: 16px; max-width: 760px; flex-wrap: wrap; }
#hearth-hero { display: flex; gap: 12px; align-items: center; flex: 1; min-width: 220px; }
#hearth-hero .ic { font-size: 2rem; }
#hearth-hero b { display: block; font-family: var(--title); font-size: 1.15rem; }
#hearth-hero small { color: var(--muted); }

.hero-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.hero-card {
  position: relative;
  text-align: left;
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, color-mix(in srgb, var(--hero) 18%, transparent), rgba(20, 14, 28, 0.85));
  transition: transform 0.15s ease, border-color 0.2s ease;
}
.hero-card:hover:not(.locked) { transform: translateY(-2px); border-color: var(--hero); }
.hero-card.chosen { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 24px rgba(255, 190, 80, 0.25); }
.hero-card.locked { filter: grayscale(0.8); opacity: 0.7; cursor: default; }
.hero-icon { font-size: 2.1rem; }
.hero-name { font-family: var(--title); font-weight: 700; font-size: 1.1rem; margin: 4px 0; }
.hero-desc { font-size: 0.85rem; color: #ddd0bb; line-height: 1.4; }
.hero-weapon { margin-top: 8px; font-size: 0.85rem; color: var(--gold); }
.hero-best { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
.hero-chosen {
  position: absolute; top: 10px; right: 10px;
  background: var(--gold); color: #2a1606;
  font-size: 0.7rem; font-weight: 800;
  padding: 2px 8px; border-radius: 999px;
}

.talent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.talent {
  border-radius: var(--radius);
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(20, 14, 28, 0.78);
  display: grid; gap: 6px;
}
.talent.maxed { border-color: rgba(126, 224, 122, 0.45); }
.talent-head { display: flex; align-items: center; gap: 8px; }
.talent-head .ic { font-size: 1.4rem; }
.talent-desc { font-size: 0.85rem; color: #ddd0bb; }
.talent-desc small { color: var(--muted); }
.pips { display: flex; gap: 3px; flex-wrap: wrap; }
.pips i { width: 14px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.12); }
.pips i.on { background: linear-gradient(90deg, var(--gold), var(--ember)); box-shadow: 0 0 6px rgba(255, 150, 60, 0.6); }
.buy {
  justify-self: start;
  border: 1px solid rgba(255, 150, 60, 0.5);
  background: rgba(255, 140, 50, 0.16);
  border-radius: 999px;
  padding: 5px 14px;
  font-weight: 700;
}
.buy:hover:not(:disabled) { background: rgba(255, 140, 50, 0.32); }
.buy.poor { opacity: 0.5; }
.panel-foot { margin-top: 12px; }

.locked-note { color: var(--muted); padding: 20px; border: 1px dashed var(--line); border-radius: var(--radius); }
.pact-head p { color: var(--muted); margin: 6px 0 12px; }
.gloom-meter { display: flex; align-items: baseline; gap: 8px; font-size: 1.4rem; font-family: var(--title); }
.gloom-meter b { color: #c8a8ff; text-shadow: 0 0 12px rgba(180, 140, 255, 0.6); }
.gloom-meter span { color: var(--muted); font-size: 1rem; }
.gloom-meter em { margin-left: auto; color: var(--gold); font-style: normal; font-size: 1rem; }
.pact-grid { display: grid; gap: 8px; }
.pact {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgba(20, 14, 28, 0.78);
  border: 1px solid rgba(180, 140, 255, 0.18);
}
.pact.on { border-color: rgba(180, 140, 255, 0.6); background: linear-gradient(90deg, rgba(90, 50, 160, 0.3), rgba(20, 14, 28, 0.78)); }
.pact-icon { font-size: 1.5rem; }
.pact-body { flex: 1; }
.pact-body small { display: block; color: var(--muted); }
.pact-ctl { display: flex; gap: 4px; }
.rank {
  min-width: 34px; height: 30px;
  border-radius: 8px;
  border: 1px solid rgba(180, 140, 255, 0.3);
  background: rgba(255, 255, 255, 0.04);
  font-weight: 800;
  font-family: var(--title);
}
.rank.on { background: rgba(180, 140, 255, 0.4); border-color: #c8a8ff; }

.feats-count { color: var(--muted); margin: 0 0 8px; }
.feat-list { display: grid; gap: 6px; }
.feat {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px;
  border-radius: 12px;
  background: rgba(20, 14, 28, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.feat.done { border-color: rgba(255, 207, 107, 0.35); background: linear-gradient(90deg, rgba(255, 190, 80, 0.12), rgba(20, 14, 28, 0.7)); }
.feat-icon { font-size: 1.3rem; width: 1.6em; text-align: center; color: var(--muted); }
.feat-body { flex: 1; }
.feat-body small { display: block; color: var(--muted); }
.feat-body em { display: block; color: var(--gold); font-style: normal; font-size: 0.8rem; }
.feat-reward { color: var(--gold); font-weight: 700; white-space: nowrap; }

.codex-title { font-family: var(--title); margin: 14px 0 8px; color: var(--gold); }
.codex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.codex {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px;
  border-radius: 12px;
  background: rgba(20, 14, 28, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.07);
}
.codex.dim { opacity: 0.6; }
.codex .ic { font-size: 1.5rem; }
.codex small { display: block; color: #d8ccb6; font-size: 0.8rem; }
.codex em { display: block; color: var(--gold); font-size: 0.75rem; font-style: normal; margin-top: 2px; }

.record-grid, .boss-record, .end-stats, .stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.boss-record { margin-top: 12px; }
.stat {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(20, 14, 28, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.07);
}
.stat span { display: block; color: var(--muted); font-size: 0.8rem; }
.stat b { font-size: 1.25rem; font-family: var(--title); }

/* --- HUD ----------------------------------------------------------------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 3; }
#hud button, #hud .slots { pointer-events: auto; }
#xp {
  position: absolute; top: 0; left: 0; right: 0;
  height: 14px;
  background: rgba(10, 6, 16, 0.75);
  border-bottom: 1px solid rgba(90, 210, 255, 0.35);
}
#xp-fill {
  position: absolute; inset: 0;
  transform-origin: left;
  transform: scaleX(0);
  background: linear-gradient(90deg, #2a8fff, #5ad8ff, #b8f4ff);
  box-shadow: 0 0 12px rgba(90, 216, 255, 0.8);
  transition: transform 0.15s linear;
}
#hud-level {
  position: absolute; right: 10px; top: 0;
  font-size: 0.72rem; font-weight: 800; line-height: 14px;
  text-shadow: 0 1px 2px #000;
}
#hud-left {
  position: absolute;
  top: calc(22px + env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  display: grid; gap: 6px;
}
#hp {
  position: relative;
  width: 220px; height: 18px;
  border-radius: 9px;
  background: rgba(10, 6, 16, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.15);
  overflow: hidden;
}
#hp-fill {
  position: absolute; inset: 0;
  transform-origin: left;
  background: linear-gradient(180deg, #ff7a6a, #d8303a);
  transition: transform 0.12s ease;
}
#hp.low #hp-fill { animation: pulse 0.6s infinite alternate; }
@keyframes pulse { to { filter: brightness(1.6); } }
#hp-text { position: absolute; inset: 0; text-align: center; font-size: 0.75rem; font-weight: 800; line-height: 18px; text-shadow: 0 1px 2px #000; }
.slots { display: flex; gap: 4px; }
.slot {
  position: relative;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: rgba(16, 10, 24, 0.75);
  border: 1px solid rgba(255, 207, 107, 0.3);
  font-size: 1.25rem;
}
.slot.small { width: 30px; height: 30px; font-size: 1rem; border-color: rgba(160, 200, 255, 0.25); }
.slot.empty { border-style: dashed; opacity: 0.45; }
.slot.evolved { border-color: var(--legendary); box-shadow: 0 0 10px rgba(255, 185, 58, 0.5); }
.slot b {
  position: absolute; right: -3px; bottom: -4px;
  font-size: 0.62rem; font-weight: 800;
  background: #2a1a36; border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px; padding: 0 4px;
}
.boons { display: flex; gap: 3px; font-size: 1rem; filter: drop-shadow(0 1px 2px #000); }
#hud-center {
  position: absolute; top: calc(22px + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%);
  text-align: center;
}
#realm-name { font-family: var(--title); font-size: 0.85rem; color: var(--muted); text-shadow: 0 1px 3px #000; }
#timer {
  font-family: var(--title); font-size: 2.1rem; font-weight: 700;
  text-shadow: 0 2px 6px #000, 0 0 18px rgba(255, 190, 90, 0.35);
  font-variant-numeric: tabular-nums;
}
#timer.urgent { color: #ff7a5a; animation: pulse 0.5s infinite alternate; }
#timer-sub { font-size: 0.8rem; color: #e8d8c0; text-shadow: 0 1px 3px #000; }
#boss-bar { margin-top: 8px; width: min(520px, 70vw); }
#boss-name { font-family: var(--title); font-size: 1.05rem; color: #ffb0a0; text-shadow: 0 0 10px rgba(255, 60, 60, 0.6), 0 1px 3px #000; }
#boss-bar .bar { height: 12px; border-radius: 6px; background: rgba(10, 6, 16, 0.8); border: 1px solid rgba(255, 90, 90, 0.5); overflow: hidden; margin-top: 3px; }
#boss-fill { height: 100%; transform-origin: left; background: linear-gradient(90deg, #8a1020, #ff3a4a, #ff8a6a); box-shadow: 0 0 10px #ff3a4a; transition: transform 0.15s; }
#hud-right {
  position: absolute; top: calc(22px + env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right));
  display: flex; gap: 8px; align-items: center;
}
.counter {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(16, 10, 24, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.banner {
  position: absolute; left: 50%; top: 30%;
  transform: translate(-50%, -10px);
  text-align: center;
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
  width: min(90vw, 760px);
}
.banner.show { opacity: 1; transform: translate(-50%, 0); }
.b-title { font-family: var(--title); font-size: clamp(1.6rem, 4.5vw, 2.8rem); font-weight: 700; text-shadow: 0 0 20px rgba(255, 170, 70, 0.6), 0 3px 8px #000; }
.b-sub { color: #eadfcb; margin-top: 4px; text-shadow: 0 2px 6px #000; font-size: 1.05rem; }
.banner.realm .b-title { font-size: clamp(2.2rem, 6vw, 3.8rem); color: #fff1d0; }
.banner.boss .b-title { color: #ff8a7a; text-shadow: 0 0 24px rgba(255, 40, 40, 0.8), 0 3px 8px #000; }
.banner.warn .b-title { color: #ffb070; }
.banner.gold .b-title { color: var(--gold); }
.banner.elite .b-title { color: #ffd36b; }
.banner.portal .b-title { color: #fff3c8; font-size: 1.6rem; }
#btn-dash {
  display: none;
  position: absolute; right: max(24px, env(safe-area-inset-right)); bottom: max(28px, env(safe-area-inset-bottom));
  width: 78px; height: 78px; border-radius: 50%;
  font-size: 2rem;
  border: 2px solid rgba(159, 224, 255, 0.6);
  background: rgba(20, 30, 50, 0.55);
  backdrop-filter: blur(4px);
}
body.touch #btn-dash { display: grid; place-items: center; }
#btn-flare {
  --fill: 0;
  position: absolute; left: 50%; bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: 64px; height: 64px; border-radius: 50%;
  border: 0;
  display: grid; place-items: center;
  background:
    radial-gradient(circle, rgba(20, 12, 28, 0.92) 58%, transparent 60%),
    conic-gradient(#ffcf6b calc(var(--fill) * 1turn), rgba(255, 255, 255, 0.12) 0);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  transition: box-shadow 0.3s ease;
}
#btn-flare .ic { font-size: 1.7rem; filter: grayscale(0.7) brightness(0.7); transition: filter 0.3s ease; }
#btn-flare kbd { position: absolute; bottom: -6px; }
#btn-flare.ready { animation: flareReady 1.1s ease-in-out infinite alternate; }
#btn-flare.ready .ic { filter: none; }
@keyframes flareReady { from { box-shadow: 0 0 12px rgba(255, 190, 80, 0.5); } to { box-shadow: 0 0 34px rgba(255, 190, 80, 0.95); } }
body.touch #btn-flare { left: auto; right: max(116px, calc(env(safe-area-inset-right) + 116px)); bottom: max(34px, env(safe-area-inset-bottom)); transform: none; }
body.touch #btn-flare kbd { display: none; }
#stick {
  position: fixed; z-index: 4;
  width: 120px; height: 120px; margin: -60px 0 0 -60px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.05);
  pointer-events: none;
}
#stick div {
  position: absolute; left: 50%; top: 50%;
  width: 48px; height: 48px; margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: rgba(255, 220, 160, 0.45);
  box-shadow: 0 0 16px rgba(255, 190, 90, 0.5);
}

/* --- Overlays: choices, pause, end, modal --------------------------------- */
.overlay-screen {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at center, rgba(12, 8, 18, 0.55), rgba(8, 5, 12, 0.88));
  backdrop-filter: blur(3px);
  padding: 16px;
  overflow-y: auto;
  animation: fade 0.2s ease both;
}
@keyframes fade { from { opacity: 0; } }
.choose-inner { text-align: center; width: min(1100px, 100%); }
.choose-inner h2 { font-family: var(--title); font-size: clamp(2rem, 5vw, 3rem); margin: 0; color: #fff1d0; text-shadow: 0 0 22px rgba(255, 170, 70, 0.6); }
.choose.chest h2, .choose.drop h2 { color: var(--gold); }
.choose.shrine h2 { color: #ffe9a8; }
.choose.boon h2 { color: #d8c0ff; text-shadow: 0 0 22px rgba(180, 140, 255, 0.6); }
#choose-hint { color: var(--muted); margin: 6px 0 18px; }
#cards { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.card {
  --c: var(--common);
  position: relative;
  width: 230px; min-height: 250px;
  padding: 16px 14px 14px;
  border-radius: 18px;
  border: 2px solid color-mix(in srgb, var(--c) 70%, transparent);
  background:
    radial-gradient(circle at 50% 22%, color-mix(in srgb, var(--c) 22%, transparent), transparent 60%),
    linear-gradient(180deg, #241a32, #150f1e);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  text-align: center;
  display: flex; flex-direction: column; align-items: center;
  animation: deal 0.35s cubic-bezier(.2, 1.4, .4, 1) both;
  animation-delay: calc(var(--i) * 70ms);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.card:hover, .card:focus-visible, .card.focus { transform: translateY(-6px) scale(1.02); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), 0 0 28px color-mix(in srgb, var(--c) 45%, transparent); outline: none; }
@keyframes deal { from { opacity: 0; transform: translateY(40px) rotate(-3deg) scale(0.9); } }
.card.rare { --c: var(--rare); }
.card.epic { --c: var(--epic); }
.card.legendary { --c: var(--legendary); }
.card.evolve, .card.fuse {
  --c: #ffd36b;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 211, 107, 0.4), transparent 60%),
    linear-gradient(180deg, #3a2a14, #1a1208);
  animation: deal 0.35s cubic-bezier(.2, 1.4, .4, 1) both, shine 1.6s ease-in-out infinite alternate;
}
.card.fuse { --c: #d8b8ff; background: radial-gradient(circle at 50% 30%, rgba(216, 184, 255, 0.4), transparent 60%), linear-gradient(180deg, #2a1a40, #120c1e); }
@keyframes shine { to { box-shadow: 0 0 40px color-mix(in srgb, var(--c) 70%, transparent); } }
.card.boon { --c: #c8a8ff; }
.card.blessing { --c: #ffe9a8; }
.card-tag { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; color: var(--c); }
.card-icon { font-size: 3.2rem; margin: 10px 0 6px; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6)); }
.card-name { font-family: var(--title); font-size: 1.2rem; font-weight: 700; line-height: 1.2; }
.card-rarity { font-size: 0.75rem; color: var(--c); font-weight: 700; margin-top: 2px; }
.card-lines { list-style: none; padding: 0; margin: 10px 0 0; font-size: 0.9rem; color: #eadfcb; line-height: 1.45; }
.card-foot { margin-top: auto; padding-top: 10px; font-size: 0.75rem; color: var(--gold); }
.card kbd { position: absolute; top: 10px; right: 10px; }
.choose-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }

.panel {
  width: min(640px, 100%);
  background: linear-gradient(180deg, rgba(36, 26, 50, 0.96), rgba(20, 14, 28, 0.96));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  animation: rise 0.3s ease both;
}
.panel h2 { font-family: var(--title); margin: 0 0 12px; font-size: 1.9rem; color: #fff1d0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }
.stat-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.stat-grid div { padding: 6px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.04); font-size: 0.85rem; }
.stat-grid span { margin-right: 6px; }
#pause-damage, #end-damage { margin-top: 12px; }
#end-damage h3, #end-feats h3 { font-family: var(--title); margin: 12px 0 6px; color: var(--gold); font-size: 1.05rem; }
.dmg-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 0.85rem; }
.dmg-row .ic { width: 1.6em; text-align: center; }
.dmg-bar { flex: 1; position: relative; height: 20px; border-radius: 6px; background: rgba(255, 255, 255, 0.05); overflow: hidden; }
.dmg-bar i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, rgba(255, 150, 60, 0.6), rgba(255, 207, 107, 0.35)); }
.dmg-bar b { position: relative; padding-left: 8px; line-height: 20px; font-weight: 700; }
.dmg-row em { font-style: normal; color: var(--muted); min-width: 8.5em; text-align: right; font-variant-numeric: tabular-nums; }
.end-panel { text-align: center; max-height: calc(100vh - 32px); overflow-y: auto; }
.end.win h2 { color: var(--gold); text-shadow: 0 0 24px rgba(255, 190, 80, 0.7); }
.end.lose h2 { color: #ffb0a0; }
#end-sub { color: var(--muted); margin-top: -4px; }
.end-stats { margin-top: 12px; text-align: left; }
.end-embers { margin-top: 12px; display: flex; justify-content: center; gap: 10px; align-items: baseline; font-size: 1.1rem; }
.end-embers b { font-size: 1.7rem; color: var(--gold); text-shadow: 0 0 14px rgba(255, 150, 60, 0.7); font-family: var(--title); }
.end-panel .dmg-row, .end-panel .feat-done { text-align: left; }
.feat-done { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: rgba(255, 190, 80, 0.1); margin: 4px 0; }
.feat-done span { font-size: 1.3rem; }
.feat-done div { flex: 1; }
.feat-done small { display: block; color: var(--gold); }
.feat-done em { font-style: normal; color: var(--gold); font-weight: 700; }
.hint { color: var(--muted); font-size: 0.85rem; }
.modal-panel { z-index: 30; }
#modal { z-index: 30; }
.settings { display: grid; gap: 8px; }
.set-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.04); }
.switch { min-width: 64px; border-radius: 999px; padding: 6px 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); font-weight: 700; }
.switch.on { background: rgba(126, 224, 122, 0.25); border-color: rgba(126, 224, 122, 0.6); }
.set-foot { margin-top: 10px; text-align: right; }
.help-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.help-list li { display: flex; gap: 12px; align-items: flex-start; line-height: 1.45; }
.help-list span { font-size: 1.3rem; }

#toast { position: fixed; z-index: 40; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast-item {
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(20, 14, 28, 0.92);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: rise 0.3s ease both;
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.toast-item.feat { border-color: var(--gold); color: var(--gold); font-weight: 700; }
.toast-item.out { opacity: 0; transform: translateY(10px); }
.noscript { padding: 2rem; text-align: center; font-family: var(--body); color: var(--ink); }

/* --- Small screens ---------------------------------------------------------- */
@media (max-width: 760px) {
  #hearth { background: rgba(10, 6, 16, 0.82); }
  .hearth-top h1 { font-size: 1.6rem; }
  .hearth-top p { display: none; }
  #hp { width: 150px; }
  .slot { width: 32px; height: 32px; font-size: 1.05rem; }
  .slot.small { width: 26px; height: 26px; font-size: 0.9rem; }
  #timer { font-size: 1.6rem; }
  #hud-center { top: calc(64px + env(safe-area-inset-top)); }
  #hud-right .counter { padding: 4px 8px; font-size: 0.85rem; }
  .card { width: calc(50% - 8px); min-width: 150px; min-height: 0; padding: 12px 10px; }
  .card-icon { font-size: 2.4rem; margin: 6px 0 4px; }
  .card-name { font-size: 1rem; }
  .card-lines { font-size: 0.8rem; }
  .card kbd { display: none; }
  .hero-grid, .talent-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 420px) {
  .card { width: 100%; }
  .hero-grid, .talent-grid { grid-template-columns: 1fr; }
}
