:root {
  --ink: #3f4a6b; --ink2: #6b7697; --card: rgba(255, 255, 255, 0.92); --mint: #6cc6b3; --mint2: #d8f3ec;
  --coral: #ff8a80; --gold: #ffc94d; --sky: #bfe0f5; --shadow: 0 4px 14px rgba(63, 74, 107, 0.16);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sky); color: var(--ink); font-family: var(--font); user-select: none; -webkit-user-select: none; }
canvas { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--mint); outline-offset: 2px; }

.ic { width: 46px; height: 46px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); display: grid; place-items: center; padding: 0; flex: none; }
.ic svg { width: 24px; height: 24px; stroke: var(--ink); fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.ic.sm { width: 38px; height: 38px; border-radius: 12px; }
.ic.sm svg { width: 20px; height: 20px; }
.ic:active { transform: scale(0.94); }
.ic.on { background: var(--mint); }
.ic.on svg { stroke: #fff; }
.ic:disabled { opacity: 0.4; }

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
.top { position: absolute; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r)); display: flex; gap: 8px; align-items: center; pointer-events: none; }
.top > * { pointer-events: auto; }
.info { flex: 1; min-width: 0; background: var(--card); box-shadow: var(--shadow); border-radius: 14px; padding: 5px 12px; height: 46px; display: flex; flex-direction: column; justify-content: center; }
.info b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.info span { font-size: 12.5px; color: var(--ink2); white-space: nowrap; display: flex; gap: 10px; align-items: center; }
.info .over { color: #e07a3f; font-weight: 700; }
.gemi { display: inline-block; width: 9px; height: 9px; background: #8fd6ff; transform: rotate(45deg); border-radius: 2px; margin-right: 4px; border: 1px solid #5aa9d6; }

.hint { position: absolute; top: calc(66px + var(--safe-t)); left: 50%; transform: translateX(-50%); max-width: min(440px, calc(100% - 24px)); background: #fffbe9; border-radius: 14px; padding: 9px 14px; box-shadow: var(--shadow); font-size: 14px; text-align: center; line-height: 1.35; }
.toast { position: absolute; top: calc(66px + var(--safe-t)); left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; border-radius: 12px; padding: 8px 14px; font-size: 14px; box-shadow: var(--shadow); white-space: nowrap; }

.zoom { position: absolute; right: calc(10px + var(--safe-r)); bottom: calc(80px + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; }

.bar { position: absolute; left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r)); bottom: calc(10px + var(--safe-b)); display: flex; gap: 8px; align-items: flex-end; justify-content: center; pointer-events: none; }
.bar > * { pointer-events: auto; }
.tools { display: flex; gap: 5px; background: rgba(255, 255, 255, 0.55); padding: 5px; border-radius: 18px; box-shadow: var(--shadow); align-items: center; min-width: 0; }
.tools .ic { box-shadow: none; }
.tools .sep { width: 1px; height: 30px; background: rgba(63, 74, 107, 0.18); margin: 0 2px; flex: none; }
.play { width: 64px; height: 64px; border-radius: 22px; background: var(--coral); box-shadow: var(--shadow); display: grid; place-items: center; flex: none; }
.play svg { width: 30px; height: 30px; fill: #fff; stroke: #fff; stroke-width: 2; stroke-linejoin: round; }
.play.stop { background: var(--ink); }
.play:active { transform: scale(0.95); }
.playing .tools, .playing .zoom #bFit { opacity: 0.35; pointer-events: none; }

/* narrow phones: smaller tool buttons so the whole bar fits */
@media (max-width: 430px) {
  .tools { gap: 2px; padding: 4px; }
  .tools .ic { width: 38px; height: 40px; border-radius: 12px; }
  .tools .ic svg { width: 21px; height: 21px; }
  .play { width: 56px; height: 56px; border-radius: 19px; }
  .tools .sep { margin: 0; }
}
@media (max-width: 350px) { .tools .ic { width: 33px; } }
/* short landscape phones: tools go down the left side */
@media (max-height: 460px) and (orientation: landscape) {
  .bar { left: calc(8px + var(--safe-l)); right: auto; top: calc(64px + var(--safe-t)); bottom: calc(8px + var(--safe-b)); flex-direction: column; align-items: flex-start; justify-content: space-between; }
  .tools { flex-direction: column; flex-wrap: wrap; max-height: 100%; align-content: flex-start; }
  .tools .ic { width: 40px; height: 38px; }
  .tools .sep { width: 30px; height: 1px; margin: 1px 0; }
  .play { position: fixed; right: calc(10px + var(--safe-r)); bottom: calc(10px + var(--safe-b)); }
  .zoom { bottom: calc(84px + var(--safe-b)); flex-direction: row; }
  .hint, .toast { top: calc(62px + var(--safe-t)); }
}

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b)); }
.card { background: var(--card); border-radius: 24px; box-shadow: var(--shadow); padding: 22px; text-align: center; }
.titlecard { width: min(360px, 100%); display: flex; flex-direction: column; gap: 10px; backdrop-filter: blur(4px); }
h1 { margin: 0; font-size: 46px; letter-spacing: -1px; color: var(--ink); }
h1 span { color: var(--coral); }
.titlecard p { margin: 0 0 8px; color: var(--ink2); }
.big { height: 54px; border-radius: 16px; background: var(--coral); color: #fff; font-size: 19px; font-weight: 700; box-shadow: var(--shadow); }
.big.alt, .mid.alt { background: #fff; color: var(--ink); border: 2px solid #dfe6f3; }
.big:active, .mid:active { transform: scale(0.97); }
.stars-total { color: var(--ink2); font-size: 14px; font-weight: 600; }
.corner { position: fixed; top: calc(12px + var(--safe-t)); right: calc(12px + var(--safe-r)); }

#select { justify-content: flex-start; overflow-y: auto; background: rgba(191, 224, 245, 0.55); }
.selhead { display: flex; align-items: center; gap: 12px; width: min(720px, 100%); margin-bottom: 14px; }
.selhead h2 { margin: 0; flex: 1; font-size: 26px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; width: min(720px, 100%); padding-bottom: 20px; }
.lv { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 12px; text-align: left; display: flex; flex-direction: column; gap: 4px; min-height: 92px; }
.lv .n { font-size: 13px; color: var(--ink2); font-weight: 700; }
.lv .nm { font-size: 16px; font-weight: 700; }
.lv .st { margin-top: auto; font-size: 18px; letter-spacing: 2px; color: #d9dfec; }
.lv .st i { font-style: normal; color: var(--gold); }
.lv.locked { opacity: 0.55; }
.lv.free { background: var(--mint2); }
.lv.free .st { color: var(--ink2); }

.modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(63, 74, 107, 0.18); padding: 16px; }
.modal .card { width: min(380px, 100%); animation: pop 0.25s ease-out; }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal h2 { margin: 0 0 4px; font-size: 26px; }
.modal p { margin: 0 0 10px; color: var(--ink2); }
.resstars { list-style: none; padding: 0; margin: 0 0 14px; text-align: left; display: flex; flex-direction: column; gap: 6px; }
.resstars li { display: flex; gap: 10px; align-items: center; font-size: 15px; color: var(--ink2); }
.resstars li b { font-size: 24px; color: #d9dfec; width: 26px; text-align: center; }
.resstars li.got b { color: var(--gold); animation: pop 0.3s ease-out backwards; }
.resstars li.got { color: var(--ink); }
.row { display: flex; gap: 8px; }
.mid { flex: 1; height: 48px; border-radius: 14px; background: var(--coral); color: #fff; font-weight: 700; font-size: 16px; box-shadow: var(--shadow); }
