:root {
  --yellow: #FFE100;
  --yellow-deep: #F5C400;
  --ink: #141414;
  --ink-2: #4a443d;
  --muted: #7a7168;
  --cream: #F6EFE4;
  --paper: #FFFCF6;
  --line: rgba(20, 20, 20, 0.1);
  --red: #E5484D;
  --display: "Baloo 2", ui-rounded, system-ui, sans-serif;
  --ui: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  display: flex;
  justify-content: center;
  background: #E7DED1;
  color: var(--ink);
  font-family: var(--ui);
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app {
  position: relative;
  width: 100%;
  max-width: 460px;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--cream);
  user-select: none;
  -webkit-user-select: none;
}
@media (min-width: 520px) {
  #app { box-shadow: 0 0 0 1px var(--line), 0 30px 80px rgba(60, 40, 10, 0.18); }
}

#stage { position: absolute; inset: 0; touch-action: none; }
#stage canvas { display: block; width: 100%; height: 100%; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; pointer-events: none; }
.screen > * { pointer-events: auto; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 0 0 1px var(--line), 0 2px 0 rgba(20, 20, 20, 0.08);
  cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.sound-btn .off { display: none; }
.muted .sound-btn .on { display: none; }
.muted .sound-btn .off { display: block; }

/* ---------- Start screen ---------- */
.menu-top { padding: calc(var(--safe-top) + 14px) 20px 0; text-align: center; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.logo { height: 26px; width: auto; display: block; }
.title {
  margin: 4px 0 0;
  font-family: var(--display);
  font-weight: 800;
  line-height: 0.82;
  letter-spacing: -0.01em;
}
.title .t1 { display: block; font-size: 30px; color: var(--ink); }
.title .t2 {
  display: inline-block;
  font-size: 64px;
  color: var(--yellow);
  transform: rotate(-3deg);
  text-shadow:
    3px 0 var(--ink), -3px 0 var(--ink), 0 3px var(--ink), 0 -3px var(--ink),
    2px 2px var(--ink), -2px 2px var(--ink), 2px -2px var(--ink), -2px -2px var(--ink),
    0 7px 0 var(--ink);
  animation: wobble 3.2s ease-in-out infinite;
}
@keyframes wobble { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(-1deg) scale(1.03); } }
.tagline {
  margin: 12px auto 0;
  max-width: 320px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink-2);
  text-wrap: balance;
}

.sheet {
  margin-top: auto;
  padding: 16px 16px calc(var(--safe-bottom) + 12px);
  background: var(--paper);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -1px 0 var(--line), 0 -18px 40px rgba(60, 40, 10, 0.1);
}
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 14px; padding: 0; list-style: none; }
.intro .steps { margin-top: 12px; }
.steps li {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 6px;
  border-radius: 14px;
  background: var(--cream);
  font-size: 11.5px;
  line-height: 1.3;
  text-align: center;
  color: var(--ink-2);
}
.steps svg { width: 34px; height: 34px; }
.steps b { color: var(--ink); }

