:root {
  --bg: #1b1622; --panel: #2a2233; --panel2: #342a40; --line: #453a54;
  --gold: #f4c65a; --gem: #6fd3ff; --txt: #ece6f2; --dim: #a294b5;
  --hp: #e5564e; --ok: #6fcf72; --accent: #b98cff;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; width: 100%; background: #0e0b12; color: var(--txt);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none;
  overflow-x: hidden; }
#app { width: 100%; max-width: 480px; margin: 0 auto; height: 100%; display: flex; flex-direction: column;
  background: var(--bg); position: relative; overflow-x: hidden; }

/* 상단 자원 */
#topbar { display: flex; gap: 10px; align-items: center; padding: calc(8px + var(--safe-t)) 12px 8px;
  background: #17131d; border-bottom: 1px solid var(--line); }
.res { display: flex; align-items: center; gap: 5px; font-weight: 700; font-size: 15px;
  background: #241d2e; padding: 5px 10px; border-radius: 20px; }
.res .ic { font-size: 14px; }
.res.grow { flex: 1; background: none; justify-content: flex-end; font-size: 11px; color: var(--dim); font-weight: 500; }
#money { color: var(--gold); } #gems { color: var(--gem); }

/* 던전 패널 */
#dungeon-panel { padding: 12px; background: linear-gradient(180deg, #2a2233, #221b2b);
  border-bottom: 1px solid var(--line); }
