/* heartbeat♡ — cotton-candy dreamcore.
 * Soft pink ground, pink dot grid, chunky candy controls, pixel-crisp mascot.
 * The play field stays a touch deeper than the chrome so notes keep their contrast.
 */
:root {
  --bg: #ffe3f1;
  --bg2: #f3d9ff;
  --field: #ffd1e8;
  --field2: #ecd0fb;

  --ink: #7a2e5c;
  --dim: #b87fa6;
  --line: #ffb8d9;

  --pink: #ff2e88;
  --pink-soft: #ff9cc9;
  --pink-pale: #ffd9ec;

  /* lanes: pink · lavender · mint · sky */
  --l0: #ff2e88;
  --l1: #b57bee;
  --l2: #2fc9b8;
  --l3: #5f9cff;

  --perfect: #ff2e88;
  --great: #2fc9b8;
  --good: #5f9cff;
  --miss: #b87fa6;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; width: 100%;
  position: fixed; overscroll-behavior: none;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Pretendard, "Malgun Gothic", sans-serif;
  overflow: hidden; touch-action: none; user-select: none;

  background-color: var(--bg);
  /* dreamy blobs + the pink dot grid */
  background-image:
    radial-gradient(circle at 18% 12%, rgba(255,255,255,.85), transparent 42%),
    radial-gradient(circle at 82% 8%,  rgba(181,123,238,.30), transparent 46%),
    radial-gradient(circle at 88% 88%, rgba(255,46,136,.20), transparent 44%),
    radial-gradient(circle at 8% 84%,  rgba(95,156,255,.20), transparent 46%),
    radial-gradient(circle, rgba(255,46,136,.16) 1.4px, transparent 1.5px),
    linear-gradient(160deg, var(--bg), var(--bg2));
  background-size: auto, auto, auto, auto, 14px 14px, auto;
}
#app {
  position: relative; height: 100dvh; width: 100vw;
  display: flex; flex-direction: column; align-items: center;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}

/* ---------- HUD ---------- */
#hud {
  width: 100%; max-width: 560px; display: flex; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 18px 6px; z-index: 4;
  flex: 0 0 auto;
}
.hb { text-align: center; }
.hl { font-size: 10px; color: var(--dim); letter-spacing: .14em; font-weight: 700; }
.hv {
  font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(255,255,255,.9);
}
#vScore { color: var(--ink); }
#vCombo { color: var(--pink); }
#vAcc { color: var(--l2); }

/* ---------- Stage ---------- */
#stageWrap {
  position: relative; flex: 1 1 auto; min-height: 0; width: 100%; max-width: 560px;
  background:
    radial-gradient(circle, rgba(255,255,255,.5) 1.4px, transparent 1.5px),
    linear-gradient(180deg, var(--field), var(--field2));
  background-size: 12px 12px, auto;
  border-left: 3px solid rgba(255,255,255,.65);
  border-right: 3px solid rgba(255,255,255,.65);
  box-shadow: inset 0 0 40px rgba(255,255,255,.55);
}
canvas { display: block; width: 100%; height: 100%; }

#progress {
  width: 100%; max-width: 560px; height: 5px; background: var(--pink-pale); position: relative;
  flex: 0 0 auto; margin-bottom: env(safe-area-inset-bottom);
}
#progressFill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--l0), var(--l1), var(--l2));
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center;
  /* `safe` keeps the top reachable: plain `center` clips the overflowing start
     edge of a scroll container, so the logo becomes unscrollable on short screens. */
  justify-content: center;
  justify-content: safe center;
  gap: 13px; padding: 24px; text-align: center;
  background:
    radial-gradient(circle, rgba(255,46,136,.10) 1.4px, transparent 1.5px),
    linear-gradient(160deg, rgba(255,227,241,.96), rgba(243,217,255,.96));
  background-size: 14px 14px, auto;
  backdrop-filter: blur(6px);
  overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
}
.hidden { display: none !important; }

/* ---------- Logo + title ---------- */
#logo { line-height: 0; filter: drop-shadow(0 4px 0 rgba(255,156,201,.55)); }
#logo svg, #logo img {
  width: 104px; height: auto; display: block;
  image-rendering: pixelated; image-rendering: crisp-edges;
}
h1 {
  margin: 0; font-size: 34px; font-weight: 800; letter-spacing: .02em;
  color: var(--pink);
  text-shadow: 0 3px 0 #fff, 0 5px 0 var(--pink-soft), 0 8px 14px rgba(255,46,136,.3);
}
h1 .heart { display: inline-block; animation: beat 1.1s ease-in-out infinite; }
@keyframes beat {
  0%, 100% { transform: scale(1); }
  18% { transform: scale(1.22); }
  36% { transform: scale(1); }
}
.desc {
  color: var(--dim); font-size: 13px; line-height: 1.75; max-width: 380px;
  /* Korean wraps mid-phrase by default, which leaves orphan words like "분석해"
     stranded on their own line; keep-all breaks only at spaces. */
  word-break: keep-all;
  text-wrap: balance;
}
.desc b { color: var(--pink); }

