:root {
    color-scheme: light;
    --ink: #31415a;
    --accent: #287f93;
    --page: #e5f6f7;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
    margin: 0;
    color: var(--ink);
    background: radial-gradient(ellipse at top, #fffaf0, var(--page));
    font-family: 'Nunito', 'Trebuchet MS', sans-serif;
    min-height: 100vh;
    min-height: 100dvh;
    touch-action: pan-y;
}
body[data-game="garage"] { --accent: #ad5036; --page: #ffead8; }
body[data-game="garden"] { --accent: #397d50; --page: #e3f2d7; }
body[data-game="painting"] { --accent: #8053aa; --page: #f0e6fa; }
button, a { touch-action: manipulation; }
button { font: inherit; cursor: pointer; color: inherit; }
button, .home {
    border: 2px solid #fff;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 4px 0 #00000012;
    min-width: 48px;
    min-height: 48px;
    font-weight: 800;
    transition: transform .15s, background .15s;
}
button:active, .home:active { transform: translateY(3px); }
button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 4px solid #284f9e; outline-offset: 3px; }
button[aria-pressed="true"] { border-color: var(--accent); background: #fff9dc; }
button:disabled { cursor: default; opacity: .6; }
.topbar {
    max-width: 920px;
    margin: auto;
    padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
}
.home { display: grid; place-items: center; text-decoration: none; font-size: 26px; }
.settings { display: flex; gap: 6px; }
.settings button { padding: 8px; border-radius: 16px; }
.game { width: min(100%, 820px); margin: auto; padding: 8px 16px max(24px, env(safe-area-inset-bottom)); }
.heading { text-align: center; margin: 4px auto 12px; }
h1 { font-size: clamp(1.65rem, 5vw, 2.5rem); margin: 0 0 4px; color: var(--accent); font-weight: 900; }
#instruction { margin: 0; font-size: clamp(1rem, 3vw, 1.2rem); font-weight: 800; min-height: 1.5em; }
.stage {
    position: relative;
    box-sizing: content-box;
    width: calc(100% - 10px);
    max-width: calc(440px * 600 / 380);
    margin-inline: auto;
    aspect-ratio: 600 / 380;
    border: 5px solid white;
    border-radius: 32px;
    overflow: hidden;
    background: #daf1f6;
    box-shadow: 0 10px 0 #00000008, 0 16px 35px #31415a12;
    user-select: none;
}
.stage > svg, .stage > canvas { width: 100%; height: 100%; display: block; }
.rub-area, #paper { touch-action: none; }
.rub-area { cursor: grab; }
.toolbar { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.tool { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 8px 14px; min-width: 76px; }
.tool-icon { font-size: 29px; line-height: 1.2; pointer-events: none; }
.tool-label { font-size: .9rem; max-width: 100%; overflow-wrap: anywhere; }
body[data-game="painting"] .toolbar, body[data-game="wash"] .toolbar { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
body[data-game="painting"] .toolbar .tool, body[data-game="wash"] .toolbar .tool { min-width: 0; padding-inline: 5px; }
.primary { background: var(--accent); color: white; }
.primary[aria-pressed="true"] { background: var(--accent); color: white; }
.palette { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 12px 0 0; }
.palette.road-picker { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.road-picker .tool { min-width: 0; padding-inline: 5px; }
.swatch { width: 50px; height: 50px; border-radius: 50%; background: var(--swatch); padding: 0; border: 4px solid #fff; }
.swatch[aria-pressed="true"] { background: var(--swatch); border-color: var(--ink); box-shadow: inset 0 0 0 3px white; }
.message { text-align: center; font-weight: 800; min-height: 1.5em; margin: 14px 0 0; color: var(--accent); }
.steps { display: flex; justify-content: center; gap: 8px; margin: 10px 0 0; padding: 0; list-style: none; }
.steps li { background: #ffffffb3; padding: 6px 12px; border-radius: 20px; font-weight: 800; font-size: .9rem; }
.steps .done { background: #d3efce; }
.steps .current { outline: 2px solid var(--accent); }
.helper { font-size: .85rem; text-align: center; margin: 12px 0 0; color: #52637a; }
.bubble { pointer-events: none; animation: bubble-rise 1s ease-out forwards; }
.sparkle { pointer-events: none; animation: sparkle 1s ease-out forwards; }
.water { pointer-events: none; opacity: 0; }
.rinsing .water { animation: water .7s ease-out; }
.driving #car-art { animation: cruising 1.8s ease-in-out infinite; transform-box: view-box; transform-origin: center; }
.driving #car-art.hop { animation: hop .7s ease-in-out; }
.driving .garage-backdrop { display: none; }
.drive-backdrop { display: none; }
.driving .drive-backdrop { display: inline; }
.plant-pop { animation: grow .5s ease-out; transform-box: fill-box; transform-origin: bottom; }
.butterfly { animation: flutter 4s ease-in-out infinite alternate; }
.painting-stage { background: white; }
.painting-stage canvas { position: absolute; inset: 0; }
.painting-stage svg { position: absolute; inset: 0; pointer-events: none; }
.play-effect { position: absolute; pointer-events: none; font-size: clamp(22px, 5vw, 38px); z-index: 4; animation: play-pop 1.3s ease-out forwards; }
.scene-button { position: absolute; transform: translate(-50%, -50%); padding: 3px; min-width: 48px; min-height: 48px; border-radius: 50%; background: #ffffffcf; z-index: 3; }
.scene-button .tool-label { display: none; }
.scene-button:active { transform: translate(-50%, -50%) scale(.92); }
.scene-button .tool-icon { font-size: 28px; }
.wiggle { animation: wiggle .65s ease-in-out; transform-box: fill-box; transform-origin: center bottom; }
.hop { animation: hop .7s ease-in-out; transform-box: fill-box; transform-origin: center bottom; }
.floating-toy { animation: bob 2.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.driving .road-lines { animation: road-roll 1.6s linear infinite; }
.driving .road-scenery { animation: scenery-roll 12s linear infinite; }
.stage .rainbow-arch { fill: none; stroke-width: 9; opacity: .65; }
.rain-drops { animation: gentle-rain 1s ease-in-out infinite; }
@keyframes gentle-rain { from { transform: translateY(-12px); opacity: .4; } to { transform: translateY(35px); opacity: .9; } }
@keyframes cruising { 0%, 100% { transform: translateY(0) rotate(-.5deg); } 50% { transform: translateY(-5px) rotate(.5deg); } }
@keyframes road-roll { to { stroke-dashoffset: -140; } }
@keyframes scenery-roll { 50% { transform: translateX(-45px); } }
@keyframes play-pop { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.4) rotate(-15deg); } 20% { opacity: 1; transform: translate(-50%, -65%) scale(1.2) rotate(10deg); } 100% { opacity: 0; transform: translate(-50%, -150%) scale(.7); } }
@keyframes wiggle { 20%, 60% { transform: rotate(-6deg); } 40%, 80% { transform: rotate(6deg); } }
@keyframes hop { 40% { transform: translateY(-22px) scale(1.04); } 70% { transform: translateY(2px) scale(.98); } }
@keyframes bob { 50% { transform: translateY(-7px) rotate(5deg); } }
@keyframes bubble-rise { to { transform: translateY(-35px); opacity: 0; } }
@keyframes sparkle { to { transform: translateY(-25px) scale(1.15); opacity: 0; } }
@keyframes water { 20%, 70% { opacity: .8; } 100% { opacity: 0; } }
@keyframes grow { from { transform: scale(.8); } to { transform: scale(1); } }
@keyframes flutter { to { transform: translate(18px, -12px) rotate(8deg); } }
@media (max-width: 420px) {
    .game { padding-inline: 10px; }
    .topbar { padding-inline: 10px; }
    .stage { border-radius: 24px; }
    .toolbar { gap: 7px; }
    .tool { min-width: 65px; padding: 7px 9px; }
    .tool-label { font-size: .8rem; }
    .steps li { padding: 5px 9px; }
}
@media (orientation: landscape) and (max-height: 600px) {
    .topbar { padding-top: 8px; }
    .heading { margin: 2px auto 10px; min-height: 48px; }
    h1 { font-size: 1.6rem; }
    #instruction { font-size: .95rem; }
    .stage { width: min(calc(100% - 10px), calc(245px * 600 / 380)); margin: auto; }
    .toolbar { margin-top: 12px; }
}
@media (orientation: landscape) and (min-width: 600px) and (max-height: 600px) {
    .game { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 8px 12px; }
    .heading { grid-column: 1 / -1; margin: 0; }
    .stage { grid-column: 1; grid-row: 2 / span 3; width: min(calc(100% - 10px), calc(245px * 600 / 380)); align-self: start; }
    .palette { grid-column: 2; grid-row: 2; margin: 0; gap: 4px; align-content: start; }
    .swatch { width: 48px; height: 48px; }
    .toolbar { grid-column: 2; grid-row: 3; margin: 0; gap: 6px; align-content: start; }
    .tool { min-width: 68px; padding: 5px 8px; }
    .tool-icon { font-size: 25px; }
    .steps { grid-column: 2; grid-row: 2; margin: 0; align-self: start; }
    body[data-game="garden"] .palette { grid-row: 3; }
    body[data-game="garden"] .toolbar { grid-row: 4; }
    .message { grid-column: 1 / -1; grid-row: 5; margin-top: 4px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
