:root {
  --bg: #2a1d16; --panel: #3a281d; --panel2: #4a3424; --card: #f3e6cc; --card2: #e8d6b4;
  --ink: #3a2414; --ink2: #7a5a3a; --gold: #ffcf3a; --accent: #e8743a; --good: #5ab05a; --fame: #b48af0;
  --line: #2a1a10; --font: 'Jua', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--card); font-family: var(--font); overflow: hidden; overscroll-behavior: none; }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; max-width: 100vw; }
#view { position: relative; height: 46%; min-height: 240px; overflow: hidden; background: #8fd3f4; touch-action: none; user-select: none; -webkit-user-select: none; }
#world { position: absolute; left: 0; top: 0; image-rendering: pixelated; image-rendering: crisp-edges; }
#fx { position: absolute; left: 0; top: 0; pointer-events: none; }
#panel { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-top: 4px solid var(--line); }

/* 가로 화면: 게임 뷰 + 패널 좌우 배치 */
@media (min-aspect-ratio: 1/1) {
  #app { flex-direction: row; }
  #view { height: 100%; flex: 1; }
  #panel { flex: 0 0 min(440px, 42vw); border-top: 0; border-left: 4px solid var(--line); }
}

/* HUD */
#hud { position: absolute; inset: 0; pointer-events: none; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); }
.hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.gold-box { display: flex; align-items: center; gap: 6px; background: rgba(42, 26, 16, .72); border-radius: 12px; padding: 4px 10px 4px 6px; }
.gold-box > div { display: flex; flex-direction: column; line-height: 1.05; }
#gold { font-size: 24px; color: var(--gold); text-shadow: 0 2px 0 #6a3a10; }
#dps { font-size: 11px; color: #f0dcc0; opacity: .9; }
.coin { width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff2a0, #ffcf3a 45%, #c8901a); box-shadow: 0 2px 0 #7a4a10; }
.stage-box { text-align: right; background: rgba(42, 26, 16, .72); border-radius: 12px; padding: 4px 10px; }
#region { font-size: 12px; color: #f8e0b0; }
#stage { font-size: 16px; }
#enemyBar { margin: 8px auto 0; width: min(78%, 360px); text-align: center; }
#enemyName { font-size: 14px; text-shadow: 0 1px 0 #000, 0 0 4px #000; }
#enemyBar.boss #enemyName { color: #ffb070; font-size: 16px; }
.bar { position: relative; height: 14px; background: rgba(30, 16, 10, .8); border: 2px solid var(--line); border-radius: 8px; overflow: hidden; margin-top: 3px; }
#hpFill { height: 100%; background: linear-gradient(#ff7a5a, #d0402a); transition: width .1s; }
.bar span { position: absolute; inset: 0; font-size: 10px; line-height: 10px; color: #fff; text-shadow: 0 1px 0 #000; }
.bar.timer { height: 10px; }
#bossFill { height: 100%; background: linear-gradient(#ffd23c, #e89a1a); }
.hud-btns { position: absolute; left: 50%; transform: translateX(-50%); top: 52%; display: flex; gap: 8px; pointer-events: auto; }
#retryBtn, #regionBtn { font-size: 15px; padding: 7px 14px; border-radius: 12px; border: 3px solid var(--line); background: #e8743a; color: #fff; box-shadow: 0 3px 0 var(--line); animation: pulse 1.2s infinite; }
#regionBtn { background: #4a9a6a; }
@keyframes pulse { 50% { transform: scale(1.06); } }

#devBtn { position: absolute; right: 8px; top: 64px; z-index: 5; font-size: 11px; padding: 4px 8px; border-radius: 8px; border: 2px dashed #ff5ad0; background: rgba(60, 10, 50, .75); color: #ffb0f0; }
#devBtn:active { transform: scale(.95); }

/* 스킬 바 */
#skillbar { position: absolute; left: 0; right: 0; bottom: 6px; display: flex; justify-content: center; gap: 6px; padding: 0 8px; padding-bottom: env(safe-area-inset-bottom); }
.skill { position: relative; width: 46px; height: 46px; border-radius: 12px; border: 3px solid var(--line); background: #f3e6cc; box-shadow: 0 3px 0 var(--line); overflow: hidden; padding: 0; --cd: 0; }
.skill .ic { font-size: 22px; line-height: 40px; }
.skill::after { content: ''; position: absolute; inset: 0; background: conic-gradient(rgba(30, 16, 10, .72) calc(var(--cd) * 360deg), transparent 0); pointer-events: none; }
.skill .cd { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 13px; text-shadow: 0 1px 0 #000; z-index: 2; }
.skill .key { position: absolute; left: 3px; top: 1px; font-size: 9px; color: var(--ink2); z-index: 2; }
.skill .lock { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; font-size: 11px; color: #ccc; background: rgba(40, 28, 20, .85); z-index: 3; }
.skill.locked .lock { display: flex; }
.skill.ready { animation: glow 1.6s infinite; }
.skill.active { background: #ffe9a0; border-color: #c8701a; }
@keyframes glow { 50% { box-shadow: 0 3px 0 var(--line), 0 0 10px 2px #ffe070; } }

/* 탭 */
#tabs { display: flex; background: var(--panel2); border-bottom: 3px solid var(--line); }
#tabs button { position: relative; flex: 1; padding: 6px 2px 5px; background: none; border: 0; color: #d8c0a0; font-size: 13px; display: flex; flex-direction: column; align-items: center; gap: 1px; }
#tabs button span { font-size: 18px; }
#tabs button.on { background: var(--panel); color: #fff; box-shadow: inset 0 -3px 0 var(--accent); }
.badge { position: absolute; top: 4px; right: 22%; width: 9px; height: 9px; border-radius: 50%; background: #ff4a3a; border: 2px solid var(--panel2); }
#buyRow { display: flex; gap: 6px; align-items: center; padding: 6px 10px; font-size: 12px; color: #c8b090; }
#buyRow span { margin-right: auto; }
#buyRow button { padding: 3px 10px; border-radius: 8px; border: 2px solid var(--line); background: var(--panel2); color: #e8d4b8; font-size: 13px; }
#buyRow button.on { background: var(--accent); color: #fff; }
#panelBody { flex: 1; overflow-y: auto; padding: 4px 10px 16px; -webkit-overflow-scrolling: touch; }
#panelBody::-webkit-scrollbar { width: 6px; } #panelBody::-webkit-scrollbar-thumb { background: #6a4a34; border-radius: 3px; }

.row-card, .hero-card { display: flex; align-items: center; gap: 10px; background: var(--card); color: var(--ink); border: 3px solid var(--line); border-radius: 12px; padding: 8px; margin: 8px 0; box-shadow: 0 3px 0 rgba(0, 0, 0, .3); }
.row-card .ic, .hero-card .portrait { flex: 0 0 40px; height: 40px; border-radius: 10px; background: var(--card2); display: flex; align-items: center; justify-content: center; font-size: 22px; }
.hero-card .portrait { flex-basis: 52px; height: 52px; font-size: 30px; }
.info { flex: 1; min-width: 0; }
.info b { font-size: 15px; font-weight: normal; }
.info p { margin: 1px 0 0; font-size: 12px; color: var(--ink2); line-height: 1.3; }
.info .lv { font-size: 12px; color: var(--accent); }
.info .ms { color: #8a6a9a; }
.info .role { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-card.locked { opacity: .55; filter: grayscale(.6); }
.row-card.comp:not(.hired) { background: #f8eedc; border-style: dashed; }
.avatar { background: linear-gradient(var(--h) 0 30%, #f0c8a0 30% 62%, var(--b) 62%) !important; image-rendering: pixelated; }
.wagon-ic { background: linear-gradient(transparent 20%, var(--c) 20% 72%, #3a2a1a 72%) !important; }
.tag { display: inline-block; font-size: 10px; padding: 0 5px; border-radius: 6px; background: var(--c); color: #fff; vertical-align: 2px; }
.buy { flex: 0 0 auto; min-width: 92px; border: 3px solid var(--line); border-radius: 10px; padding: 5px 8px; background: var(--good); color: #fff; font-size: 14px; box-shadow: 0 3px 0 var(--line); display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.buy small { font-size: 11px; color: #fff6d0; display: flex; align-items: center; gap: 3px; }
i.c { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff2a0, #ffcf3a 50%, #c8901a); box-shadow: 0 1px 0 #7a4a10; }
.buy.big { min-width: 110px; padding: 8px; }
.buy.fame { background: #8a6ac8; }
.buy.dis { background: #9a8a7a; box-shadow: 0 2px 0 var(--line); opacity: .75; }
.buy:active:not(.dis) { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.prestige .buy { background: var(--accent); }
.sec { margin: 14px 2px 4px; font-weight: normal; color: #f3dcb8; font-size: 15px; }
.sec small { color: #b89a7a; font-size: 11px; margin-left: 4px; }
.statgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.statgrid div { background: rgba(0, 0, 0, .2); border-radius: 8px; padding: 4px 6px; display: flex; flex-direction: column; }
.statgrid span { font-size: 10px; color: #c8b090; } .statgrid b { font-weight: normal; font-size: 13px; }
.syn { font-size: 12px; padding: 6px 8px; border-radius: 8px; background: rgba(0, 0, 0, .2); margin: 4px 0; color: #b8a08a; }
.syn.on { background: rgba(90, 176, 90, .25); color: #e8f8d8; }
.syn b { font-weight: normal; }
.fame-box { margin: 8px 0; padding: 10px; border-radius: 12px; background: linear-gradient(135deg, #5a3a8a, #3a2a5a); border: 3px solid var(--line); font-size: 16px; display: flex; align-items: baseline; gap: 6px; }
.fame-box b { font-size: 24px; color: #e8d0ff; font-weight: normal; }
.fame-box small { margin-left: auto; color: #c8b0e8; font-size: 11px; }

/* 기념품 */
.offer { background: rgba(0, 0, 0, .2); border-radius: 12px; padding: 8px; margin: 8px 0; }
.offer h4 { margin: 0 0 6px; font-weight: normal; }
.offer h4 small { color: #b89a7a; font-size: 11px; }
.cards { display: flex; gap: 6px; }
.scard { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border-radius: 10px; border: 3px solid var(--r); background: var(--card); color: var(--ink); box-shadow: 0 3px 0 var(--line); }
.scard .ic { font-size: 28px; } .scard b { font-weight: normal; font-size: 13px; }
.scard .rar { font-size: 10px; color: var(--r); filter: brightness(.75); }
.scard .eff { font-size: 11px; color: var(--ink2); text-align: center; }
.scard.cursed { background: #e8d0d0; }
.scard:active { transform: translateY(2px); }
.sets { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.set { font-size: 12px; padding: 5px 8px; border-radius: 8px; background: rgba(0, 0, 0, .2); border-left: 4px solid var(--c); }
.set b { font-weight: normal; } .set small { display: block; color: #b89a7a; font-size: 10px; }
.set.on { background: rgba(255, 220, 120, .15); }
.owned { display: flex; flex-wrap: wrap; gap: 4px; }
.own { font-size: 12px; padding: 3px 7px; border-radius: 8px; background: var(--card); color: var(--ink); border: 2px solid var(--r); }
.empty { padding: 16px; text-align: center; color: #c8b090; font-size: 13px; background: rgba(0, 0, 0, .15); border-radius: 12px; margin: 8px 0; line-height: 1.5; }
.opt { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 8px 2px; }
.opt select { font-family: inherit; font-size: 13px; padding: 2px 6px; border-radius: 6px; }
.opt input { width: 18px; height: 18px; }

/* 일지 */
.subtabs { display: flex; gap: 4px; margin: 8px 0; }
.subtabs button { flex: 1; padding: 6px; border-radius: 8px; border: 2px solid var(--line); background: var(--panel2); color: #d8c0a0; font-size: 13px; }
.subtabs button.on { background: var(--accent); color: #fff; }
.jentry { background: var(--card); color: var(--ink); border-radius: 10px; padding: 8px 10px; margin: 6px 0; border: 2px solid var(--line); }
.jentry h5 { margin: 0 0 4px; font-weight: normal; font-size: 14px; }
.jentry h5 small { color: var(--ink2); font-size: 10px; }
.jentry p { margin: 2px 0; font-size: 13px; line-height: 1.4; }
.jentry.locked { opacity: .5; }
.sub { color: #b89a7a; font-size: 12px; }
.settings .row, .row { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }

.btn { padding: 8px 14px; border-radius: 10px; border: 3px solid var(--line); background: var(--card); color: var(--ink); font-size: 14px; box-shadow: 0 3px 0 var(--line); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; color: #e8d4b8; border-color: #6a4a34; box-shadow: none; }
.btn.danger { background: #c83a3a; color: #fff; }
.btn.small { font-size: 12px; padding: 4px 10px; margin-top: 6px; }
.btn:disabled { opacity: .5; }

/* 토스트 / 모달 */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); top: 110px; z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; width: min(92vw, 440px); }
@media (min-aspect-ratio: 1/1) { #toasts { left: calc((100vw - min(440px, 42vw)) / 2); } }
.toast { background: rgba(42, 26, 16, .92); border: 2px solid #e8a83a; border-radius: 12px; padding: 7px 14px; font-size: 14px; text-align: center; animation: tin .25s; transition: opacity .4s, transform .4s; }
.toast small { display: block; color: #c8b090; font-size: 11px; }
.toast b { color: var(--gold); font-weight: normal; }
.toast.out { opacity: 0; transform: translateY(-10px); }
@keyframes tin { from { opacity: 0; transform: translateY(10px); } }
#modal { position: fixed; inset: 0; z-index: 40; background: rgba(20, 10, 5, .7); display: flex; align-items: center; justify-content: center; padding: 16px; }
#modalBox { width: min(480px, 100%); max-height: 90vh; overflow-y: auto; background: var(--panel); border: 4px solid var(--line); border-radius: 18px; padding: 18px; text-align: center; box-shadow: 0 8px 0 rgba(0, 0, 0, .4); animation: tin .25s; }
#modalBox h2 { margin: 4px 0 6px; font-weight: normal; color: #ffe0b0; }
#modalBox h2 small { font-size: 13px; color: #c8b090; }
#modalBox .row { justify-content: center; }
#modalBox textarea { width: 100%; font-size: 11px; border-radius: 8px; padding: 6px; font-family: monospace; }
.camp { font-size: 48px; animation: flick 1.2s infinite; }
@keyframes flick { 50% { transform: scale(1.08) rotate(-3deg); } }
.journal { background: var(--card); color: var(--ink); border-radius: 12px; padding: 10px 14px; text-align: left; margin: 10px 0; border: 3px solid var(--line); }
.journal p { margin: 4px 0; font-size: 14px; line-height: 1.45; }
.reward { font-size: 16px; } .reward b { color: var(--gold); font-weight: normal; font-size: 20px; }
.rcards { display: flex; gap: 10px; margin: 12px 0; }
.rcard { flex: 1; border-radius: 14px; border: 3px solid var(--line); padding: 10px; background: linear-gradient(var(--a), var(--b)); color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); display: flex; flex-direction: column; gap: 4px; }
.rcard h3 { margin: 0; font-weight: normal; font-size: 20px; }
.rcard p { margin: 0; font-size: 12px; } .rcard .bonus { font-size: 14px; color: #fff6c0; }
.rcard .btn { margin-top: auto; text-shadow: none; }
.two { display: flex; gap: 8px; text-align: left; }
.two > div { flex: 1; background: rgba(0, 0, 0, .2); border-radius: 10px; padding: 6px 10px; }
.two h4 { margin: 0; font-weight: normal; } .two p { margin: 2px 0; font-size: 12px; color: #c8b090; }

/* 시작 화면 */
#start { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 40%, #6a4a2a, #2a1a10 70%); transition: opacity .5s; cursor: pointer; }
#start.gone { opacity: 0; pointer-events: none; }
.start-inner { text-align: center; padding: 20px; }
.start-wagon { font-size: 54px; animation: walk 1s infinite; }
@keyframes walk { 50% { transform: translateY(-4px); } }
#start h1 { font-weight: normal; font-size: 44px; margin: 6px 0; color: #ffd890; text-shadow: 0 4px 0 #6a3a10; }
#start p { color: #e8d0b0; margin: 0 0 24px; }
.tapstart { display: inline-block; font-size: 22px; padding: 10px 28px; border-radius: 14px; background: var(--accent); border: 4px solid var(--line); box-shadow: 0 4px 0 var(--line); animation: pulse 1.2s infinite; }
#start small { display: block; margin-top: 18px; color: #a88a6a; }
