:root {
  --ink: #3a2e2a; --paper: #f7f0e3; --white: #fffdf8; --pink: #e3a4aa; --pink-deep: #c9727c;
  --sage: #b9c79f; --gold: #f2c14e; --earth: #bfa694; --line: 2.5px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #8f7b70; color: var(--ink);
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  overscroll-behavior: none; user-select: none; -webkit-user-select: none; touch-action: none;
}
#stage {
  position: relative; height: 100dvh; max-width: 480px; margin: 0 auto; overflow: hidden;
  background: var(--paper);
}
canvas#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

#hud { position: absolute; inset: 0; pointer-events: none; }
#hud button, #hud .pill { pointer-events: auto; }
.top {
  position: absolute; left: 0; right: 0; top: 0; display: flex; gap: 8px; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 12px 0;
}
.spacer { flex: 1; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px 0 8px;
  background: var(--white); border: var(--line) solid var(--ink); border-radius: 999px;
  font-weight: 800; font-size: 19px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
.pill img { width: 26px; height: 26px; }
.pill .arrow { padding-left: 6px; font-weight: 900; }
.pill.small { height: 32px; font-size: 15px; padding-right: 12px; }
.pill.small img { width: 20px; height: 20px; }
.pill.bump { animation: bump 0.22s ease-out; }
@keyframes bump { 40% { transform: scale(1.13); } }

button { font: inherit; color: inherit; cursor: pointer; }
.round {
  position: relative; width: 44px; height: 44px; border-radius: 50%; padding: 0;
  background: var(--white); border: var(--line) solid var(--ink);
  display: inline-grid; place-items: center;
}
.round svg { width: 24px; height: 24px; fill: none; stroke: var(--ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.round:active, .big:active, .mini:active { transform: translateY(2px) scale(0.97); }
.round.side { position: absolute; bottom: calc(108px + env(safe-area-inset-bottom)); width: 54px; height: 54px; }
.round.side.left { left: 12px; }
.round.side.right { right: 12px; }
.round .label {
  position: absolute; top: 100%; left: 50%; transform: translate(-50%, 2px); white-space: nowrap;
  font-size: 11px; font-weight: 800; background: var(--white); border: 2px solid var(--ink);
  border-radius: 999px; padding: 0 6px; line-height: 16px;
}
.round .dot {
  position: absolute; top: -3px; right: -3px; width: 14px; height: 14px; border-radius: 50%;
  background: #e2574c; border: 2px solid var(--ink);
}
.round:disabled { opacity: 0.5; }
#btn-fast.on { background: var(--gold); }

.bottom {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 10px;
  padding: 10px 12px calc(14px + env(safe-area-inset-bottom));
}
.big {
  height: 64px; border-radius: 22px; border: var(--line) solid var(--ink);
  box-shadow: 0 4px 0 var(--ink); font-weight: 900; font-size: 22px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.big.buy { flex: 1 1 0; background: var(--white); padding: 0 10px; }
.big.buy img#buy-img { height: 46px; width: auto; max-width: 44px; object-fit: contain; }
.buy-text { display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.buy-text .c { width: 22px; height: 22px; }
.big.buy.poor { background: #e9e2d6; color: #8b7f78; }
.big.buy.poor img { opacity: 0.55; }
.big.buy.trash { background: #f3c9c4; }
.big.go { flex: 1.25 1 0; background: var(--pink); font-size: 28px; letter-spacing: 0.02em; }
.big.go svg { width: 26px; height: 26px; fill: none; stroke: var(--ink); stroke-width: 2.2; stroke-linejoin: round; }
.big.plain { background: var(--white); }
.big:disabled { opacity: 0.55; box-shadow: 0 2px 0 var(--ink); }

.run {
  position: absolute; left: 0; right: 0; top: calc(58px + env(safe-area-inset-top)); text-align: center;
}
#run-total {
  font-size: 44px; font-weight: 900; color: #ffcf3f; letter-spacing: -0.02em; line-height: 1;
  -webkit-text-stroke: 7px var(--ink); paint-order: stroke fill; font-variant-numeric: tabular-nums;
}
#run-total.pop { animation: pop 0.16s ease-out; }
@keyframes pop { 30% { transform: scale(1.12); } }
#combo {
  display: inline-block; margin-top: 6px; padding: 1px 12px; border-radius: 999px;
  background: var(--white); border: 2px solid var(--ink); font-weight: 900; font-size: 17px;
}
#combo.hot { background: #ffd65c; }
#combo.max { background: #ff8f6b; animation: pop 0.3s ease-out infinite; }

.banner {
  position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%); white-space: nowrap;
  background: var(--white); border: var(--line) solid var(--ink); border-radius: 18px;
  padding: 8px 18px; font-weight: 900; font-size: 22px; animation: drop-in 0.35s cubic-bezier(.2,1.6,.4,1);
}
@keyframes drop-in { from { transform: translate(-50%, -120%) scale(0.6); opacity: 0; } }
.hint {
  position: absolute; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 150px); text-align: center; font-size: 13px; font-weight: 800; line-height: 1.35;
  color: var(--paper); background: rgba(58, 46, 42, 0.86); border-radius: 14px; padding: 6px 12px;
}
.hint:empty { display: none; }

.sheet {
  position: absolute; inset: 0; z-index: 10; background: rgba(58, 46, 42, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet.center { align-items: center; padding: 20px; }
.sheet-body {
  width: 100%; max-height: 82%; overflow-y: auto; background: var(--paper);
  border: var(--line) solid var(--ink); border-bottom: 0; border-radius: 24px 24px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); touch-action: pan-y;
  animation: sheet-up 0.22s ease-out;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
.sheet-body.card { border-bottom: var(--line) solid var(--ink); border-radius: 24px; max-width: 360px; text-align: center; }
.sheet-head { display: flex; align-items: center; gap: 10px; text-align: left; }
.sheet-head h2 { margin: 0; font-size: 22px; flex: 1; }
.x { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--ink); background: var(--white); font-size: 22px; line-height: 1; font-weight: 800; }
.sheet-note { margin: 6px 0 12px; font-size: 13px; color: #6f625b; }
.up {
  display: flex; align-items: center; gap: 10px; background: var(--white);
  border: 2px solid var(--ink); border-radius: 16px; padding: 10px 12px; margin-bottom: 8px; text-align: left;
}
.up-main { flex: 1; min-width: 0; }
.up-name { font-weight: 900; font-size: 16px; }
.up-name small { font-weight: 700; color: var(--pink-deep); margin-left: 6px; }
.up-desc { font-size: 13px; color: #6f625b; }
.mini {
  min-width: 92px; height: 44px; border-radius: 14px; border: 2px solid var(--ink); background: var(--sage);
  font-weight: 900; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  box-shadow: 0 3px 0 var(--ink); font-variant-numeric: tabular-nums;
}
.mini img { width: 18px; height: 18px; }
.mini:disabled { background: #e9e2d6; color: #8b7f78; box-shadow: 0 1px 0 var(--ink); }
.mini.danger { background: #f3c9c4; margin-top: 14px; }
.rebirth { border: 2px dashed var(--ink); border-radius: 16px; padding: 12px; margin-top: 14px; text-align: left; }
.rebirth h3 { margin: 0 0 4px; font-size: 17px; }
.rebirth p { margin: 0 0 8px; font-size: 13px; color: #6f625b; }
.bar { height: 12px; border: 2px solid var(--ink); border-radius: 999px; background: var(--white); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--pink); }
.rebirth-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; font-size: 13px; font-weight: 700; }

.badge { display: inline-block; background: #ffd65c; border: 2px solid var(--ink); border-radius: 999px; padding: 2px 14px; font-weight: 900; margin-bottom: 8px; }
.res-coins { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 46px; font-weight: 900; font-variant-numeric: tabular-nums; }
.res-coins img { width: 46px; height: 46px; }
.res-line { font-size: 15px; font-weight: 700; color: #6f625b; margin: 4px 0 10px; }
.res-boss, .res-gift { background: var(--white); border: 2px solid var(--ink); border-radius: 14px; padding: 8px 10px; margin-bottom: 8px; font-weight: 800; font-size: 15px; }
.res-buttons { display: flex; gap: 10px; margin-top: 12px; }
.res-buttons .big { flex: 1; height: 58px; font-size: 20px; }
.toggle { display: flex; align-items: center; gap: 10px; padding: 10px 4px; font-weight: 800; text-align: left; }
.toggle input { width: 22px; height: 22px; accent-color: var(--pink-deep); }
.link { display: block; margin-top: 6px; font-weight: 800; color: var(--pink-deep); }

.ad { position: absolute; inset: 0; z-index: 30; background: #2c2422; display: grid; place-items: center; color: var(--paper); text-align: center; }
.ad-tag { display: inline-block; border: 2px solid var(--paper); border-radius: 8px; padding: 2px 10px; font-weight: 900; }
.ad-box p { max-width: 240px; font-size: 14px; opacity: 0.8; }
.ad-count { font-size: 64px; font-weight: 900; }

.toast {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%); z-index: 20; white-space: nowrap;
  background: var(--ink); color: var(--paper); border-radius: 999px; padding: 8px 18px; font-weight: 800; font-size: 15px;
  animation: drop-in 0.3s ease-out;
}
