:root {
  --bg: #0a0a0f; --panel: #13131b; --card: #1a1a24; --line: rgba(255,255,255,.08);
  --text: #ece7df; --sub: #9a948a; --accent: #f59e0b; --fire: #f97316; --green: #34d399;
  --red: #f43f5e; --blue: #38bdf8; --violet: #a78bfa;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Noto Sans Mono CJK KR", monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { background: var(--bg); color: var(--text); }
body {
  font-family: var(--mono); font-size: 13px; line-height: 1.5; min-height: 100vh;
  background-image: radial-gradient(circle at 20% 0%, rgba(249,115,22,.07), transparent 45%);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
body.warm { background-image: radial-gradient(circle at 20% 0%, rgba(249,115,22,.16), transparent 55%); }
button { font-family: inherit; color: inherit; cursor: pointer; }
.app { max-width: 1040px; margin: 0 auto; padding: 10px 12px 24px; }
.top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.top h1 { font-size: 16px; margin-right: auto; white-space: nowrap; }
.back-btn {
  display: inline-flex; align-items: center; gap: 5px; padding: 6px 11px; border-radius: 9px;
  color: var(--accent); text-decoration: none; font-weight: 700; font-size: 12px; white-space: nowrap;
  background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.28);
}
.badge { font-size: 11px; color: var(--blue); padding: 3px 9px; border-radius: 99px; border: 1px solid rgba(56,189,248,.3); white-space: nowrap; }
.icon-btn { background: var(--card); border: 1px solid var(--line); border-radius: 9px; width: 32px; height: 32px; font-size: 15px; flex: none; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; border-bottom: 1px solid var(--line); margin-bottom: 10px; scrollbar-width: none; }
.tabs button { flex: none; background: var(--card); border: 1px solid var(--line); border-radius: 9px; padding: 7px 12px; font-size: 12px; font-weight: 700; color: var(--sub); position: relative; }
.tabs button.on { color: var(--accent); border-color: var(--accent); background: rgba(245,158,11,.12); }
.tabs button.dot::after { content: ''; position: absolute; top: 4px; right: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--fire); }

