/* One dark look on purpose: the toy sits in a dim, glossy room. Phone-first single screen. */
:root {
  --bg: #0f1012;
  --surface: #1b1c20;
  --surface-2: #25272c;
  --line: #2a2c31;
  --fg: #f2f3f5;
  --muted: #a9adb5;
  --accent: #7ddc3a;
  --accent-ink: #0f1012;
  --accent-soft: rgba(125, 220, 58, 0.45);
  --warn: #ffb020;
  --new: #ff4d6d;
  --font: 'Noto Sans TC', 'PingFang TC', 'Heiti TC', system-ui, sans-serif;
  color-scheme: dark;
}

[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; color: inherit; touch-action: manipulation; }
button:focus-visible, canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  box-sizing: border-box;
}

.top { display: flex; align-items: center; gap: 6px; padding-block: 14px 8px; }
.logo { flex: 1; font-weight: 900; font-size: 16px; letter-spacing: 0.06em; color: var(--accent); }
.pill {
  height: 32px; padding: 0 12px; border-radius: 16px; background: var(--surface);
  display: inline-flex; align-items: center; font-size: 13px; color: #c9ccd2;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.ib {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: 14px; padding: 0;
  background: var(--surface); color: #e9eaee; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.ib:disabled { opacity: 0.35; cursor: default; }
#btnSound .ic-off { display: none; }
#btnSound[aria-pressed="true"] .ic-on { display: none; }
#btnSound[aria-pressed="true"] .ic-off { display: block; }

.toys { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.seg {
  margin-top: 4px; padding: 4px; border-radius: 18px; background: var(--surface);
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px;
}
.seg button {
  height: 40px; border: 0; border-radius: 14px; background: transparent; color: #c9ccd2;
  font-size: 15px; font-weight: 700; cursor: pointer; transition: background 0.2s, color 0.2s;
}
.seg button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); box-shadow: 0 0 18px var(--accent-soft); }

.stage { flex: 1; min-height: 0; position: relative; margin-inline: calc(-1 * max(16px, env(safe-area-inset-left, 0px))); }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.stage-top { position: absolute; left: max(16px, env(safe-area-inset-left, 0px)); top: 12px; z-index: 2; pointer-events: none; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 12px;
  border-radius: 15px; border: 1.5px solid var(--accent); font-size: 13px; font-weight: 700; background: rgba(15, 16, 18, 0.6);
}
.chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

.loading, .soon {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  margin: 0; padding: 24px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.7;
}
.soon { background: var(--bg); z-index: 3; }
.loading { background: var(--bg); z-index: 4; }
.soon p { margin: 0; max-width: 26em; }
.soon .soon-title { color: var(--fg); font-size: 20px; font-weight: 900; margin-bottom: 8px; }