.levels-label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; font-size: 13px; font-weight: 700; }
.levels-label #couponNow { font-weight: 700; font-size: 12px; color: var(--ink-2); text-align: right; }
.levels { display: flex; flex-direction: column; gap: 8px; margin: 0 0 14px; padding: 0; list-style: none; }
.level-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px 12px 8px 8px;
  border: 0;
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 0 0 1.5px var(--line);
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}
.level-row:active { transform: scale(0.98); }
.level-row.next { background: #FFF6BF; box-shadow: 0 0 0 2px var(--ink); }
.level-row img { width: 52px; height: 52px; flex: none; border-radius: 12px; object-fit: cover; background: var(--cream); }
.level-row.locked img { filter: grayscale(1) opacity(0.5); }
.level-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.level-text small { font-size: 11px; font-weight: 700; color: var(--muted); }
.level-text b { font-size: 15px; line-height: 1.2; }
.level-text em { font-style: normal; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.level-row.locked .level-text em { color: var(--muted); }
.level-state { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; font-size: 14px; font-weight: 800; }
.level-state.done { background: #2E9F6B; color: #fff; }
.level-state.go { background: var(--ink); color: var(--yellow); }
.level-state svg { width: 16px; height: 16px; }
.dots { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: 1px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: #d9cfc2; }
.dots i.on { background: var(--ink); }

.btn-primary, .btn-ghost {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 56px;
  border-radius: 16px;
  font-family: var(--display);
  font-weight: 800;
  font-size: 21px;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn-primary {
  border: 2px solid var(--ink);
  background: var(--yellow);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--ink);
}
.btn-primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn-ghost {
  margin-top: 10px;
  border: 2px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-size: 17px;
  height: 50px;
}
.fine { margin: 10px 0 0; text-align: center; font-size: 11.5px; color: var(--muted); }

/* ---------- HUD ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; padding: calc(var(--safe-top) + 12px) 14px 0; pointer-events: none; }
#hud button { pointer-events: auto; }
.hud-row { display: flex; align-items: center; gap: 10px; }
.timer {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 44px;
  padding: 0 14px;
  overflow: hidden;
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 0 0 1px var(--line);
  font-family: var(--display);
  font-weight: 800;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}
.timer svg { position: relative; width: 20px; height: 20px; }
.timer span { position: relative; padding-top: 3px; }
.timer i {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  background: var(--yellow);
  transform-origin: left;
  transition: background 0.3s;
}
.timer.low i { background: #FFB4A8; }
.timer.low { animation: pulse 0.5s ease-in-out infinite alternate; }
@keyframes pulse { to { transform: scale(1.04); } }
.plate {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  padding: 0 12px 0 10px;
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 0 0 1px var(--line);
  font-family: var(--display);
  font-weight: 800;
  font-size: 20px;
}
.plate svg { width: 28px; height: 28px; }
.plate span { padding-top: 3px; min-width: 1.2em; text-align: center; }
.plate.bump { animation: bump 0.3s ease-out; }
@keyframes bump { 40% { transform: scale(1.18); } }

.score-wrap { display: flex; flex-direction: column; align-items: center; margin-top: 6px; }
.hud-tags { display: flex; gap: 6px; margin-top: 2px; min-height: 24px; }
#targetPill {
  padding: 3px 12px 1px;
  border-radius: 99px;
  background: var(--paper);
  box-shadow: 0 0 0 1px var(--line);
  font-family: var(--display);
  font-weight: 800;
  font-size: 15px;
  color: var(--ink-2);
  transition: background 0.3s, color 0.3s;
}
#targetPill.hit { background: #2E9F6B; color: #fff; box-shadow: none; animation: bump 0.35s ease-out; }
#scoreText {
  font-family: var(--display);
  font-weight: 800;
  font-size: 46px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  padding-top: 6px;
}
#scoreText.bump { animation: bump 0.25s ease-out; }
#combo {
  padding: 3px 12px 1px;
  border-radius: 99px;
  background: var(--ink);
  color: var(--yellow);
  font-family: var(--display);
  font-weight: 800;
  font-size: 15px;
}
#combo.pop { animation: bump 0.25s ease-out; }

#hint {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 18px);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 9px 16px;
  border-radius: 99px;
  background: rgba(255, 252, 246, 0.94);
  box-shadow: 0 0 0 1px var(--line);
  font-size: 13.5px;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.5s;
}
#hint.fade { opacity: 0; }

#banner {
  position: absolute;
  left: 0;
  right: 0;
  top: 44%;
  transform: translateY(-50%);
  text-align: center;
  font-family: var(--display);
  font-weight: 800;
  font-size: 92px;
  line-height: 1;
  color: var(--yellow);
  text-shadow:
    4px 0 var(--ink), -4px 0 var(--ink), 0 4px var(--ink), 0 -4px var(--ink),
    3px 3px var(--ink), -3px 3px var(--ink), 3px -3px var(--ink), -3px -3px var(--ink),
    0 9px 0 var(--ink);
  pointer-events: none;
}
#banner.small { font-size: 58px; }
#banner span { display: inline-block; animation: pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
@keyframes pop { from { transform: scale(0.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- Pause ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(30, 22, 12, 0.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.card {
  width: 100%;
  max-width: 340px;
  padding: 24px 20px 18px;
  border-radius: 24px;
  background: var(--paper);
  text-align: center;
  animation: pop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.card h2 { margin: 0; font-family: var(--display); font-weight: 800; font-size: 28px; line-height: 1.1; }
.card p { margin: 8px 0 18px; color: var(--ink-2); font-size: 14px; }

/* ---------- Result ---------- */
.result { background: var(--cream); pointer-events: auto; animation: slideUp 0.45s cubic-bezier(0.2, 0.9, 0.3, 1) both; }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.result-scroll {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-top) + 18px) 18px calc(var(--safe-bottom) + 20px);
  text-align: center;
}
.logo.small { height: 22px; margin: 0 auto 10px; }
.level-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 99px;
  background: var(--ink);
  color: var(--yellow);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.result h2 { margin: 10px 0 0; font-family: var(--display); font-weight: 800; font-size: 32px; line-height: 1.05; }
.final-score { margin-top: 2px; font-family: var(--display); font-weight: 800; }
.final-score span { font-size: 60px; line-height: 1; font-variant-numeric: tabular-nums; }
.final-score small { margin-left: 6px; font-size: 20px; color: var(--muted); }
.res-sub { margin: 4px auto 0; max-width: 320px; font-size: 14px; color: var(--ink-2); text-wrap: balance; }
.target-bar { position: relative; height: 12px; margin: 8px 6px 0; border-radius: 99px; background: #E6DCCD; overflow: hidden; }
.target-bar i { position: absolute; inset: 0; background: var(--yellow-deep); border-radius: inherit; transform-origin: left; transform: scaleX(0); transition: transform 0.9s cubic-bezier(0.2, 0.9, 0.3, 1); }
.target-bar i.hit { background: #2E9F6B; }
.target-caption { display: flex; justify-content: space-between; gap: 8px; margin: 6px 6px 0; font-size: 12.5px; font-weight: 700; color: var(--muted); }
.best.record { color: var(--ink); }
.best.record::before { content: "★ "; color: var(--yellow-deep); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 18px; padding: 0; list-style: none; }
.stats li { display: flex; flex-direction: column; padding: 10px 4px 8px; border-radius: 14px; background: var(--paper); box-shadow: 0 0 0 1px var(--line); }
.stats b { font-family: var(--display); font-weight: 800; font-size: 26px; line-height: 1; padding-top: 3px; }
.stats span { font-size: 11.5px; color: var(--muted); font-weight: 600; }

.ticket {
  position: relative;
  border-radius: 18px;
  background: var(--yellow);
  border: 2px solid var(--ink);
  box-shadow: 0 5px 0 var(--ink);
  text-align: left;
  overflow: hidden;
}
.ticket-top { display: flex; flex-direction: column; padding: 16px 18px 14px; }
.ticket-label { font-size: 11.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.ticket-top strong { font-family: var(--display); font-weight: 800; font-size: 30px; line-height: 1.05; margin-top: 4px; }
.ticket-top span:last-child { font-size: 13px; color: #4a3f00; font-weight: 600; }
.ticket-bottom::before, .ticket-bottom::after {
  content: "";
  position: absolute;
  top: -13px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--cream);
  border: 2px solid var(--ink);
}
.ticket-bottom::before { left: -13px; }
.ticket-bottom::after { right: -13px; }
.ticket-bottom {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 14px 18px;
  border-top: 2px dashed rgba(20, 20, 20, 0.45);
}
.code { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-weight: 700; font-size: 18px; letter-spacing: 0.04em; }
.code em { font-family: var(--ui); font-style: normal; font-size: 10px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; padding: 2px 6px; border-radius: 6px; background: var(--ink); color: var(--yellow); }
.copy-btn { flex: none; height: 38px; padding: 0 14px; border: 2px solid var(--ink); border-radius: 12px; background: var(--paper); font-weight: 800; font-size: 14px; cursor: pointer; }
.ticket-note { margin: 12px 0 0; font-size: 12px; color: var(--muted); }

.next-card, .product {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 0 0 1px var(--line);
  text-align: left;
  color: inherit;
  text-decoration: none;
}
.next-card { margin-top: 16px; background: #FFF6BF; box-shadow: 0 0 0 2px var(--ink); animation: pop 0.4s 0.5s cubic-bezier(0.2, 1.5, 0.4, 1) both; }
.next-card img, .product img { width: 56px; height: 56px; flex: none; border-radius: 12px; object-fit: cover; }
.next-card > span, .product > span:nth-child(2) { display: flex; flex-direction: column; flex: 1; font-size: 14px; }
.next-card small { font-size: 11.5px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.next-card b { font-size: 17px; }
.next-card em { font-style: normal; font-size: 13px; color: var(--ink-2); }
.product small { font-size: 12px; color: var(--muted); }
.product svg { width: 20px; height: 20px; flex: none; }
.actions { margin: 16px 0 20px; }
.btn-text { display: block; width: 100%; margin-top: 6px; padding: 10px; border: 0; background: none; color: var(--ink-2); font: 700 14px var(--ui); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.shop-link { margin-top: 10px; }
.ticket.upgraded { animation: pop 0.5s 0.3s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
.ticket-label .new { margin-left: 6px; padding: 1px 7px; border-radius: 6px; background: var(--ink); color: var(--yellow); letter-spacing: 0.04em; }

/* ---------- Pan intro ---------- */
.intro { align-items: end; padding: 0; place-items: end center; }
.intro-card {
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 26px 26px 0 0;
  background: var(--paper);
  animation: slideUp 0.4s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
.intro-photo { position: relative; height: 190px; background: var(--cream); }
.intro-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.intro-photo .level-chip { position: absolute; left: 16px; bottom: 12px; }
.intro-body { padding: 16px 18px calc(var(--safe-bottom) + 12px); }
.intro-body h2 { margin: 0; font-family: var(--display); font-weight: 800; font-size: 30px; line-height: 1.05; }
.intro-tag { margin: 2px 0 10px; color: var(--ink-2); font-size: 14px; font-weight: 600; }
.intro-facts { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.intro-facts li { position: relative; padding-left: 24px; font-size: 13.5px; line-height: 1.4; }
.intro-facts li::before { content: ""; position: absolute; left: 2px; top: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--yellow) no-repeat center / 10px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2l2.2 2.2 4.8-4.8' fill='none' stroke='%23141414' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); box-shadow: 0 0 0 1.5px var(--ink); }
.intro-link { display: inline-block; margin: 10px 0 0; color: var(--ink); font-size: 13.5px; font-weight: 700; text-underline-offset: 3px; }
.challenge { margin-top: 14px; padding: 12px 14px; border-radius: 16px; background: var(--cream); }
.challenge-row { display: grid; grid-template-columns: 1.6fr 1fr; gap: 10px; }
.challenge small { display: block; font-size: 11px; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.challenge b { font-size: 14.5px; }
.challenge p { margin: 8px 0 0; font-size: 13.5px; line-height: 1.4; }
.challenge .harder { color: #B4441E; font-weight: 700; }
.challenge .harder:empty { display: none; }

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 24px);
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  border-radius: 99px;
  background: var(--ink);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 700px) {
  .title .t2 { font-size: 54px; }
  .tagline { font-size: 13px; margin-top: 8px; }
  .steps li { padding: 8px 4px; font-size: 11px; }
  .steps svg { width: 28px; height: 28px; }
  .sheet { padding-top: 12px; }
  .levels { margin-bottom: 10px; gap: 6px; }
  .level-row img { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .title .t2, .timer.low { animation: none; }
  .result, .card, #banner span, .next-card, .ticket.upgraded, .intro-card { animation-duration: 0.01s; }
}

/* ?poster — renders the 1200×630 share image */
.poster body { background: #fff; }
.poster #app { width: 1200px; height: 630px; max-width: none; box-shadow: none; }
.poster #menu, .poster #hud, .poster #hint, .poster #banner, .poster #toast, .poster #result, .poster #pause { display: none !important; }
