:root {
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --wood: #e6bb88;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--wood);
  font-family: var(--font); color: #4a2d1a;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none; touch-action: none;
}
canvas { position: fixed; inset: 0; display: block; touch-action: none; }
#safe-probe {
  position: fixed; visibility: hidden; pointer-events: none;
  padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
}
.hidden { display: none !important; }
button { font-family: var(--font); cursor: pointer; border: 0; }

/* ── home ── */
.screen {
  position: fixed; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 56px) 20px calc(env(safe-area-inset-bottom) + 40px);
  background:
    radial-gradient(ellipse at 50% 42%, rgba(255,240,200,.55), rgba(255,240,200,0) 55%),
    repeating-linear-gradient(90deg, #e8bf8c 0 84px, #a8723f 84px 85.5px, #f3d3a8 85.5px 86.5px, #e4b884 86.5px 170px, #a8723f 170px 171.5px, #f3d3a8 171.5px 172.5px);
}
.corner {
  position: absolute; top: calc(env(safe-area-inset-top) + 12px);
  width: 42px; height: 42px; border-radius: 50%;
  background: #8166dc; color: #fff; font-size: 20px;
  box-shadow: 0 3px 0 #4b3a8f;
}
.corner.left { left: 16px; } .corner.right { right: 16px; font-weight: 800; }
.title-wrap { text-align: center; }
#title {
  margin: 0; font-size: clamp(44px, 14vw, 68px); line-height: .95; font-weight: 900; letter-spacing: 1px;
  color: #fff8e6;
  -webkit-text-stroke: 3px #e88a1a;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 #b35a12, 0 7px 0 #7a3a0a, 0 12px 18px rgba(80,30,0,.35);
}
.subtitle {
  display: inline-block; margin-top: 14px; padding: 6px 16px; border-radius: 99px;
  background: #ff6f91; color: #fff; font-weight: 800; letter-spacing: .5px;
  box-shadow: 0 3px 0 #c43c63;
}
.subtitle:empty { display: none; }
.hole-wrap { position: relative; width: 240px; height: 210px; display: grid; place-items: center; }
.hole {
  position: absolute; bottom: 10px; width: 150px; height: 92px; border-radius: 50%;
  background: radial-gradient(ellipse at 50% 60%, #2a160c 0%, #4a2a17 65%, #7a4a2a 100%);
  box-shadow: 0 0 0 6px rgba(255,235,205,.5);
}
.level-block {
  position: relative; z-index: 1; margin-bottom: 56px;
  width: 118px; height: 106px; border-radius: 22px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(#ffe36a, #ffc928);
  box-shadow: 0 10px 0 #d99a12, 0 0 0 4px #fff3b5, 0 0 40px 10px rgba(255,220,90,.75);
  color: #a0600a; animation: bob 2.4s ease-in-out infinite;
}
.level-block small { font-size: 18px; font-weight: 800; }
.level-block b { font-size: 44px; line-height: 1; font-weight: 900; }
@keyframes bob { 50% { transform: translateY(-8px); } }
.level-dots { display: flex; gap: 12px; }
.dot {
  width: 44px; height: 44px; border-radius: 14px; font-weight: 900; font-size: 18px;
  background: #fff8ee; color: #a0600a; box-shadow: 0 4px 0 #c9a070;
}
.dot.done { background: #5ccf6a; color: #fff; box-shadow: 0 4px 0 #2f9a42; }
.dot.current { background: #ffd23f; box-shadow: 0 4px 0 #d99a12; }
.dot.locked { opacity: .55; }

.btn {
  display: block; min-width: 200px; padding: 14px 26px; border-radius: 22px;
  font-size: 22px; font-weight: 900; color: #fff; letter-spacing: .3px;
  text-shadow: 0 2px 0 rgba(0,0,0,.25);
  transition: transform .08s;
}
.btn:active { transform: translateY(3px) scale(.98); }
.btn.big { font-size: 40px; padding: 16px 60px; border-radius: 30px; color: #fff; }
.btn.yellow { background: linear-gradient(#ffe36a, #ffc21e); color: #fff; box-shadow: 0 6px 0 #d18f0d, 0 0 0 4px #fff7d6; text-shadow: 0 2px 0 #c77f00; }
.btn.green { background: linear-gradient(#7ee26a, #3fbf43); box-shadow: 0 5px 0 #2b8f2e, 0 0 0 3px #e9ffd9; }
.btn.grey { background: linear-gradient(#b8b1cc, #8f86aa); box-shadow: 0 5px 0 #675e83; font-size: 18px; }

/* ── modal ── */
#overlay {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center;
  background: rgba(30,15,40,.55); padding: 20px;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }
.modal {
  position: relative; width: min(360px, 100%);
  border-radius: 28px; padding: 46px 20px 22px; text-align: center;
  border: 5px solid #fff1df; box-shadow: 0 10px 0 rgba(0,0,0,.18), 0 20px 50px rgba(0,0,0,.35);
  animation: pop .25s cubic-bezier(.2,1.4,.5,1);
}
.modal.blue { background: linear-gradient(#a9cdf0, #7fb1e3); }
.modal.green { background: linear-gradient(#bdf0a8, #86d878); }
.modal.pink, .modal.red { background: linear-gradient(#ff9fb8, #e9567a); }
.modal .ribbon {
  position: absolute; top: -26px; left: 50%; transform: translateX(-50%);
  white-space: nowrap; padding: 10px 26px; border-radius: 18px;
  font-size: 26px; font-weight: 900; color: #fff;
  background: #3f6fb5; border: 4px solid #fff1df;
  text-shadow: 0 2px 0 rgba(0,0,0,.25);
}
.modal.green .ribbon { background: #3ea84a; }
.modal.pink .ribbon, .modal.red .ribbon { background: #c33a62; }
.modal .close {
  position: absolute; top: -14px; right: -12px; width: 44px; height: 44px; border-radius: 50%;
  background: #e8384f; color: #fff; font-size: 20px; font-weight: 900;
  border: 4px solid #fff1df;
}
.modal .body { background: rgba(255,255,255,.55); border-radius: 18px; padding: 16px; margin-bottom: 18px; }
.modal h3 { margin: 4px 0 6px; font-size: 22px; color: #2d4a1c; }
.modal .message { margin: 0; white-space: pre-line; font-size: 19px; font-weight: 700; color: #3a2a4a; line-height: 1.35; }
.modal .muted { margin: 0; font-weight: 700; color: #3a4a6a; }
.win-art { font-size: 54px; color: #ffc21e; text-shadow: 0 3px 0 #c77f00; line-height: 1.1; }
.modal.pink .win-art { color: #fff; text-shadow: 0 3px 0 #c33a62; font-size: 70px; }
.modal .buttons { display: flex; flex-direction: column; gap: 14px; align-items: center; }

#loading { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(230,187,136,.6); }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 6px solid #fff; border-top-color: #8166dc; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
