:root {
  --bg: #fff8ef; --ink: #4a3d44; --muted: #9a8b8f; --line: #f0dfcc;
  --accent: #ff8a5c; --accent-d: #e86a3a; --teal: #3fb8a9; --gold: #f2b632;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --shadow: 0 6px 20px rgba(90, 50, 30, .18);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #f3d7bd; color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif; user-select: none; -webkit-user-select: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#top { position: absolute; top: calc(10px + var(--sat)); left: 12px; right: 12px; display: flex; gap: 8px; align-items: center; pointer-events: none; }
#top > * { pointer-events: auto; }
.spacer { flex: 1; pointer-events: none !important; }
.chip { background: var(--bg); border-radius: 999px; padding: 8px 14px; box-shadow: var(--shadow); font-weight: 700; display: flex; align-items: center; gap: 8px; font-size: 15px; }
#lvl .xp { width: 84px; height: 9px; background: var(--line); border-radius: 9px; overflow: hidden; }
#lvl .xp i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--teal), #7fdccd); border-radius: 9px; transition: width .4s; }
.round { width: 40px; height: 40px; border-radius: 50%; background: var(--bg); box-shadow: var(--shadow); font-size: 17px; display: grid; place-items: center; }

#needs { position: absolute; top: calc(60px + var(--sat)); left: 12px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.need { display: flex; align-items: center; gap: 6px; background: rgba(255, 248, 239, .9); border-radius: 999px; padding: 4px 10px 4px 6px; box-shadow: 0 3px 10px rgba(90, 50, 30, .12); font-size: 14px; }
.need .bar { width: 64px; height: 8px; background: var(--line); border-radius: 8px; overflow: hidden; }
.need .bar i { display: block; height: 100%; background: var(--teal); border-radius: 8px; transition: width .5s, background .5s; }
.need.low .bar i { background: #f06a5a; }
.need.low { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

#bar { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 10px calc(10px + var(--sab)); display: flex; gap: 8px; justify-content: center; overflow-x: auto; scrollbar-width: none; }
#bar::-webkit-scrollbar { display: none; }
#bar button { flex: 0 0 auto; min-width: 64px; background: var(--bg); border-radius: 18px; padding: 8px 8px 7px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11.5px; font-weight: 700; transition: transform .12s; }
#bar button span { font-size: 25px; line-height: 1.1; }
#bar button:active { transform: scale(.92); }
#bar button.locked { opacity: .6; }
@media (max-width: 560px) { #bar { justify-content: flex-start; } }

#hint { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(22px + var(--sab)); background: var(--bg); border-radius: 999px; padding: 8px 8px 8px 18px; box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center; font-weight: 700; font-size: 14px; max-width: calc(100vw - 24px); }
#hint button, #car-exit, .btn { background: var(--accent); color: #fff; border-radius: 999px; padding: 9px 18px; font-weight: 800; box-shadow: 0 3px 0 var(--accent-d); white-space: nowrap; }
#hint button:active, #car-exit:active, .btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--accent-d); }
.btn.ghost { background: var(--line); color: var(--ink); box-shadow: 0 3px 0 #dcc8b0; }
.btn.teal { background: var(--teal); box-shadow: 0 3px 0 #2c9a8c; }
.btn:disabled { opacity: .5; }

#carhud { position: absolute; top: calc(60px + var(--sat)); right: 12px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
#joy { position: absolute; left: 26px; bottom: calc(30px + var(--sab)); width: 132px; height: 132px; border-radius: 50%; background: rgba(255, 248, 239, .55); border: 3px solid rgba(255, 255, 255, .8); touch-action: none; }
#joy i { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px; border-radius: 50%; background: var(--accent); box-shadow: 0 4px 0 var(--accent-d); }
#keys { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(24px + var(--sab)); background: rgba(255, 248, 239, .85); padding: 8px 16px; border-radius: 999px; font-size: 13px; font-weight: 700; }
@media (hover: none) { #keys { display: none !important; } }

#decor { position: absolute; left: 10px; right: 10px; bottom: calc(10px + var(--sab)); background: var(--bg); border-radius: 22px; box-shadow: var(--shadow); padding: 10px 12px; }
#decor .row { display: flex; gap: 8px; overflow-x: auto; align-items: center; padding-bottom: 2px; scrollbar-width: none; }
#decor .lab { font-size: 12px; font-weight: 700; color: var(--muted); margin: 0 0 6px 2px; }
#decor .dchip { flex: 0 0 auto; background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 6px 10px; font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 5px; }
#decor .dchip.on { border-color: var(--teal); background: #e9f8f5; }
#decor .dchip span { font-size: 20px; }
#decor .sep { flex: 0 0 1px; height: 30px; background: var(--line); }
#decor .grow { flex: 1; }

#bubble { position: fixed; left: 0; top: 0; background: #fff; border-radius: 50%; width: 44px; height: 44px; display: grid; place-items: center; font-size: 22px; box-shadow: var(--shadow); pointer-events: none; transform: translate(-50%, -100%); animation: bob 1.6s ease-in-out infinite; }
#bubble::after { content: ""; position: absolute; bottom: -5px; left: 50%; margin-left: -6px; border: 6px solid transparent; border-top-color: #fff; border-bottom: 0; }
@keyframes bob { 50% { margin-top: -6px; } }
#fx { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
#fx span { position: absolute; font-size: 26px; font-weight: 800; color: var(--accent-d); text-shadow: 0 2px 0 #fff; animation: floatup 1.1s ease-out forwards; white-space: nowrap; }
@keyframes floatup { from { transform: translate(-50%, -50%) scale(.6); opacity: 0; } 20% { opacity: 1; transform: translate(-50%, -80%) scale(1.15); } to { transform: translate(-50%, -260%) scale(1); opacity: 0; } }

#toasts { position: fixed; top: calc(62px + var(--sat)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 150px); z-index: 30; }
.toast { background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 16px; font-size: 14px; font-weight: 700; box-shadow: var(--shadow); animation: toast 3.2s forwards; text-align: center; }
@keyframes toast { from { transform: translateY(-12px); opacity: 0; } 8%, 85% { transform: none; opacity: 1; } to { opacity: 0; transform: translateY(-8px); } }

#sheet { position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: min(600px, 100vw); max-height: 66vh; background: var(--bg); border-radius: 26px 26px 0 0; box-shadow: 0 -8px 30px rgba(90, 50, 30, .25); display: flex; flex-direction: column; padding-bottom: var(--sab); animation: up .22s ease-out; z-index: 20; }
@keyframes up { from { transform: translate(-50%, 40%); opacity: 0; } }
#sheet header { display: flex; align-items: center; padding: 14px 14px 6px 20px; }
#sheet h2 { margin: 0; flex: 1; font-size: 20px; }
#sheet .round { box-shadow: none; background: var(--line); width: 34px; height: 34px; font-size: 14px; }
#sheet-tabs { display: flex; gap: 6px; padding: 4px 14px 8px; overflow-x: auto; scrollbar-width: none; }
#sheet-tabs:empty { display: none; }
#sheet-tabs button { flex: 0 0 auto; background: var(--line); border-radius: 999px; padding: 7px 14px; font-weight: 700; font-size: 13px; }
#sheet-tabs button.on { background: var(--ink); color: #fff; }
#sheet-b { overflow-y: auto; padding: 6px 14px 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.card { background: #fff; border: 2px solid var(--line); border-radius: 18px; padding: 10px 6px 9px; display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center; position: relative; transition: transform .1s; min-height: 108px; }
.card:active { transform: scale(.95); }
.card .ic { font-size: 34px; line-height: 1.15; }
.card .nm { font-size: 12.5px; font-weight: 800; line-height: 1.2; }
.card .sub { font-size: 11.5px; font-weight: 700; color: var(--muted); }
.card .price { font-size: 12.5px; font-weight: 800; color: #b07a10; background: #fff3d1; border-radius: 999px; padding: 2px 9px; margin-top: auto; }
.card.locked { opacity: .55; }
.card.poor .price { background: #fde3df; color: #c0463a; }
.card.on { border-color: var(--teal); background: #e9f8f5; }
.card .badge { position: absolute; top: 5px; right: 7px; font-size: 11.5px; font-weight: 800; background: var(--ink); color: #fff; border-radius: 999px; padding: 1px 7px; }
.note { font-size: 13px; color: var(--muted); font-weight: 600; margin: 10px 4px 2px; }
.rowbtns { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.trick { display: flex; align-items: center; gap: 12px; background: #fff; border: 2px solid var(--line); border-radius: 18px; padding: 10px 12px; margin-bottom: 8px; }
.trick .ic { font-size: 28px; }
.trick .mid { flex: 1; min-width: 0; }
.trick .nm { font-weight: 800; font-size: 15px; }
.trick .prog { height: 8px; background: var(--line); border-radius: 8px; overflow: hidden; margin-top: 6px; }
.trick .prog i { display: block; height: 100%; background: var(--gold); }
.trick .sub { font-size: 12px; color: var(--muted); font-weight: 700; }
.trick .btn { padding: 8px 14px; font-size: 13px; }

#overlay { position: fixed; left: 50%; bottom: calc(14px + var(--sab)); transform: translateX(-50%); width: min(460px, calc(100vw - 20px)); background: var(--bg); border-radius: 24px; box-shadow: var(--shadow); padding: 16px; z-index: 25; text-align: center; }
#overlay h3 { margin: 0 0 4px; font-size: 18px; }
#overlay .sub { font-size: 13px; color: var(--muted); font-weight: 700; min-height: 18px; }
.timing { position: relative; height: 26px; background: var(--line); border-radius: 13px; margin: 12px 0; overflow: hidden; }
.timing .zone { position: absolute; top: 0; bottom: 0; background: #9be0b0; }
.timing .zone::after { content: ""; position: absolute; left: 33%; right: 33%; top: 0; bottom: 0; background: #4cc47a; }
.timing .mark { position: absolute; top: -2px; bottom: -2px; width: 6px; margin-left: -3px; background: var(--ink); border-radius: 3px; }
.prog2 { height: 10px; background: var(--line); border-radius: 10px; overflow: hidden; margin: 8px 0 2px; }
.prog2 i { display: block; height: 100%; background: var(--gold); transition: width .3s; }
.prompt { font-size: 44px; line-height: 1.1; margin: 4px 0 0; }
.pname { font-size: 20px; font-weight: 800; }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.choices button { background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 8px 4px; font-weight: 800; font-size: 12.5px; display: flex; flex-direction: column; align-items: center; }
.choices button span { font-size: 24px; }
.choices button:active { transform: scale(.94); }
.timer { height: 8px; background: var(--line); border-radius: 8px; overflow: hidden; margin-top: 10px; }
.timer i { display: block; height: 100%; background: var(--accent); }

#modal { position: fixed; inset: 0; background: rgba(60, 35, 25, .45); display: grid; place-items: center; z-index: 40; padding: 20px; }
#modal .mcard { background: var(--bg); border-radius: 28px; padding: 24px 22px 20px; text-align: center; max-width: 360px; width: 100%; box-shadow: var(--shadow); animation: popin .3s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes popin { from { transform: scale(.7); opacity: 0; } }
#modal .big { font-size: 54px; line-height: 1.1; }
#modal h3 { margin: 6px 0; font-size: 22px; }
#modal p { margin: 4px 0 16px; font-size: 14.5px; font-weight: 600; color: #6d5d63; line-height: 1.45; }

#fade { position: fixed; inset: 0; background: #fff8ef; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 35; }
#fade.on { opacity: 1; }

#title { position: fixed; inset: 0; background: linear-gradient(160deg, #ffe3c7, #f7c6a8 60%, #f2ab94); display: grid; place-items: center; z-index: 50; padding: 20px; transition: opacity .5s; }
#title.out { opacity: 0; pointer-events: none; }
.tcard { text-align: center; display: flex; flex-direction: column; align-items: center; }
.tcard img { width: 190px; height: 190px; border-radius: 50%; object-fit: cover; object-position: 50% 22%; border: 7px solid #fff; box-shadow: var(--shadow); }
.tcard h1 { font-size: 58px; margin: 16px 0 0; letter-spacing: -1px; color: #5a3d3a; }
.tcard p { margin: 4px 0 22px; font-weight: 700; color: #8a5d50; }
#start { background: var(--accent); color: #fff; font-size: 21px; font-weight: 800; padding: 15px 38px; border-radius: 999px; box-shadow: 0 5px 0 var(--accent-d); }
#start:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--accent-d); }
#start:disabled { opacity: .6; }
.link { background: none; margin-top: 18px; font-size: 12.5px; color: #a07868; text-decoration: underline; font-weight: 600; }

#map { width: 132px; height: 132px; border-radius: 50%; border: 4px solid var(--bg); box-shadow: var(--shadow); background: #7fb35c; }
@media (max-width: 560px) { #map { width: 104px; height: 104px; } }

.tcard .credit { font-size: 11px; font-weight: 600; color: #a07868; max-width: 300px; margin: 14px 0 0; line-height: 1.4; }

#photobar { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(22px + var(--sab)); display: flex; gap: 10px; }
#flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 45; }
#flash.on { animation: flash .45s ease-out; }
@keyframes flash { from { opacity: .9; } to { opacity: 0; } }
#boost { position: relative; background: #3f7fe0; color: #fff; border-radius: 999px; padding: 9px 18px; font-weight: 800; box-shadow: 0 3px 0 #2a5fb5; overflow: hidden; touch-action: none; }
#boost i { position: absolute; left: 0; bottom: 0; height: 4px; width: 100%; background: #ffd84a; transform-origin: left; }
#boost.empty { opacity: .55; }
.quest { display: flex; align-items: center; gap: 12px; background: #fff; border: 2px solid var(--line); border-radius: 18px; padding: 12px; margin-bottom: 8px; }
.quest .mid { flex: 1; min-width: 0; }
.quest .nm { font-weight: 800; font-size: 14px; }
.quest .prog { height: 8px; background: var(--line); border-radius: 8px; overflow: hidden; margin-top: 7px; }
.quest .prog i { display: block; height: 100%; background: var(--teal); }
.quest .sub { font-size: 12px; color: var(--muted); font-weight: 700; margin-top: 3px; }
.quest.done { border-color: var(--teal); background: #e9f8f5; }
.quest .btn { padding: 8px 14px; font-size: 13px; }

#ctrlbar { position: absolute; right: 14px; bottom: calc(26px + var(--sab)); display: flex; flex-direction: column; gap: 9px; align-items: flex-end; }
