:root {
  --ink: #2b2540;
  --paper: #fffaf0;
  --accent: #ff6b4a;
  --accent-2: #ffd23f;
  --blue: #3a6ee8;
  --shadow: 0 6px 0 rgba(43, 37, 64, 0.25);
  --font: "Trebuchet MS", "Avenir Next Rounded", "Nunito", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #9fd6f4; font-family: var(--font); color: var(--ink); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font-family: var(--font); font-weight: 700; font-size: 16px; color: var(--ink); background: var(--paper); border: 3px solid var(--ink); border-radius: 14px; padding: 10px 18px; cursor: pointer; box-shadow: var(--shadow); transition: transform .08s; }
button:hover { transform: translateY(-2px); }
button:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(43,37,64,.25); }
button.big { background: var(--accent); color: #fff; font-size: 20px; padding: 12px 28px; }
button.linkish { background: none; border: none; box-shadow: none; font-size: 13px; text-decoration: underline; opacity: .6; margin-top: 12px; padding: 4px 8px; }
button.linkish:hover { opacity: 1; transform: none; }
button.toggle.off { opacity: .45; text-decoration: line-through; }
.label { font-size: 12px; font-weight: 800; letter-spacing: .12em; opacity: .7; }
.small { font-size: 14px; opacity: .75; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(43, 37, 64, 0.28); z-index: 20; }
#screen-loading, #screen-title { background: linear-gradient(180deg, rgba(159,214,244,.55), rgba(127,207,110,.55)); }
.panel { background: var(--paper); border: 4px solid var(--ink); border-radius: 24px; padding: 24px 28px; max-width: 560px; width: 100%; box-shadow: 0 10px 0 rgba(43,37,64,.3); max-height: calc(100vh - 32px); overflow-y: auto; }
.center { text-align: center; }
.logo { font-size: clamp(44px, 9vw, 76px); margin: 0; line-height: 1; letter-spacing: -0.02em; color: var(--accent); text-shadow: 3px 3px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink); transform: rotate(-2deg); }
.tag { font-size: 18px; margin: 10px 0 18px; }
h2 { margin: 6px 0 10px; font-size: 28px; }
.loadbar { height: 16px; border: 3px solid var(--ink); border-radius: 10px; overflow: hidden; margin: 20px auto 8px; max-width: 320px; }
#load-fill { height: 100%; width: 0; background: var(--accent-2); transition: width .2s; }