.hands { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.hand { position: absolute; top: 46%; color: #ffd24a; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5)); }
.hand.l { left: 50%; transform: translate(-110%, -50%) scaleX(-1) rotate(-80deg); animation: pullL 1.3s ease-in-out infinite; }
.hand.r { left: 50%; transform: translate(10%, -50%) rotate(-80deg); animation: pullR 1.3s ease-in-out infinite; }
@keyframes pullL { 0%, 100% { margin-left: 0; } 50% { margin-left: -70px; } }
@keyframes pullR { 0%, 100% { margin-left: 0; } 50% { margin-left: 70px; } }

.hint { min-height: 40px; display: flex; align-items: center; justify-content: center; }
.hint .pill-cta {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 14px; border-radius: 16px;
  background: var(--accent); color: var(--accent-ink); font-size: 13px; font-weight: 700; box-shadow: 0 0 22px var(--accent-soft);
}
.hint p { margin: 0; font-size: 13px; color: var(--muted); text-align: center; text-wrap: balance; }

.edit-row { display: flex; justify-content: flex-end; }
.link {
  display: inline-flex; align-items: center; gap: 4px; height: 28px; border: 0; background: transparent;
  font-size: 12px; color: var(--muted); cursor: pointer;
}

.carousel { display: flex; align-items: center; gap: 4px; padding-block: 4px 18px; }
.arrow {
  width: 28px; height: 44px; border: 0; background: transparent; color: #e9eaee; cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.arrow:disabled { opacity: 0.3; cursor: default; }
.items { flex: 1; min-width: 0; display: flex; justify-content: space-between; align-items: center; }
.swatch {
  position: relative; width: 48px; height: 48px; border-radius: 50%; padding: 3px; border: 2px solid transparent;
  background: transparent; cursor: pointer; flex: none;
}
.swatch[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 16px var(--accent-soft); }
.swatch .thumb { display: block; width: 100%; height: 100%; object-fit: contain; transform: scale(1.18); }
.swatch .ball { display: block; width: 100%; height: 100%; border-radius: 50%; box-shadow: inset -4px -5px 8px rgba(0, 0, 0, 0.3); }
.swatch .plus {
  display: flex; width: 100%; height: 100%; border-radius: 50%; align-items: center; justify-content: center;
  border: 2px solid var(--accent); box-sizing: border-box; color: var(--accent);
}
.swatch .new {
  position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%); padding: 1px 5px; border-radius: 6px;
  background: var(--new); color: #fff; font-size: 9px; font-weight: 900; letter-spacing: 0.04em;
}



.sheet { position: absolute; inset: 0; z-index: 20; }
.scrim { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(0, 0, 0, 0.6); cursor: pointer; }
.panel {
  position: absolute; left: 0; right: 0; bottom: 0; border-radius: 26px 26px 0 0; background: var(--surface);
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  animation: up 0.24s cubic-bezier(.2, .9, .3, 1);
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.panel .grip { width: 40px; height: 5px; border-radius: 3px; background: #44464d; }
.panel h2 { margin: 0; font-size: 18px; font-weight: 900; }
.panel p { margin: 0; font-size: 13px; color: var(--muted); text-align: center; line-height: 1.6; }
.btn-primary, .btn-outline, .btn-plain {
  width: 100%; border-radius: 16px; font-size: 15px; font-weight: 900; cursor: pointer; font-family: inherit;
}
.btn-primary { height: 50px; border: 0; background: var(--accent); color: var(--accent-ink); }
.btn-outline { height: 46px; border: 1.5px solid var(--accent); background: transparent; color: #9be15d; font-size: 14px; font-weight: 700; }
.btn-plain { height: 44px; border: 0; background: transparent; color: var(--muted); font-size: 14px; font-weight: 500; width: auto; padding: 0 20px; }
.stats { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stats div { padding: 14px; border-radius: 16px; background: var(--surface-2); }
.stats span { display: block; font-size: 12px; color: var(--muted); }
.stats strong { font-size: 26px; font-weight: 900; font-variant-numeric: tabular-nums; }


.toast {
  position: absolute; left: 50%; top: calc(64px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); z-index: 40;
  max-width: 320px; padding: 10px 16px; border-radius: 14px; background: #f2f3f5; color: #0f1012;
  font-size: 13px; font-weight: 700; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .hand.l, .hand.r, .panel { animation: none; }
}

/* ---------- tabs share one stage; each tab shows its own canvas and controls ---------- */
.toys[data-tab="key"] .ball-only, .toys:not([data-tab="key"]) .key-only { display: none !important; }
.stage canvas.cv { visibility: hidden; }
.toys[data-tab="wax"] .cv-wax, .toys[data-tab="sq"] .cv-sq, .toys[data-tab="key"] .cv-key { visibility: visible; }

.key-top { display: flex; flex-direction: column; gap: 8px; padding-top: 10px; }
.level {
  height: 40px; border-radius: 14px; background: var(--surface); border: 1.5px solid var(--line);
  display: flex; align-items: center; gap: 10px; padding: 0 12px; transition: border-color 0.2s;
}
.level .lv { padding: 2px 8px; border-radius: 8px; background: #2c3a22; color: #9be15d; font-size: 12px; font-weight: 900; font-variant-numeric: tabular-nums; }
.level .track { flex: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.level .fill { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--accent); transition: width 0.12s; }
.level .x2 { padding: 1px 6px; border-radius: 6px; background: #ff5a4f; color: #fff; font-size: 11px; font-weight: 900; }
.level .left { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.level.fever { border-color: #ff5a4f; }
.level.fever .fill { background: linear-gradient(90deg, var(--warn), #ff5a4f); }
.key-controls { display: flex; align-items: center; gap: 8px; }
.stepper { display: flex; align-items: center; height: 44px; border-radius: 14px; background: var(--surface); }
.stepper span { min-width: 24px; text-align: center; font-weight: 900; font-size: 15px; font-variant-numeric: tabular-nums; }
.ib.flat { background: transparent; }
.ib.round { border-radius: 50%; }
#btnLock[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.combo {
  position: absolute; right: max(18px, env(safe-area-inset-right, 0px)); top: 8px; z-index: 2; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; color: #9be15d; text-shadow: 0 0 18px currentColor;
}
.combo strong { font-size: 44px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.combo span { font-size: 11px; font-weight: 900; letter-spacing: 0.18em; }
.combo[data-tier="2"] { color: var(--warn); }
.combo[data-tier="3"] { color: #ff5a4f; }
.combo.pop strong { animation: pop 0.16s ease-out; }
@keyframes pop { from { transform: scale(1.25); } to { transform: none; } }
.palette { position: absolute; right: max(16px, env(safe-area-inset-right, 0px)); bottom: 8px; z-index: 2; }

.presets { display: flex; gap: 6px; overflow-x: auto; padding-top: 8px; scrollbar-width: none; }
.presets button {
  flex: none; height: 32px; padding: 0 14px; border-radius: 16px; border: 0; background: var(--surface);
  color: #e9eaee; font-size: 12px; font-weight: 700; cursor: pointer;
}
.presets button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.key-items { display: flex; align-items: center; gap: 8px; padding-block: 10px 18px; }
.kitem {
  width: 52px; height: 52px; border-radius: 14px; border: 2px solid transparent; background: var(--surface);
  color: #e9eaee; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.kitem[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 16px var(--accent-soft); }
.kitem .dot { width: 30px; height: 30px; border-radius: 50%; }
@media (prefers-reduced-motion: reduce) { .combo.pop strong { animation: none; } }
