:root {
  --ink: #3a2128;
  --cream: #fff6e8;
  --cream2: #ffe9cf;
  --pink: #ff7aa2;
  --pink-d: #d9467a;
  --wood: #8a5232;
  --wood-d: #5b3220;
  --gold: #ffc94a;
  --mint: #6ed3a8;
  --sky: #6cc6ff;
  --bg: #2a1a20;
  --font: 'DotGothic16', ui-monospace, 'Courier New', monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg);
  font-family: var(--font); color: var(--ink);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
canvas#game { position: fixed; inset: 0; touch-action: none; display: block; }
.hidden { display: none !important; }
button { font-family: var(--font); cursor: pointer; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: calc(8px + env(safe-area-inset-top)); left: 8px; right: 8px;
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; pointer-events: none; z-index: 5;
}
.chip {
  display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 12px;
  background: var(--cream); border: 3px solid var(--wood-d); border-radius: 14px;
  box-shadow: 0 4px 0 var(--wood-d); font-size: 18px; white-space: nowrap;
}
.chip img { width: 26px; height: 26px; }
.day-chip { gap: 10px; }
.clock { width: 70px; height: 12px; background: #e9d2bb; border: 2px solid var(--wood-d); border-radius: 6px; overflow: hidden; }
#dayBar { height: 100%; width: 0; background: linear-gradient(90deg, var(--mint), var(--gold), var(--pink)); }
.coin-chip .yen { color: #c98a00; font-weight: bold; }
#hearts { color: var(--pink-d); letter-spacing: 2px; font-size: 20px; }
#hearts .lost { color: #cdb7a8; }
#hearts.hit { animation: shake .4s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-5px)} 75%{transform:translateX(5px)} }

#hint {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom));
  max-width: min(560px, 92vw); padding: 8px 14px; z-index: 5; pointer-events: none;
  background: rgba(255, 246, 232, .94); border: 3px solid var(--pink-d); border-radius: 12px;
  font-size: 15px; text-align: center; box-shadow: 0 4px 0 var(--pink-d);
  animation: pop .3s ease-out;
}
@keyframes pop { from { transform: translateX(-50%) scale(.85); opacity: 0; } }
#toasts { position: fixed; left: 50%; transform: translateX(-50%); top: 24%; z-index: 6; pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.toast {
  padding: 8px 16px; background: var(--ink); color: var(--cream); border-radius: 12px; font-size: 18px;
  border: 3px solid var(--gold); animation: toast 2.4s forwards; white-space: nowrap;
}
@keyframes toast { 0%{opacity:0;transform:translateY(10px) scale(.9)} 10%{opacity:1;transform:none} 80%{opacity:1} 100%{opacity:0;transform:translateY(-16px)} }

