/* ===============================================================
   Beat Runners — styles
   =============================================================== */
:root {
  --bg1: #ff8fa3; --bg2: #7a2e8f; --panel: #fff; --panel-ink: #1f2933; --accent: #ff5d8f; --accent2: #ffb347; --muted: #6b7280;
  --font-head: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-body); color: var(--panel-ink); overflow: hidden;
  background: linear-gradient(160deg, #2a0f5c, #7a1f6b 50%, #ff7b54) fixed, #2a0f5c;
}
.screen { position: fixed; inset: 0; display: none; overflow: auto; }
.screen.active { display: flex; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
kbd { font: 800 11px var(--font-body); background: rgba(0,0,0,.1); border: 1px solid rgba(0,0,0,.15); border-radius: 5px; padding: 1px 6px; }
code { background: rgba(0,0,0,.07); padding: 1px 5px; border-radius: 4px; }

/* ---------- buttons & inputs ---------- */
.btn {
  font: 800 15px var(--font-body); border: 0; border-radius: 12px; padding: 10px 16px; cursor: pointer;
  background: #fff; color: #1f2933; box-shadow: 0 3px 0 rgba(0,0,0,.22), 0 6px 16px rgba(0,0,0,.12);
  transition: transform .12s, filter .12s, box-shadow .12s; display: inline-flex; align-items: center; justify-content: center; gap: 5px; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.22); }
