:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --ink: #2a2622;
  --muted: #7a726a;
  --line: #e2dcd2;
  --accent: #5b5bd6;
  --hp: #4caf50;
  --hp-low: #e0464b;
  --en: #f2b705;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(60, 40, 20, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

.screen { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* ---------- 버튼 ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.08s, box-shadow 0.15s, background 0.15s;
}
.btn:hover:not(:disabled) { box-shadow: var(--shadow); transform: translateY(-1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.link-btn { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; }

/* ---------- 상단바 ---------- */
.topbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.topbar h1 { font-size: 22px; margin: 0; flex: 1; }
.potions { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; }
.notice { background: #fff7e0; border: 1px solid #f0dca6; border-radius: 10px; padding: 10px 14px; }
.notice.gift { background: #eef6ff; border-color: #bcd6f5; }

/* ---------- 스테이지 선택 ---------- */
.party-strip { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.party-face {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 2px solid var(--c); border-radius: 999px; padding: 3px 12px 3px 3px;
}
.party-face img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; object-position: 50% 12%; background: #f6f6f6; }
.party-face span { font-weight: 700; font-size: 14px; display: flex; flex-direction: column; line-height: 1.1; }
.party-face small { color: var(--muted); font-weight: 500; }
.party-buttons { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.chapter h2 { font-size: 18px; margin: 0 0 10px; }
.stage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stage-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 12px 8px; cursor: pointer; box-shadow: var(--shadow);
}
.stage-btn:hover:not(:disabled) { border-color: var(--accent); }
.stage-btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.stage-btn.cleared { border-color: #9fd3a2; }
.stage-id { font-size: 20px; font-weight: 800; }
.stage-enemies { display: flex; gap: 2px; min-height: 30px; align-items: center; font-size: 20px; }
.mini-slime svg { width: 30px; height: 26px; }
.stage-meta { font-size: 12px; color: var(--muted); }
.map-foot { margin-top: 28px; text-align: center; }

/* 챕터 탭 */
.chapter-tabs { display: flex; gap: 8px; margin-bottom: 14px; overflow-x: auto; }
.chapter-tab {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-width: 150px;
  border: 2px solid var(--line); background: var(--panel); border-radius: 12px; padding: 8px 14px;
  font-weight: 800; font-size: 15px; cursor: pointer; text-align: left;
}
.chapter-tab small { font-size: 11px; font-weight: 600; color: var(--muted); }
.chapter-tab.on { border-color: var(--accent); box-shadow: var(--shadow); }
.chapter-tab:disabled { opacity: 0.55; cursor: not-allowed; font-size: 13px; }

/* 보스 */
.boss-tag {
  position: absolute; top: 6px; right: 6px; font-size: 10px; font-weight: 900; letter-spacing: 0.08em;
  background: #7b3fd0; color: #fff; padding: 2px 7px; border-radius: 999px;
}
.stage-btn { position: relative; }
.stage-btn.boss { grid-column: span 2; border-color: #b48cff; background: linear-gradient(135deg, #fff 40%, #f1e8ff); }
.stage-btn.boss .mini-slime svg { width: 40px; height: 36px; }
.chapter-2 .stage-btn.cleared.boss { border-color: #9fd3a2; }

/* 난이도 선택 */
.difficulty { background: var(--panel); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); margin-bottom: 20px; }
.difficulty h2 { font-size: 16px; margin: 0 0 8px; }
.segmented { display: inline-flex; flex-wrap: wrap; background: #ece7df; border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button { border: 0; background: none; border-radius: 9px; padding: 8px 14px; font-weight: 700; color: var(--muted); cursor: pointer; }
.segmented button.on { background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.diff-groups { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.diff-group { display: flex; align-items: center; gap: 8px; }
.diff-group-name { font-size: 13px; font-weight: 800; color: var(--muted); min-width: 52px; }
.difficulty-note { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.difficulty-note b { color: var(--c, var(--ink)); margin-right: 3px; }
.diff-chip { font-size: 12px; font-weight: 700; background: #ece9ff; color: var(--accent); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }

/* ---------- 파티 ---------- */
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.char-card {
  display: grid; grid-template-columns: 120px 1fr; gap: 12px;
  background: var(--panel); border-radius: var(--radius); border-top: 5px solid var(--c);
  padding: 12px; box-shadow: var(--shadow);
}
.char-portrait img { width: 120px; height: 180px; object-fit: cover; object-position: 50% 10%; border-radius: 10px; background: #f8f8f8; }
.char-body h3 { margin: 0 0 6px; font-size: 18px; display: flex; align-items: baseline; gap: 6px; }
.char-body h3 small { color: var(--c); font-size: 13px; }
.char-body .lv { margin-left: auto; font-size: 15px; }
.stats { border-collapse: collapse; font-size: 14px; margin-bottom: 8px; }
.stats th { text-align: left; font-weight: 500; color: var(--muted); padding: 1px 10px 1px 0; }
.stats td { font-weight: 700; padding: 1px 6px 1px 0; }
.stats td.next { color: #2e9a4f; }
.kit { font-size: 13px; margin: 10px 0 0; grid-column: 1 / -1; }
.kit dt { font-weight: 700; margin-top: 6px; color: var(--c); }
.kit dd { margin: 2px 0 0; line-height: 1.45; }
.kit em { font-style: normal; font-weight: 700; }

.stats td.equip { color: #3a6fd8; font-weight: 800; }
.equip-note { font-size: 12px; color: var(--muted); margin: 4px 0 8px; }
.char-title { display: block; font-size: 11px !important; color: var(--muted) !important; width: 100%; }
.char-body h3 { flex-wrap: wrap; }
.skill-lv { font-size: 13px; font-weight: 800; color: var(--c); margin: 8px 0 0; }
.skill-lv small { color: var(--muted); font-weight: 500; }
.skill-note, .party-count { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.party-count b { color: var(--ink); }
.char-portrait { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.party-toggle { font-size: 13px; padding: 6px 8px; }
.party-toggle.on { background: var(--c); border-color: var(--c); color: #fff; }
.char-card.benched { opacity: 0.75; }
.char-card.benched .char-portrait img { filter: grayscale(0.5); }
.party-warn { font-size: 13px; font-weight: 700; color: #b06a00; background: #fff4dd; border-radius: 999px; padding: 6px 12px; }
.unlock.join { display: flex; align-items: center; gap: 8px; text-align: left; }
.unlock.join img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; object-position: 50% 12%; flex: none; }

/* ---------- 보석 · 뽑기 · 돌파 ---------- */
.gem { display: inline-block; width: 12px; height: 12px; transform: rotate(45deg); border-radius: 2px; vertical-align: -1px; margin: 0 2px; box-shadow: inset -2px -2px 0 rgba(0,0,0,.18), inset 2px 2px 0 rgba(255,255,255,.45); }
.gem.ruby { background: #e0284f; }
.gem.sapphire { background: #2f6fe0; }
.gem.emerald { background: #1fae6b; }
.gem-count b { margin-left: 2px; }
.gacha-btn { border-color: #f3b4c3; background: #fff5f7; }
.gacha-banner { background: linear-gradient(135deg, #fff, #fff1f4 60%, #f3ecff); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); text-align: center; }
.gacha-banner p { color: var(--muted); font-size: 14px; }
.gacha-faces { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; }
.gacha-face { display: flex; flex-direction: column; align-items: center; gap: 3px; font-weight: 700; font-size: 14px; }
.gacha-face img { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; object-position: 50% 10%; border: 3px solid var(--c); background: #fff; }
.gacha-face small { color: var(--muted); font-weight: 500; }
.gacha-face.missing img { filter: grayscale(1) brightness(0.9); }
.gacha-buttons { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.gacha-buttons .btn { min-width: 160px; padding: 12px 18px; font-size: 16px; }
.gacha-buttons .btn small { display: block; font-size: 12px; opacity: 0.9; }
.pull-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-top: 16px; }
.pull-card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px; background: var(--panel); border-radius: var(--radius); border-top: 5px solid var(--c); box-shadow: var(--shadow); opacity: 0; animation: pull-in 0.45s ease-out forwards; }
.pull-card img { width: 90px; height: 110px; object-fit: cover; object-position: 50% 8%; border-radius: 10px; background: #f8f8f8; }
.pull-card small { color: var(--muted); font-size: 12px; text-align: center; }
.pull-card.new { box-shadow: 0 0 0 3px #ffd36b, 0 0 20px #ffd36b; }
.pull-new { position: absolute; top: 6px; right: 6px; background: #e0284f; color: #fff; font-size: 11px; font-weight: 900; padding: 2px 7px; border-radius: 999px; }
@keyframes pull-in { from { opacity: 0; transform: rotateY(90deg) scale(0.8); } to { opacity: 1; transform: none; } }
.center { text-align: center; }
.stars { color: #f2b705; letter-spacing: 1px; }
.break-box { margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: #fffaf0; border: 1px solid #f3e3b8; }
.break-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.break-head small { color: #2e9a4f; font-weight: 700; }
.limit-btn { background: linear-gradient(90deg, #1fae6b, #2f6fe0); border-color: transparent; color: #fff; }
.limit-btn:disabled { background: #cfd8d3; color: #fff; }
.break-btn { margin-left: auto; font-size: 12px; padding: 5px 9px; }
.break-effects { margin: 6px 0 0; padding: 0; list-style: none; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.break-effects li.on { color: var(--ink); }
.break-effects li b { color: #b08d2e; margin-right: 3px; }
.break-effects li:not(.on) b { color: var(--muted); }
.gem-reward { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 12px; }

/* ---------- 장비 ---------- */
.equip-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.equip-tab {
  display: flex; align-items: center; gap: 8px; background: var(--panel); border: 2px solid var(--line);
  border-radius: 999px; padding: 3px 14px 3px 3px; cursor: pointer; font-weight: 700;
}
.equip-tab.on { border-color: var(--c); box-shadow: 0 0 0 2px var(--c); }
.equip-tab img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; object-position: 50% 12%; }
.equip-tab span { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.equip-tab small { color: var(--muted); font-weight: 500; font-size: 11px; }
.equip-layout { display: grid; grid-template-columns: 240px 1fr; gap: 14px; }
.equip-char { background: var(--panel); border-radius: var(--radius); border-top: 5px solid var(--c); padding: 12px; box-shadow: var(--shadow); text-align: center; }
.equip-char img { width: 160px; height: 200px; object-fit: cover; object-position: 50% 8%; border-radius: 10px; background: #f8f8f8; }
.equip-char h3 { margin: 6px 0; }
.equip-char h3 small { color: var(--muted); }
.equip-total { margin: 0 auto; }
.equip-total tr:first-child td { font-size: 11px; color: var(--muted); font-weight: 600; }
.equip-slots { display: flex; flex-direction: column; gap: 10px; }
.equip-slot {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 12px; align-items: center;
  background: var(--panel); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); border: 2px solid transparent;
}
.equip-slot.maxed { border-color: #f2c94c; background: linear-gradient(90deg, #fffbea, #fff 50%); }
.equip-slot.flash { animation: enhance-flash 0.9s ease-out; }
@keyframes enhance-flash { 0% { border-color: #ffd36b; box-shadow: 0 0 0 4px #ffe9a8, 0 0 24px #ffd36b; transform: scale(1.02); } 100% { border-color: transparent; } }
.equip-icon { font-size: 30px; width: 52px; height: 52px; display: grid; place-items: center; background: #f4f1ea; border-radius: 12px; }
.equip-name { font-weight: 800; }
.equip-name small { color: var(--muted); font-weight: 600; margin-right: 4px; }
.equip-name .plus { color: var(--c); margin-left: 4px; }
.equip-stat { font-size: 14px; color: #4a443e; margin-top: 2px; }
.equip-stat .next { color: #2e9a4f; font-weight: 700; }
.enh-bar { height: 6px; background: #ece7df; border-radius: 999px; overflow: hidden; margin-top: 6px; }
.enh-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--c), #ffd36b); }

/* ---------- 전투 ---------- */
.battle { display: flex; flex-direction: column; gap: 12px; }
.battle-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.stage-title { font-weight: 800; font-size: 18px; }
.round { color: var(--muted); flex: 1; }
.sp { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); }
.sp span { margin-right: 4px; }
.sp i { width: 16px; height: 16px; transform: rotate(45deg); border: 2px solid var(--accent); border-radius: 3px; display: inline-block; }
.sp i.on { background: var(--accent); }

.turn-strip { display: flex; align-items: center; gap: 6px; min-height: 40px; overflow-x: auto; }
.strip-label { font-size: 12px; color: var(--muted); margin-right: 4px; white-space: nowrap; }
.strip-unit {
  width: 36px; height: 36px; border-radius: 50%; overflow: hidden; flex: none;
  border: 2px solid var(--c); background: var(--panel); display: grid; place-items: center;
}
.strip-unit.enemy { border-color: #9aa; }
.strip-unit.now { width: 44px; height: 44px; box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--accent); }
.strip-unit img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 10%; }
.strip-slime svg { width: 30px; height: 26px; }

.enemy-row { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.enemy-card {
  position: relative; width: 180px; padding: 10px; background: var(--panel);
  border: 2px solid var(--line); border-radius: var(--radius); cursor: pointer; box-shadow: var(--shadow);
}
.enemy-card .slime-svg { width: 110px; height: 90px; display: block; margin: 6px auto 0; }
.enemy-card.targeted { border-color: var(--hp-low); }
.enemy-card.active { box-shadow: 0 0 0 3px #ffd36b; }
.enemy-card.dead { opacity: 0.3; cursor: default; filter: grayscale(1); }
.enemy-card.boss { width: 230px; border-color: #b48cff; background: linear-gradient(180deg, #f5efff, #fff 60%); }
.enemy-card.boss.targeted { border-color: var(--hp-low); }
.enemy-card.boss .slime-svg { width: 160px; height: 150px; }
.monster-img { object-fit: cover; object-position: 50% 12%; border-radius: 12px; background: radial-gradient(circle at 50% 40%, #e9fbff, #cdeff5 70%); }
.mini-slime .monster-img, .strip-slime .monster-img { border-radius: 50%; }
.mini-slime .monster-img { width: 30px; height: 30px; display: block; }
.stage-btn.boss .mini-slime .monster-img { width: 40px; height: 40px; }
.strip-slime:has(.monster-img) { display: block; width: 100%; height: 100%; }
.strip-slime .monster-img { width: 100%; height: 100%; display: block; }
.witch-svg .cipher-orbit text { animation: orbit 3s ease-in-out infinite; }
.witch-svg .cipher-orbit text:nth-child(2) { animation-delay: -0.8s; }
.witch-svg .cipher-orbit text:nth-child(3) { animation-delay: -1.6s; }
.witch-svg .cipher-orbit text:nth-child(4) { animation-delay: -2.4s; }
.witch-orb { animation: orb 1.6s ease-in-out infinite; }
@keyframes orbit { 50% { transform: translateY(-5px); opacity: 0.5; } }
@keyframes orb { 50% { fill: #fff; filter: drop-shadow(0 0 4px #b48cff); } }
.casting { animation: casting 1.2s ease-out; }
@keyframes casting { 20% { box-shadow: 0 0 0 4px #c9a6ff, 0 0 28px #b48cff; transform: scale(1.04); } }
.ally-card.casting { animation: casting-ally 1.2s ease-out; }
@keyframes casting-ally { 20% { box-shadow: 0 0 0 4px var(--c), 0 0 26px var(--c); } }
.target-mark { position: absolute; top: -12px; left: 50%; transform: translateX(-50%); background: var(--hp-low); color: #fff; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }

.unit-name { font-weight: 700; font-size: 14px; margin: 4px 0; }
.unit-name small { color: var(--muted); font-weight: 500; }

.bar { position: relative; height: 16px; background: #ece7df; border-radius: 999px; overflow: hidden; margin-top: 4px; }
.bar i { position: absolute; inset: 0 auto 0 0; background: var(--hp); transition: width 0.35s; }
.bar.en i { background: var(--en); }
.bar span { position: relative; font-size: 11px; font-weight: 700; display: block; text-align: center; line-height: 16px; }

.chips { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; min-height: 18px; }
.chip { font-size: 10.5px; padding: 1px 6px; border-radius: 999px; font-weight: 700; }
.chip.up { background: #e3f4e4; color: #2e7d32; }
.chip.down { background: #fde6e6; color: #c62828; }
.chip.silence { background: #3b3f4a; color: #fff; }
.chip.imag { background: #fbf1d9; color: #8a6413; font-family: ui-serif, Georgia, serif; }
.chip.shield { background: #e3eefc; color: #2a5db0; }
.fx-num.crit { color: #ff7a00; font-size: 30px; text-shadow: 0 0 10px #ffe0a8, 0 2px 0 #fff; animation: float-crit 1s ease-out forwards; }
@keyframes float-crit { 0% { opacity: 1; translate: 0 0; scale: 1.5; } 20% { scale: 1; } 100% { opacity: 0; translate: 0 -55px; } }
.crit-hit { animation: shake-crit 0.35s; }
@keyframes shake-crit { 20% { transform: translateX(-8px) rotate(-1.5deg); } 60% { transform: translateX(8px) rotate(1.5deg); } }
.ghost-svg .ghost-body { animation: ghost-float 2.4s ease-in-out infinite; }
@keyframes ghost-float { 50% { transform: translateY(-5px); opacity: 0.8; } }
.fx-num.burst { color: #b8892b; font-size: 28px; text-shadow: 0 0 8px #ffe9a8, 0 2px 0 #fff; }
.chip.mark { background: #dff6fa; color: #13707f; font-family: ui-serif, Georgia, serif; }
.ally-card.silenced .portrait img { filter: grayscale(0.6) brightness(0.9); }
.ally-card.silenced { outline: 2px dashed #3b3f4a; outline-offset: -2px; }

.mid { display: grid; grid-template-columns: 1fr 320px; gap: 12px; }
.action-bar { background: var(--panel); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); min-height: 110px; }
.turn-label { font-size: 16px; margin-bottom: 10px; }
.turn-label b { color: var(--c, var(--ink)); }
.turn-label.enemy { color: var(--muted); }
.action-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn.action { text-align: left; padding: 12px 14px; font-size: 16px; }
.btn.action small { display: block; font-weight: 500; font-size: 12.5px; opacity: 0.85; margin-top: 3px; }
.btn.action .cost { font-size: 12px; background: rgba(255,255,255,.25); border-radius: 999px; padding: 1px 7px; margin-left: 4px; }
.log { background: var(--panel); border-radius: var(--radius); padding: 10px 12px; height: 134px; overflow-y: auto; font-size: 13px; line-height: 1.55; box-shadow: var(--shadow); color: #4a443e; }

.ally-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.ally-card {
  display: grid; grid-template-columns: 78px 1fr; gap: 8px; background: var(--panel);
  border-radius: var(--radius); border-bottom: 5px solid var(--c); padding: 8px; box-shadow: var(--shadow);
  transition: transform 0.2s;
}
.ally-card.active { transform: translateY(-8px); box-shadow: 0 0 0 3px var(--c), var(--shadow); }
.ally-card.dead { opacity: 0.4; filter: grayscale(1); }
.portrait img { width: 78px; height: 120px; object-fit: cover; object-position: 50% 8%; border-radius: 10px; background: #f8f8f8; }
.ult-btn {
  width: 100%; margin-top: 6px; border: 0; border-radius: 8px; padding: 6px 4px; font-size: 12px; font-weight: 700;
  background: #ece7df; color: var(--muted); cursor: not-allowed;
}
.ult-btn.ready { background: var(--c); color: #fff; cursor: pointer; animation: glow 1.2s ease-in-out infinite; }
.ult-btn.ready:disabled { animation: none; opacity: 0.7; cursor: default; }
@keyframes glow { 50% { box-shadow: 0 0 12px var(--c); } }

.hit { animation: shake 0.3s; }
.healed { animation: pulse 0.4s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px #9fe0a3; } }

#fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.fx-num { position: fixed; transform: translateX(-50%); font-weight: 900; font-size: 24px; animation: float 1s ease-out forwards; text-shadow: 0 2px 0 #fff, 0 0 6px #fff; }
.fx-num.damage { color: #d32f2f; }
.fx-num.heal { color: #2e9a4f; }
@keyframes float { from { opacity: 1; translate: 0 0; } to { opacity: 0; translate: 0 -50px; } }

/* 스킬 이름 배너 */
.skill-banner {
  position: fixed; left: 50%; top: 30%; transform: translate(-50%, -50%); z-index: 60;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: min(420px, 90vw); padding: 12px 28px; border-radius: 14px; color: #fff; text-align: center;
  background: linear-gradient(90deg, transparent, var(--c, #5b5bd6) 18%, var(--c, #5b5bd6) 82%, transparent);
  animation: banner 1.5s ease-out forwards;
}
.skill-banner.enemy { --c: #6a2fc0; }
.skill-banner.mark, .skill-banner.seal { --c: #157385; }
.skill-banner b { font-size: 30px; letter-spacing: 0.04em; text-shadow: 0 2px 8px rgba(0,0,0,.35); }
.skill-banner small { font-size: 13px; opacity: 0.9; }
.skill-banner.cipher b, .skill-banner.decrypt b { font-family: ui-monospace, "SF Mono", Menlo, monospace, sans-serif; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scaleX(0.3); }
  15% { opacity: 1; transform: translate(-50%, -50%) scaleX(1.05); }
  25% { transform: translate(-50%, -50%) scaleX(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%); }
}

/* 암호화 치환: 쏟아지는 암호 문자 */
.fx-cipher {
  position: fixed; font: 900 22px ui-monospace, Menlo, monospace; color: #8b4dff;
  text-shadow: 0 0 8px #c9a6ff; opacity: 0; animation: cipher-fall 1s ease-in forwards;
}
@keyframes cipher-fall {
  0% { opacity: 0; transform: translateY(0) rotate(-20deg); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translateY(150px) rotate(15deg); }
}
.ally-row.cipher-hit .ally-card { animation: cipher-hit 1.2s ease-out; }
@keyframes cipher-hit { 30% { box-shadow: 0 0 0 3px #8b4dff, 0 0 22px #b48cff; filter: hue-rotate(40deg) saturate(1.3); } }

/* 복호화 엔진: 초록 고리와 정리되는 글자 */
.fx-ring {
  position: fixed; width: 40px; height: 40px; margin: -20px 0 0 -20px; border-radius: 50%;
  border: 3px solid #4cd07d; opacity: 0; animation: ring 1.1s ease-out forwards;
}
@keyframes ring { 0% { opacity: 0.9; transform: scale(0.3); } 100% { opacity: 0; transform: scale(4); } }
.fx-decrypt {
  position: fixed; transform: translateX(-50%); font: 900 20px ui-monospace, Menlo, monospace; color: #2e9a4f;
  text-shadow: 0 0 6px #fff, 0 0 10px #9fe0a3; opacity: 0; animation: decrypt-rise 1.3s ease-out forwards;
}
@keyframes decrypt-rise { 0% { opacity: 0; translate: 0 20px; } 25% { opacity: 1; } 75% { opacity: 1; translate: 0 -10px; } 100% { opacity: 0; translate: 0 -30px; } }

/* 허수 표식: 내려앉는 i */
.fx-imag {
  position: fixed; transform: translateX(-50%); font: italic 900 26px ui-serif, Georgia, serif; color: #1f8a9e;
  text-shadow: 0 0 8px #8ff0ff, 0 0 2px #fff; opacity: 0; animation: imag-drop 1.3s ease-out forwards;
}
@keyframes imag-drop { 0% { opacity: 0; translate: 0 -20px; } 30% { opacity: 1; } 70% { opacity: 1; translate: 0 40px; } 100% { opacity: 0; translate: 0 50px; } }

/* 허수 봉인 */
.ally-row.seal-hit .ally-card:not(.dead) { animation: seal-hit 1.2s ease-out; }
@keyframes seal-hit { 30% { box-shadow: 0 0 0 3px #1f8a9e, 0 0 20px #8ff0ff; filter: grayscale(0.7); } }
.fx-seal { position: fixed; transform: translate(-50%, -50%); font-size: 64px; animation: seal-pop 1.2s ease-out forwards; }
@keyframes seal-pop { 0% { opacity: 0; scale: 0.3; } 25% { opacity: 1; scale: 1.2; } 70% { opacity: 1; scale: 1; } 100% { opacity: 0; scale: 1.4; } }

/* 궁극기: 캐릭터 색 번쩍임 */
.fx-burst {
  position: fixed; width: 60px; height: 60px; margin: -30px 0 0 -30px; border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, var(--c, #ffd36b) 40%, transparent 70%);
  animation: burst 0.9s ease-out forwards;
}
@keyframes burst { 0% { opacity: 1; transform: scale(0.2); } 100% { opacity: 0; transform: scale(5); } }

@media (prefers-reduced-motion: reduce) {
  .fx-cipher, .fx-ring, .fx-decrypt, .fx-burst, .fx-imag, .fx-seal { display: none; }
  .skill-banner { animation-duration: 2s; }
}

/* ---------- 퀴즈 / 결과 ---------- */
.overlay { position: fixed; inset: 0; background: rgba(30, 25, 20, 0.45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.quiz-card, .result-card {
  background: var(--panel); border-radius: 18px; padding: 20px; width: min(440px, 100%);
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.quiz-card { border-top: 6px solid var(--c); }
.quiz-head { display: flex; gap: 12px; align-items: center; }
.quiz-head > div { flex: 1; }
.pad-toggle {
  flex: none; align-self: flex-start; border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 5px 11px; font-size: 13px; font-weight: 700; cursor: pointer; color: var(--muted);
}
.pad-toggle.on { background: var(--c); border-color: var(--c); color: #fff; }

/* 연습장을 켜면 퀴즈 창이 넓어지고 오른쪽에 모눈 캔버스가 붙는다 */
.quiz-card.with-pad { width: min(1000px, 100%); display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 18px; align-items: stretch; }
.quiz-pad { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.quiz-pad[hidden] { display: none; }
.pad-toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pad-spacer { flex: 1; }
.pad-tool {
  display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); background: var(--panel);
  border-radius: 8px; padding: 5px 9px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.pad-tool i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.pad-tool.on { border-color: var(--c); box-shadow: 0 0 0 2px var(--c); }
.pad-canvas {
  width: 100%; flex: 1; min-height: 340px; border-radius: 12px; border: 1px solid var(--line); cursor: crosshair;
  touch-action: none; background-color: #fffef8;
  background-image: linear-gradient(#e9e4d8 1px, transparent 1px), linear-gradient(90deg, #e9e4d8 1px, transparent 1px);
  background-size: 24px 24px;
}

.quiz-head img { width: 54px; height: 54px; border-radius: 50%; object-fit: cover; object-position: 50% 10%; border: 2px solid var(--c); }
.quiz-title { font-weight: 800; }
.quiz-reward { font-size: 13px; color: var(--muted); }
.quiz-q { font-size: 28px; line-height: 1.35; font-weight: 800; text-align: center; margin: 18px 0 10px; display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
.frac { display: inline-flex; flex-direction: column; align-items: center; font-size: 0.75em; line-height: 1.1; vertical-align: middle; margin: 0 2px; }
.frac span:first-child { border-bottom: 2px solid currentColor; padding: 0 4px; }
.quiz-q sup, .quiz-q sub { font-size: 0.6em; }
.quiz-q .frac { vertical-align: middle; }
.quiz-q .rep { position: relative; display: inline-block; }
.quiz-q .rep::before { content: '·'; position: absolute; left: 50%; top: -0.55em; transform: translateX(-50%); font-weight: 900; }
.quiz-q .sys { display: inline-block; text-align: left; border-left: 3px solid currentColor; border-radius: 10px 0 0 10px; padding: 2px 0 2px 12px; font-size: 0.85em; line-height: 1.5; }
.quiz-q .sigma, .quiz-q .integral { display: inline-flex; flex-direction: column; align-items: center; line-height: 1; vertical-align: middle; }
.quiz-q .sigma small, .quiz-q .integral small { display: block; width: auto; margin: 0; font-size: 0.45em; color: inherit; font-weight: 700; }
.quiz-q .integral { font-family: ui-serif, Georgia, serif; }
.quiz-figure { display: block; width: 100%; max-width: 280px; margin: 0 auto 8px; }
.fig-shape { fill: #e8f0fe; stroke: #3a6fd8; stroke-width: 2.5; }
.fig-dash { stroke: #e0464b; stroke-width: 2; stroke-dasharray: 5 4; }
.fig-mark { fill: none; stroke: #e0464b; stroke-width: 1.5; }
.fig-label { font-size: 14px; font-weight: 700; fill: var(--ink); }
.fig-vertex { font-size: 13px; font-weight: 700; fill: var(--muted); font-style: italic; }
.fig-angle { font-size: 14px; font-weight: 800; fill: #e0464b; }
.fig-line { stroke: #3a6fd8; stroke-width: 2; }
.fig-circle { fill: #e8f0fe; stroke: #3a6fd8; stroke-width: 2.5; }
.fig-dot { fill: #3a6fd8; }
.fig-inner { fill: none; stroke: #3a6fd8; stroke-width: 2; }
.fig-grid { stroke: #e2dcd2; stroke-width: 1; }
.fig-bar { fill: #7aa6e8; }
.fig-tick { font-size: 11px; fill: var(--muted); font-weight: 600; }
.quiz-q small { display: block; width: 100%; font-size: 15px; font-weight: 600; color: var(--muted); margin-top: 6px; }
.quiz-form { display: flex; gap: 8px; }
.quiz-form input { flex: 1; font-size: 22px; padding: 8px 12px; border: 2px solid var(--line); border-radius: 10px; text-align: center; min-width: 0; }
.quiz-form input:focus { outline: none; border-color: var(--c); }
.quiz-hint { font-size: 12px; color: var(--muted); margin-top: 6px; text-align: center; }
.mark-warn { display: inline-block; margin-top: 3px; font-weight: 700; color: #13707f; background: #dff6fa; border-radius: 6px; padding: 1px 6px; }
.quiz-table { margin: 0 auto 10px; border-collapse: collapse; font-size: 15px; text-align: center; }
.quiz-table th, .quiz-table td { border: 1px solid var(--line); padding: 5px 9px; }
.quiz-table tr:first-child th { background: #f4f1ea; }
.quiz-table tr th:first-child { background: #ece7df; white-space: nowrap; }
.quiz-table .tally { display: inline-block; max-width: 4.6em; line-height: 1.05; letter-spacing: -1px; color: #3a6fd8; font-size: 14px; }
.quiz-data { text-align: center; font-size: 18px; font-weight: 700; margin: 0 0 10px; letter-spacing: 0.02em; }
.quiz-result { min-height: 28px; margin-top: 10px; text-align: center; font-weight: 800; font-size: 18px; }
.quiz-result.ok { color: #2e9a4f; }
.quiz-result.ng { color: #d32f2f; }
.quiz-result small { display: block; font-size: 13px; font-weight: 500; color: var(--muted); }

.result-card { text-align: center; }
.choose-card { background: var(--panel); border-radius: 18px; padding: 20px; width: min(520px, 100%); border-top: 6px solid #1f8a9e; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.choose-desc { color: var(--muted); font-size: 14px; margin: 6px 0 14px; }
.choose-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 10px; }
.choose-ally { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; border: 2px solid var(--line); border-radius: 12px; background: var(--panel); cursor: pointer; }
.choose-ally:hover { border-color: var(--c); box-shadow: 0 0 0 3px var(--c); }
.choose-ally img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; object-position: 50% 10%; border: 2px solid var(--c); }
.choose-ally small { color: var(--muted); }
.result-card h2 { font-size: 34px; margin: 0; }
.result-card.win h2 { color: #2e9a4f; }
.result-card.lose h2 { color: #d32f2f; }
.result-stage { color: var(--muted); margin-top: 2px; }
.repeat-note { color: var(--muted); }
.unlock { background: #fff7e0; border-radius: 10px; padding: 8px; }
.result-buttons { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

/* ---------- 좁은 화면 ---------- */
@media (max-width: 820px) {
  .mid { grid-template-columns: 1fr; }
  .log { height: 76px; }
  .ally-row { grid-template-columns: repeat(2, 1fr); }
  .enemy-card { width: 150px; }
  .enemy-card.boss { width: 200px; }
  .stage-btn.boss { grid-column: span 1; }
}
@media (max-width: 720px) {
  .equip-layout { grid-template-columns: 1fr; }
  .equip-char img { width: 110px; height: 140px; }
}
@media (max-width: 760px) {
  .quiz-card.with-pad { grid-template-columns: 1fr; max-height: calc(100vh - 32px); overflow-y: auto; }
  .pad-canvas { min-height: 240px; }
}
@media (max-width: 480px) {
  .screen { padding: 12px; }
  .action-buttons { grid-template-columns: 1fr; }
  .ally-card { grid-template-columns: 56px 1fr; }
  .portrait img { width: 56px; height: 90px; }
  .char-card { grid-template-columns: 90px 1fr; }
  .char-portrait img { width: 90px; height: 140px; }
}
