:root {
  --bg: #120f0c;
  --panel: #1d1813;
  --panel2: #261f18;
  --line: #3d3226;
  --text: #ede3d1;
  --muted: #a8977d;
  --gold: #f0c35a;
  --red: #e45b5b;
  --green: #6fd47a;
  --blue: #6fb6ff;
  --t1: #c3cad3; --t2: #4fa3ff; --t3: #b46cff; --t4: #ffb020; --t5: #ff4d6d;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: 'Noto Sans KR', system-ui, sans-serif; font-size: 14px; }
body { background: radial-gradient(ellipse at top, #2a2018 0%, var(--bg) 60%); overflow-x: hidden; }
button { font-family: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- 상단 바 ---------- */
#topbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: linear-gradient(#2b221a, #1a1510);
  border-bottom: 2px solid #5a4630; flex-wrap: wrap; }
.logo { font-family: 'Cinzel', serif; font-weight: 800; font-size: 20px; color: var(--gold); letter-spacing: 1px;
  text-shadow: 0 2px 0 #000, 0 0 12px rgba(240,195,90,.35); margin-right: 8px; }
.logo span { color: #e8607e; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 12px; min-width: 96px; }
.stat small { display: block; font-size: 11px; color: var(--muted); }
.stat b { font-size: 17px; }
.stat em { font-style: normal; font-size: 11px; color: var(--muted); margin-left: 6px; }
.stat.gold b { color: var(--gold); }
.stat.enemy { min-width: 150px; }
.stat .bar { height: 5px; background: #000; border-radius: 3px; overflow: hidden; margin-top: 3px; }
.stat .bar i { display: block; height: 100%; width: 0; background: var(--green); transition: width .2s; }
.stat.enemy.warn b { color: var(--red); animation: blink .6s infinite alternate; }
@keyframes blink { to { opacity: .45; } }
.ctrl { margin-left: auto; display: flex; gap: 6px; }
.ctrl button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font-weight: 700; }
.ctrl button.on { background: #5a4630; border-color: var(--gold); color: var(--gold); }

/* ---------- 본문 ---------- */
main { flex: 1; display: flex; gap: 12px; padding: 12px; min-height: 0; }
#field { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
#canvas-wrap { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; overflow: hidden; position: relative; }
/* 등장 대사 배너 (클릭을 막지 않음) */
#quote { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; gap: 10px; align-items: center;
  max-width: min(560px, calc(100% - 32px)); padding: 8px 14px 8px 8px; border-radius: 10px; pointer-events: none;
  background: rgba(14, 10, 8, .88); border: 2px solid #ffd24a; box-shadow: 0 4px 18px rgba(0,0,0,.6); transition: opacity .35s, transform .35s; z-index: 10; }
#quote.off { opacity: 0; transform: translateX(-50%) translateY(8px); }
#quote.boss { border-color: #ff4a4a; background: rgba(40, 6, 10, .9); }
#quote canvas { width: 64px; height: 64px; image-rendering: pixelated; flex: none; background: rgba(255,255,255,.06); border-radius: 6px; }
#quote b { display: block; font-size: 13px; color: #ffd24a; }
#quote.boss b { color: #ff9a9a; }
#quote p { margin: 2px 0 0; font-size: 15px; line-height: 1.35; color: #fff; word-break: keep-all; }
#cv { border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.6), 0 0 0 2px #4a3a28; touch-action: none; }

#bossbar { background: linear-gradient(#3a1018, #22080d); border: 1px solid #7a2030; border-radius: 8px; padding: 6px 12px; margin-bottom: 8px; flex: none; }
#bossbar.off { visibility: hidden; }   /* 자리는 항상 확보 → 보스 등장 시 맵이 밀리거나 잘리지 않음 */
#bossbar .bname { display: flex; justify-content: space-between; font-weight: 800; color: #ffb3b3; }
#bossbar .bar { height: 10px; background: #000; border-radius: 5px; overflow: hidden; margin-top: 4px; }
#bossbar .bar i { display: block; height: 100%; background: linear-gradient(90deg, #ff3b3b, #ff8a3b); width: 100%; }
#boss-time.danger { color: #ff5050; animation: blink .4s infinite alternate; }

#actionbar { display: flex; gap: 10px; justify-content: center; padding-top: 8px; flex-wrap: wrap; }
#fsummon { display: flex; gap: 6px; justify-content: center; align-items: center; padding-top: 10px; flex-wrap: wrap; }
#fsummon:empty { display: none; }
.fs-label { font-size: 12px; color: var(--muted); margin-right: 4px; }
.fs { background: var(--panel2); border: 1px solid var(--fc); color: var(--fc); border-radius: 8px; padding: 5px 12px; font-weight: 800; font-size: 13px; }
#buffbar { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; min-height: 0; }
#buffbar:empty { display: none; }
.buff { background: #3a2a10; border: 1px solid var(--gold); color: var(--gold); border-radius: 12px; padding: 2px 10px; font-size: 12px; font-weight: 700; }
#btn-bounty { border-color: #e8b84a; }
.mission { background: var(--panel2); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; border-left: 4px solid #5a4630; }
.mission.done { border-left-color: var(--green); opacity: .8; }
.mission .row { display: flex; justify-content: space-between; }
.mission .row span { color: var(--gold); font-size: 12px; font-weight: 700; }
.mission small { display: block; color: var(--muted); font-size: 11px; }
.mission .bar { height: 5px; background: #000; border-radius: 3px; overflow: hidden; margin: 4px 0 2px; }
.mission .bar i { display: block; height: 100%; background: var(--green); }
.mission .prog { text-align: right; }
.codex { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; max-height: 46vh; overflow-y: auto; }
.cx { background: rgba(0,0,0,.3); border-radius: 6px; padding: 4px 2px; text-align: center; }
.cx small { display: block; font-size: 9px; line-height: 1.2; color: var(--muted); word-break: keep-all; }
.cx.locked .q { height: 40px; line-height: 40px; font-size: 18px; color: #4a3f30; font-weight: 800; }
.ach { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ach div { background: rgba(0,0,0,.3); border-radius: 6px; padding: 6px 8px; font-size: 13px; color: var(--muted); }
.ach div.on { color: var(--gold); }
.ach small { display: block; font-size: 11px; color: var(--muted); }
.fs-key { font-size: 10px; color: var(--muted); margin-right: 4px; }
.fs em { font-style: normal; color: var(--gold); font-size: 12px; margin-left: 3px; }
.fs:disabled { opacity: .35; cursor: default; }
.map-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.map-card { background: rgba(0,0,0,.3); border: 2px solid #3a3024; border-radius: 10px; padding: 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.map-card.on { border-color: var(--gold); box-shadow: 0 0 12px rgba(240,195,90,.3); }
.map-card b { color: var(--text); font-size: 14px; }
.map-card small { color: var(--muted); font-size: 11px; line-height: 1.35; text-align: center; }
.map-thumb { border-radius: 4px; }
.diff { font-size: 11px; font-weight: 800; padding: 1px 8px; border-radius: 9px; }
.d-이지 { background: #1f4a2a; color: #7ee08f; } .d-노말 { background: #4a3f1f; color: #f0c35a; } .d-하드 { background: #4a1f24; color: #ff7b7b; }
.pool-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.pool-card { background: rgba(0,0,0,.3); border: 2px solid #3a3024; border-radius: 10px; padding: 10px 8px; text-align: center; display: flex; flex-direction: column; gap: 4px; }
.pool-card b { color: var(--fc); font-size: 15px; }
.pool-card small { color: var(--muted); font-size: 11px; line-height: 1.4; }
.pool-card.on { border-color: var(--fc); background: rgba(255,255,255,.06); box-shadow: 0 0 12px rgba(255,255,255,.12); }
.modal-actions button:disabled { opacity: .4; cursor: default; }
.big { background: linear-gradient(#4a3a28, #2e241a); border: 1px solid #7a6040; border-radius: 10px; padding: 10px 18px;
  font-size: 16px; font-weight: 800; min-width: 140px; position: relative; }
.big:hover:not(:disabled) { border-color: var(--gold); box-shadow: 0 0 12px rgba(240,195,90,.3); }
.big:disabled { opacity: .4; cursor: default; }
.big em { font-style: normal; color: var(--gold); font-size: 13px; margin-left: 4px; }
.big .k { position: absolute; top: 3px; left: 6px; font-size: 10px; color: var(--muted); }
#btn-summon { background: linear-gradient(#6a4a1a, #3a2810); border-color: var(--gold); }
#btn-next.waiting { border-color: #6fe08a; box-shadow: 0 0 16px rgba(111,224,138,.55); animation: blink .7s infinite alternate; }

/* 게임판 왼쪽 전황 칸: 히든 스킬 효과 + 알림 (맵을 가리지 않음) */
#stage { flex: 1; display: flex; gap: 10px; min-height: 0; }
#feed { width: 220px; flex: none; display: flex; flex-direction: column; gap: 8px; min-height: 0; overflow: hidden; pointer-events: none; }
#skillfeed { display: flex; flex-direction: column; gap: 6px; }
#skillfeed:empty { display: none; }
.skc { display: flex; gap: 8px; padding: 8px; border-radius: 10px; background: linear-gradient(#3a2a10, #201608); border: 2px solid #ffd24a;
  box-shadow: 0 0 14px rgba(255,210,74,.35); animation: skc 7s forwards; }
.skc canvas { width: 40px; height: 40px; image-rendering: pixelated; flex: none; }
.skc b { display: block; font-size: 12px; color: #ffd24a; }
.skc .sn { font-size: 14px; font-weight: 800; color: #fff; margin: 1px 0 3px; }
.skc p { margin: 0; font-size: 12px; line-height: 1.35; color: #e8dcc4; word-break: keep-all; }
.skc small { display: block; margin-top: 3px; font-size: 11px; color: var(--muted); }
@keyframes skc { 0% { opacity: 0; transform: translateX(-10px); } 6% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }
#toasts { display: flex; flex-direction: column; align-items: stretch; gap: 6px; pointer-events: none; z-index: 5; }
.toast { background: rgba(20,15,10,.92); border: 1px solid var(--gold); padding: 6px 10px; border-radius: 8px; font-size: 13px;
  font-weight: 700; animation: toast 2.4s forwards; text-align: left; word-break: keep-all; }
.toast.bad { border-color: var(--red); color: #ffb0b0; }
.toast.epic { border-color: var(--t4); color: var(--t4); font-size: 14px; box-shadow: 0 0 12px rgba(255,176,32,.35); }
.toast.myth { border-color: var(--t5); color: #ffd0da; font-size: 15px; box-shadow: 0 0 16px rgba(255,77,109,.5); }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 10% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- 사이드 패널 ---------- */
#side { width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: none; padding: 10px 2px; font-size: 13px; font-weight: 700; color: var(--muted); border-bottom: 2px solid transparent; position: relative; }
.tabs button.on { color: var(--gold); border-bottom-color: var(--gold); }
.badge { font-style: normal; background: var(--t4); color: #000; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 3px; }
.tab-body { padding: 12px; overflow-y: auto; flex: 1; }
.badge.green { background: #3fbf5a; color: #fff; }

/* 승급표 */
.promo { background: var(--panel2); border-radius: 8px; padding: 8px; margin-bottom: 8px; border-left: 4px solid; }
.promo-h { font-weight: 800; font-size: 13px; margin-bottom: 6px; }
.promo-line { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.pnode { position: relative; text-align: center; background: #15110d; border: 1px solid #3a3024; border-radius: 6px; padding: 4px 2px; cursor: default; }
.pnode.own { cursor: pointer; }
.pnode.own:hover { border-color: var(--gold); }
.pnode.ready { border-color: #3fbf5a; box-shadow: 0 0 8px rgba(63,191,90,.35); }
.pcol { display: flex; flex-direction: column; justify-content: center; gap: 4px; position: relative; }
.pcol:not(:last-child)::after { content: '▶'; position: absolute; right: -12px; top: 50%; transform: translateY(-50%); font-size: 9px; color: var(--muted); }
.pnode .pn { font-size: 11px; line-height: 1.25; margin-top: 2px; word-break: keep-all; }
.pnode .pc { font-size: 11px; color: var(--muted); }
.pnode.ready .pc { color: #6fe08a; font-weight: 800; }
.promo-note { font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; line-height: 1.7; }

.u-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.u-head canvas { flex: none; }
.u-name { font-size: 18px; font-weight: 800; }
.u-tags { display: flex; gap: 5px; margin-top: 4px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 10px; border: 1px solid currentColor; }
.u-desc { color: var(--muted); font-size: 13px; margin: 6px 0 10px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.stats div { background: var(--panel2); border-radius: 6px; padding: 5px 8px; font-size: 12px; color: var(--muted); }
.stats b { display: block; color: var(--text); font-size: 14px; }
.stats b i { font-style: normal; color: var(--green); font-size: 11px; margin-left: 3px; }
.abil { font-size: 12px; background: #2a2218; border-left: 3px solid var(--gold); padding: 6px 8px; margin-bottom: 4px; border-radius: 0 6px 6px 0; }
h4 { margin: 14px 0 6px; font-size: 13px; color: var(--gold); }

.recipe { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 8px; }
.recipe.ready { border-color: var(--t4); box-shadow: 0 0 10px rgba(255,176,32,.25); }
.recipe .r-top { display: flex; align-items: center; gap: 8px; }
.recipe .r-top b { flex: 1; }
.recipe button, .upg button, .mini-btn { background: #5a4630; border: 1px solid var(--gold); border-radius: 6px; padding: 4px 10px; font-weight: 700; color: var(--gold); }
.recipe button:disabled, .upg button:disabled, .mini-btn:disabled { opacity: .35; cursor: default; }
.ings { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.ing { font-size: 11px; padding: 2px 6px; border-radius: 5px; background: #15110d; border: 1px solid #3a3024; }
.ing.ok { border-color: var(--green); color: var(--green); }
.ing.no { color: #9a8a7a; }
.r-desc { font-size: 11px; color: var(--muted); margin-top: 4px; }
.filter { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.filter button { background: var(--panel2); border: 1px solid var(--line); border-radius: 14px; padding: 3px 10px; font-size: 12px; }
.filter button.on { border-color: var(--gold); color: var(--gold); }
.rule { font-size: 12px; background: #2a2218; border-radius: 8px; padding: 8px 10px; color: var(--muted); line-height: 1.6; margin-bottom: 10px; }
.rule b { color: var(--text); }

.upg { display: flex; align-items: center; gap: 10px; background: var(--panel2); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; border-left: 4px solid; }
.upg .n { flex: 1; }
.upg .n b { display: block; }
.upg .n small { color: var(--muted); }

.syn { background: var(--panel2); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; border-left: 4px solid; }
.syn .row { display: flex; justify-content: space-between; }
.syn .steps { display: flex; gap: 4px; margin-top: 5px; }
.syn .steps span { flex: 1; text-align: center; font-size: 11px; padding: 2px; border-radius: 4px; background: #15110d; color: #776a5a; }
.syn .steps span.on { background: #4a3a20; color: var(--gold); font-weight: 700; }
.aug-list { display: flex; flex-wrap: wrap; gap: 6px; }
.aug-chip { background: #2a2218; border: 1px solid #5a4630; border-radius: 6px; padding: 4px 8px; font-size: 12px; }

/* ---------- 모달 ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.72); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.modal-card { background: linear-gradient(#2b221a, #1a1510); border: 2px solid #7a6040; border-radius: 14px; padding: 22px; max-width: 760px; width: 100%;
  max-height: 92vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.7); }
.modal-card h2 { font-family: 'Cinzel', 'Noto Sans KR', serif; color: var(--gold); margin: 0 0 6px; font-size: 26px; text-align: center; }
.modal-card .sub { text-align: center; color: var(--muted); margin-bottom: 16px; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.card { background: linear-gradient(#3a2e20, #241c14); border: 1px solid #7a6040; border-radius: 12px; padding: 16px 12px; text-align: center; cursor: pointer; transition: transform .12s; }
.card:hover { transform: translateY(-4px); border-color: var(--gold); box-shadow: 0 0 20px rgba(240,195,90,.3); }
.card .ic { font-size: 34px; }
.card b { display: block; margin: 8px 0 6px; font-size: 15px; color: var(--gold); }
.card p { margin: 0; font-size: 13px; color: var(--text); }
.card small { display: block; margin-top: 8px; color: var(--muted); }
.card.fac { border-width: 2px; position: relative; }
.card.hid { border: 2px solid #ffd24a; position: relative; background: linear-gradient(#4a3a14, #2a200c); box-shadow: 0 0 16px rgba(255,210,74,.45); }
.card.hid .ftag { background: #ffd24a; }
.card .ftag { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 800; color: #120c08; padding: 2px 8px; border-radius: 8px; white-space: nowrap; }
.wpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; max-height: 46vh; overflow-y: auto; margin-bottom: 6px; }
.wp { display: flex; gap: 8px; align-items: center; text-align: left; background: var(--panel2); border: 2px solid var(--line); border-radius: 10px; padding: 6px 8px; color: var(--text); cursor: pointer; }
.wp b { display: block; font-size: 14px; }
.wp small { display: block; font-size: 11px; color: var(--muted); }
.wp.on { border-color: var(--gold); background: #3a2e18; box-shadow: 0 0 10px rgba(240,195,90,.35); }
.modal-actions { display: flex; justify-content: center; gap: 10px; margin-top: 16px; }
.modal-actions button { background: #5a4630; border: 1px solid var(--gold); color: var(--gold); border-radius: 8px; padding: 10px 22px; font-weight: 800; font-size: 15px; }
.modal-actions button.sec { background: var(--panel2); border-color: var(--line); color: var(--text); }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; font-size: 13px; line-height: 1.65; }
.help-grid section { background: rgba(0,0,0,.25); border-radius: 8px; padding: 10px 12px; }
.help-grid h3 { margin: 0 0 4px; color: var(--gold); font-size: 14px; }
.help-grid ul { margin: 0; padding-left: 18px; }
.tierline { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 8px 0; }
.tierline span { padding: 2px 10px; border-radius: 10px; border: 1px solid currentColor; font-size: 12px; font-weight: 700; }
.result { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.result div { background: rgba(0,0,0,.3); border-radius: 8px; padding: 8px; text-align: center; color: var(--muted); font-size: 12px; }
.result b { display: block; color: var(--text); font-size: 20px; }

/* 높이가 낮은 화면: 시작 화면의 목표/성장 설명 숨김 (자세한 규칙에 같은 내용) → 시작 버튼이 보이도록 */
@media (max-height: 860px) { .start-help { display: none; } .modal-card h2 { font-size: 22px; } }

/* ---------- 반응형 ---------- */
@media (max-width: 980px) {
  #app { height: auto; min-height: 100vh; }
  main { flex-direction: column; padding: 8px 16px; }
  #side { width: 100%; max-height: none; }
  #canvas-wrap { min-height: 0; }
  #stage { display: block; }
  #feed { position: absolute; top: 50px; left: 0; right: 0; width: auto; align-items: center; z-index: 5; }
  #feed > div { width: calc(100% - 32px); max-width: 420px; }
  .ctrl { margin-left: 0; }
  .cards { grid-template-columns: 1fr; }
  .help-grid { grid-template-columns: 1fr; }
  .pool-grid { grid-template-columns: repeat(2, 1fr); }
  .map-grid { grid-template-columns: 1fr; }
  .codex { grid-template-columns: repeat(5, 1fr); }
  .ach { grid-template-columns: 1fr; }
  .result { grid-template-columns: repeat(2, 1fr); }
  .big { min-width: 0; flex: 1; padding: 10px 8px; font-size: 14px; }
  #topbar { padding: 8px 16px; }
  .stat { min-width: 0; padding: 4px 8px; }
}
