:root {
  --bg: #14182b;
  --panel: #1f2540;
  --text: #f2f4ff;
  --muted: #9aa3c7;
  --accent: #ffb547;
  --good: #4ade80;
  --bad: #f87171;
  --keep: #93c5fd;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.app {
  max-width: 440px; margin: 0 auto; min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
}
.top { display: flex; justify-content: space-between; align-items: center; }
.top h1 { font-size: 20px; margin: 0; letter-spacing: 1px; }
.money { font-size: 18px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }

.stage {
  background: radial-gradient(circle at 50% 30%, #2c3560, var(--panel));
  border-radius: 20px; padding: 16px 12px 14px; text-align: center;
}
.level { font-size: 28px; font-weight: 800; color: var(--accent); }
.stage-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px; }
.tree { font-size: 13px; color: var(--muted); }
/* 도트 그림은 80칸이라 정수배(240px = 3배)로만 키워야 도트 크기가 고르다 */
.art { width: 240px; height: 240px; margin: 4px auto 6px; border-radius: 12px; overflow: hidden; }
.art svg { width: 240px; height: 240px; display: block; }
.name { font-size: 22px; font-weight: 700; }
.result { min-height: 28px; margin-top: 10px; font-size: 18px; font-weight: 700; }
.result.success { color: var(--good); }
.result.keep, .result.protected { color: var(--keep); }
.result.destroy, .result.broke { color: var(--bad); }

.stage.working .art { animation: shake .12s linear infinite; }
.stage.pop .art { animation: pop .45s ease-out; }
.stage.boom .art { animation: boom .5s ease-out; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.2); } 100% { transform: scale(1); } }
@keyframes boom { 0% { transform: scale(1.3) rotate(-8deg); opacity: .3; } 100% { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .stage .art { animation: none !important; } }

.odds, .stats { display: grid; gap: 8px; }
.odds { grid-template-columns: repeat(3, 1fr); }
.stats { grid-template-columns: repeat(4, 1fr); }
.odds div, .stats div {
  background: var(--panel); border-radius: 12px; padding: 10px 6px; text-align: center;
  display: flex; flex-direction: column; gap: 2px;
}
.odds span, .stats span { font-size: 12px; color: var(--muted); }
.odds b, .stats b { font-size: 16px; font-variant-numeric: tabular-nums; }

.protect { display: flex; align-items: center; gap: 10px; padding: 4px 2px; font-size: 15px; }
.protect input { width: 22px; height: 22px; accent-color: var(--accent); }
.protect small { color: var(--muted); }

.actions { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }
.btn {
  border: 0; border-radius: 14px; padding: 16px 10px; font-size: 18px; font-weight: 800;
  background: var(--panel); color: var(--text); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-family: inherit;
}
.btn small { font-size: 12px; font-weight: 600; opacity: .8; font-variant-numeric: tabular-nums; }
.btn.primary { background: var(--accent); color: #2a1a00; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.subsidy { background: #2f6b4a; }
.btn[hidden] { display: none; }

.foot { margin-top: auto; display: flex; justify-content: center; gap: 12px; }
.link { background: none; border: 0; color: var(--muted); font-size: 13px; text-decoration: underline; cursor: pointer; padding: 8px; }

.dex { width: min(96vw, 720px); max-height: 88dvh; border: 0; border-radius: 18px; padding: 16px; background: var(--bg); color: var(--text); }
.dex::backdrop { background: rgba(0, 0, 0, .6); }
.dex-head { display: flex; justify-content: space-between; align-items: center; }
.dex-head h2 { margin: 0; font-size: 18px; }
.dex-head small { color: var(--muted); font-weight: 400; }
.dex-help { color: var(--muted); font-size: 12px; margin: 6px 0 12px; }
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, 88px); justify-content: center; gap: 6px; }
.dex-cell { background: var(--panel); border-radius: 10px; padding: 4px; text-align: center; }
.dex-cell svg { width: 80px; height: 80px; display: block; border-radius: 6px; }
.dex-cell span { display: block; font-size: 10px; color: var(--muted); line-height: 1.3; }
.dex-cell.locked .q { width: 80px; height: 80px; display: grid; place-items: center; font-size: 28px; color: #3a4166; }

.btn.keep { background: #2c4a73; }
.estates { background: var(--panel); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.estates-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.estates-head h2 { margin: 0; font-size: 16px; }
.estates-head small { color: var(--muted); font-weight: 400; }
.rent-rate { color: var(--good); font-size: 13px; font-variant-numeric: tabular-nums; }
.estate-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.estate { background: var(--bg); border-radius: 12px; padding: 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; text-align: center; }
.estate svg { width: 80px; height: 80px; display: block; border-radius: 6px; }
.estate .e-name { font-size: 11px; line-height: 1.3; min-height: 2.6em; overflow-wrap: anywhere; }
.estate .e-rent { font-size: 11px; color: var(--good); font-variant-numeric: tabular-nums; }
.estate .e-sell { border: 0; border-radius: 8px; padding: 4px 8px; font: 600 11px inherit; background: var(--panel); color: var(--text); cursor: pointer; }
.estate.empty { color: #5a6290; font-size: 12px; min-height: 150px; border: 1px dashed #34395a; }
.estate.empty .e-empty { margin: auto 0; }
.estate.buy { border: 1px dashed var(--accent); color: var(--accent); background: transparent; font: 700 13px inherit; justify-content: center; min-height: 150px; cursor: pointer; }
.estate.buy small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; }
.btn.rent { background: #2f6b4a; padding: 12px 10px; font-size: 16px; }
.estate-help { margin: 0; color: var(--muted); font-size: 11px; }

.e-land { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 999px; background: #3a4166; color: #dfe4ff; white-space: nowrap; }
.e-land.land-town { background: #3f6b4a; }
.e-land.land-station { background: #2c5a8a; }
.e-land.land-beach { background: #1f7f8c; }
.e-land.land-downtown { background: #7a4aa8; }
.e-land.land-prime { background: #b8860b; color: #2a1a00; }
.land-list { display: flex; flex-direction: column; gap: 8px; }
.land-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; background: var(--panel); border-radius: 12px; padding: 10px 12px; }
.land-row .e-land { justify-self: start; font-size: 13px; padding: 4px 10px; }
.land-info { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.land-info b { color: var(--text); font-size: 14px; }
.btn.land-buy { padding: 10px 14px; font-size: 14px; background: var(--accent); color: #2a1a00; }

.debt-line { margin: 0; font-size: 12px; color: #ffb4a8; }
.e-debt { width: 100%; font-size: 10px; color: var(--muted); background: linear-gradient(90deg, var(--keep) calc(var(--r) * 100%), #2a2f4a 0); border-radius: 4px; padding: 2px 3px; color: #10142a; font-weight: 700; font-variant-numeric: tabular-nums; }
.e-debt.warn { background: linear-gradient(90deg, var(--accent) calc(var(--r) * 100%), #2a2f4a 0); }
.e-debt.danger { background: linear-gradient(90deg, var(--bad) calc(var(--r) * 100%), #2a2f4a 0); }
.e-debt span { mix-blend-mode: normal; color: #f2f4ff; text-shadow: 0 0 2px #000; }
.e-btns { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.e-btns button { border: 0; border-radius: 8px; padding: 5px 4px; font: 600 11px inherit; background: var(--panel); color: var(--text); cursor: pointer; font-variant-numeric: tabular-nums; }
.e-btns button:disabled { opacity: .4; cursor: not-allowed; }
.e-btns .e-loan { background: #3a2f5a; }
.e-btns .e-repay { background: #2f6b4a; }