.main { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 12px; align-items: start; }
.pane { display: none; flex-direction: column; gap: 10px; }
.pane.on { display: flex; }
.pane h2 { font-size: 12px; color: var(--sub); font-weight: 700; margin-top: 6px; letter-spacing: .5px; }
.pane h2 small { font-weight: 400; margin-left: 6px; opacity: .8; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.muted { color: var(--sub); }

.fire-card { display: flex; align-items: center; gap: 14px; }
.fire-card b { display: block; font-size: 14px; }
.fire-card small { color: var(--sub); }
.flame { font-size: 34px; filter: grayscale(1) brightness(.4); transition: filter .6s, transform .6s; }
.flame.l1 { filter: grayscale(.6) brightness(.7); transform: scale(.75); }
.flame.l2 { filter: none; animation: flick 1.4s infinite; }
.flame.l3 { filter: none; transform: scale(1.12); animation: flick 1s infinite; }
.flame.l4 { filter: drop-shadow(0 0 12px #f97316); transform: scale(1.25); animation: flick .7s infinite; }
@keyframes flick { 0%,100% { opacity: 1; } 50% { opacity: .82; } }

.acts { display: flex; flex-direction: column; gap: 7px; }
.act {
  position: relative; overflow: hidden; text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 14px; font-size: 13px; font-weight: 700; min-height: 44px;
}
.act:not(:disabled):hover { border-color: var(--accent); }
.act:disabled { opacity: .45; cursor: default; }
.act .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--fire); width: 0; }
.builder { color: var(--accent); font-size: 12px; padding: 0 4px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 7px; }
.item {
  text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px;
  display: flex; flex-direction: column; gap: 2px; min-height: 44px;
}
.item:not(:disabled):hover { border-color: var(--accent); }
.item:disabled { opacity: .5; cursor: default; }
.item b { font-size: 13px; }
.item b em { font-style: normal; color: var(--sub); font-weight: 400; font-size: 11px; margin-left: 4px; }
.item small { color: var(--sub); font-size: 11px; }
.item .cost { font-size: 11px; color: var(--accent); }
.item .cost .no { color: var(--red); }
.item.done { opacity: .55; }

.row-card { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-card b { font-size: 15px; display: block; }
.row-card small { color: var(--sub); }
.mines { font-size: 12px; color: var(--sub); text-align: right; }
.jobs { display: flex; flex-direction: column; gap: 6px; }
.job { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; }
.job .nm { flex: 1; min-width: 0; }
.job .nm b { display: block; font-size: 13px; }
.job .nm small { color: var(--sub); font-size: 11px; }
.job .cnt { min-width: 28px; text-align: center; font-weight: 700; font-size: 14px; }
.job button { width: 34px; height: 34px; border-radius: 8px; background: #23232f; border: 1px solid var(--line); font-weight: 700; font-size: 12px; }
.job button:disabled { opacity: .3; }
.lh-card b { display: block; font-size: 14px; margin-bottom: 4px; }
.lh-card .big-btn { margin-top: 8px; }

#miniMap { width: 100%; max-width: 330px; aspect-ratio: 1; display: block; margin: 0 auto; image-rendering: pixelated; border-radius: 8px; background: #050508; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11px; color: var(--sub); margin-top: 8px; justify-content: center; }
.pack { display: flex; flex-direction: column; gap: 6px; }
.gear { font-size: 12px; color: var(--sub); display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; }
.gear b { color: var(--text); }
.big-btn {
  width: 100%; padding: 13px; border-radius: 12px; font-size: 14px; font-weight: 800; border: 1px solid var(--fire);
  background: linear-gradient(180deg, rgba(249,115,22,.28), rgba(249,115,22,.12));
}
.big-btn:disabled { opacity: .4; cursor: default; }

.ach { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.ach div { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 7px 9px; font-size: 11px; color: var(--sub); }
.ach div b { display: block; color: var(--text); font-size: 12px; }
.ach div.no { opacity: .4; filter: grayscale(1); }
#statText { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 12px; font-size: 12px; color: var(--sub); }
#statText b { color: var(--text); }

.side { display: flex; flex-direction: column; gap: 10px; position: sticky; top: 10px; }
.stores { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 2px 10px; font-size: 12px; padding: 10px 12px; }
.stores div { display: flex; justify-content: space-between; gap: 6px; color: var(--sub); }
.stores div b { color: var(--text); }
.stores div i { font-style: normal; font-size: 10px; margin-left: 3px; }
.stores div i.up { color: var(--green); } .stores div i.dn { color: var(--red); }
.stores .empty { color: var(--sub); grid-column: 1 / -1; }
.log-card { padding: 10px 12px; }
.log-head { font-size: 11px; color: var(--sub); border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-bottom: 6px; }
.log { height: min(56vh, 520px); overflow-y: auto; display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }
.log p { color: #8f897f; border-left: 2px solid transparent; padding-left: 8px; animation: fade .4s; }
.log p.new { color: var(--text); border-color: var(--fire); }
.log p.event { color: #fdba74; border-color: var(--fire); }
.log p.gain { color: #6ee7b7; border-color: var(--green); }
.log p.danger { color: #fda4af; border-color: var(--red); }
@keyframes fade { from { opacity: 0; transform: translateY(-3px); } }

/* 황야 */
.world { position: fixed; inset: 0; z-index: 20; background: #050507; display: flex; flex-direction: column; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.w-hud { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 10px 14px; align-items: center; border-bottom: 1px solid var(--line); }
.w-stat { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.meter { width: 90px; height: 8px; border-radius: 99px; background: #222; overflow: hidden; }
.meter i { display: block; height: 100%; width: 100%; transition: width .2s; }
.meter.hp i { background: var(--red); } .meter.water i { background: var(--blue); }
.w-chips { display: flex; gap: 10px; font-size: 12px; color: var(--sub); margin-left: auto; }
.w-map { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px; }
#mapCv { max-width: 100%; max-height: 100%; aspect-ratio: 1; touch-action: none; border-radius: 10px; }
.w-panel {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 150px; width: min(560px, calc(100% - 24px));
  max-height: calc(100% - 230px); overflow-y: auto; background: rgba(19,19,27,.97); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.7);
}
.w-panel h3 { font-size: 15px; margin-bottom: 6px; }
.w-panel p { color: #d6d0c6; margin-bottom: 10px; }
.w-panel .opts { display: flex; flex-direction: column; gap: 6px; }
.w-panel .opts button, .m-acts button {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; text-align: left; font-weight: 700; min-height: 42px;
}
.w-panel .opts button:not(:disabled):hover, .m-acts button:hover { border-color: var(--accent); }
.w-panel .opts button:disabled { opacity: .4; }
.w-panel .opts small { display: block; font-weight: 400; color: var(--sub); font-size: 11px; }
.foe { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.foe .ic { font-size: 34px; }
.foe .meter { width: 100%; height: 10px; margin-top: 4px; }
.foe .meter i { background: var(--fire); }
.foe.shake { animation: shake .25s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.fmsg { font-size: 12px; color: var(--accent); min-height: 18px; margin-bottom: 8px; }
.fgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.fgrid button { position: relative; overflow: hidden; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; text-align: left; font-weight: 700; min-height: 48px; }
.fgrid button:disabled { opacity: .45; }
.fgrid button small { display: block; font-weight: 400; color: var(--sub); font-size: 11px; }
.fgrid button .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--fire); }
.loot { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.lrow { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px; }
.lrow span { flex: 1; }
.lrow button { background: #23232f; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12px; min-height: 34px; }
.lrow button:disabled { opacity: .35; }
.w-bottom { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 8px 14px 14px; }
.w-btn { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-weight: 700; justify-self: start; }
.w-note { font-size: 11px; color: var(--sub); justify-self: end; text-align: right; }
.dpad { display: grid; grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 40px); gap: 3px; }
.dpad button { background: var(--card); border: 1px solid var(--line); border-radius: 10px; font-size: 15px; }
.dpad button:active { background: rgba(245,158,11,.25); }
.dpad .up { grid-area: 1 / 2; } .dpad .lf { grid-area: 2 / 1; } .dpad .rt { grid-area: 2 / 3; } .dpad .dn { grid-area: 3 / 2; }

/* 모달·알림 */
.modal, .err { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; padding: 16px; }
.err { z-index: 60; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; width: min(480px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; }
.modal-box h3 { font-size: 16px; margin-bottom: 8px; }
.modal-box p { margin-bottom: 10px; color: #d6d0c6; }
.modal-box ul { margin: 0 0 10px 18px; color: #d6d0c6; font-size: 12px; }
.modal-box li { margin-bottom: 3px; }
.m-acts { display: flex; flex-direction: column; gap: 6px; }
.m-acts button:disabled { opacity: .4; }
.m-acts small { display: block; font-weight: 400; color: var(--sub); font-size: 11px; }
.ev-timer { height: 3px; background: var(--fire); border-radius: 99px; margin-bottom: 10px; transition: width 1s linear; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; background: #2a2116; border: 1px solid var(--accent); border-radius: 12px; padding: 9px 14px; font-size: 12px; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.5); }

@media (max-width: 760px) {
  .app { padding: 8px 10px 20px; }
  .main { grid-template-columns: 1fr; }
  .side { position: static; }
  .log { height: 34vh; }
  .top h1 { font-size: 14px; }
  .badge { display: none; }
  .grid { grid-template-columns: 1fr 1fr; }
  .w-hud { padding: 8px 10px; }
  .meter { width: 64px; }
  .w-chips { margin-left: 0; width: 100%; justify-content: space-between; }
  .w-note { display: none; }
  .w-panel { bottom: 146px; max-height: calc(100% - 210px); }
}
@media (max-width: 380px) { .grid { grid-template-columns: 1fr; } .back-btn { padding: 6px 8px; } }
