:root {
  --bg: #3e2a20; --panel: #fff8ee; --panel2: #f6e7d2; --line: rgba(109, 76, 65, 0.2);
  --text: #4e342e; --dim: #8d6e63; --accent: #ff8a65; --accent2: #ffb74d; --ok: #66bb6a; --bad: #e57373;
  --r: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, #5d4033 0%, #3e2a20 60%, #2a1b14 100%);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  display: flex; flex-direction: column; overflow: hidden; height: 100dvh;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }
[hidden] { display: none !important; }
.dim { color: var(--dim); }
.small { font-size: 0.82rem; }

.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); color: #fff3e0; }
.back-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; flex: none;
  background: rgba(56, 189, 248, 0.14); border: 1px solid rgba(56, 189, 248, 0.35); color: #7dd3fc;
  text-decoration: none; font-size: 0.85rem; font-weight: 700;
}
.back-btn:hover { background: rgba(56, 189, 248, 0.24); }
.hud { display: flex; gap: 6px; margin-left: auto; min-width: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; border-radius: 999px; white-space: nowrap;
  background: rgba(255, 248, 238, 0.12); border: 1px solid rgba(255, 248, 238, 0.2); font-size: 0.86rem; color: #fff3e0;
}
.chip.lv { flex-direction: column; gap: 2px; padding: 3px 10px; align-items: stretch; }
.chip.lv span { line-height: 1.1; font-size: 0.8rem; text-align: center; }
.bar { display: block; width: 52px; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.2); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent2); border-radius: 3px; transition: width 0.3s; }
.chip.food.low { background: rgba(229, 115, 115, 0.35); border-color: #e57373; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.6; } }
.tools { display: flex; gap: 6px; flex: none; }
.mini { width: 32px; height: 32px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.25); background: rgba(255,255,255,0.1); color: inherit; font-weight: 800; }

.stage { flex: 1; position: relative; min-height: 0; display: grid; place-items: center; overflow: hidden; }
#room { display: block; touch-action: manipulation; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,0.4); }
.deco-bar {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); width: min(94%, 460px);
  display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px; border-radius: 14px;
  background: rgba(255, 248, 238, 0.95); font-size: 0.82rem; font-weight: 700; box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}