/* ---------- Combo chip ---------- */
.combo-chip { background: linear-gradient(180deg, #ffe14d, #ff9f43); color: var(--ink); font-weight: bold; }
.combo-chip b { font-size: 22px; color: #d9467a; text-shadow: 0 2px 0 #fff; margin-left: 4px; }
.combo-chip.bump { animation: comboBump .35s ease-out; }
.combo-chip.hot { background: linear-gradient(180deg, #ff7aa2, #ff3d6e); color: #fff; }
.combo-chip.hot b { color: #fff; text-shadow: 0 2px 0 #a01848; }
@keyframes comboBump { 0% { transform: scale(1.5) rotate(-6deg); } 100% { transform: scale(1); } }

/* ---------- Entrance queue ---------- */
#queue {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(56px + env(safe-area-inset-top));
  display: flex; align-items: center; gap: 6px; z-index: 5; height: 52px; padding: 4px 10px 4px 6px;
  background: #2a4277; border: 3px solid #17264a; border-radius: 14px; box-shadow: 0 4px 0 #17264a;
}
#queue .door {
  writing-mode: vertical-rl; color: #fff; font-size: 13px; letter-spacing: 2px; padding: 0 2px;
  border-right: 2px dashed rgba(255,255,255,.35); height: 40px; display: flex; align-items: center;
}
#queueList { display: flex; gap: 6px; align-items: center; min-width: 120px; }
#queueList .empty { color: rgba(255,255,255,.6); font-size: 12px; white-space: nowrap; }
.qc {
  position: relative; width: 42px; height: 42px; border-radius: 50%; padding: 3px; border: none;
  background: conic-gradient(var(--c, #5fcf8e) var(--p, 100%), rgba(255,255,255,.2) 0);
  animation: qIn .3s ease-out;
}
.qc .face {
  display: block; width: 100%; height: 100%; border-radius: 50%;
  background-color: var(--cream); background-size: 150%; background-position: 50% 8%; border: 2px solid var(--ink);
}
.qc.first::after {
  content: 'TAP'; position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%);
  font-size: 10px; background: var(--pink); color: #fff; border-radius: 6px; padding: 0 4px; animation: bob .8s infinite;
}
.qc.urgent { animation: shake .4s infinite; }
.qc.selected { transform: translateY(6px) scale(1.18); box-shadow: 0 0 0 3px #ffe14d, 0 0 14px #ffe14d; animation: none; }
.qc.selected::after {
  content: 'SEAT ME'; position: absolute; bottom: -12px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  font-size: 9px; background: #ffe14d; color: var(--ink); border-radius: 6px; padding: 0 4px;
}
@keyframes qIn { from { transform: translateX(20px) scale(.5); opacity: 0; } }

/* ---------- Mini-game panel ---------- */
.screen.mg-screen { background: rgba(30, 14, 22, .45); z-index: 20; }
.mg-panel {
  width: min(520px, 94vw); background: var(--cream); border: 4px solid var(--ink); border-radius: 18px;
  box-shadow: 0 8px 0 var(--ink), 0 0 0 6px rgba(255,255,255,.25); padding: 10px; animation: mgIn .22s cubic-bezier(.2,1.6,.4,1);
}
.mg-panel.hit { animation: mgHit .35s ease-out; }
.mg-panel.bad { animation: shake .4s; }
@keyframes mgIn { from { transform: scale(.6) rotate(-4deg); opacity: 0; } }
@keyframes mgHit { 0% { transform: scale(1.06) rotate(1.5deg); } 100% { transform: none; } }
.mg-head { display: flex; justify-content: center; font-size: 20px; color: var(--pink-d); margin-bottom: 6px; }
.mg-timer { height: 10px; background: #e9d2bb; border: 2px solid var(--ink); border-radius: 6px; overflow: hidden; margin-bottom: 8px; }
#mgBar { height: 100%; width: 100%; background: linear-gradient(90deg, var(--mint), var(--gold)); }
#mgBar.low { background: #ff4d6d; }
#mgc { display: block; width: 100%; aspect-ratio: 360 / 270; border: 3px solid var(--ink); border-radius: 12px; touch-action: none; cursor: pointer; }
#mgHint { margin: 8px 0 2px; text-align: center; font-size: 14px; }
canvas#fx { position: fixed; inset: 0; z-index: 40; pointer-events: none; }

/* ---------- Toolbar ---------- */
#toolbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 6px; align-items: center; padding: 6px; z-index: 5;
  background: var(--wood); border: 3px solid var(--wood-d); border-radius: 16px; box-shadow: 0 5px 0 var(--wood-d);
}
#toolbar button {
  position: relative; height: 58px; min-width: 58px; border: 3px solid var(--wood-d); border-radius: 12px;
  background: var(--cream2); color: var(--ink); font-size: 13px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 2px 8px;
  box-shadow: 0 3px 0 var(--wood-d); transition: transform .08s;
}
#toolbar button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--wood-d); }
#toolbar button.active { background: var(--pink); color: #fff; }
#toolbar button.sys { font-size: 20px; min-width: 48px; }
#toolbar button b {
  position: absolute; top: -10px; right: -8px; min-width: 24px; height: 22px; padding: 0 5px; line-height: 18px;
  background: var(--gold); border: 2px solid var(--wood-d); border-radius: 11px; font-size: 13px; color: var(--ink);
}
#toolbar button b.empty { background: #ff5a5a; color: #fff; animation: shake .4s; }
#toolbar .sep { width: 2px; height: 40px; background: var(--wood-d); margin: 0 2px; }
#toolbar button:disabled { opacity: .45; }
.ico { width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; }
.belt-ico {
  background: url(../assets/road_base.png) -90px -90px / 120px 120px; image-rendering: pixelated;
}
.erase-ico { font-size: 22px; color: var(--pink-d); font-weight: bold; }
#toolbar button.active .erase-ico { color: #fff; }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  background: rgba(30, 14, 22, .6); padding: 16px; overflow-y: auto;
}
.panel {
  background: var(--cream); border: 4px solid var(--wood-d); border-radius: 20px; box-shadow: 0 8px 0 var(--wood-d);
  padding: 20px 24px; max-width: 480px; width: 100%; text-align: center; margin: auto;
  animation: panelIn .25s ease-out;
}
.panel.wide { max-width: 760px; }
@keyframes panelIn { from { transform: scale(.9) translateY(12px); opacity: 0; } }
.panel h2 { margin: 4px 0 8px; font-size: 28px; color: var(--pink-d); }
.panel h3 { margin: 18px 0 8px; font-size: 18px; }
.sub { color: #8a6a5a; font-size: 14px; margin: 0 0 10px; }
.big-btn {
  display: block; margin: 12px auto 4px; padding: 12px 30px; font-size: 22px; color: #fff;
  background: var(--pink); border: 4px solid var(--pink-d); border-radius: 16px; box-shadow: 0 6px 0 var(--pink-d);
}
.big-btn:hover { filter: brightness(1.06); }
.big-btn:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--pink-d); }
.small-btn {
  display: block; margin: 10px auto 0; padding: 7px 18px; font-size: 15px;
  background: var(--cream2); border: 3px solid var(--wood-d); border-radius: 12px; box-shadow: 0 3px 0 var(--wood-d); color: var(--ink);
}

/* title */
#title { background: #f9c7d2; padding: 0; }
.title-bg {
  position: absolute; inset: 0; background: url(../assets/title_background.png) center / cover no-repeat;
  filter: saturate(1.05);
}
.title-bg::after { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(255,240,245,.25), rgba(60,20,40,.55)); }
.title-wrap { position: relative; display: flex; align-items: center; justify-content: center; gap: 2vw; padding: 16px; width: 100%; max-width: 1000px; }
.title-char { height: min(70vh, 520px); filter: drop-shadow(0 8px 0 rgba(60,20,40,.35)); animation: bob 2.4s ease-in-out infinite; }
.title-col { display: flex; flex-direction: column; align-items: center; max-width: 440px; }
.title-logo { width: min(440px, 80vw); filter: drop-shadow(0 6px 0 rgba(60,20,40,.4)); animation: bob 3s ease-in-out infinite reverse; }
.tagline { background: rgba(255,246,232,.92); border: 3px solid var(--wood-d); border-radius: 12px; padding: 8px 14px; text-align: center; font-size: 16px; margin: 8px 0 4px; }
.best { color: #fff; text-shadow: 0 2px 0 var(--ink), 0 0 6px var(--ink); font-size: 16px; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
#loading { position: absolute; bottom: 20px; left: 0; right: 0; text-align: center; color: #fff; text-shadow: 0 2px 0 var(--ink); font-size: 16px; }
@media (max-aspect-ratio: 1/1) {
  .title-wrap { flex-direction: column; gap: 0; }
  .title-char { height: 30vh; order: 2; }
  .title-col { order: 1; }
}

/* how */
.how-list { text-align: left; padding: 0; list-style: none; margin: 8px 0; }
.how-list li { display: flex; gap: 12px; align-items: center; margin: 10px 0; font-size: 15px; line-height: 1.35; }
.how-list li img, .how-list li .ico { width: 48px; height: 48px; flex: none; object-fit: contain; }
.how-list li .belt-ico { background-size: 192px 192px; background-position: -144px -144px; }

/* upgrade cards */
#cards { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.card {
  width: 200px; padding: 12px 10px 14px; border: 4px solid var(--wood-d); border-radius: 16px; background: #fff;
  box-shadow: 0 6px 0 var(--wood-d); display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: transform .12s; color: var(--ink); font-size: 14px;
}
.card:hover { transform: translateY(-4px) rotate(-1deg); border-color: var(--pink-d); }
.card img { width: 88px; height: 88px; object-fit: contain; }
.card .txt { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.card .name { font-size: 18px; color: var(--pink-d); }
.card .desc { line-height: 1.3; min-height: 54px; }
.card.risky { background: #fff3d6; }
.card .tag { font-size: 11px; padding: 2px 8px; border-radius: 8px; background: var(--gold); }
#shop { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.shop-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; font-size: 14px; color: var(--ink);
  background: var(--cream2); border: 3px solid var(--wood-d); border-radius: 12px; box-shadow: 0 3px 0 var(--wood-d);
}
.shop-item img { width: 32px; height: 32px; object-fit: contain; }
.shop-item .price { color: #c98a00; font-weight: bold; }
.shop-item:disabled { opacity: .4; cursor: default; }

/* over */
.over-img { width: 160px; }
.stats { display: grid; grid-template-columns: 1fr auto; gap: 6px 20px; text-align: left; font-size: 17px; max-width: 280px; margin: 8px auto; }
.stats .new { color: var(--pink-d); grid-column: 1 / -1; text-align: center; animation: bob 1s infinite; }

@media (max-width: 560px) {
  #hud { gap: 5px; left: 4px; right: 4px; flex-wrap: nowrap; }
  .chip { height: 32px; font-size: 14px; padding: 0 7px; gap: 4px; border-width: 2px; box-shadow: 0 3px 0 var(--wood-d); }
  .chip img { width: 18px; height: 18px; }
  .day-chip { gap: 6px; }
  .clock { width: 32px; height: 10px; }
  #hearts { font-size: 15px; letter-spacing: 0; }
  .combo-chip b { font-size: 16px; }
  #queue { top: calc(44px + env(safe-area-inset-top)); height: 44px; }
  .qc { width: 34px; height: 34px; }
  #queueList { min-width: 90px; }
  #toolbar button { height: 50px; min-width: 50px; padding: 2px 5px; font-size: 11px; }
  #toolbar button.sys { min-width: 40px; font-size: 17px; }
  .ico { width: 24px; height: 24px; }
  .belt-ico { background-size: 96px 96px; background-position: -72px -72px; }
  .card { width: 100%; flex-direction: row; text-align: left; }
  .card img { width: 64px; height: 64px; }
  .card .desc { min-height: 0; }
  .card .txt { align-items: flex-start; }
  #hint { bottom: calc(80px + env(safe-area-inset-bottom)); font-size: 13px; }
}
