:root {
  --ink: #3b2414; --sun: #ffd23f; --pink: #ff6fa8; --sky: #5fb8ff; --card: #fffaf0; --muted: #8a6a52;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #bfe6ff; color: var(--ink); font-family: 'Baloo 2', system-ui, sans-serif; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; border: 0; color: inherit; }

#loading { position: fixed; inset: 0; display: grid; place-items: center; background: #bfe6ff; font-size: 24px; font-weight: 700; z-index: 50; padding: 24px; text-align: center; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b)); z-index: 20; overflow-y: auto; }
.overlay { background: rgba(30, 60, 90, 0.45); backdrop-filter: blur(3px); }
.logo { margin: 0; font-size: clamp(44px, 9vw, 92px); font-weight: 800; line-height: 0.95; color: #fff; text-align: center;
  text-shadow: 0 4px 0 #ff6fa8, 0 8px 0 #c2407a, 0 12px 18px rgba(0, 0, 0, 0.25); letter-spacing: 1px; }
.logo span { color: var(--sun); text-shadow: 0 4px 0 #e0a100, 0 8px 0 #a86f00, 0 12px 18px rgba(0, 0, 0, 0.25); }
.tag { margin: 0 0 6px; font-size: clamp(15px, 2.4vw, 20px); font-weight: 700; color: #fff; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.35); text-align: center; }
.help { max-width: 560px; margin: 4px 0 0; font-size: 13px; color: #fff; text-align: center; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }
@media (pointer: coarse) { .help { display: none; } }

.card { width: min(380px, 100%); background: var(--card); border-radius: 24px; padding: 18px 20px 20px; box-shadow: 0 10px 0 rgba(0, 0, 0, 0.08), 0 18px 40px rgba(0, 0, 0, 0.18); display: flex; flex-direction: column; gap: 10px; }
.card h2 { margin: 0; font-size: 26px; text-align: center; }
.card p { margin: 0; text-align: center; line-height: 1.4; }
.hello { font-size: 22px; }
.stats { font-weight: 800; font-size: 20px; color: #c2407a; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: #f3e6d0; border-radius: 14px; padding: 4px; }
.tabs button { padding: 8px; border-radius: 10px; background: transparent; font-weight: 700; font-size: 17px; color: var(--muted); }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08); }
form { display: flex; flex-direction: column; gap: 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: 15px; }
input { font: inherit; font-size: 18px; padding: 10px 14px; border-radius: 14px; border: 2px solid #ecd9bb; background: #fff; color: var(--ink); outline: none; }
input:focus { border-color: var(--pink); }
.err { color: #d32f2f; min-height: 1.2em; font-size: 14px; font-weight: 600; text-align: center; margin: 0; }
.big { background: var(--pink); color: #fff; font-size: 21px; font-weight: 800; padding: 12px 18px; border-radius: 18px; box-shadow: 0 5px 0 #c2407a; transition: transform 0.08s; }
.big:active { transform: translateY(4px); box-shadow: 0 1px 0 #c2407a; }
.big:disabled { opacity: 0.6; }
.ghost { background: #f3e6d0; font-weight: 700; font-size: 17px; padding: 10px 14px; border-radius: 14px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button { pointer-events: auto; }
.tl { position: absolute; top: calc(10px + var(--safe-t)); left: calc(12px + var(--safe-l)); display: flex; flex-direction: column; gap: 6px; }
#hearts { display: flex; gap: 4px; }
.h { width: 28px; height: 26px; display: inline-block; background: rgba(0, 0, 0, 0.25);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 22'%3E%3Cpath d='M12 21S1 14 1 7a5.5 5.5 0 0 1 11-1 5.5 5.5 0 0 1 11 1c0 7-11 14-11 14z'/%3E%3C/svg%3E") center/contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 22'%3E%3Cpath d='M12 21S1 14 1 7a5.5 5.5 0 0 1 11-1 5.5 5.5 0 0 1 11 1c0 7-11 14-11 14z'/%3E%3C/svg%3E") center/contain no-repeat; }
.h.on { background: #ff4d6d; }
.chips { display: flex; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: rgba(255, 250, 240, 0.92); border-radius: 999px; padding: 2px 12px 2px 6px; font-size: 17px; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1); }
.ic { width: 20px; height: 20px; display: inline-block; }
.ic.star { background: #ffc93c; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.ic.pearl { border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff, #f6d6ee 60%, #d9a8cf); }
.mission { position: absolute; top: calc(10px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; max-width: min(56vw, 520px);
  background: rgba(255, 250, 240, 0.94); border-radius: 999px; padding: 6px 16px 6px 8px; font-weight: 700; font-size: 16px; line-height: 1.2; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1); }
#arrow { width: 30px; height: 30px; flex: none; border-radius: 50%; background: var(--sun); position: relative; transition: transform 0.2s; }
#arrow::after { content: ''; position: absolute; left: 8px; top: 5px; border: 7px solid transparent; border-bottom: 14px solid var(--ink); border-top: 0; }
.pauseBtn { position: absolute; top: calc(10px + var(--safe-t)); right: calc(12px + var(--safe-r)); width: 48px; height: 48px; border-radius: 16px; background: rgba(255, 250, 240, 0.94); display: flex; gap: 7px; align-items: center; justify-content: center; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1); }
.pauseBtn i { width: 7px; height: 20px; border-radius: 3px; background: var(--ink); }
#boss { position: absolute; top: calc(62px + var(--safe-t)); left: 50%; transform: translateX(-50%); width: min(420px, 70vw); text-align: center; font-weight: 800; color: #fff; text-shadow: 0 2px 3px rgba(0, 0, 0, 0.5); }
#boss .bar { height: 14px; border-radius: 999px; background: rgba(0, 0, 0, 0.35); overflow: hidden; border: 2px solid #fff; }
#bossFill { height: 100%; width: 100%; background: linear-gradient(90deg, #ff6fa8, #ffd23f); transition: width 0.2s; }
#banner { position: absolute; top: 26%; left: 50%; transform: translate(-50%, -20px) scale(0.9); opacity: 0; text-align: center; color: #fff; transition: opacity 0.35s, transform 0.35s; width: 90vw; }
#banner.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
#banner b { display: block; font-size: clamp(30px, 6vw, 56px); font-weight: 800; text-shadow: 0 4px 0 #c2407a, 0 8px 16px rgba(0, 0, 0, 0.3); }
#banner span { font-size: clamp(16px, 2.6vw, 22px); font-weight: 700; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5); }
#say { position: absolute; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translate(-50%, 20px); opacity: 0; display: flex; align-items: center; gap: 10px; background: #fffaf0; border-radius: 22px; padding: 8px 18px 8px 10px; max-width: min(560px, 92vw); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1); transition: opacity 0.3s, transform 0.3s; }
#say.show { opacity: 1; transform: translate(-50%, 0); }
#say p { margin: 0; font-weight: 600; font-size: 16px; line-height: 1.3; }
#toast { position: absolute; left: 50%; top: 40%; transform: translateX(-50%); background: rgba(59, 36, 20, 0.85); color: #fff; padding: 6px 14px; border-radius: 12px; font-weight: 600; opacity: 0; transition: opacity 0.2s; }
#toast.show { opacity: 1; }
.chick { width: 40px; height: 40px; flex: none; border-radius: 50%; background: #fbe48a; position: relative; display: inline-block; box-shadow: inset -4px -4px 0 #f2d067; }
.chick::before { content: ''; position: absolute; left: 11px; top: 14px; width: 5px; height: 6px; border-radius: 50%; background: #5a1818; box-shadow: 13px 0 0 #5a1818; }
.chick::after { content: ''; position: absolute; left: 15px; top: 21px; width: 10px; height: 7px; border-radius: 50%; background: #f4a07a; }

/* Touch controls */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 11; }
#joy { position: absolute; left: 0; top: 0; width: 130px; height: 130px; border-radius: 50%; background: rgba(255, 255, 255, 0.25); border: 3px solid rgba(255, 255, 255, 0.6); opacity: 0; transition: opacity 0.15s; }
#joy.on { opacity: 1; }
#knob { position: absolute; left: 37px; top: 37px; width: 56px; height: 56px; border-radius: 50%; background: rgba(255, 255, 255, 0.85); }
.tb { position: absolute; pointer-events: auto; border-radius: 50%; display: grid; place-items: center; touch-action: none; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.18); user-select: none; -webkit-user-select: none; }
.tb svg { width: 52%; height: 52%; fill: #fff; }
.tb.down { transform: translateY(3px) scale(0.95); }
.tb.sword { width: 88px; height: 88px; right: calc(22px + var(--safe-r)); bottom: calc(26px + var(--safe-b)); background: #ffb300; }
.tb.jump { width: 74px; height: 74px; right: calc(122px + var(--safe-r)); bottom: calc(18px + var(--safe-b)); background: var(--sky); }
.tb.lemon { width: 70px; height: 70px; right: calc(34px + var(--safe-r)); bottom: calc(128px + var(--safe-b)); background: #fff3bd; --cd: 0; }
.tb.lemon::after { content: ''; position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(rgba(60, 40, 20, 0.55) calc(var(--cd) * 360deg), transparent 0); }
body.playing #say { bottom: calc(18px + var(--safe-b)); }
@media (pointer: coarse) { body.playing #say { left: 45%; bottom: auto; top: calc(96px + var(--safe-t)); } .mission { font-size: 14px; max-width: 52vw; } }

#fade { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity 0.5s; z-index: 30; display: grid; place-items: center; }
#fade.on { opacity: 1; pointer-events: auto; }
#fade p { font-size: 24px; font-weight: 800; color: var(--ink); text-align: center; padding: 20px; }
#rotate { display: none; }
@media (pointer: coarse) and (orientation: portrait) {
  body.playing #rotate { position: fixed; inset: 0; z-index: 40; background: #bfe6ff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; font-size: 22px; font-weight: 800; text-align: center; padding: 24px; }
  body.playing #rotate .chick { width: 90px; height: 90px; animation: tilt 1.6s ease-in-out infinite; }
}
@keyframes tilt { 50% { transform: rotate(-90deg); } }