.deco-bar span { flex: 1; }
.toasts { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: min(92%, 420px); }
.deco-bar:not([hidden]) ~ .toasts { top: 60px; }
.toast {
  padding: 8px 14px; border-radius: 14px; background: rgba(62, 42, 32, 0.92); color: #fff3e0; font-size: 0.86rem; font-weight: 600;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3); animation: tin 0.25s ease-out; text-align: center;
}
.toast.gold { background: linear-gradient(135deg, #ff9f43, #ff7043); color: #fff; }
@keyframes tin { from { opacity: 0; transform: translateY(-8px); } }

.dock { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 6px 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.dbtn {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px; border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.14); background: rgba(255,248,238,0.1); color: #fff3e0; font-size: 1.25rem;
}
.dbtn span { font-size: 0.72rem; font-weight: 700; }
.dbtn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.dot { position: absolute; top: 5px; right: calc(50% - 20px); width: 9px; height: 9px; border-radius: 50%; background: #ff5252; box-shadow: 0 0 0 2px #3e2a20; }

/* ── 아래 서랍 ── */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,0.35); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card {
  width: min(100%, 560px); max-height: 82dvh; display: flex; flex-direction: column; background: var(--panel); border-radius: 20px 20px 0 0;
  padding-bottom: env(safe-area-inset-bottom); animation: up 0.22s ease-out; box-shadow: 0 -8px 30px rgba(0,0,0,0.3);
}
@keyframes up { from { transform: translateY(40px); opacity: 0.4; } }
.sheet-head { flex: none; display: flex; align-items: center; padding: 12px 14px 6px 18px; font-size: 1.05rem; }
.sheet-head b { flex: 1; }
.sheet-head .mini { color: var(--text); border-color: var(--line); background: var(--panel2); }
.sheet-tabs { flex: none; display: flex; gap: 6px; padding: 0 14px 8px; overflow-x: auto; scrollbar-width: none; }
.sheet-tabs:empty { display: none; }
.stab { flex: none; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel2); font-weight: 700; font-size: 0.84rem; }
.stab.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.sheet-body { overflow-y: auto; padding: 4px 14px 18px; -webkit-overflow-scrolling: touch; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.card {
  position: relative; display: flex; flex-direction: column; gap: 4px; padding: 10px; border-radius: 14px; text-align: left;
  border: 1px solid var(--line); background: #fff; color: var(--text);
}
.card.locked { opacity: 0.55; }
.card.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.card canvas { width: 100%; height: 76px; border-radius: 10px; background: var(--panel2); }
.card b { font-size: 0.9rem; }
.card small { color: var(--dim); font-size: 0.74rem; line-height: 1.35; }
.card .price { margin-top: auto; font-weight: 800; font-size: 0.86rem; }
.card .price.no { color: var(--bad); }
.card .owned { color: var(--ok); font-weight: 800; font-size: 0.8rem; }
.tagline { display: flex; flex-wrap: wrap; gap: 3px; }
.tg { font-size: 0.68rem; padding: 1px 6px; border-radius: 999px; background: var(--panel2); color: var(--dim); }
.row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; border: 1px solid var(--line); background: #fff; margin-bottom: 8px;
}
.row .ico { font-size: 1.6rem; flex: none; width: 36px; text-align: center; }
.row .txt { flex: 1; min-width: 0; }
.row .txt b { display: block; font-size: 0.92rem; }
.row .txt small { color: var(--dim); font-size: 0.78rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 9px 14px; border-radius: 12px; border: 0;
  background: var(--accent); color: #fff; font-weight: 800; text-decoration: none; white-space: nowrap;
}
.btn.small { padding: 6px 11px; font-size: 0.82rem; }
.btn.ghost { background: var(--panel2); color: var(--text); }
.btn.ok { background: var(--ok); }
.note { padding: 10px 12px; border-radius: 12px; background: var(--panel2); font-size: 0.84rem; margin-bottom: 10px; line-height: 1.5; }
.hearts { letter-spacing: -1px; font-size: 0.78rem; }
.prog { height: 7px; border-radius: 4px; background: var(--panel2); overflow: hidden; margin-top: 4px; }
.prog > i { display: block; height: 100%; background: var(--ok); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; margin-bottom: 12px; }
.stat { padding: 8px 10px; border-radius: 12px; background: var(--panel2); }
.stat b { display: block; font-size: 1.1rem; }
.stat small { color: var(--dim); font-size: 0.74rem; }
.ach { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; }
.ach div { padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 0.8rem; }
.ach div.no { opacity: 0.45; filter: grayscale(1); }
.ach b { display: block; font-size: 0.86rem; }
h3.sec { margin: 12px 0 8px; font-size: 0.95rem; }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,0.5); display: grid; place-items: center; padding: 16px; }
.mcard {
  width: min(100%, 400px); max-height: 86dvh; overflow-y: auto; background: var(--panel); border-radius: 20px; padding: 18px; text-align: center;
  animation: pop 0.25s ease-out; box-shadow: 0 16px 40px rgba(0,0,0,0.4);
}
@keyframes pop { from { transform: scale(0.9); opacity: 0; } }
.mcard h2 { margin: 6px 0 8px; font-size: 1.2rem; }
.mcard p { margin: 6px 0; font-size: 0.9rem; line-height: 1.5; }
.mcard .big { font-size: 2.6rem; }
.mcard canvas { width: 120px; height: 110px; }
.mcard ul { text-align: left; padding-left: 20px; margin: 8px 0; font-size: 0.86rem; line-height: 1.6; }
.mcard .acts { display: flex; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.away-cats { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; margin: 8px 0; }
.away-cats span { padding: 3px 8px; border-radius: 999px; background: var(--panel2); font-size: 0.8rem; }

.err { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: #2a1b14; padding: 16px; }
.err-card { background: var(--panel); border-radius: 20px; padding: 22px; text-align: center; max-width: 380px; }
.err-ico { font-size: 3rem; }
.err-card .btn { margin: 4px; }
.noscript { color: #fff; text-align: center; }

@media (max-width: 480px) {
  .back-txt { display: none; }
  .back-btn { padding: 7px 9px; }
  .chip { padding: 4px 8px; font-size: 0.8rem; }
  .bar { width: 40px; }
  .grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 360px) {
  .tools #helpBtn { display: none; }
}