#level-list { display: grid; gap: 8px; margin: 6px 0 14px; }
#diff-row { display: flex; gap: 8px; justify-content: center; margin: 6px 0 6px; }
.diff-btn { width: 46px; height: 46px; padding: 0; font-size: 20px; border-radius: 12px; }
.diff-btn.on { background: var(--accent); color: #fff; transform: translateY(-2px); }
.diff-btn:nth-child(1).on { background: #3fae5a; } .diff-btn:nth-child(2).on { background: #7cbf3a; }
.diff-btn:nth-child(3).on { background: #f0a020; } .diff-btn:nth-child(4).on { background: #ff6b4a; } .diff-btn:nth-child(5).on { background: #d62a4a; }
#diff-desc { font-size: 14px; margin-bottom: 14px; min-height: 20px; }
.errand-btn .num { font-size: 15px; font-weight: 900; opacity: .5; width: 14px; }
.errand-btn.locked { opacity: .5; cursor: not-allowed; transform: none; }
.intro-diff { font-size: 14px; font-weight: 800; color: var(--blue); margin: -8px 0 16px; }
.errand-btn { display: flex; align-items: center; gap: 12px; text-align: left; width: 100%; padding: 12px 14px; }
.errand-btn .emoji { font-size: 30px; }
.errand-btn .t { font-size: 17px; }
.errand-btn .s { font-size: 13px; font-weight: 600; opacity: .7; }
.errand-btn .stars { margin-left: auto; font-size: 18px; white-space: nowrap; }
.controls-help { font-size: 13px; line-height: 1.6; opacity: .8; margin-top: 4px; }

.intro p { font-size: 17px; line-height: 1.45; }
.intro-meta { display: flex; justify-content: center; gap: 22px; margin: 6px 0 18px; font-size: 17px; flex-wrap: wrap; }

#end-stars { font-size: 44px; letter-spacing: 6px; margin: 6px 0; }
#end-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
#end-stats div { background: #f2ecdf; border-radius: 12px; padding: 8px 4px; }
#end-stats b { display: block; font-size: 22px; }
#end-rank { font-size: 18px; font-weight: 800; color: var(--blue); }
#end-line { font-size: 17px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left)); }
#errand-card { position: absolute; left: 12px; top: 12px; background: var(--paper); border: 3px solid var(--ink); border-radius: 14px; padding: 8px 12px; box-shadow: var(--shadow); max-width: min(300px, 40vw); }
#errand-title { font-weight: 800; font-size: 15px; }
#errand-dest { font-size: 13px; opacity: .8; }
#timer-wrap { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
#timer { font-size: 34px; font-weight: 900; background: var(--paper); border: 3px solid var(--ink); border-radius: 14px; padding: 2px 16px; box-shadow: var(--shadow); font-variant-numeric: tabular-nums; }
#timer.urgent { background: var(--accent); color: #fff; animation: pulse .5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); } }
#compass { width: 40px; height: 40px; border-radius: 50%; background: var(--paper); border: 3px solid var(--ink); display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow); }
#compass-arrow { color: var(--accent); font-size: 20px; line-height: 1; }
#right-col { position: absolute; right: 12px; top: 12px; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
#meter { background: var(--paper); border: 3px solid var(--ink); border-radius: 14px; padding: 6px 10px; width: 170px; box-shadow: var(--shadow); }
#meter .label { display: flex; justify-content: space-between; align-items: center; font-size: 11px; opacity: 1; }
#meter-face { font-size: 18px; }
#meter .bar { height: 12px; border: 2px solid var(--ink); border-radius: 8px; overflow: hidden; margin-top: 4px; background: #eee; }
#meter-fill { height: 100%; width: 0; background: linear-gradient(90deg, #ffd23f, #ff6b4a 70%, #d62a4a); transition: width .25s; }
#meter.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-5px) rotate(-2deg); } 75% { transform: translateX(5px) rotate(2deg); } }
#score-box { background: var(--paper); border: 3px solid var(--ink); border-radius: 14px; padding: 4px 10px; width: 170px; box-shadow: var(--shadow); display: flex; align-items: baseline; gap: 6px; }
#score-box .label { opacity: .7; font-size: 11px; }
#score { font-size: 20px; font-variant-numeric: tabular-nums; }
#streak { margin-left: auto; font-weight: 900; color: var(--accent); font-size: 14px; }
#score-box.pop { animation: scorepop .25s; }
@keyframes scorepop { 50% { transform: scale(1.08); } }
.float.pts { font-size: 18px; }
#score-total { margin: -2px 0 8px; font-weight: 700; }
#end-score { background: #f2ecdf; border-radius: 14px; padding: 8px 12px; margin: 8px 0; }
#end-score-num { font-size: 40px; font-weight: 900; color: var(--accent); line-height: 1.1; font-variant-numeric: tabular-nums; }
#end-new { font-weight: 800; font-size: 14px; margin-bottom: 6px; opacity: .8; }
#end-new.hot { color: #d62a4a; opacity: 1; animation: pulse .5s infinite alternate; }
#end-score-lines { font-size: 13px; text-align: left; }
#end-score-lines div { display: flex; justify-content: space-between; padding: 2px 0; border-top: 1px dashed rgba(43,37,64,.15); }
#end-score-lines .mult b { color: var(--blue); }
#minimap { width: 150px; height: 150px; border-radius: 50%; border: 3px solid var(--ink); box-shadow: var(--shadow); background: #7fcf6e; }
#hint { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); background: rgba(43,37,64,.82); color: #fff; padding: 8px 14px; border-radius: 12px; font-size: 14px; white-space: nowrap; transition: opacity .6s; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; }
#pause-btn { position: absolute; left: 12px; bottom: 12px; pointer-events: auto; padding: 6px 12px; font-size: 14px; }

/* ---------- speech bubbles & floating text ---------- */
#bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 11; overflow: hidden; }
.bubble { position: absolute; transform: translate(-50%, -100%); background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 5px 10px; font-weight: 800; font-size: 15px; white-space: nowrap; box-shadow: 0 3px 0 rgba(43,37,64,.25); animation: pop .18s ease-out; max-width: 260px; }
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -10px; transform: translateX(-50%); border: 7px solid transparent; border-top-color: var(--ink); }
.bubble.player { background: #fff6c9; }
.bubble.thought { font-style: italic; font-weight: 600; background: #f3f0ff; border-style: dashed; }
.bubble.alert { background: var(--accent-2); font-size: 22px; padding: 0 9px; border-radius: 50%; }
@keyframes pop { from { transform: translate(-50%, -100%) scale(.4); } to { transform: translate(-50%, -100%) scale(1); } }
.float { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 22px; color: #fff; text-shadow: 2px 2px 0 var(--ink), -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink); animation: rise 1.2s ease-out forwards; white-space: nowrap; }
.float.good { color: #7ef08a; }
.float.bad { color: #ff8a6a; }
@keyframes rise { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -60px; } }

/* ---------- touch ---------- */
#touch-ui { position: fixed; inset: 0; pointer-events: none; z-index: 12; }
#stick { position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 3px solid rgba(255,255,255,.8); background: rgba(43,37,64,.2); display: none; }
#stick-knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(255,255,255,.9); border: 3px solid var(--ink); }
#hurry-btn { position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: max(24px, env(safe-area-inset-bottom)); width: 92px; height: 92px; border-radius: 50%; pointer-events: auto; background: var(--accent); color: #fff; font-size: 16px; padding: 0; touch-action: none; }
#hurry-btn.on { transform: scale(.92); background: #e04a2a; }
#jump-btn { position: absolute; right: max(124px, calc(env(safe-area-inset-right) + 106px)); bottom: max(34px, calc(env(safe-area-inset-bottom) + 10px)); width: 72px; height: 72px; border-radius: 50%; pointer-events: auto; background: var(--blue); color: #fff; font-size: 14px; padding: 0; touch-action: none; }

@media (max-width: 640px) {
  #errand-card { max-width: 34vw; padding: 5px 7px; left: 8px; top: 8px; }
  #timer-wrap { top: 8px; }
  #right-col { right: 8px; top: 8px; }
  #errand-title { font-size: 12px; }
  #errand-dest { font-size: 11px; }
  #timer { font-size: 22px; padding: 0 8px; }
  #meter { width: 108px; padding: 4px 7px; }
  #score-box { width: 108px; padding: 2px 7px; }
  #score { font-size: 15px; }
  #score-box .label { display: none; }
  #meter .label { font-size: 9px; }
  #minimap { width: 104px; height: 104px; }
  #compass { width: 32px; height: 32px; }
  .panel { padding: 18px 16px; }
  .bubble { font-size: 13px; }
  #hint { font-size: 12px; bottom: 130px; white-space: normal; text-align: center; }
}
