@font-face {
  font-family: 'Shrikhand';
  src: url('../assets/fonts/shrikhand-latin-400-normal.woff2') format('woff2');
  font-display: swap;
}
@font-face {
  font-family: 'Barlow SC';
  font-weight: 500;
  src: url('../assets/fonts/barlow-semi-condensed-latin-500-normal.woff2') format('woff2');
  font-display: swap;
}
@font-face {
  font-family: 'Barlow SC';
  font-weight: 700;
  src: url('../assets/fonts/barlow-semi-condensed-latin-700-normal.woff2') format('woff2');
  font-display: swap;
}

:root {
  --malam: #1b1030;
  --aspal: #0e0818;
  --ungu: #2c1b4d;
  --garis: #4a3477;
  --kunyit: #ffc629;
  --sambal: #f0353c;
  --tosca: #22e6d2;
  --kapur: #f5f0ff;
  --redup: #b3a6cf;
  --display: 'Shrikhand', 'Georgia', serif;
  --ui: 'Barlow SC', 'Arial Narrow', 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 { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  background:
    radial-gradient(120% 70% at 12% -10%, rgba(255, 198, 41, 0.16), transparent 60%),
    radial-gradient(110% 70% at 95% 0%, rgba(34, 230, 210, 0.12), transparent 55%),
    linear-gradient(var(--malam), var(--aspal));
  color: var(--kapur);
  font: 500 17px/1.4 var(--ui);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
button, input, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#app { position: fixed; inset: 0; }
.version {
  position: fixed; z-index: 30; top: calc(8px + var(--safe-t)); right: calc(12px + var(--safe-r));
  font-weight: 700; font-size: 14px; color: var(--redup); pointer-events: none;
}
body.in-game .version { display: none; }

.screen { position: absolute; inset: 0; display: none; flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }
.screen.is-active { display: flex; }

/* ---------- menu ---------- */
#screen-menu { justify-content: flex-end; padding: 24px; padding-bottom: calc(24px + var(--safe-b)); gap: 22px; }
body.dim-stage #stage { opacity: 0.38; }
.wordmark {
  font: 400 clamp(64px, 23vw, 132px)/0.86 var(--display);
  color: var(--kunyit);
  transform: rotate(-5deg);
  transform-origin: left bottom;
  text-shadow: 3px 3px 0 var(--sambal), 6px 6px 0 var(--sambal), 9px 9px 0 #7a1420, 12px 12px 0 rgba(0, 0, 0, 0.45);
  margin: 0 0 8px 2px;
}
.wordmark span { display: block; }
.wordmark span + span { margin-left: 0.42em; }
.menu { display: grid; gap: 12px; width: min(100%, 380px); }
.menu-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn {
  display: block; width: 100%; text-align: left; cursor: pointer;
  padding: 14px 18px; min-height: 52px;
  font-weight: 700; font-size: 20px;
  color: var(--kapur); background: var(--ungu);
  border: 2px solid var(--garis); border-radius: 10px;
}
.btn:active { transform: translate(2px, 2px); }
.btn-primary {
  color: #1a0f00; background: var(--kunyit); border-color: #1a0f00;
  box-shadow: 4px 4px 0 var(--sambal);
}
.btn-primary:active { box-shadow: 1px 1px 0 var(--sambal); transform: translate(3px, 3px); }
.btn-quiet { background: transparent; font-size: 18px; }
.btn-danger { border-color: var(--sambal); color: #ffb3b6; background: transparent; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:focus-visible, .back:focus-visible, .chip:focus-visible, .song:focus-visible { outline: 3px solid var(--tosca); outline-offset: 2px; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; }
.btn-row .btn { width: auto; flex: 1 1 180px; }
.file-btn { cursor: pointer; }

/* ---------- bar + layout ---------- */
.bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: 10px 14px; padding-right: 64px; flex: none;
}
.bar h2 { font: 400 26px/1 var(--display); color: var(--kunyit); letter-spacing: 0.01em; }
.back, .bar-action {
  justify-self: start; background: none; border: 0; padding: 10px 4px; cursor: pointer;
  font-weight: 700; font-size: 18px; color: var(--kapur);
}
.back::before { content: '‹ '; color: var(--kunyit); }
.bar-action { justify-self: end; color: var(--kunyit); }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 16px 28px; display: grid; gap: 14px; align-content: start;
  width: min(100%, 720px); margin: 0 auto; }
.panel { background: rgba(44, 27, 77, 0.82); border: 2px solid var(--garis); border-radius: 12px; padding: 16px; display: grid; gap: 12px; }
.panel h3 { font-size: 21px; font-weight: 700; }
.panel p, .hint, .prose p { color: var(--redup); }
.hint { font-size: 15px; }
.status { min-height: 24px; color: var(--kapur); white-space: pre-line; }
.status.is-error { color: #ffb3b6; }
.desktop-only { display: none; }
@media (hover: hover) and (pointer: fine) { .desktop-only { display: block; } }

/* ---------- songs ---------- */
.songs-layout { flex: 1; min-height: 0; display: grid; grid-template-rows: 1fr auto; }
.song-list { list-style: none; margin: 0; padding: 4px 12px 12px; overflow-y: auto; -webkit-overflow-scrolling: touch; display: grid; gap: 8px; align-content: start; }
.song {
  display: grid; grid-template-columns: 54px 1fr auto; gap: 12px; align-items: center; width: 100%; text-align: left;
  padding: 8px 12px 8px 8px; background: rgba(44, 27, 77, 0.78); border: 2px solid transparent; border-radius: 10px; cursor: pointer;
}
.song.is-selected { border-color: var(--kunyit); background: var(--ungu); }
.cover { width: 54px; height: 54px; border-radius: 7px; background-size: cover; background-position: center; display: grid; place-items: center;
  font: 400 26px/1 var(--display); color: rgba(0, 0, 0, 0.6); }
.song-title { font-weight: 700; font-size: 19px; line-height: 1.15; }
.song-sub { color: var(--redup); font-size: 15px; }
.song-stars { color: var(--kunyit); font-size: 15px; letter-spacing: 1px; white-space: nowrap; }
.song-stars.is-gold { color: #fff3b0; text-shadow: 0 0 8px var(--kunyit); }
.song-detail {
  background: var(--aspal); border-top: 2px solid var(--garis);
  padding: 14px 16px calc(14px + var(--safe-b)); display: grid; gap: 12px;
}
.song-detail:empty { display: none; }
.detail-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.detail-head b { font-size: 21px; line-height: 1.1; }
.detail-head span { color: var(--redup); font-size: 15px; white-space: nowrap; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 8px 11px; min-height: 42px; border-radius: 999px; border: 2px solid var(--garis); background: transparent; cursor: pointer;
  font-weight: 700; font-size: 16px; color: var(--kapur);
}
.chip small { font-weight: 500; color: var(--redup); margin-left: 4px; }
.chip.is-on { background: var(--kapur); border-color: var(--kapur); color: var(--aspal); }
.chip.is-on small { color: #5b4a80; }
.detail-actions { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; }
.detail-actions .btn { text-align: center; }
.detail-actions .btn-quiet { width: auto; padding-inline: 14px; font-size: 16px; }
.best { color: var(--redup); font-size: 15px; }

@media (min-width: 820px) and (orientation: landscape) {
  .songs-layout { grid-template-rows: none; grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr); }
  .song-detail { border-top: 0; border-left: 2px solid var(--garis); align-content: start; background: rgba(14, 8, 24, 0.85); }
  #screen-menu { flex-direction: row; align-items: flex-end; justify-content: space-between; padding: 40px 56px; }
}
@media (max-height: 460px) and (orientation: landscape) {
  .songs-layout { grid-template-rows: none; grid-template-columns: 1fr 1fr; }
  .song-detail { border-top: 0; border-left: 2px solid var(--garis); align-content: start; overflow-y: auto; }
  #screen-menu { flex-direction: row; align-items: flex-end; justify-content: space-between; padding: 16px 28px; }
  .wordmark { font-size: clamp(48px, 15vw, 96px); }
  .menu { gap: 8px; }
  .btn { min-height: 44px; padding: 9px 16px; font-size: 18px; }
}

/* ---------- game ---------- */
.screen-game { padding: 0; }
.touch-surface { position: absolute; inset: 0; touch-action: none; }
.hud { position: absolute; pointer-events: none; }
.hud-top { top: calc(8px + var(--safe-t)); left: calc(12px + var(--safe-l)); right: calc(12px + var(--safe-r));
  display: grid; grid-template-columns: 1fr minmax(90px, 34%) 1fr; align-items: start; gap: 10px; }
.num { font-variant-numeric: tabular-nums; font-weight: 700; }
#hud-score { font-size: 30px; line-height: 1; }
.hud-stars { color: var(--kunyit); font-size: 15px; letter-spacing: 2px; margin-top: 2px; }
.hud-stars i { font-style: normal; opacity: 0.25; }
.hud-stars i.on { opacity: 1; }
.hud-mid { display: grid; gap: 4px; text-align: center; padding-top: 4px; }
.hud-section { font-size: 14px; color: var(--redup); min-height: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.16); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--kunyit); }
.pause-btn { pointer-events: auto; justify-self: end; width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--garis);
  background: rgba(14, 8, 24, 0.7); font-weight: 700; font-size: 16px; cursor: pointer; }
