:root,
[data-theme="candle"] {
  --bg: #120d0c;
  --bg-alt: #1f1613;
  --surface: #261b17;
  --paper: #efe3c8;
  --paper-edge: #c9b286;
  --ink: #1b1512;
  --ink-line: #0d0908;
  --fg: #f4ead7;
  --muted: #b9a792;
  --accent: #d98a3c;
  --crimson: #b8292f;
  --crimson-soft: rgba(184, 41, 47, 0.24);
  --blessed: #e5b84b;
  --blessed-soft: rgba(229, 184, 75, 0.2);
  --ash: #9da3a8;
  --brass: #d5a84f;
  --brass-dark: #7d5b20;
  --spirit-glow: #e06b3c;
  --bride-robe: #2c2322;
  --bride-face: #e9dfd1;
  --bride-veil: #d6c8b6;
  --eye-color: #160c0c;
  --kit-bg: #120d0c;
  --kit-sheet: #1f1613;
  --kit-fg: #f4ead7;
}

[data-theme="moonlit"] {
  --bg: #0a0e17;
  --bg-alt: #121a29;
  --surface: #182336;
  --paper: #e3e8ef;
  --paper-edge: #9eb0c4;
  --ink: #101826;
  --ink-line: #070b12;
  --fg: #e8eef7;
  --muted: #93a4bc;
  --accent: #6ec6d9;
  --crimson: #c93b4b;
  --crimson-soft: rgba(201, 59, 75, 0.24);
  --blessed: #6ee7b7;
  --blessed-soft: rgba(110, 231, 183, 0.18);
  --ash: #94a3b8;
  --brass: #b8c4d4;
  --brass-dark: #58697e;
  --spirit-glow: #6ec6d9;
  --bride-robe: #1b2436;
  --bride-face: #dce6f2;
  --bride-veil: #9fb7d1;
  --eye-color: #0b1320;
  --kit-bg: #0a0e17;
  --kit-sheet: #121a29;
  --kit-fg: #e8eef7;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
  overflow: hidden;
  user-select: none;
  touch-action: manipulation;
}

.hidden { display: none !important; }

.altar {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px calc(env(safe-area-inset-bottom, 0px) + 34px);
  background: radial-gradient(circle at 50% 24%, var(--bg-alt) 0%, var(--bg) 74%);
  overflow: hidden;
}

.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 48%, rgba(0, 0, 0, 0.62) 100%);
  z-index: 1;
}

.ink-grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.06;
  background-image: repeating-linear-gradient(0deg, rgba(255,255,255,0.4) 0 1px, transparent 1px 4px);
  z-index: 1;
}

.altar > *:not(.vignette):not(.ink-grain) {
  position: relative;
  z-index: 2;
}

/* HUD */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
}

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

.brand-kr {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.round-pill {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.14);
}

.hud-spacer {
  width: 46px;
  flex-shrink: 0;
}

