:root {
  --wood: #5a3519;
  --wood-dark: #2e1a0b;
  --wood-light: #8a5a2f;
  --parch: #f7e8c4;
  --parch-dark: #e2c88e;
  --gold: #ffd34d;
  --ink: #3a210d;
  --green: #7cc35a;
  --red: #e8483a;
  --font: "Trebuchet MS", "Avenir Next", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #3f7a35; font-family: var(--font); color: var(--ink); user-select: none; -webkit-user-select: none; touch-action: none; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.bar { position: absolute; top: max(10px, env(safe-area-inset-top)); display: flex; gap: 8px; pointer-events: auto; }
.bar.left { left: 12px; }
.bar.right { right: 12px; }
.pill {
  display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px 0 6px; border-radius: 22px;
  background: linear-gradient(#6b4220, #4a2a12); border: 2px solid var(--wood-dark);
  box-shadow: inset 0 2px 0 rgba(255,220,160,.35), inset 0 -3px 0 rgba(0,0,0,.25), 0 3px 0 rgba(0,0,0,.35);
  color: #fff6dc; font-weight: 800; font-size: 19px; text-shadow: 0 2px 0 rgba(0,0,0,.5); min-width: 76px;
}
.pill b { font-weight: 900; letter-spacing: .5px; }
.pill.wave span { font-size: 15px; } .pill.wave b { font-size: 19px; }
.pill.bump { animation: bump .35s ease-out; }
.pill.hurt { animation: hurt .45s ease-out; }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes hurt { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-6px); background: #a8221a; } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } }
.ico { width: 28px; height: 28px; flex: none; }
.ico.heart path { fill: #ff4f5e; stroke: #7a0f18; stroke-width: 1.5; }
.ico.coin circle { fill: #ffcb2f; stroke: #8a5a00; stroke-width: 1.4; }
.ico.coin .in { fill: #ffdf6b; stroke: #c98f00; stroke-width: 1; }
.ico.coin .mark { fill: #b57a00; }
.ico.skull path { fill: #f3ead6; stroke: #2a1a0c; stroke-width: 1.2; }
.btn {
  pointer-events: auto; cursor: pointer; border: 2px solid var(--wood-dark); color: #fff6dc; font-family: var(--font); font-weight: 900;
  background: linear-gradient(#7d4c22, #57321a); border-radius: 14px; padding: 10px 18px; font-size: 17px; text-shadow: 0 2px 0 rgba(0,0,0,.45);
  box-shadow: inset 0 2px 0 rgba(255,220,160,.35), inset 0 -3px 0 rgba(0,0,0,.25), 0 4px 0 rgba(0,0,0,.35); transition: transform .08s;
}
.btn:active { transform: translateY(2px) scale(.97); }
.btn.round { width: 44px; height: 44px; padding: 0; border-radius: 50%; display: grid; place-items: center; }
.btn.round .ico { width: 24px; height: 24px; fill: #fff6dc; stroke: #fff6dc; }
.btn.round.muted #snd-wave { opacity: 0; }
.btn.big { font-size: 26px; padding: 14px 44px; border-radius: 18px; background: linear-gradient(#8ccf4a, #4f9a2a); border-color: #23460f; box-shadow: inset 0 3px 0 rgba(255,255,220,.45), inset 0 -4px 0 rgba(0,0,0,.25), 0 5px 0 rgba(0,0,0,.4); }
#speed-label { font-size: 16px; }
#btn-speed.fast { background: linear-gradient(#f0b23a, #b9741a); }

/* ---------- wave call ---------- */
#wavecall { position: fixed; left: 0; top: 0; z-index: 6; display: flex; align-items: center; gap: 8px; pointer-events: none; }
#btn-call {
  pointer-events: auto; position: relative; width: 64px; height: 64px; border-radius: 50%; border: none; cursor: pointer; padding: 0;
  background: radial-gradient(circle at 50% 40%, #a8322a, #5e120e); box-shadow: 0 4px 0 rgba(0,0,0,.4), 0 0 0 3px #2a0d08, 0 0 22px rgba(255,80,40,.55);
  animation: pulse 1.1s ease-in-out infinite;
}
#btn-call .ico.skull { width: 34px; height: 34px; position: absolute; left: 15px; top: 14px; }
#btn-call .ring { position: absolute; inset: 0; width: 64px; height: 64px; transform: rotate(-90deg); }
#btn-call .ring circle { fill: none; stroke-width: 5; }
#btn-call .ring .track { stroke: rgba(0,0,0,.35); }
#btn-call .ring .prog { stroke: var(--gold); stroke-linecap: round; stroke-dasharray: 176; stroke-dashoffset: 0; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.preview {
  pointer-events: none; background: linear-gradient(var(--parch), var(--parch-dark)); border: 2px solid var(--wood); border-radius: 12px;
  padding: 6px 10px; box-shadow: 0 4px 0 rgba(0,0,0,.3); min-width: 120px;
}
.ptitle { display: flex; justify-content: space-between; gap: 10px; font-weight: 900; font-size: 14px; color: var(--ink); }
.ptitle .bonus { color: #9a6a00; }
.units { display: flex; gap: 6px; margin-top: 4px; }
.unit { position: relative; width: 38px; height: 38px; border-radius: 9px; background: rgba(90,53,25,.18); }
.unit img { width: 38px; height: 38px; display: block; }
.unit b { position: absolute; right: -4px; bottom: -4px; background: var(--wood); color: #fff; font-size: 11px; border-radius: 8px; padding: 1px 5px; }

/* ---------- radial menu ---------- */
#radial { position: fixed; left: 0; top: 0; width: 0; height: 0; z-index: 7; }
#radial .ring-bg { position: absolute; left: -78px; top: -78px; width: 156px; height: 156px; border-radius: 50%; border: 3px dashed rgba(255,246,220,.75); animation: spin 14s linear infinite; pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.rbtn {
  position: absolute; width: 60px; height: 60px; margin: -30px 0 0 -30px; border-radius: 50%; cursor: pointer; padding: 0;
  background: radial-gradient(circle at 50% 35%, #fff4d6, #d9b878); border: 3px solid var(--wood-dark);
  box-shadow: 0 4px 0 rgba(0,0,0,.35); transform: scale(0); animation: pop .22s cubic-bezier(.3,1.6,.5,1) forwards; font-family: var(--font);
}
.rbtn img { width: 52px; height: 52px; margin-top: 1px; pointer-events: none; }
.rbtn .price {
  position: absolute; left: 50%; bottom: -14px; transform: translateX(-50%); background: var(--wood-dark); color: var(--gold);
  font-weight: 900; font-size: 13px; border-radius: 9px; padding: 1px 7px; white-space: nowrap; display: flex; align-items: center; gap: 3px;
}
.rbtn.poor { filter: grayscale(.85) brightness(.85); }
.rbtn.poor .price { color: #ff8a7a; }
.rbtn.sell { background: radial-gradient(circle at 50% 35%, #ffe0d6, #d98a78); }
.rbtn.max { background: radial-gradient(circle at 50% 35%, #fff6c8, #e9c24a); }
.rbtn svg { width: 30px; height: 30px; margin-top: 2px; pointer-events: none; }
@keyframes pop { to { transform: scale(1); } }

#tip {
  position: fixed; z-index: 8; pointer-events: none; transform: translate(-50%, -100%); background: linear-gradient(var(--parch), var(--parch-dark));
  border: 2px solid var(--wood); border-radius: 10px; padding: 6px 10px; font-size: 13px; font-weight: 700; max-width: 220px; box-shadow: 0 4px 0 rgba(0,0,0,.3);
}
#tip h4 { margin: 0 0 2px; font-size: 15px; font-weight: 900; }
#tip .row { display: flex; gap: 10px; color: #6a4520; }

#hint {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 6; pointer-events: none;
  background: rgba(30,18,8,.82); color: #fff6dc; font-weight: 800; font-size: 17px; padding: 10px 18px; border-radius: 14px; border: 2px solid rgba(255,220,150,.5);
  animation: hintIn .4s ease-out; text-align: center; max-width: 92vw;
}
@keyframes hintIn { from { opacity: 0; transform: translate(-50%, 12px); } }

#banner { position: fixed; left: 0; right: 0; top: 22%; z-index: 9; display: flex; justify-content: center; pointer-events: none; }
#banner .inner {
  display: flex; flex-direction: column; align-items: center; padding: 10px 46px; background: linear-gradient(90deg, transparent, rgba(40,20,8,.88) 18%, rgba(40,20,8,.88) 82%, transparent);
  color: #fff3d0; animation: banner 2.4s ease-in-out forwards;
}
#banner span { font-size: clamp(28px, 6vw, 54px); font-weight: 900; letter-spacing: 2px; text-shadow: 0 3px 0 #000, 0 0 24px rgba(255,140,40,.6); }
#banner small { font-size: 15px; font-weight: 800; letter-spacing: 4px; color: var(--gold); text-transform: uppercase; }
#banner.boss span { color: #ff6a4a; }
@keyframes banner { 0% { opacity: 0; transform: scale(1.4); } 12% { opacity: 1; transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: scale(.96); } }

/* ---------- popups ---------- */
#popups, #coins { position: fixed; inset: 0; pointer-events: none; z-index: 4; overflow: hidden; }
.pop { position: absolute; left: 0; top: 0; font-weight: 900; white-space: nowrap; will-change: transform; }
.pop.gold { color: var(--gold); font-size: 17px; text-shadow: 0 2px 0 #4a2a00, 0 0 6px rgba(0,0,0,.4); }
.pop.combo { font-size: 26px; letter-spacing: 1px; text-shadow: 0 3px 0 #0b2a3a, 0 0 14px rgba(120,220,255,.8); }
.pop.leak { color: #ff5a4a; font-size: 22px; text-shadow: 0 2px 0 #3a0000; }
.pop.info { color: #fff; font-size: 16px; text-shadow: 0 2px 0 #000; }
.coin-fly { position: absolute; left: 0; top: 0; width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff2a0, #ffc21a 55%, #b57a00); box-shadow: 0 0 8px rgba(255,200,60,.8); will-change: transform; }
#flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; z-index: 3; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; }
#title { background: #24401c; }
#title .keyart { position: absolute; inset: 0; background: url(assets/ui/keyart.jpg) center/cover no-repeat; filter: saturate(1.08); animation: kenburns 30s ease-in-out infinite alternate; }
#title::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 55%, rgba(0,0,0,0) 30%, rgba(0,0,0,.55) 100%); pointer-events: none; }
@keyframes kenburns { from { transform: scale(1.02); } to { transform: scale(1.1) translate(-1%, 1%); } }
.title-inner { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 20px; text-align: center; }
#logo { width: min(640px, 88vw); filter: drop-shadow(0 6px 10px rgba(0,0,0,.6)); animation: logoIn .9s cubic-bezier(.2,1.4,.4,1) both; }
#logo-fallback { display: none; margin: 0; font-size: 64px; color: var(--gold); text-shadow: 0 4px 0 var(--wood-dark); }
.tag { margin: 0; color: #fff6dc; font-weight: 800; font-size: 18px; text-shadow: 0 2px 4px rgba(0,0,0,.8); max-width: 520px; }
.hintline { margin: 0; color: rgba(255,246,220,.8); font-weight: 700; font-size: 14px; text-shadow: 0 1px 3px #000; }
@keyframes logoIn { from { opacity: 0; transform: translateY(-30px) scale(.8); } }
.loading { display: flex; flex-direction: column; align-items: center; gap: 6px; color: #fff6dc; font-weight: 700; font-size: 13px; text-shadow: 0 1px 2px #000; }
.lbar { width: 220px; height: 10px; border-radius: 6px; background: rgba(0,0,0,.45); overflow: hidden; border: 2px solid rgba(0,0,0,.4); }
.lbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffd34d, #ff9a2a); transition: width .2s; }
#btn-play[disabled] { filter: grayscale(.7) brightness(.8); }

#pause, #end { background: rgba(20,12,4,.55); backdrop-filter: blur(2px); }
.panel {
  background: linear-gradient(var(--parch), var(--parch-dark)); border: 4px solid var(--wood); border-radius: 22px; padding: 22px 34px 26px;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.35), 0 10px 0 rgba(0,0,0,.35), 0 20px 50px rgba(0,0,0,.5);
  display: flex; flex-direction: column; align-items: center; gap: 12px; min-width: min(360px, 90vw); max-width: 92vw; animation: panelIn .45s cubic-bezier(.2,1.4,.4,1);
}
@keyframes panelIn { from { transform: scale(.6) translateY(40px); opacity: 0; } }
.panel h2 { margin: 0; font-size: 40px; font-weight: 900; color: var(--wood); text-shadow: 0 3px 0 rgba(255,255,255,.6); letter-spacing: 1px; }
.panel p { margin: 0; font-weight: 700; color: #6a4520; text-align: center; }
.toggle { font-weight: 700; font-size: 14px; color: #6a4520; display: flex; align-items: center; gap: 6px; }
.stars { display: flex; gap: 10px; height: 74px; align-items: flex-end; }
.stars i {
  width: 64px; height: 64px; display: block; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  background: #8f7650; opacity: .45; transform: scale(.8);
}
.stars i:nth-child(2) { width: 74px; height: 74px; }
.stars i.on { background: radial-gradient(circle at 40% 35%, #fff6b0, #ffc21a 55%, #d48a00); opacity: 1; animation: starIn .45s cubic-bezier(.2,1.8,.4,1) both; }
@keyframes starIn { from { transform: scale(2.4) rotate(-30deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }
.stats { display: grid; grid-template-columns: auto auto; gap: 2px 18px; font-weight: 800; color: var(--ink); font-size: 15px; }
.stats span:nth-child(odd) { color: #7a5530; }
#end.lose h2 { color: #8a1c12; }

@media (max-width: 600px) {
  .pill { height: 34px; font-size: 16px; min-width: 60px; padding: 0 10px 0 4px; }
  .ico { width: 24px; height: 24px; }
  .pill.wave span { font-size: 13px; }
  .btn.round { width: 38px; height: 38px; }
  .bar { gap: 5px; }
  .bar.left { left: 8px; } .bar.right { right: 8px; }
  .tag { font-size: 15px; }
  .preview { min-width: 0; }
  .unit, .unit img { width: 32px; height: 32px; }
}
@media (max-width: 420px) {
  .bar.left { flex-wrap: wrap; max-width: 60vw; }
}