.hud-left, .hud-right { top: 36%; display: grid; gap: 6px; justify-items: center; }
.hud-left { left: calc(10px + var(--safe-l)); }
.hud-right { right: calc(10px + var(--safe-r)); }
.mult { width: 62px; height: 62px; border-radius: 50%; display: grid; place-items: center; font: 400 26px/1 var(--display);
  color: var(--aspal); background: var(--kapur); border: 3px solid var(--aspal); box-shadow: 3px 3px 0 var(--garis); }
.mult[data-m='2'] { background: var(--kunyit); }
.mult[data-m='3'] { background: #ff8a1e; }
.mult[data-m='4'] { background: var(--sambal); color: #fff; }
.mult.is-super { background: var(--tosca); color: var(--aspal); box-shadow: 0 0 18px var(--tosca); }
.streak { font-size: 14px; color: var(--redup); text-align: center; line-height: 1.1; }
.streak .num { display: block; font-size: 22px; color: var(--kapur); }
.super-meter { position: relative; width: 20px; height: 110px; border-radius: 10px; border: 2px solid var(--garis); background: rgba(14, 8, 24, 0.7); overflow: hidden; }
.super-meter i { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: var(--tosca); }
.super-meter b { position: absolute; left: 0; right: 0; bottom: 50%; height: 2px; background: var(--kapur); opacity: 0.7; }
.super-btn { pointer-events: auto; padding: 10px 8px; min-width: 62px; border-radius: 10px; border: 2px solid var(--garis); background: rgba(14, 8, 24, 0.7);
  font-weight: 700; font-size: 15px; color: var(--redup); cursor: pointer; }
.super-btn:not(:disabled) { color: var(--aspal); background: var(--tosca); border-color: var(--aspal); box-shadow: 0 0 16px var(--tosca); animation: nudge 0.7s ease-in-out infinite alternate; }
@keyframes nudge { to { transform: scale(1.08); } }
.feedback:empty { display: none; }
.feedback { position: absolute; left: 0; right: 0; top: 17%; text-align: center; pointer-events: none;
  font: 400 34px/1 var(--display); color: var(--kunyit); text-shadow: 3px 3px 0 var(--aspal); opacity: 0; }
.feedback.show { animation: pop 0.9s ease-out; }
@keyframes pop { 0% { opacity: 0; transform: scale(0.7) rotate(-4deg); } 15% { opacity: 1; transform: scale(1.1) rotate(-4deg); } 70% { opacity: 1; } 100% { opacity: 0; transform: scale(1) rotate(-4deg) translateY(-14px); } }
.countdown:empty { display: none; }
.countdown { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; transform: translateZ(0); font: 400 120px/1 var(--display); color: var(--kunyit);
  text-shadow: 5px 5px 0 var(--sambal); }
.judge { position: absolute; left: 0; right: 0; top: 46%; text-align: center; pointer-events: none; }
.grade { font: 400 38px/1 var(--display); text-shadow: 3px 3px 0 var(--aspal); opacity: 0; }
.grade.show { animation: judge 0.45s ease-out forwards; }
.grade[data-g='perfect'] { color: var(--kunyit); }
.grade[data-g='great'] { color: var(--tosca); }
.grade[data-g='cool'] { color: var(--kapur); }
.grade[data-g='miss'] { color: var(--sambal); }
.combo { font-weight: 700; font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; text-shadow: 2px 2px 0 var(--aspal); min-height: 24px; }
.combo b { font-size: 34px; }
.plus { font-weight: 700; font-size: 18px; color: var(--kunyit); font-variant-numeric: tabular-nums; text-shadow: 2px 2px 0 var(--aspal); opacity: 0; }
.plus.show { animation: plus 0.5s ease-out forwards; }
@keyframes judge { 0% { opacity: 1; transform: scale(1.25); } 25% { transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; } }
@keyframes plus { 0% { opacity: 1; transform: translateY(4px); } 100% { opacity: 0; transform: translateY(-12px); } }
@media (max-height: 460px) { .judge { top: 34%; } .grade { font-size: 30px; } .combo b { font-size: 26px; } }
@media (max-height: 460px) { .hud-left, .hud-right { top: 30%; } .super-meter { height: 70px; } .mult { width: 52px; height: 52px; font-size: 22px; } }

/* ---------- overlay ---------- */
.overlay { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(14, 8, 24, 0.78); padding: 20px; }
.overlay[hidden], .toast[hidden] { display: none; }
.sheet { width: min(100%, 360px); display: grid; gap: 12px; background: var(--malam); border: 2px solid var(--garis); border-radius: 14px; padding: 20px; }
.sheet h2 { font: 400 34px/1 var(--display); color: var(--kunyit); }
.sheet-loading { text-align: center; font-weight: 700; font-size: 19px; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(22px + var(--safe-b)); transform: translateX(-50%); max-width: 92vw;
  background: var(--kapur); color: var(--aspal); font-weight: 700; padding: 10px 16px; border-radius: 10px; box-shadow: 4px 4px 0 var(--garis); }

/* ---------- results ---------- */
.results { margin: auto; width: min(100%, 440px); padding: 20px; display: grid; gap: 14px; }
.verdict { font: 400 clamp(44px, 14vw, 68px)/0.95 var(--display); color: var(--kunyit); transform: rotate(-4deg); text-shadow: 4px 4px 0 var(--sambal); }
.res-stars { font-size: 40px; letter-spacing: 6px; color: var(--kunyit); }
.res-stars i { font-style: normal; opacity: 0.22; }
.res-stars i.on { opacity: 1; }
.res-stars.is-gold i.on { color: #fff3b0; text-shadow: 0 0 14px var(--kunyit); }
.res-score { font-size: 52px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.res-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.res-grid div { display: flex; justify-content: space-between; border-bottom: 1px solid var(--garis); padding: 4px 0; color: var(--redup); }
.res-grid b { color: var(--kapur); font-variant-numeric: tabular-nums; }
.res-note { color: var(--redup); font-size: 15px; }

/* ---------- settings ---------- */
.field { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; align-items: center; }
.field label, .field .label { font-weight: 700; }
.field small { grid-column: 1 / -1; color: var(--redup); font-size: 15px; }
.field input[type='range'] { grid-column: 1 / -1; width: 100%; accent-color: var(--kunyit); height: 32px; }
.field output { font-variant-numeric: tabular-nums; color: var(--kunyit); font-weight: 700; }
select { background: var(--aspal); border: 2px solid var(--garis); border-radius: 8px; padding: 8px 10px; min-height: 42px; }
.switch { appearance: none; width: 54px; height: 32px; border-radius: 16px; background: var(--aspal); border: 2px solid var(--garis); position: relative; cursor: pointer; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--redup); transition: transform 0.15s; }
.switch:checked { background: var(--kunyit); border-color: var(--kunyit); }
.switch:checked::after { transform: translateX(22px); background: var(--aspal); }
.keys { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.keycap { padding: 8px 2px; text-align: center; border-radius: 8px; border: 2px solid var(--garis); background: var(--aspal); font-weight: 700; font-size: 15px; cursor: pointer; }
.keycap.is-wait { border-color: var(--kunyit); color: var(--kunyit); }
.calib { text-align: center; justify-items: center; }
.calib-pad { width: min(70vw, 260px); aspect-ratio: 1; border-radius: 50%; border: 4px solid var(--aspal); background: var(--kunyit); color: #1a0f00;
  font: 400 34px/1 var(--display); box-shadow: 6px 6px 0 var(--sambal); cursor: pointer; touch-action: none; }
.calib-pad.is-beat { background: #fff3b0; }
.prose { gap: 10px; }
.prose h3 { font-size: 21px; color: var(--kunyit); margin-top: 8px; }
.prose ul { margin: 0; padding-left: 20px; color: var(--redup); display: grid; gap: 4px; }
.prose b { color: var(--kapur); }

/* ---------- editor ---------- */
.screen-editor { padding: 0; background: var(--aspal); }
.ed-top { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: calc(6px + var(--safe-t)) 8px 6px; flex: none; }
.ed-top .back { padding: 8px 6px; flex: none; }
.ed-title { font-weight: 700; flex: 1 1 120px; min-width: 60px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-btn { flex: none; min-width: 42px; min-height: 42px; padding: 6px 10px; border-radius: 8px; border: 2px solid var(--garis); background: var(--ungu); font-weight: 700; font-size: 15px; cursor: pointer; }
.ed-btn.is-on { background: var(--kunyit); color: #1a0f00; border-color: var(--kunyit); }
.ed-btn:disabled { opacity: 0.4; }
.ed-main { flex: 1; min-height: 0; position: relative; }
.ed-main canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.ed-bottom { flex: none; display: grid; gap: 6px; padding: 6px 8px calc(6px + var(--safe-b)); border-top: 2px solid var(--garis); }
.ed-row { display: flex; gap: 6px; overflow-x: auto; align-items: center; }
.ed-row select { min-height: 42px; padding: 4px 8px; font-size: 15px; }
.ed-time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 86px; text-align: center; color: var(--kunyit); }
.ed-pads { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.ed-pad { height: 46px; border-radius: 8px; border: 3px solid var(--aspal); cursor: pointer; touch-action: none; }
.ed-pick { margin: auto; width: min(100%, 460px); padding: 20px; display: grid; gap: 12px; max-height: 100%; overflow-y: auto; }
.ed-form { display: grid; gap: 10px; }
.ed-form input[type='text'], .ed-form input[type='number'] { width: 100%; background: var(--aspal); border: 2px solid var(--garis); border-radius: 8px; padding: 10px; min-height: 44px; -webkit-user-select: text; user-select: text; }

@media (prefers-reduced-motion: reduce) {
  .super-btn:not(:disabled), .feedback.show { animation: none; }
  .grade.show, .plus.show { animation-duration: 0.01s; }
  .feedback.show { opacity: 1; }
}

.cloud-tag { font-weight: 700; color: var(--tosca); }
.sync { display: grid; gap: 6px; }
.sync[hidden] { display: none; }
.sync-label { font-size: 15px; color: var(--kapur); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync .progress { height: 8px; }