.candles {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.candle {
  position: relative;
  width: 14px;
  height: 28px;
  border-radius: 3px 3px 2px 2px;
  background: linear-gradient(180deg, #f3e6cf 0%, #c8b28c 100%);
  border: 1px solid rgba(0,0,0,0.45);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.candle .flame {
  position: absolute;
  top: -12px;
  left: 50%;
  width: 9px;
  height: 13px;
  margin-left: -4.5px;
  border-radius: 50% 50% 50% 50% / 65% 65% 35% 35%;
  background: radial-gradient(circle at 50% 65%, #fff7d6 0%, #ffb732 55%, #d94814 100%);
  box-shadow: 0 0 10px rgba(255, 168, 52, 0.85);
  transform-origin: bottom center;
  animation: flicker 1.1s ease-in-out infinite alternate;
}

.candle.out {
  opacity: 0.32;
  height: 18px;
}

.candle.out .flame {
  display: none;
}

@keyframes flicker {
  0% { transform: scale(0.92, 1.04) rotate(-3deg); opacity: 0.9; }
  50% { transform: scale(1.06, 0.96) rotate(2deg); opacity: 1; }
  100% { transform: scale(0.95, 1.08) rotate(-2deg); opacity: 0.85; }
}

/* Ghost Bride */
.bride-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.bride-frame {
  width: 148px;
  height: 92px;
  transition: transform 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.bride-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.bride-frame.tell-feed {
  transform: translateX(12px) scale(1.05);
}

.bride-frame.tell-feed .bride-eyes ellipse {
  fill: var(--crimson);
  filter: drop-shadow(0 0 5px var(--crimson));
}

.bride-frame.tell-draw {
  transform: translateX(-12px) scale(1.05);
}

.bride-frame.tell-draw .bride-eyes ellipse {
  fill: var(--blessed);
  filter: drop-shadow(0 0 5px var(--blessed));
}

.whisper-box {
  width: 100%;
  text-align: center;
  font-size: 13px;
  line-height: 1.3;
  color: var(--fg);
  background: rgba(0, 0, 0, 0.34);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 6px 10px;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.twist-banner {
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  padding: 5px 8px;
  border-radius: 6px;
  background: var(--crimson-soft);
  border: 1px solid var(--crimson);
  color: #ffd7d9;
  letter-spacing: 0.02em;
}

/* Brass Balance Scale */
.scale-zone {
  position: relative;
  flex: 1 1 auto;
  min-height: 140px;
  max-height: 210px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scale-svg {
  width: 100%;
  height: 100%;
  max-width: 340px;
}

.scale-beam {
  transform-origin: 170px 40px;
  transition: transform 0.55s cubic-bezier(0.22, 1.35, 0.36, 1);
}

.pan-weight-txt {
  font-size: 20px;
  font-weight: 800;
  fill: var(--fg);
  paint-order: stroke;
  stroke: rgba(0,0,0,0.8);
  stroke-width: 3px;
}

.pan-label-txt {
  font-size: 11px;
  font-weight: 700;
  fill: var(--muted);
  letter-spacing: 0.08em;
}

.token-pop {
  position: absolute;
  top: 46%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.7);
  opacity: 0;
  pointer-events: none;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.04em;
  border: 2px solid currentColor;
  background: rgba(12, 9, 9, 0.92);
  transition: opacity 0.22s ease, transform 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.token-pop.show {
  opacity: 1;
  transform: translate(-50%, -82%) scale(1);
}

.token-pop.cursed { color: #ff6b72; }
.token-pop.blessed { color: var(--blessed); }
.token-pop.ash { color: #d6dde6; }

.status-badges {
  position: absolute;
  bottom: 2px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 6px;
  pointer-events: none;
}

.status-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--accent);
}

/* Offering Bag */
.bag-zone {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bag-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
}

.bag-title {
  font-weight: 800;
  color: var(--fg);
  letter-spacing: 0.05em;
}

.bag-counts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.token-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 11px;
}

.token-chip.cursed { border-color: var(--crimson); background: var(--crimson-soft); }
.token-chip.blessed { border-color: var(--blessed); background: var(--blessed-soft); }
.token-chip.ash { border-color: var(--ash); }

.tok-sym { font-size: 13px; }
.tok-name { flex: 1; font-weight: 600; white-space: nowrap; }
.tok-num { font-size: 15px; font-weight: 800; }

.peek-strip {
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--accent);
}

/* Controls & Talismans */
.controls-zone {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr 0.78fr;
  gap: 8px;
}

.act-btn {
  min-height: 52px;
  border-radius: 10px;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  background: var(--surface);
  color: var(--fg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.18s ease, background 0.18s ease;
}

.act-btn:active:not(:disabled) { transform: scale(0.96); }
.act-btn:disabled { opacity: 0.38; cursor: not-allowed; }

.act-btn.draw {
  border-color: var(--blessed);
  background: linear-gradient(180deg, rgba(229, 184, 75, 0.22), rgba(229, 184, 75, 0.08));
}

.act-btn.feed {
  border-color: var(--crimson);
  background: linear-gradient(180deg, rgba(184, 41, 47, 0.28), rgba(184, 41, 47, 0.1));
}

.act-main { font-size: 14px; font-weight: 800; letter-spacing: 0.05em; }
.act-sub { font-size: 10px; color: var(--muted); }

.charm-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  min-height: 54px;
}

.charm-card {
  position: relative;
  min-height: 52px;
  padding: 5px 6px;
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  border: 1.5px solid var(--paper-edge);
  box-shadow: inset 0 0 0 2px rgba(184, 41, 47, 0.18);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.charm-card:active:not(:disabled) { transform: scale(0.95); }
.charm-card:disabled { opacity: 0.45; cursor: not-allowed; }
.charm-kr { font-size: 12px; font-weight: 800; color: var(--crimson); line-height: 1.1; }
.charm-en { font-size: 10px; font-weight: 700; line-height: 1.15; }

.charm-empty {
  min-height: 52px;
  border-radius: 6px;
  border: 1px dashed rgba(255, 255, 255, 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--muted);
  opacity: 0.6;
}

/* Modals / Overlays */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  background: rgba(6, 5, 7, 0.82);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.talisman-modal {
  width: 100%;
  max-width: 340px;
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--paper-edge);
  border-radius: 10px;
  padding: 20px 18px;
  text-align: center;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.65), inset 0 0 0 4px rgba(184, 41, 47, 0.14);
}

.talisman-modal.wide { max-width: 370px; }

.seal-stamp {
  display: inline-block;
  padding: 3px 10px;
  border: 2px solid var(--crimson);
  color: var(--crimson);
  font-size: 13px;
  font-weight: 800;
  border-radius: 4px;
  margin-bottom: 8px;
}

.title-kr { margin: 0; font-size: 36px; font-weight: 900; line-height: 1.05; }
.title-en { margin: 2px 0 12px; font-size: 14px; letter-spacing: 0.22em; color: var(--crimson); }
.modal-title { margin: 4px 0 8px; font-size: 22px; font-weight: 800; }
.modal-copy { margin: 0 0 14px; font-size: 13px; line-height: 1.45; }
.best-line { font-size: 12px; font-weight: 700; margin-bottom: 14px; opacity: 0.8; }

.pri-btn, .sec-btn {
  width: 100%;
  min-height: 46px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  border: none;
}

.pri-btn {
  background: var(--crimson);
  color: #fff8f0;
}

.sec-btn {
  background: rgba(0, 0, 0, 0.1);
  color: var(--ink);
  border: 1px solid rgba(0, 0, 0, 0.22);
  min-height: 38px;
  font-size: 13px;
  margin-top: 8px;
}

.charm-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.charm-pick-btn {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1.5px solid var(--paper-edge);
  background: rgba(255, 255, 255, 0.65);
  color: var(--ink);
  cursor: pointer;
}

.charm-pick-head {
  display: flex;
  justify-content: space-between;
  font-weight: 800;
  font-size: 14px;
  margin-bottom: 2px;
}

.charm-pick-kr { color: var(--crimson); }
.charm-pick-desc { font-size: 12px; opacity: 0.85; }

.score-box {
  background: rgba(0, 0, 0, 0.08);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
}

.score-val { font-size: 28px; font-weight: 900; color: var(--crimson); }
.score-best { font-size: 12px; font-weight: 700; }

.share-box {
  margin-bottom: 12px;
}

.share-box code {
  display: block;
  font-size: 11px;
  background: rgba(0, 0, 0, 0.08);
  padding: 8px;
  border-radius: 6px;
  word-break: break-word;
}

@media (max-height: 620px) {
  .bride-frame { width: 116px; height: 70px; }
  .scale-zone { min-height: 118px; max-height: 155px; }
  .act-btn { min-height: 44px; }
  .charm-card, .charm-empty { min-height: 44px; }
}

@media (max-width: 360px) {
  .bag-counts { gap: 4px; }
  .bag-counts > .token-chip { min-width: 0; padding: 5px 5px; font-size: 10px; gap: 2px; }
  .bag-counts .tok-sym { font-size: 11px; }
  .bag-counts .tok-name { overflow: hidden; text-overflow: clip; }
  .bag-counts .tok-num { font-size: 13px; }
}

/* scroll/overlay fix: overlays must cover the viewport and scroll on short screens */
.altar > .overlay.overlay.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  align-items: flex-start;
  justify-content: center;
}
.overlay > * { margin: auto; }

/* short screens (landscape, small phones): let the page scroll instead of clipping the board */
html, body { overflow-y: auto; overflow-x: hidden; height: auto; min-height: 100%; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.altar { height: auto; min-height: 100dvh; overflow: visible; }
