:root {
  --night: #0b1230;
  --night2: #16224a;
  --snow: #eef4ff;
  --win: #ffd36a;
  --plow: #ff8a1f;
  --glass: rgba(14, 24, 56, .62);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--snow);
  font-family: "Trebuchet MS", "Avenir Next", system-ui, sans-serif;
  touch-action: none; overscroll-behavior: none; user-select: none; -webkit-user-select: none;
}
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#top {
  position: fixed; left: 0; right: 0; top: 0; z-index: 2; pointer-events: none;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(12px + env(safe-area-inset-top)) 16px 0;
}
#town { display: flex; flex-direction: column; gap: 2px; text-shadow: 0 2px 8px #000a; }
#tag { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--win); font-weight: 700; min-height: 13px; }
#name { font-size: 22px; letter-spacing: .01em; }
#score { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
#ringw { position: relative; width: 56px; height: 56px; }
#ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
#ring circle { fill: rgba(8, 14, 40, .45); stroke-width: 4; }
#ring .bg { stroke: rgba(255, 255, 255, .16); }
#ring .fg { fill: none; stroke: var(--win); stroke-linecap: round; stroke-dasharray: 163.4; stroke-dashoffset: 163.4; transition: stroke-dashoffset .12s linear, stroke .3s; filter: drop-shadow(0 0 3px #ffb34788); }
#ringw.hot .fg { stroke: var(--plow); }
#ringw.pulse { animation: ringpulse .7s ease-out; }
#ringw.pulse2 { animation: ringpulse2 .9s ease-out; }
@keyframes ringpulse { 0% { transform: scale(1); } 30% { transform: scale(1.28); filter: drop-shadow(0 0 10px #ffd36a); } 100% { transform: scale(1); } }
@keyframes ringpulse2 { 0% { transform: scale(1); } 25% { transform: scale(1.42); filter: drop-shadow(0 0 16px #ff8a1f); } 55% { transform: scale(1.1); } 100% { transform: scale(1); } }
#count {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 800; line-height: 1; color: #fff;
  text-shadow: 0 2px 10px #000a; transition: color .2s;
}
#count.over { color: #ffb347; }
body[data-view=map] #top, body[data-view=map] #bar .g, body[data-view=world] #top, body[data-view=world] #bar .g { display: none; }
body:not([data-view=map]):not([data-view=world]) #bar .m { display: none; }
body[data-view=world] #bar #backb { display: none; }
#count.pop { animation: pop .22s ease-out; }
@keyframes pop { 0% { transform: scale(1.5); } 100% { transform: scale(1); } }
#par { display: flex; gap: 2px; max-width: 230px; flex-wrap: wrap; justify-content: flex-end; }
#par svg { width: 22px; height: 13px; color: #fff; opacity: .28; transition: opacity .2s, color .2s; }
#par svg.on { color: var(--plow); opacity: 1; }

#bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2;
  display: flex; justify-content: center; gap: 8px;
  padding: 8px 16px calc(12px + env(safe-area-inset-bottom));
}
button {
  font: inherit; color: var(--snow); border: 0; cursor: pointer; touch-action: manipulation;
}
#bar button {
  width: 62px; height: 62px; border-radius: 18px; background: var(--glass);
  border: 1px solid #ffffff22; backdrop-filter: blur(6px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
#bar button:active { transform: scale(.94); background: #ffffff24; }
#bar svg { width: 26px; height: 26px; }
#bar span { font-size: 11px; letter-spacing: .03em; opacity: .85; }
#bar button.off { opacity: .4; }

#win {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 3; width: min(340px, calc(100vw - 32px)); padding: 16px 18px 14px;
  background: linear-gradient(180deg, #1b2b63ee, #0d1638f2); border: 1px solid #ffffff2a; border-radius: 26px;
  box-shadow: 0 12px 40px #000a, 0 0 60px #ffb34733;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  transition: opacity .3s, transform .35s cubic-bezier(.2, 1.4, .4, 1);
}
#win.hidden { opacity: 0; transform: translate(-50%, 40px) scale(.9); pointer-events: none; }
#stars { display: flex; gap: 6px; }
#stars svg { width: 54px; height: 54px; color: #ffffff24; transform: scale(.6); transition: transform .1s; }
#stars svg.on { color: #ffcf4a; filter: drop-shadow(0 0 10px #ffb347aa); animation: starslam .6s cubic-bezier(.2, 1.5, .4, 1) both; }
#stars svg:nth-child(2) { margin-top: -8px; }
@keyframes starslam { 0% { transform: scale(3.2) rotate(-50deg); opacity: 0; } 45% { transform: scale(.82) rotate(6deg); opacity: 1; } 70% { transform: scale(1.12); } 100% { transform: scale(1) rotate(0); opacity: 1; } }
#win.thump { animation: thump .22s ease-out; }
@keyframes thump { 0% { transform: translate(-50%, 0) scale(1.05); } 100% { transform: translate(-50%, 0) scale(1); } }
#tease { display: block; width: 180px; height: 56px; margin: -4px 0; }
#tease.hidden { display: none; }
#tease.go { animation: tease 1.2s ease-in-out both; }
@keyframes tease { 0% { opacity: 0; transform: scale(.5); } 18% { opacity: 1; transform: scale(1.15); } 30% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }
#result { font-size: 15px; opacity: .85; min-height: 18px; }
.primary {
  width: 100%; height: 56px; border-radius: 18px; font-size: 20px; font-weight: 800; color: #3a1a00;
  background: linear-gradient(180deg, #ffb347, var(--plow)); box-shadow: 0 4px 0 #b4560a, 0 8px 24px #ff8a1f55;
}
.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 #b4560a; }
.row { display: flex; gap: 10px; width: 100%; }
.ghost { flex: 1; height: 44px; border-radius: 14px; background: #ffffff14; border: 1px solid #ffffff22; font-size: 15px; }
.ghost:active { background: #ffffff30; }

#toast {
  position: fixed; left: 50%; top: 22%; transform: translate(-50%, 0); z-index: 5; background: #000b; padding: 8px 16px;
  border-radius: 999px; font-size: 14px; opacity: 0; transition: opacity .25s; pointer-events: none;
}
#toast.show { opacity: 1; }

#gain { display: flex; align-items: center; gap: 6px; font-size: 20px; font-weight: 800; color: #ffd36a; min-height: 24px; }
#gain svg { width: 24px; height: 24px; }
#cname { width: 100%; height: 36px; border-radius: 12px; border: 1px solid #ffffff2a; background: #ffffff10; color: var(--snow); text-align: center; font: inherit; font-size: 15px; user-select: text; -webkit-user-select: text; }
#cname::placeholder { color: #ffffff66; }
.row .ghost { font-size: 14px; padding: 0 4px; }
#chalbanner { position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 2; display: flex; align-items: center; gap: 8px; padding: 4px 14px 4px 8px; border-radius: 999px; background: var(--glass); border: 1px solid #ffffff33; font-weight: 800; font-size: 16px; pointer-events: none; }
#chalbanner.hidden { display: none; }
#par svg.ghost { outline: 2px dashed #7ad7ff; outline-offset: 1px; border-radius: 3px; }
#par svg.limit { outline: 2px solid #ff6a5a; outline-offset: 1px; border-radius: 3px; }
#story { position: fixed; inset: 0; z-index: 8; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 10px; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); background: linear-gradient(180deg, #0000 40%, #050a1ecc); }
#story.hidden, #garage.hidden, #dbg.hidden { display: none; }
#bubble { position: relative; width: min(420px, 100%); min-height: 96px; padding: 14px 40px 14px 84px; border-radius: 22px; background: linear-gradient(180deg, #1b2b63f2, #0d1638f8); border: 1px solid #ffffff33; box-shadow: 0 12px 40px #000a; font-size: 19px; line-height: 1.3; display: flex; align-items: center; }
#who { position: absolute; left: 12px; top: 16px; width: 60px; height: 60px; }
#more { position: absolute; right: 14px; bottom: 10px; color: var(--win); font-style: normal; animation: nudge 1s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateX(5px); } }
#skip { flex: none; width: 150px; height: 38px; opacity: .8; }
#garage { position: fixed; inset: 0; z-index: 7; background: linear-gradient(180deg, #0b1230, #16224a); display: flex; flex-direction: column; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px calc(10px + env(safe-area-inset-bottom)); }
#ghead { width: 100%; display: flex; align-items: center; justify-content: space-between; font-size: 22px; }
#ghead .ghost { flex: none; width: 44px; }
#gcoins { display: flex; align-items: center; gap: 4px; font-weight: 800; color: #ffd36a; }
#gcoins svg { width: 24px; height: 24px; } #gcoins em { font-style: normal; min-width: 2ch; }
#gprev { width: 100%; max-width: 420px; height: auto; border-radius: 20px; background: #0a1129; border: 1px solid #ffffff22; }
#gact { height: 48px; font-size: 18px; max-width: 420px; }
#gact:disabled { filter: grayscale(.8); opacity: .6; }
#ggrid { width: 100%; max-width: 420px; flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; align-content: start; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.card { position: relative; height: 92px; border-radius: 16px; background: #ffffff10; border: 2px solid #ffffff1a; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 4px 2px 5px; font-size: 12px; }
.card.sel { border-color: var(--win); background: #ffd36a22; }
.card canvas { width: 84px; height: 46px; }
.card .pr { display: flex; align-items: center; gap: 3px; font-weight: 800; color: #ffd36a; }
.card .pr svg { width: 15px; height: 15px; }
.card.soon canvas { opacity: .45; filter: grayscale(.7); }
#dbg { position: fixed; left: 8px; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 9; display: flex; gap: 6px; }
#dbg .ghost { height: 30px; flex: none; padding: 0 8px; font-size: 12px; }
@media (max-height: 520px) { #name { font-size: 18px; } #count { font-size: 30px; } #bar button { height: 50px; } }

#winplow { width: 132px; height: 44px; margin: -4px 0 -6px; }

#win { padding: 10px 14px 10px; gap: 6px; bottom: calc(92px + env(safe-area-inset-bottom)); }
#stars svg { width: 42px; height: 42px; }
#winplow { height: 30px; width: 90px; margin: -2px 0 -8px; }
#cname { height: 30px; font-size: 14px; }
.primary { height: 48px; font-size: 19px; }
.ghost { height: 38px; }
#result { min-height: 0; font-size: 14px; }
#gain { min-height: 0; font-size: 18px; }

body.no-daily #bar #dailyb, body.no-garb #bar #garb, body.no-weekb #bar #weekb { display: none; }
#garb.pulse { animation: ringpulse 1.4s ease-in-out infinite; border-color: #ffd36a; }
#undo.nudge { animation: ringpulse 1.2s ease-in-out infinite; border-color: #ffd36a; }
#chalbanner { top: auto; bottom: calc(80px + env(safe-area-inset-bottom)); }
#dbg { z-index: 1; }
#par.tight svg { width: 17px; height: 11px; }
#par { max-width: 260px; }
#bar button { width: 64px; }

#cnote { font-size: 11px; opacity: .6; margin-top: -4px; }
.about { color: var(--snow); opacity: .55; font-size: 12px; text-decoration: underline; text-align: center; padding: 4px 8px; }
#garage .about { flex: none; }
#aboutlink { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 2; display: none; white-space: nowrap; }
body[data-view=world] #aboutlink { display: block; }
body.garage-open #aboutlink { display: none; }
