* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #16241a; --bg2: #0e1812; --panel: #1f3326; --line: rgba(255,255,255,.1);
  --ink: #f0ecdf; --muted: #a9bba6; --gold: #ffd23f; --accent: #6fae5a;
}
html, body { height: 100%; }
body {
  margin: 0; background: radial-gradient(120% 90% at 50% 0%, #24382a 0%, var(--bg) 45%, var(--bg2) 100%);
  color: var(--ink); overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
  display: flex; flex-direction: column;
}

/* 상단바 */
#topbar {
  display: flex; align-items: center; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px; flex-wrap: nowrap;
  background: rgba(13,21,15,.7); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); position: relative; z-index: 5;
}
.back { color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 600; white-space: nowrap; }
.back:hover { color: var(--ink); }
.brand { font-weight: 800; font-size: 15px; display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.brand .ic { font-size: 17px; }
.spacer { flex: 1; }
#moonBar { width: 96px; height: 7px; border-radius: 6px; background: rgba(255,255,255,.12); overflow: hidden; }
#moonFill { height: 100%; width: 0%; background: linear-gradient(90deg, #5fa3ff, #b6e0ff); transition: width .12s linear; }
.hud {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 13px;
  background: rgba(255,255,255,.07); border: 1px solid var(--line); border-radius: 9px;
  padding: 4px 8px; white-space: nowrap;
}
.hud.warn { background: rgba(220,70,70,.25); border-color: rgba(255,120,120,.5); color: #ffd2d2; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
#topbar button {
  width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--line);
  background: rgba(255,255,255,.07); color: var(--ink); font-size: 15px; cursor: pointer;
}
#topbar button:hover { background: rgba(255,255,255,.15); }

/* 상점 바 */
#shopbar {
  display: flex; align-items: center; gap: 8px; padding: 7px 12px;
  background: rgba(13,21,15,.5); border-bottom: 1px solid var(--line); z-index: 4;
  overflow-x: auto; white-space: nowrap;
}
.shoplabel { font-size: 12px; color: var(--muted); font-weight: 700; }
.pack {
  border: 1px solid rgba(255,210,63,.35); background: rgba(202,162,62,.14); color: var(--ink);
  border-radius: 10px; padding: 7px 12px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.pack b { color: var(--gold); margin-left: 3px; }
.pack:hover { background: rgba(202,162,62,.28); }
.pack:active { transform: scale(.96); }
.shophint { font-size: 11px; color: var(--muted); margin-left: auto; }

/* 보드 */
#stage { flex: 1; position: relative; min-height: 0; }
#board { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#board:active { cursor: grabbing; }

/* 오버레이 */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  padding: 18px; background: rgba(6,10,8,.72); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.overlay[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 440px; max-height: 88vh; overflow: auto;
  background: linear-gradient(180deg, #233827, #18271c); border: 1px solid var(--line);
  border-radius: 20px; padding: 24px 22px; box-shadow: 0 24px 70px rgba(0,0,0,.55);
}
.sheet h2 { font-size: 23px; font-weight: 800; letter-spacing: -.01em; margin-bottom: 6px; }
.sheet .lede { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.sheet .muted { color: var(--muted); }
.sheet .small { font-size: 12px; }
.how { list-style: none; margin: 6px 0 18px; display: flex; flex-direction: column; gap: 9px; }
.how li { font-size: 13.5px; line-height: 1.5; color: #dde7d8; padding-left: 2px; }
.how b { color: var(--accent); font-weight: 700; }
button.big {
  width: 100%; padding: 14px; border: 0; border-radius: 13px; cursor: pointer;
  background: linear-gradient(180deg, #7cc063, #5b9a48); color: #0e1812; font-size: 16px; font-weight: 800;
  box-shadow: 0 8px 22px rgba(111,174,90,.35);
}
button.big:hover { filter: brightness(1.06); }
button.big:active { transform: translateY(1px); }
.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.stat {
  background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; text-align: center;
}
.stat span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stat b { font-size: 20px; font-weight: 800; }

/* 토스트 */
#toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px);
  background: rgba(13,21,15,.92); border: 1px solid var(--line); color: var(--ink);
  padding: 10px 16px; border-radius: 12px; font-size: 13.5px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 40; max-width: 86vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 560px) {
  .only-wide { display: none; }
  .brand { font-size: 13px; }
  .hud { font-size: 12px; padding: 4px 6px; }
  #moonBar { width: 64px; }
  .shophint { display: none; }
}
