:root {
  --bg: #1e1712; --panel: rgba(36, 27, 20, 0.94); --card: #3a2c20; --card2: #4a3828; --line: #6a5038; --text: #f6ecd8; --sub: #c8b498;
  --accent: #ffc35a; --good: #6be08a; --bad: #ff7a5a; --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif; }
button { font: inherit; color: inherit; }
#app { position: fixed; inset: 0; overflow: hidden; user-select: none; -webkit-user-select: none; }
#cv { position: absolute; left: 0; top: 0; width: 100%; height: calc(100% - 64px - var(--safe-b)); display: block; touch-action: none; }

.back-btn { position: absolute; top: 8px; left: 8px; z-index: 30; display: inline-flex; align-items: center; gap: 5px; padding: 6px 10px; background: rgba(20, 14, 10, 0.8); color: #fff; text-decoration: none; font-size: 12px; border: 1px solid rgba(255,255,255,0.4); border-radius: 8px; }
.bar { position: absolute; top: 8px; right: 8px; left: 120px; z-index: 20; display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; pointer-events: none; }
.chip { background: rgba(20, 14, 10, 0.78); border: 1px solid rgba(255,255,255,0.15); border-radius: 999px; padding: 4px 9px; font-size: 12px; white-space: nowrap; }
.chip b { color: var(--accent); }
.chip .xp { display: inline-block; width: 38px; height: 5px; background: #4a3a2a; border-radius: 3px; vertical-align: middle; margin-left: 4px; overflow: hidden; }
.chip .xp i { display: block; height: 100%; background: var(--good); }

.btn { background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; cursor: pointer; font-size: 14px; font-weight: 600; }
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: 0.4; cursor: default; filter: none; }
.btn.primary { background: linear-gradient(#ffcf6a, #e8a23a); color: #2a1a0a; border-color: #ffd88a; }
.btn.ghost { background: transparent; }
.btn.danger { background: #6a2a20; border-color: #a04a3a; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.on { outline: 2px solid var(--accent); outline-offset: 1px; background: #5a4428; }

/* 아래 탭 */
.tabs { position: absolute; left: 0; right: 0; bottom: 0; height: calc(64px + var(--safe-b)); padding-bottom: var(--safe-b); z-index: 25; display: grid; grid-template-columns: repeat(4, 1fr); background: #17110c; border-top: 1px solid var(--line); }
.tabs button { background: none; border: 0; cursor: pointer; font-size: 12px; color: var(--sub); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.tabs button span { font-size: 22px; }
.tabs button.on { color: var(--accent); background: #241a12; }
.tabs.lock button:not(.on) { opacity: 0.35; pointer-events: none; }

/* 패널: 오른쪽(넓은 화면) / 아래(좁은 화면) */
.panel { position: absolute; right: 10px; top: 52px; bottom: calc(74px + var(--safe-b)); width: min(380px, 42vw); z-index: 20; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow-y: auto; padding: 12px; touch-action: pan-y; }
.panel[hidden] { display: none; }
.panel h2 { font-size: 16px; margin: 0 0 8px; }
.panel h3 { font-size: 13px; color: var(--sub); margin: 14px 0 6px; font-weight: 600; }
.note { font-size: 12px; color: var(--sub); line-height: 1.6; margin: 4px 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; text-align: left; width: 100%; }
.card.sel { outline: 2px solid var(--accent); background: #4a3622; }
.card.off { opacity: 0.45; cursor: default; }
.card .t { font-weight: 700; font-size: 14px; }
.card .s { font-size: 11px; color: var(--sub); margin-top: 2px; line-height: 1.5; }
.card .ic { font-size: 22px; }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.mats { display: flex; gap: 6px; flex-wrap: wrap; }
.mat { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; cursor: pointer; font-size: 13px; }
.mat.sel { outline: 2px solid var(--accent); background: #4a3622; }
.mat.off { opacity: 0.4; cursor: default; }
.grade { display: inline-block; min-width: 22px; text-align: center; font-weight: 800; border-radius: 6px; padding: 0 5px; color: #1a120a; }
.stat { font-size: 12px; color: var(--sub); }
.stat b { color: var(--text); }
.dur { height: 5px; background: #2a2018; border-radius: 3px; overflow: hidden; margin-top: 4px; }
.dur i { display: block; height: 100%; background: var(--good); }
.big-btn { width: 100%; margin-top: 12px; padding: 12px; font-size: 16px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.item { display: grid; grid-template-columns: 36px 1fr auto; gap: 8px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.item .ic { font-size: 24px; text-align: center; }
.item .t { font-weight: 700; font-size: 14px; }
.subtabs { display: flex; gap: 4px; margin-bottom: 8px; }
.subtabs button { flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px; cursor: pointer; font-size: 13px; }
.subtabs button.on { background: #5a4428; border-color: var(--accent); }

/* 깎기 HUD */
.carve-hud { position: absolute; left: 0; right: 0; top: 46px; bottom: calc(64px + var(--safe-b)); z-index: 22; pointer-events: none; display: flex; flex-direction: column; gap: 6px; padding: 8px; }
.carve-hud[hidden] { display: none; }
.carve-hud > * { pointer-events: auto; }
.carve-top { align-self: center; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; text-align: center; font-size: 13px; min-width: 240px; }
.carve-top .pct { font-size: 22px; font-weight: 800; }
.carve-top .bad { color: var(--bad); }
.carve-tools { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; margin-top: auto; }
.seg { display: flex; flex-wrap: wrap; max-width: 100%; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg button { background: none; border: 0; border-radius: 8px; padding: 7px 10px; cursor: pointer; font-size: 13px; color: var(--sub); }
.seg button.on { background: #5a4428; color: var(--text); }
.seg .sep { width: 1px; align-self: stretch; margin: 4px 2px; background: var(--line); }
.carve-actions { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }

/* 원정 HUD */
.battle-hud { position: absolute; left: 50%; transform: translateX(-50%); top: 46px; z-index: 22; width: min(460px, calc(100% - 16px)); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 13px; }
.battle-hud[hidden] { display: none; }
.bh-row { display: grid; grid-template-columns: 110px 1fr 70px; gap: 8px; align-items: center; margin: 3px 0; }
.bh-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 10px; background: #2a2018; border-radius: 5px; overflow: hidden; }
.bar-track i { display: block; height: 100%; background: var(--good); transition: width 0.2s; }
.bar-track.foe i { background: var(--bad); }
.bh-btns { display: flex; gap: 4px; justify-content: center; margin-top: 6px; }
.floats { position: absolute; inset: 0; pointer-events: none; z-index: 21; overflow: hidden; }
.float { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 20px; text-shadow: 0 2px 0 #000, 0 0 6px #000; animation: rise 0.9s ease-out forwards; white-space: nowrap; }
.float.dmg { color: #fff; } .float.crit { color: #ffd23f; font-size: 26px; } .float.hurt { color: #ff7a6a; } .float.warn { color: #ffb45a; font-size: 16px; }
@keyframes rise { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -46px; } }

.modal { position: absolute; inset: 0; z-index: 50; background: rgba(10, 6, 4, 0.6); display: flex; align-items: center; justify-content: center; padding: 14px; }
.modal[hidden] { display: none; }
.modal .box { background: #2a2018; border: 1px solid var(--line); border-radius: 14px; padding: 16px; width: min(420px, 100%); max-height: 100%; overflow-y: auto; }
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.toast { position: absolute; left: 50%; top: 56px; transform: translate(-50%, -8px); z-index: 60; background: #120c08; border: 1px solid var(--accent); padding: 8px 14px; border-radius: 10px; font-size: 13px; opacity: 0; transition: 0.25s; pointer-events: none; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.loading { position: absolute; inset: 0; z-index: 70; background: var(--bg); display: grid; place-items: center; text-align: center; }
.loading h1 { font-size: 30px; color: var(--accent); margin: 0 0 14px; }
.load-track { width: 220px; height: 8px; background: #3a2a1a; border-radius: 4px; overflow: hidden; margin: 0 auto; }
.load-track i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.loading[hidden] { display: none; }
.error { position: absolute; inset: 0; z-index: 100; background: rgba(14, 10, 6, 0.94); display: grid; place-items: center; text-align: center; padding: 20px; }
.error[hidden] { display: none; }

@media (max-width: 720px) {
  .panel { left: 8px; right: 8px; width: auto; top: auto; max-height: 46%; bottom: calc(70px + var(--safe-b)); }
  .panel.min { max-height: 30%; }
  .bar { left: 108px; }
  .chip { font-size: 11px; padding: 3px 7px; }
  .bh-row { grid-template-columns: 82px 1fr 54px; }
  .carve-top { min-width: 0; font-size: 12px; padding: 6px 10px; }
  .carve-top .pct { font-size: 18px; }
  .carve-tools { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .seg button { padding: 6px 7px; font-size: 12px; }
  .carve-actions .btn { padding: 8px 10px; font-size: 13px; }
}
.seg[hidden] { display: none; }

/* 단면 보기 · 주문 · 꾸미기 */
#sliceBar { align-items: center; }
#sliceBar input[type=range] { width: 140px; accent-color: var(--accent); margin: 0 6px; }
.item.order { grid-template-columns: 36px 1fr auto; }
.item .col { display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
.subtabs .dot { color: var(--good); font-size: 10px; vertical-align: top; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; border: 1px solid rgba(0,0,0,0.35); }