/* ---------- Candy buttons ---------- */
.btn {
  border: none; border-radius: 999px; padding: 13px 30px; font-size: 15px; font-weight: 800;
  color: #fff; background: linear-gradient(180deg, #ff6fae, var(--pink));
  cursor: pointer;
  box-shadow: 0 4px 0 #d81b6e, 0 9px 18px rgba(255,46,136,.32);
  transition: transform .08s, box-shadow .08s;
}
.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #d81b6e, 0 4px 10px rgba(255,46,136,.3);
}
.btn.ghost {
  color: var(--ink); background: #fff;
  box-shadow: 0 4px 0 var(--line), 0 9px 18px rgba(255,46,136,.16);
}
.btn.ghost:active { box-shadow: 0 1px 0 var(--line), 0 4px 10px rgba(255,46,136,.16); }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* Built-in track buttons: title over a small duration line. */
.song-btn {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 9px 20px; line-height: 1.25;
}
.song-btn span { font-size: 14px; }
.song-btn small { font-size: 10px; color: var(--dim); font-weight: 700; letter-spacing: .04em; }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.field-label { font-size: 11px; color: var(--dim); letter-spacing: .1em; font-weight: 700; }
.seg {
  display: flex; border-radius: 999px; overflow: hidden;
  background: #fff; box-shadow: 0 3px 0 var(--line);
}
.seg button {
  background: transparent; border: none; color: var(--dim);
  padding: 8px 16px; font-size: 13px; cursor: pointer; font-weight: 800;
}
.seg button.on { background: linear-gradient(180deg, #ff6fae, var(--pink)); color: #fff; }

input[type=range] { width: 220px; accent-color: var(--pink); }
.val { font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; font-weight: 700; }

#fileName {
  font-size: 12px; color: var(--pink); font-weight: 700;
  max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#loadStatus { font-size: 13px; color: var(--dim); min-height: 18px; font-weight: 600; }

#bar {
  width: 260px; height: 8px; background: #fff; border-radius: 999px; overflow: hidden;
  box-shadow: 0 2px 0 var(--line);
}
#barFill {
  height: 100%; width: 0%; transition: width .15s;
  background: linear-gradient(90deg, var(--l1), var(--l0));
}

/* ---------- Result ---------- */
#grade {
  font-size: 62px; font-weight: 800; line-height: 1;
  text-shadow: 0 4px 0 #fff, 0 7px 16px rgba(255,46,136,.3);
}
#rScore { font-size: 34px; font-weight: 800; color: var(--ink); }
.stats {
  display: grid; grid-template-columns: repeat(4, auto); gap: 14px;
  font-size: 11px; color: var(--dim); font-weight: 700;
}
.stats b { display: block; font-size: 17px; margin-bottom: 2px; }
#sP b { color: var(--perfect); } #sG b { color: var(--great); }
#sO b { color: var(--good); }   #sM b { color: var(--miss); }

#pauseBtn {
  position: absolute; top: 8px; right: 10px; z-index: 5;
  background: #fff; border: none; color: var(--pink);
  border-radius: 999px; padding: 8px 14px; font-size: 12px; font-weight: 800;
  cursor: pointer; box-shadow: 0 3px 0 var(--line);
}
.note-small { font-size: 11px; color: var(--dim); }

/* ---- Landscape / short viewports: compress chrome, keep the lane tall ---- */
@media (max-height: 560px) {
  #hud { padding: calc(4px + env(safe-area-inset-top)) 14px 2px; }
  .hl { font-size: 9px; }
  .hv { font-size: 15px; }
  #stageWrap, #progress { max-width: 760px; }
  #pauseBtn { padding: 5px 11px; font-size: 11px; }

  .overlay { gap: 8px; padding: 12px 16px; justify-content: flex-start; }
  #logo svg, #logo img { width: 56px; }
  h1 { font-size: 22px; }
  .desc { font-size: 11px; line-height: 1.5; max-width: 460px; }
  .btn { padding: 9px 20px; font-size: 13px; }
  .field { flex-direction: row; align-items: center; gap: 10px; }
  .field-label { font-size: 10px; }
  input[type=range] { width: 170px; }
  .seg button { padding: 6px 13px; font-size: 12px; }
  #grade { font-size: 38px; }
  #rScore { font-size: 24px; }
  .stats { gap: 10px; font-size: 10px; }
  .stats b { font-size: 14px; }
  #loadStatus { font-size: 12px; min-height: 14px; }
  .note-small { font-size: 10px; }
}

/* Very short (landscape phones): two columns so the controls fit without scrolling.
   justify-items:center matters — grid items stretch by default, which blows the
   candy buttons up to full column width and wraps their labels. */
@media (max-height: 440px) and (orientation: landscape) {
  #menuOverlay {
    display: grid; grid-template-columns: auto auto;
    justify-content: center; align-content: center; justify-items: center;
    gap: 7px 26px; padding: 10px 18px;
  }
  #menuOverlay h1 { grid-column: 1 / -1; font-size: 20px; }
  #menuOverlay #playBtn { grid-column: 1 / -1; }
  #menuOverlay #logo,
  #menuOverlay .desc,
  #menuOverlay .note-small { display: none; }
  #menuOverlay .field-label { white-space: nowrap; }
}

/* Narrow phones in portrait */
@media (max-width: 400px) {
  .hv { font-size: 18px; }
  h1 { font-size: 28px; }
  #logo svg, #logo img { width: 84px; }
  .desc { font-size: 12px; }
  .btn { padding: 12px 22px; font-size: 14px; }
  input[type=range] { width: 200px; }
}