.d-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
#d-name { font-size: 17px; font-weight: 800; }
.badge { font-size: 12px; color: var(--dim); background: #1c1724; padding: 3px 9px; border-radius: 12px; }
#enemy-name { font-size: 13px; color: var(--dim); margin-bottom: 5px; }
.hpbar { position: relative; height: 20px; background: #1a151f; border-radius: 10px; overflow: hidden; }
#enemy-hp { height: 100%; width: 0%; background: linear-gradient(90deg, #ff7b6e, var(--hp)); transition: width .12s linear; }
.hpbar span { position: absolute; inset: 0; text-align: center; font-size: 11px; line-height: 20px; font-weight: 700; text-shadow: 0 1px 2px #000; }
.d-stats { display: flex; justify-content: space-between; margin-top: 10px; font-size: 12px; color: var(--dim); }
.d-stats b { color: var(--txt); }
#drop-log { margin-top: 8px; height: 34px; overflow: hidden; font-size: 11px; color: var(--dim); line-height: 17px; }
#drop-log .gain { color: var(--gold); } #drop-log .unl { color: var(--accent); font-weight: 700; }

/* 콘텐츠 */
#content { flex: 1; overflow-y: auto; padding: 10px 12px 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; margin-bottom: 9px; }
.card .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.card .name { font-weight: 700; font-size: 14px; }
.card .sub { font-size: 11px; color: var(--dim); margin-top: 2px; }
button.buy { background: var(--accent); color: #1a1020; border: none; border-radius: 9px; font-weight: 800;
  padding: 8px 12px; font-size: 13px; min-width: 92px; cursor: pointer; }
button.buy:disabled { background: #3a3346; color: #6a5f79; cursor: default; }
button.buy .cost { display: block; font-size: 10px; opacity: .8; font-weight: 600; }

.dsel { width: 100%; text-align: left; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; color: var(--txt); cursor: pointer; }
.dsel.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.dsel.locked { opacity: .45; }
.dsel .name { font-weight: 700; } .dsel .sub { font-size: 11px; color: var(--dim); margin-top: 3px; }

.inv-item { display: flex; justify-content: space-between; font-size: 13px; padding: 6px 2px; border-bottom: 1px solid #2c2436; }
.inv-item .q { color: var(--gold); font-weight: 700; }
.empty { color: var(--dim); font-size: 12px; text-align: center; padding: 20px 0; }
.sec-title { font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; margin: 4px 2px 8px; }

/* 하단 탭 */
#tabs { display: flex; border-top: 1px solid var(--line); background: #17131d; padding-bottom: var(--safe-b); }
.tab { flex: 1; background: none; border: none; color: var(--dim); font-size: 12px; font-weight: 700;
  padding: 12px 0; cursor: pointer; }
.tab.active { color: var(--accent); box-shadow: 0 -2px 0 var(--accent) inset; }

/* ── 원본 아트 스프라이트 ── */
.spr { image-rendering: pixelated; image-rendering: crisp-edges; vertical-align: middle; }
.ic-img { width: 18px; height: 18px; image-rendering: pixelated; vertical-align: middle; }

/* 상단 통화 */
.res .ic-img { margin-right: 2px; }

/* 하단 네비 (아이콘 위, 라벨 아래) */
#tabs .tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 calc(8px + var(--safe-b)); }
#tabs .tab img { width: 26px; height: 26px; image-rendering: pixelated; opacity: .55; filter: brightness(1.6); }
#tabs .tab.active img { opacity: 1; }
#tabs .tab .navemo { font-size: 21px; line-height: 26px; filter: grayscale(.3); opacity: .7; }
#tabs .tab.active .navemo { opacity: 1; }
#tabs .tab span { font-size: 11px; }

/* 전투 패널 배경 = 지역 아트 */
#dungeon-panel { background-size: cover; background-position: center 30%; background-repeat: no-repeat; }
#scene { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; min-height: 46px; }
#party-sprites, #enemy-sprites { display: flex; gap: 1px; flex: 1; }
#enemy-sprites { justify-content: flex-end; }
#vs { font-size: 15px; opacity: .7; flex: none; }
.spr-fighter { width: 46px; height: 46px; image-rendering: pixelated; filter: drop-shadow(0 2px 2px rgba(0,0,0,.6)); }
.spr-fighter.foe { transform: scaleX(-1); }

/* 지역 리스트 썸네일 */
.dsel { display: flex; align-items: center; gap: 10px; }
.spr-area { width: 58px; height: 58px; border-radius: 8px; object-fit: cover; image-rendering: pixelated; flex: none; }
.locked-thumb { width: 58px; height: 58px; display: inline-flex; align-items: center; justify-content: center;
  background: #1a151f; border-radius: 8px; font-size: 20px; flex: none; }
.dsel-txt { flex: 1; min-width: 0; }

/* 파티/아이템 행 스프라이트 */
.unit-row { display: flex; align-items: center; gap: 9px; }
.spr-unit { width: 34px; height: 34px; image-rendering: pixelated; flex: none; }
.spr-item { width: 30px; height: 30px; image-rendering: pixelated; flex: none; }
.unit-name { flex: 1; min-width: 0; }

/* ── 상단바 액션 버튼 ── */
#topbar { flex-wrap: nowrap; }
.tb-grow { flex: 1; }
.tb-btns { display: flex; gap: 4px; align-items: center; }
.tb-btn { position: relative; width: 34px; height: 34px; padding: 0; border: none; border-radius: 9px;
  background: #241d2e; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--txt); font-size: 16px; }
.tb-btn img { width: 24px; height: 24px; image-rendering: pixelated; }
.tb-btn:active { background: #34293f; }
.badge-dot { position: absolute; top: -2px; right: -2px; min-width: 8px; height: 8px; border-radius: 5px; background: var(--hp); }

/* 화면 제목 바 */
#screen-title { display: flex; align-items: center; gap: 10px; padding: 4px 12px; background: #17131d;
  border-bottom: 1px solid var(--line); font-weight: 800; font-size: 13px; color: var(--accent); }
#screen-title #offline-note { font-size: 11px; color: var(--dim); font-weight: 500; }

/* 시설 간판 */
.spr-sign { width: 40px; height: 40px; image-rendering: pixelated; flex: none; }

/* ── 모달(다이얼로그) ── */
#overlay { position: absolute; inset: 0; background: rgba(0,0,0,.6); z-index: 40; }
#modal { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
#modal-box { width: 100%; max-width: 420px; max-height: 80%; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 12px 40px rgba(0,0,0,.5); }
#modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px;
  border-bottom: 1px solid var(--line); font-weight: 800; }
#modal-close { background: none; border: none; color: var(--dim); font-size: 18px; cursor: pointer; }
#modal-body { padding: 12px 14px; overflow-y: auto; }

/* 도감 그리드 */
.bestiary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.best-cell { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 4px; text-align: center; }
.spr-best { width: 48px; height: 48px; image-rendering: pixelated; }
.best-name { font-size: 11px; font-weight: 700; margin-top: 2px; }

/* ── 사이드 드로어 ── */
#drawer { position: absolute; top: 0; right: 0; bottom: 0; width: 74%; max-width: 300px; z-index: 60;
  background: #1d1727; border-left: 1px solid var(--line); box-shadow: -8px 0 30px rgba(0,0,0,.5);
  padding: calc(12px + var(--safe-t)) 10px; overflow-y: auto; }
.drawer-head { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 15px; padding: 6px 6px 12px; border-bottom: 1px solid var(--line); }
.drawer-item { display: flex; align-items: center; gap: 12px; width: 100%; background: none; border: none;
  color: var(--txt); padding: 12px 8px; font-size: 14px; font-weight: 600; cursor: pointer; border-radius: 8px; text-align: left; }
.drawer-item:active { background: #2a2233; }
.spr-drawer { width: 26px; height: 26px; image-rendering: pixelated; flex: none; }
.spr-drawer.emo { display: inline-flex; align-items: center; justify-content: center; font-size: 18px; }

/* hidden 속성이 display 규칙을 이기도록 */
[hidden] { display: none !important; }

/* ── 실시간 전투 유닛 ── */
#party-sprites, #enemy-sprites { align-items: flex-end; gap: 3px; }
.fighter { display: inline-flex; flex-direction: column; align-items: center; position: relative; }
.fighter.dead { opacity: .25; filter: grayscale(1); }
.minihp { width: 40px; height: 4px; background: #1a151f; border-radius: 2px; margin-top: 2px; overflow: hidden; box-shadow: 0 0 0 1px rgba(0,0,0,.4); }
.minihp i { display: block; height: 100%; background: var(--ok); transition: width .15s linear; }
.fighter.foe .minihp i { background: var(--hp); }
.fighter .fx { position: absolute; top: -6px; right: -4px; display: flex; gap: 1px; }
.fx-ic { width: 13px; height: 13px; image-rendering: pixelated; }

/* 클라우드/리딤 입력 */
.cloud-ta { width: 100%; height: 90px; background: #17131d; color: var(--txt); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; font-family: monospace; font-size: 11px; resize: vertical; }
/* 도감 미조우 실루엣 */
.best-cell.unseen { opacity: .5; }
.spr-best.silh { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; font-size: 24px; }

/* 상세 다이얼로그 */
.dlg-head { display: flex; align-items: center; gap: 12px; }
.dlg-head .spr-sign, .dlg-head .spr-best, .dlg-head .spr-item { width: 56px; height: 56px; image-rendering: pixelated; }
.statgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.statgrid > div { background: var(--panel2); border-radius: 8px; padding: 8px; text-align: center; }
.statgrid b { display: block; font-size: 15px; margin-top: 2px; }
.tappable { cursor: pointer; }
.tappable:active { filter: brightness(1.15); }

/* ── 원본식 리치 던전 패널 (layout_dungeon) ── */
.dpanel { display: block; width: 100%; text-align: left; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; margin-bottom: 10px; overflow: hidden; cursor: pointer; padding: 0; color: var(--txt); }
.dpanel.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.dpanel.locked { opacity: .5; cursor: default; }
.dpanel-top { display: flex; gap: 10px; padding: 10px; }
.dpanel .spr-area { width: 76px; height: 76px; border-radius: 10px; object-fit: cover; image-rendering: pixelated; flex: none; }
.dpanel .locked-thumb { width: 76px; height: 76px; }
.dpanel-info { flex: 1; min-width: 0; }
.dpanel-title { font-weight: 800; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.dpanel-loot { margin-left: auto; font-size: 12px; color: var(--gold); font-weight: 700; }
.dpanel-explorers { display: flex; gap: 1px; margin-top: 6px; min-height: 30px; align-items: center; overflow-x: auto; }
.spr-explorer { width: 30px; height: 30px; image-rendering: pixelated; flex: none; }
.dpanel-prog { height: 6px; background: #1a151f; }
.dpanel-prog i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #d9b3ff); transition: width .3s; }
