/* Scrub & Sort */
:root {
  --ink: #26374a;
  --ink-soft: #5a6b80;
  --cream: #fffaf0;
  --paper: #ffffff;
  --sky: #cdeeff;
  --sky2: #eef9ff;
  --teal: #13a89e;
  --teal-dark: #0c7f78;
  --gold: #ffc53d;
  --gold-dark: #e0a100;
  --pink: #ff7aa2;
  --danger: #e5484d;
  --shadow: 0 6px 18px rgba(38, 55, 74, .16);
  --radius: 16px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #b9dcf0;
  background-image: radial-gradient(circle at 20% 10%, rgba(255,255,255,.6) 0 8%, transparent 9%),
                    radial-gradient(circle at 85% 30%, rgba(255,255,255,.45) 0 6%, transparent 7%),
                    linear-gradient(#cdeeff, #e8f6ff);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
svg { display: block; }

#stage {
  position: relative;
  max-width: 480px;
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  background: linear-gradient(var(--sky), var(--sky2) 55%, var(--cream));
  box-shadow: 0 0 40px rgba(38, 55, 74, .18);
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.hidden { display: none !important; }

/* ---------- shared bits ---------- */
.back-link {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 12px;
  z-index: 3;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .7);
}
.back-link.small { position: static; font-size: 12px; padding: 5px 9px; white-space: nowrap; }

.btn {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 999px;
  padding: 13px 20px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .02em;
  color: #fff;
  background: linear-gradient(#22c3b6, var(--teal));
  box-shadow: 0 5px 0 var(--teal-dark), 0 8px 16px rgba(19, 168, 158, .3);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--teal-dark), 0 4px 10px rgba(19, 168, 158, .3); }
.btn.big { font-size: 22px; padding: 16px 20px; }
.btn.alt { background: linear-gradient(#ffd666, var(--gold)); color: #5b3d00; box-shadow: 0 5px 0 var(--gold-dark), 0 8px 16px rgba(224, 161, 0, .25); }
.btn.alt:active { box-shadow: 0 2px 0 var(--gold-dark); }
.btn.ghost { background: rgba(255, 255, 255, .75); color: var(--ink); box-shadow: 0 3px 0 rgba(38, 55, 74, .15); }
.btn.small { font-size: 14px; padding: 9px 16px; width: auto; margin: 0 auto; }

.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 10px 6px;
  min-height: 48px;
}
.bar-title {
  flex: 1;
  text-align: center;
  font-weight: 800;
  font-size: 17px;
  line-height: 1.1;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.bar-title small { font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .8);
  box-shadow: 0 3px 0 rgba(38, 55, 74, .15);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.pill {
  flex: 0 0 auto;
  background: rgba(255, 255, 255, .85);
  border-radius: 999px;
  padding: 6px 11px;
  font-weight: 800;
  font-size: 14px;
  color: #a86f00;
}

/* ---------- title ---------- */
#screen-title { align-items: center; justify-content: center; }
.title-wrap {
  position: relative;
  width: min(360px, 88%);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}
#title-art { width: 220px; height: 200px; margin: 0 auto -6px; }
.logo {
  margin: 0;
  font-size: 46px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -.01em;
  color: var(--teal-dark);
  text-shadow: 0 3px 0 #fff, 0 6px 0 rgba(12, 127, 120, .18);
}
.logo span { color: var(--pink); }
.tag { margin: 0 0 8px; color: var(--ink-soft); font-weight: 700; font-size: 15px; }
.bubbles { position: absolute; inset: -40px -10px; pointer-events: none; }
.bubbles i {
  position: absolute;
  bottom: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff, rgba(255,255,255,.2) 60%, rgba(255,255,255,.05));
  border: 1px solid rgba(255, 255, 255, .8);
  animation: rise 7s linear infinite;
  opacity: 0;
}
.bubbles i:nth-child(1) { left: 6%; animation-delay: 0s; }
.bubbles i:nth-child(2) { left: 22%; width: 22px; height: 22px; animation-delay: 1.4s; }
.bubbles i:nth-child(3) { left: 40%; width: 10px; height: 10px; animation-delay: 2.6s; }
.bubbles i:nth-child(4) { left: 62%; width: 18px; height: 18px; animation-delay: .8s; }
.bubbles i:nth-child(5) { left: 78%; animation-delay: 3.4s; }
.bubbles i:nth-child(6) { left: 90%; width: 24px; height: 24px; animation-delay: 4.8s; }
.bubbles i:nth-child(7) { left: 50%; width: 16px; height: 16px; animation-delay: 5.6s; }
@keyframes rise {
  0% { transform: translateY(0) translateX(0); opacity: 0; }
  10% { opacity: 1; }
  100% { transform: translateY(-520px) translateX(20px); opacity: 0; }
}

/* ---------- map ---------- */
#map-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
#map-path { position: relative; margin: 0 auto; width: 100%; max-width: 420px; }
#map-path svg.trail { position: absolute; inset: 0; pointer-events: none; }
.node {
  position: absolute;
  width: 74px;
  margin-left: -37px;
  text-align: center;
  border: 0;
  background: none;
  padding: 0;
}
.node .disc {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 24px;
  color: #fff;
  background: radial-gradient(circle at 35% 30%, #4fe0d2, var(--teal) 60%, var(--teal-dark));
  box-shadow: 0 5px 0 #0a6660, 0 8px 14px rgba(0, 0, 0, .18), inset 0 -4px 0 rgba(0, 0, 0, .12);
  border: 3px solid #fff;
}
.node.done .disc { background: radial-gradient(circle at 35% 30%, #ffe28a, var(--gold) 60%, var(--gold-dark)); color: #6b4700; box-shadow: 0 5px 0 #a87700, 0 8px 14px rgba(0,0,0,.18), inset 0 -4px 0 rgba(0,0,0,.1); }
.node.locked .disc { background: radial-gradient(circle at 35% 30%, #e8edf3, #c3ccd7 70%); color: #8a97a6; box-shadow: 0 5px 0 #9aa6b4; }
.node.locked { cursor: default; }
.node.current .disc { animation: bob 1.4s ease-in-out infinite; }
.node .stars { font-size: 15px; letter-spacing: 1px; color: #d4dae2; margin-top: 4px; height: 17px; text-shadow: 0 1px 0 #fff; }
.node .stars b { color: var(--gold); font-weight: 400; }
.node .name { font-size: 11px; font-weight: 800; color: var(--ink-soft); margin-top: 1px; white-space: nowrap; }
.node .lock { width: 22px; height: 22px; fill: #8a97a6; }
@keyframes bob { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-6px) scale(1.05); } }

/* ---------- play ---------- */
#screen-play { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.meter {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 6px;
  font-weight: 800;
  font-size: 13px;
}
.meter-track {
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .75);
  box-shadow: inset 0 1px 3px rgba(38, 55, 74, .2);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #7fe3d8, #13a89e);
  transition: width .25s ease-out;
}
.meter-fill.full { background: linear-gradient(90deg, #ffe07a, #ffb400); }
#meter-text { min-width: 74px; text-align: right; }
.caps-text { color: #a86f00; min-width: 70px; text-align: right; }

#scene-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 200px;
  touch-action: none;
}
#scene { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: none; }
#toast {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translate(-50%, -10px);
  max-width: 92%;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(38, 55, 74, .9);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  width: max-content;
  line-height: 1.25;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.warn { background: rgba(229, 72, 77, .95); }

#rack-wrap {
  position: relative;
  flex: 0 0 192px;
  height: 192px;
  touch-action: none;
  background: linear-gradient(rgba(255, 255, 255, .0), rgba(255, 255, 255, .55) 18%);
  border-top: 2px solid rgba(255, 255, 255, .9);
  transition: background .2s;
}
#rack-wrap.pour { background: linear-gradient(rgba(255, 197, 61, .08), rgba(255, 214, 102, .42) 18%); border-top-color: var(--gold); }
#rack { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#rack-caption {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  max-width: 92%;
  padding: 3px 12px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 2px 6px rgba(38, 55, 74, .15);
  font-size: 12px;
  font-weight: 800;
  color: var(--teal-dark);
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#rack-wrap.pour #rack-caption { color: #7a4f00; background: #fff3c4; }

.tools {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 8px 10px max(10px, env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .7);
}
.seg {
  flex: 1.6;
  display: flex;
  background: rgba(38, 55, 74, .1);
  border-radius: 14px;
  padding: 3px;
  gap: 3px;
}
.seg-btn, .tool-btn {
  flex: 1;
  border: 0;
  border-radius: 11px;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-weight: 800;
  font-size: 12px;
  background: transparent;
  color: var(--ink-soft);
  transition: background .15s, color .15s, transform .08s;
}
.seg-btn svg, .tool-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }
.seg-btn.on { color: #fff; box-shadow: 0 3px 0 rgba(0, 0, 0, .15); }
#tool-hose.on { background: linear-gradient(#22c3b6, var(--teal)); }
#tool-pour.on { background: linear-gradient(#ffd666, var(--gold)); color: #5b3d00; }
.tool-btn { background: #fff; box-shadow: 0 3px 0 rgba(38, 55, 74, .14); color: var(--ink); }
.tool-btn:active, .seg-btn:active { transform: translateY(2px); }
.tool-btn:disabled { opacity: .4; cursor: default; }
.tool-btn.confirm { background: var(--danger); color: #fff; }
.tool-btn.pulse { animation: pulse 1s ease-in-out infinite; background: #ffe3e4; color: var(--danger); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 3px 0 rgba(229, 72, 77, .3), 0 0 0 0 rgba(229, 72, 77, .5); }
  50% { box-shadow: 0 3px 0 rgba(229, 72, 77, .3), 0 0 0 8px rgba(229, 72, 77, 0); transform: scale(1.05); }
}

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: rgba(20, 40, 60, .42);
  padding: 20px;
  animation: fade .2s ease-out;
}
.card {
  width: min(320px, 100%);
  background: var(--cream);
  border-radius: 24px;
  padding: 22px 20px 20px;
  box-shadow: var(--shadow), 0 0 0 4px #fff inset;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  animation: pop .3s cubic-bezier(.2, 1.5, .5, 1);
}
.card h2 { margin: 0 0 4px; font-size: 26px; font-weight: 900; color: var(--teal-dark); }
.card p { margin: 0 0 4px; color: var(--ink-soft); font-weight: 700; }
.card .row { display: flex; gap: 10px; }
.win-stars { display: flex; justify-content: center; gap: 6px; margin-top: -4px; }
.win-stars .s { font-size: 52px; line-height: 1; color: #dfe4ea; text-shadow: 0 3px 0 #c5ccd5; transform: scale(0); }
.win-stars .s.on { color: var(--gold); text-shadow: 0 3px 0 var(--gold-dark), 0 0 14px rgba(255, 197, 61, .7); }
.win-stars .s.show { transform: scale(1); animation: starpop .45s cubic-bezier(.2, 1.6, .5, 1) forwards; }
.win-stars .s2 { font-size: 64px; margin-top: -10px; }
@keyframes starpop { from { transform: scale(0) rotate(-40deg); } to { transform: scale(1) rotate(0); } }
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- tutorial ---------- */
#tut-hand {
  position: fixed;
  z-index: 55;
  width: 54px;
  height: 54px;
  margin: -6px 0 0 -18px;
  pointer-events: none;
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .25));
  animation: tap 1.1s ease-in-out infinite;
}
#tut-hand svg { width: 100%; height: 100%; fill: #fff; stroke: var(--ink); stroke-width: 2.5; stroke-linejoin: round; }
#tut-hand.rub { animation: rub 1.2s ease-in-out infinite; }
@keyframes tap { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(0, 10px) scale(.94); } }
@keyframes rub { 0%, 100% { transform: translate(-16px, 0); } 50% { transform: translate(16px, 6px); } }
#tut-bubble {
  position: fixed;
  z-index: 56;
  transform: translate(-50%, -100%);
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  font-size: 16px;
  padding: 10px 14px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  pointer-events: none;
  white-space: nowrap;
  animation: pop .3s cubic-bezier(.2, 1.5, .5, 1);
}
#tut-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  margin-left: -8px;
  border: 8px solid transparent;
  border-bottom: 0;
  border-top-color: #fff;
}

#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

@media (max-height: 620px) {
  #rack-wrap { flex-basis: 166px; height: 166px; }
  .bar { min-height: 42px; }
  .logo { font-size: 38px; }
  #title-art { width: 170px; height: 150px; }
}
@media (prefers-reduced-motion: reduce) {
  .bubbles, .node.current .disc, #tut-hand { animation: none !important; }
}