.btn:focus-visible { outline: 3px solid var(--accent2); outline-offset: 2px; }
.btn.primary { background: linear-gradient(180deg, #ff8fb1, var(--accent)); color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.25); }
.btn.good { background: linear-gradient(180deg, #4ade80, #16a34a); color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.25); }
.btn.danger { background: linear-gradient(180deg, #ef4444, #b91c1c); color: #fff; }
.btn.ghost { background: transparent; color: inherit; box-shadow: none; border: 1.5px solid currentColor; opacity: .85; }
.btn.big { font-size: 19px; padding: 14px 26px; border-radius: 16px; }
.btn.sm { font-size: 13px; padding: 6px 10px; border-radius: 9px; box-shadow: 0 2px 0 rgba(0,0,0,.18); }
.btn.ghost.sm { box-shadow: none; }
input[type=text], input[type=number], select, textarea {
  font: 700 14px var(--font-body); padding: 7px 10px; border-radius: 9px; border: 1.5px solid rgba(0,0,0,.18); background: #fff; color: #1f2933; max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=color] { width: 46px; height: 34px; padding: 2px; border: 1.5px solid rgba(0,0,0,.2); border-radius: 8px; background: #fff; cursor: pointer; }
input[type=range] { accent-color: var(--accent); width: 160px; }
.switch { position: relative; display: inline-block; width: 48px; height: 27px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: #c3c9cf; border-radius: 27px; transition: .2s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 21px; height: 21px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(21px); }
.switch input:focus-visible + span { outline: 3px solid var(--accent2); outline-offset: 2px; }
.chip { border: 0; padding: 7px 14px; border-radius: 20px; background: rgba(0,0,0,.07); color: inherit; font: 800 14px var(--font-body); cursor: pointer; }
.chip.on { background: var(--accent); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tog { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 800; padding: 6px 10px; background: rgba(0,0,0,.05); border-radius: 12px; cursor: pointer; }

/* ---------- title ---------- */
#screen-title { align-items: center; justify-content: center; color: #fff; text-align: center; padding: 20px; }
#title-cv { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.title-wrap { position: relative; z-index: 1; background: rgba(40,10,60,.35); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); border-radius: 28px; padding: 26px 30px 22px; max-width: 680px; margin-bottom: 18vh; }
.title-logo { font-size: clamp(44px, 9vw, 72px); line-height: 1; animation: bob 1.07s ease-in-out infinite; display: inline-block; filter: drop-shadow(0 8px 14px rgba(0,0,0,.35)); }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-10px) rotate(4deg); } }
#title-name {
  font: 700 clamp(44px, 10vw, 86px)/1 var(--font-head); margin: 8px 0 6px;
  background: linear-gradient(90deg, #ffe066, #ffad33 40%, #ff8fab 70%, #c77dff); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 rgba(0,0,0,.3));
}
.title-sub { font-size: clamp(15px, 2.4vw, 20px); font-weight: 800; margin: 0 0 22px; text-shadow: 0 2px 4px rgba(0,0,0,.4); }
.title-btns { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.title-foot { margin: 18px 0 0; font-size: 13px; opacity: .8; font-weight: 700; }

/* ---------- shared menu layout ---------- */
#screen-levels, #screen-setup { flex-direction: column; color: #fff; }
.setup-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px 10px; flex-wrap: wrap; }
.setup-head h2 { flex: 1; margin: 0; font: 600 28px var(--font-head); white-space: nowrap; }
.setup-head .btn.ghost { color: #fff; }
.tabs { display: flex; gap: 6px; padding: 0 20px; flex-wrap: wrap; }
.tabs button { font: 800 15px var(--font-body); border: 0; padding: 10px 18px; border-radius: 14px 14px 0 0; background: rgba(255,255,255,.14); color: #fff; cursor: pointer; }
.tabs button:hover { background: rgba(255,255,255,.24); }
.tabs button.active { background: var(--panel); color: var(--panel-ink); }
.tab-body { flex: 1 0 auto; margin: 0 20px 20px; background: var(--panel); color: var(--panel-ink); border-radius: 0 18px 18px 18px; padding: 22px 26px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.form { column-width: 420px; column-gap: 48px; }
.fsec { font: 600 19px var(--font-head); margin: 18px 0 4px; break-after: avoid; color: var(--accent); }
.fsec:first-child { margin-top: 0; }
.frow { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid rgba(127,127,127,.18); break-inside: avoid; }
.frow > label { font-weight: 800; }
.frow > label small { display: block; color: var(--muted); font-weight: 600; font-size: 12px; }
.fin { display: flex; align-items: center; gap: 8px; flex: none; }
.fin output { min-width: 48px; text-align: right; font-weight: 800; font-size: 13px; }
.fin select { max-width: 230px; }
.ff { display: flex; flex-direction: column; gap: 3px; font-size: 12px; font-weight: 800; color: var(--muted); }

/* character picker in the level screen header */
.char-pick { display: flex; gap: 8px; }
.cp { display: flex; align-items: center; gap: 6px; border: 2px solid rgba(255,255,255,.35); background: rgba(255,255,255,.12); color: #fff; border-radius: 14px; padding: 3px 12px 3px 4px; cursor: pointer; font: 800 14px var(--font-body); }
.cp.on { background: #fff; color: var(--panel-ink); border-color: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.cp canvas { width: 44px; height: 44px; }

/* ---------- level cards ---------- */
.lv-sum { margin: 0 0 14px; font-weight: 800; }
.lv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.lv-card { display: flex; flex-direction: column; border-radius: 20px; overflow: hidden; background: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.14); border: 1px solid rgba(0,0,0,.06); cursor: pointer; transition: transform .15s, box-shadow .15s; }
.lv-card.mine { cursor: default; }
.lv-card:hover, .lv-card:focus-visible { transform: translateY(-4px); box-shadow: 0 16px 34px rgba(0,0,0,.2); outline: none; }
.lv-art { position: relative; height: 92px; background: linear-gradient(180deg, var(--s1), var(--s2) 70%, var(--tp) 70%, var(--tp) 74%, var(--gr) 74%); }
.lv-num { position: absolute; left: 14px; top: 10px; font: 700 40px var(--font-head); color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.25); }
.lv-face { position: absolute; right: 14px; top: 12px; font-size: 38px; filter: drop-shadow(0 3px 4px rgba(0,0,0,.25)); }
.lv-done { position: absolute; right: 62px; top: 18px; background: #16a34a; color: #fff; font: 700 18px var(--font-head); width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.lv-info { padding: 12px 16px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.lv-info h3 { margin: 0; font: 600 22px var(--font-head); }
.lv-info p { margin: 0; font-weight: 700; font-size: 14px; color: #4b5563; }
.lv-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.lv-chips b { font-size: 11.5px; font-weight: 800; padding: 3px 9px; border-radius: 20px; background: #f1f1f4; color: #374151; }
.lv-best { display: flex; align-items: center; gap: 8px; font-weight: 900; font-size: 13px; }
.bar { flex: 1; height: 10px; border-radius: 6px; background: #e5e7eb; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #4ade80, #16a34a); border-radius: 6px; }
.stars span, .done-stars span, .hud-coins span { color: #d1d5db; }
.stars span.got, .done-stars span.got, .hud-coins span.got { color: #ffc107; text-shadow: 0 0 6px rgba(255,200,0,.6); }
.done-stars span.had, .hud-coins span.had { color: #c9a227; opacity: .6; }
.stars { font-size: 17px; letter-spacing: 1px; }
.lv-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.lv-foot small { color: var(--muted); font-weight: 700; }
.lv-tools { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.empty { padding: 30px; text-align: center; font-weight: 700; color: var(--muted); background: rgba(0,0,0,.04); border-radius: 16px; }
.rnd { max-width: 760px; }
.rnd > p { margin-top: 0; }
.rrow { display: grid; grid-template-columns: 130px 1fr; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid rgba(127,127,127,.15); }
.rrow > b { font-weight: 900; }
.rrow select { max-width: 280px; }
.togs { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.seed { display: flex; gap: 8px; align-items: center; }
.seed input { width: 120px; }
.rbtns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; align-items: center; }

/* ---------- characters tab ---------- */
.char-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }
.char-card { border-radius: 20px; border: 3px solid transparent; background: rgba(0,0,0,.04); overflow: hidden; display: flex; flex-direction: column; }
.char-card.on { border-color: var(--accent); background: #fff6f9; }
.char-stage { position: relative; height: 210px; background: linear-gradient(180deg, #ffd6e0, #ffe9c7 80%, #e0b07a 80%); }
.char-stage canvas { width: 100%; height: 100%; display: block; }
.fly-tog { position: absolute; right: 10px; top: 10px; background: rgba(255,255,255,.7) !important; }
.char-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.char-top { display: flex; gap: 8px; }
.char-top input { flex: 1; font: 600 20px var(--font-head); min-width: 0; }
.char-bio, .char-power { margin: 0; font-weight: 700; font-size: 14px; color: #4b5563; }
.char-colors { display: flex; gap: 10px; flex-wrap: wrap; }
.char-sel { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.char-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.data-tab section { margin-bottom: 22px; }
.data-tab h3 { font: 600 19px var(--font-head); margin: 0 0 6px; color: var(--accent); }
.data-tab .btn { margin: 4px 4px 4px 0; }
.code-box { display: block; width: 100%; min-height: 110px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; }

/* ---------- game ---------- */
#screen-game { background: #000; touch-action: none; user-select: none; -webkit-user-select: none; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#game-touch { position: absolute; inset: 0; z-index: 1; cursor: pointer; touch-action: none; }
.hud { position: absolute; top: 0; left: 0; right: 0; z-index: 2; display: flex; align-items: center; gap: 12px; padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); pointer-events: none; color: #fff; }
.hud-btn { pointer-events: auto; width: 44px; height: 44px; border-radius: 14px; border: 0; background: rgba(0,0,0,.35); color: #fff; font-size: 20px; cursor: pointer; display: grid; place-items: center; position: relative; backdrop-filter: blur(4px); }
.hud-btn:hover { background: rgba(0,0,0,.5); }
.hud-btn small { position: absolute; right: 4px; bottom: 1px; font: 900 15px var(--font-body); }
.hud-mid { flex: 1; max-width: 560px; margin: 0 auto; text-align: center; }
.hud-name { font: 600 14px var(--font-head); text-shadow: 0 1px 3px rgba(0,0,0,.6); margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-bar { position: relative; height: 12px; border-radius: 8px; background: rgba(0,0,0,.35); border: 2px solid rgba(255,255,255,.8); overflow: visible; }
.hud-bar i { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, #7cff6b, #ffe066); }
.hud-bar b { position: absolute; top: -5px; width: 3px; height: 18px; background: #fff; border-radius: 2px; margin-left: -1px; box-shadow: 0 0 4px rgba(0,0,0,.5); }
.hud-right { display: flex; flex-direction: column; align-items: flex-end; min-width: 64px; }
.hud-pct { font: 700 22px var(--font-head); text-shadow: 0 2px 4px rgba(0,0,0,.5); }
.hud-coins { font-size: 16px; letter-spacing: 1px; }
.hud-coins span { color: rgba(255,255,255,.4); }
.hud-practice { position: absolute; z-index: 2; left: 50%; top: 64px; transform: translateX(-50%); background: #16a34a; color: #fff; font: 800 13px var(--font-body); padding: 4px 12px; border-radius: 20px; pointer-events: none; }
.hud-ck { position: absolute; z-index: 2; left: max(12px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: center; color: #fff; font: 800 15px var(--font-body); text-shadow: 0 1px 3px #000; }
.rotate-hint { display: none; position: absolute; z-index: 2; bottom: 16px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.55); color: #fff; padding: 6px 14px; border-radius: 20px; font-weight: 800; font-size: 13px; pointer-events: none; white-space: nowrap; }
@media (orientation: portrait) and (max-width: 700px) { .rotate-hint { display: block; } }

/* ---------- level maker ---------- */
#screen-editor { flex-direction: column; color: #fff; background: #1b1033; }
.ed-top { display: flex; align-items: center; gap: 8px; padding: 8px 12px; flex-wrap: wrap; background: rgba(0,0,0,.3); }
.ed-top .btn.ghost { color: #fff; }
.ed-top input[type=text] { width: 170px; font-family: var(--font-head); font-weight: 600; }
.ed-top select { font-size: 13px; padding: 6px 8px; }
.ed-bpm { display: flex; align-items: center; gap: 6px; font-weight: 800; }
.ed-bpm input { width: 100px; }
.ed-bpm output { min-width: 30px; font-size: 13px; }
.ed-gap { flex: 1; }
.ed-tools { display: flex; gap: 4px; padding: 6px 12px; overflow-x: auto; background: rgba(0,0,0,.18); scrollbar-width: thin; }
.tool { flex: none; width: 42px; height: 42px; font-size: 21px; border-radius: 11px; border: 2px solid transparent; background: rgba(255,255,255,.12); cursor: pointer; display: grid; place-items: center; }
.tool:hover { background: rgba(255,255,255,.22); }
.tool.on { border-color: #ffe066; background: rgba(255,224,102,.3); }
.ed-stage { flex: 1; position: relative; min-height: 200px; }
#ed-cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.ed-bottom { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: rgba(0,0,0,.3); }
.ed-bottom input { flex: 1; width: auto; }
.ed-bottom .muted { color: rgba(255,255,255,.7); font-weight: 700; font-size: 13px; white-space: nowrap; }
.more-list { display: grid; gap: 8px; }

/* ---------- modals ---------- */
#modal-root { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.modal-back { position: fixed; inset: 0; background: rgba(15,5,30,.55); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 16px; pointer-events: auto; animation: fadein .2s; }
.modal-back.closing { animation: fadeout .16s forwards; }
.modal { background: var(--panel); color: var(--panel-ink); border-radius: 22px; width: 100%; max-width: 480px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 30px 80px rgba(0,0,0,.5); animation: pop .3s cubic-bezier(.2, 1.4, .4, 1); overflow: hidden; }
.modal.wide { max-width: min(760px, 100%); }
.modal-head { display: flex; align-items: center; padding: 16px 20px 0; gap: 10px; }
.modal-head h2 { flex: 1; margin: 0; font: 600 23px var(--font-head); }
.modal-head .x { border: 0; background: rgba(0,0,0,.06); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 15px; }
.modal-body { padding: 14px 20px; overflow: auto; }
.modal-body p { margin: 0 0 10px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 0 20px 18px; flex-wrap: wrap; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
@keyframes fadein { from { opacity: 0; } }
@keyframes fadeout { to { opacity: 0; } }
.pause-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin-bottom: 12px; }
.pause-stats div { background: rgba(0,0,0,.05); border-radius: 12px; padding: 8px 10px; text-align: center; }
.pause-stats b { display: block; font: 600 20px var(--font-head); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pause-stats small { color: var(--muted); font-weight: 800; font-size: 11.5px; }
.pause-toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.done-modal { text-align: center; }
.done-hero { height: 130px; background: radial-gradient(circle, #fff3c4, #ffd6e0 60%, transparent 70%); }
.done-hero canvas { width: 100%; height: 100%; }
.done-name { font: 600 22px var(--font-head); margin: 4px 0 !important; }
.done-stars { font-size: 34px; letter-spacing: 6px; margin-bottom: 10px; }
.done-modal .modal-foot { justify-content: center; }
.howto { display: flex; flex-direction: column; gap: 10px; }
.how-row { display: flex; gap: 12px; align-items: flex-start; font-weight: 600; line-height: 1.45; }
.how-ico { font-size: 26px; width: 36px; flex: none; text-align: center; }

/* ---------- toasts, confetti, loading ---------- */
#toasts { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 60; pointer-events: none; align-items: center; width: max-content; max-width: 92vw; }
.toast { background: rgba(17,12,34,.92); color: #fff; padding: 9px 18px; border-radius: 30px; font-weight: 800; font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.35); border-left: 5px solid var(--tc, var(--accent)); animation: pop .35s cubic-bezier(.2, 1.4, .4, 1); transition: opacity .4s, transform .4s; text-align: center; }
.toast.out { opacity: 0; transform: translateY(-10px); }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
#confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
#loading { position: fixed; inset: 0; z-index: 80; background: rgba(20,8,40,.6); display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; font-weight: 800; }
.spinner { font-size: 54px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  .tab-body { margin: 0 8px 12px; padding: 16px 14px; }
  .tabs { padding: 0 8px; }
  .tabs button { padding: 9px 12px; font-size: 14px; }
  .setup-head { padding: 10px 12px 8px; }
  .setup-head h2 { font-size: 22px; }
  .form { column-width: auto; }
  .frow { flex-wrap: wrap; }
  .rrow { grid-template-columns: 1fr; gap: 6px; }
  .title-wrap { padding: 18px 16px; margin-bottom: 12vh; }
  .btn.big { font-size: 17px; padding: 12px 20px; }
  .char-grid { grid-template-columns: 1fr; }
  .ed-top input[type=text] { width: 120px; }
  .lv-grid { grid-template-columns: 1fr; }
}
@media (max-height: 520px) {
  .title-logo, .title-foot { display: none; }
  #title-name { font-size: 46px; margin-top: 0; }
  .title-sub { margin-bottom: 12px; }
  .title-wrap { margin-bottom: 0; padding: 14px 20px; }
  .btn.big { font-size: 16px; padding: 10px 18px; }
  .hud-practice { top: 54px; }
}
@media (prefers-reduced-motion: reduce) { .title-logo, .spinner { animation: none; } }
