:root {
  --ink: #142021;
  --subtle: #485755;
  --paper: #fcfdfb;
  --rule: #ccd6d1;
  --signal: #196e5b;
  --mint: #d3f0e2;
  color-scheme: light;
  font: 16px/1.35 "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 290px; color: var(--ink); background: var(--paper); }
button, kbd { font: inherit; }
button { color: inherit; }
button:focus-visible { outline: 2px solid var(--signal); outline-offset: 3px; }
.game { position: relative; min-height: 490px; height: 100vh; height: 100dvh; overflow: hidden; isolation: isolate; }
canvas { position: absolute; inset: 0; z-index: -1; display: block; width: 100%; height: 100%; touch-action: none; }
canvas.grabbable { cursor: grab; }
canvas.grabbing { cursor: grabbing; }
.title, .score { position: absolute; top: clamp(14px, 3.4vw, 36px); }
.title { left: clamp(13px, 3.2vw, 38px); display: flex; align-items: flex-start; flex-direction: column; gap: 8px; pointer-events: none; }
h1 { margin: 0; font-size: clamp(1.09rem, 3vw, 1.65rem); line-height: 1.05; letter-spacing: -.05em; }
#pause { pointer-events: auto; width: 30px; height: 28px; border: 1px solid var(--rule); border-radius: 7px; background: var(--paper); cursor: pointer; font-size: .75rem; }
#pause:hover, #pause[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: #fff; }
.score { right: clamp(13px, 3.2vw, 38px); min-width: min(185px, 50vw); background: #fcfdfbef; padding: 3px 0 7px 10px; text-align: right; pointer-events: none; }
.money { display: flex; justify-content: flex-end; align-items: baseline; gap: 5px; font-size: clamp(1.25rem, 4vw, 1.8rem); line-height: 1; }
.money > span { font-size: .65em; color: var(--signal); }
.money strong { letter-spacing: -.05em; font-variant-numeric: tabular-nums; }
.score small { color: var(--subtle); font-size: .65rem; }
.score dl { display: grid; gap: 2px; margin: 8px 0; font-size: .75rem; }
.score dl > div, .goal { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.score dt { color: var(--subtle); }
.score dd { margin: 0; font-weight: 680; font-variant-numeric: tabular-nums; }
.goal { font-size: .68rem; }
.goal strong { color: var(--signal); font-variant-numeric: tabular-nums; }
progress { display: block; width: 100%; height: 4px; appearance: none; border: 0; border-radius: 5px; overflow: hidden; background: #e0e9e3; margin: 3px 0 0; }
progress::-webkit-progress-bar { background: #e0e9e3; }
progress::-webkit-progress-value { background: var(--signal); }
progress::-moz-progress-bar { background: var(--signal); }
.controls { position: absolute; left: 50%; bottom: max(11px, env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 14px); transform: translateX(-50%); }
.dock, .shop { display: flex; align-items: flex-start; justify-content: center; gap: 7px; }
.dock { padding: 8px 10px 6px; border: 1px solid #aebfb7; border-radius: 13px; background: #fcfdfbf5; box-shadow: 0 3px 15px #18342b11; }
.shop { padding-left: 8px; border-left: 1px solid var(--rule); }
.control { position: relative; display: grid; justify-items: center; gap: 3px; min-width: 40px; }
.key { position: relative; display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 1px solid #7d9790; border-radius: 10px; background: #fff; font-size: 1.07rem; line-height: 1; cursor: pointer; touch-action: none; user-select: none; }
.key .level { position: absolute; right: 2px; bottom: 1px; font: 700 .52rem/1 ui-monospace, Consolas, monospace; }
.key[aria-disabled="true"] { color: #576561; border-color: #c3d0c9; cursor: default; }
.key.available { background: var(--mint); border-color: var(--signal); }
.key:hover:not([aria-disabled="true"]) { box-shadow: inset 0 0 0 1px var(--signal); }
.spin { background: var(--ink); color: #fff; border-color: var(--ink); font-size: 1.35rem; }
.spin.held { background: var(--signal); }
.surge { font-size: 1.29rem; }
.surge.active { background: var(--signal); color: white; }
.caption { color: var(--subtle); white-space: nowrap; font-size: .63rem; font-variant-numeric: tabular-nums; }
.tip { display: none; position: absolute; z-index: 3; bottom: calc(100% + 9px); width: max-content; max-width: 170px; padding: 7px 9px; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); box-shadow: 0 3px 14px #0001; pointer-events: none; font-size: .72rem; }
.tip strong, .tip span { display: block; }
.tip span { margin-top: 3px; color: var(--subtle); }
.control:hover .tip, .control:has(button:focus-visible) .tip { display: block; }
.hint { color: var(--subtle); margin: 5px 0 0; text-align: center; font-size: .67rem; }
.hint span { padding: 0 3px; }
.message { position: absolute; top: 19%; left: 50%; transform: translateX(-50%); z-index: 2; padding: 8px 13px; border: 1px solid var(--rule); border-radius: 9px; background: var(--paper); text-align: center; font-weight: 700; white-space: nowrap; }
.message small { display: block; color: var(--subtle); font-size: .74rem; font-weight: 400; }
.victory { color: var(--signal); }
.purchase-label { position: absolute; z-index: 4; left: 50%; top: -3px; color: var(--signal); background: #f0fff6; border: 1px solid #8cc2ad; border-radius: 20px; padding: 2px 6px; font: 700 .7rem/1.3 "Segoe UI", system-ui, sans-serif; white-space: nowrap; pointer-events: none; }
@media (max-width: 480px) {
  .dock, .shop { gap: 4px; }
  .dock { padding-inline: 5px; }
  .shop { padding-left: 4px; }
  .control { min-width: 34px; }
  .key { width: 31px; height: 32px; border-radius: 8px; }
  .dock > .control:first-child .tip { left: 0; }
  .shop > .control:last-child .tip { right: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .purchase-label { display: none; }
}

@media (max-width: 720px) { .shop { display: grid; grid-template-columns: repeat(5, auto); } .dock { align-items: center; } }

.buy-spark { position: absolute; z-index: 5; top: 15px; left: 47%; width: 7px; height: 7px; background: #196e5b; clip-path: polygon(50% 0,62% 35%,100% 50%,63% 62%,50% 100%,38% 62%,0 50%,38% 38%); pointer-events: none; }
.purchase-label { border-radius: 4px; background: #fff; border: 1.5px solid #142021; box-shadow: 1px 2px 0 #142021; color: #142021; }

.key { border-radius: 50%; border: 1.5px solid #293330; box-shadow: 0 2px 0 #bac6be; font-weight: 720; }
.shop .key .level { border-radius: 100%; background: #fcfdfb; color: #15241d; padding: 1px 2px; left: -1px; right: auto; bottom: -1px; }
.buy-ring { pointer-events:none; position:absolute; width:34px; height:34px; top:0; border-radius:50%; border:2px dashed #468469; opacity:0; z-index:4; }
.purchase-label { white-space:nowrap; z-index:8; }
.control:not([hidden]) { animation: reveal-tool .32s ease-out; }
@keyframes reveal-tool { from { opacity:0; transform:translateY(7px) scale(.8) } to { opacity:1; transform:none } }
@media (max-width:720px) { .shop { display:flex; flex-wrap:wrap; max-width:225px; } }
@media(prefers-reduced-motion:reduce){.control:not([hidden]){animation:none}}

#restart { pointer-events: auto; padding: 5px 8px; border: 1px solid var(--rule); border-radius: 7px; background: var(--paper); cursor: pointer; font-size: .73rem; }
#restart:hover { border-color: var(--ink); }
