@font-face { font-family: "Mali"; src: url("../fonts/Mali-Bold.ttf") format("truetype"); font-weight: 700; font-display: block; }
@font-face { font-family: "Fredoka"; src: url("../fonts/Fredoka.ttf") format("truetype"); font-weight: 300 700; font-display: block; }

:root {
  --ink: #3c2878;
  --purple: #7b2ff7;
  --lilac: #8e6cff;
  --pink: #ff69b4;
  --orange: #ff922b;
  --yellow: #ffca3a;
  --green: #4cc978;
  --red: #ff595e;
  --muted: #8b84a0;
  --card: rgba(255, 255, 255, 0.94);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Mali", sans-serif;
  font-weight: 700;
  color: var(--ink);
  background: linear-gradient(#fff4d6, #d6f0ff) fixed;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

.screen { position: fixed; inset: 0; overflow-y: auto; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.hidden { display: none !important; }

/* logo: white circle, purple ring, the word Musicle */
.logo {
  position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right));
  width: 84px; height: 84px; border-radius: 50%;
  background: #fff; border: 5px solid var(--purple);
  display: grid; place-items: center;
  font-family: "Fredoka", sans-serif; font-weight: 700; font-size: 18px; color: var(--purple);
  box-shadow: -3px 4px 0 rgba(0, 0, 0, 0.12);
  z-index: 2;
}

/* ---------- start screen ---------- */
#setup { display: flex; align-items: center; justify-content: center; }
.setup-card, .result-card {
  width: min(760px, 100%); margin: auto;
  background: var(--card); border: 6px solid #3a86ff; border-radius: 40px;
  padding: 22px 26px; text-align: center;
  box-shadow: 0 10px 0 rgba(58, 134, 255, 0.18);
}
.tagline { margin: 0; color: var(--orange); font-size: 20px; }
#song-th { margin: 2px 0 0; color: var(--purple); font-size: clamp(32px, 6vw, 48px); line-height: 1.2; }
.song-en { margin: 0; color: #3a86ff; font-family: "Fredoka", sans-serif; font-size: 20px; }
.note-row { display: flex; justify-content: center; gap: 8px; margin: 10px 0 6px; }
.note-row { flex-wrap: wrap; }
.note-row span {
  min-width: 44px; height: 40px; padding: 0 10px; border-radius: 999px; color: #fff;
  display: grid; place-items: center; font-size: 18px;
}

.opts { display: grid; gap: 10px; margin: 14px 0; }
.opt { display: grid; grid-template-columns: 124px 1fr; align-items: center; gap: 10px; text-align: left; }
.opt-name { font-size: 18px; }
.seg { display: flex; background: #f0eaf4; border-radius: 999px; padding: 4px; gap: 4px; }
.seg button {
  flex: 1; min-height: 46px; border-radius: 999px; font-size: 18px; color: var(--muted);
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.seg button:active { transform: scale(0.96); }
.seg button.on { background: var(--purple); color: #fff; box-shadow: 0 3px 0 #5b1fc4; }
.seg button.na { opacity: 0.55; }
.ico { font-size: 18px; }

.actions { display: flex; gap: 12px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.btn {
  min-height: 58px; padding: 0 26px; border-radius: 999px; font-size: 22px;
  transition: transform 0.1s;
}
.btn:active { transform: translateY(3px); }
.btn-main { background: linear-gradient(#ff8159, #ff5a3c); color: #fff; box-shadow: 0 5px 0 #d8431f; flex: 1.3; }
.btn-soft { background: #fff; color: var(--purple); border: 3px solid var(--lilac); box-shadow: 0 5px 0 rgba(142, 108, 255, 0.35); flex: 1; }

.rotate-hint { display: none; margin: 12px 0 0; color: var(--pink); font-size: 16px; }
@media (orientation: portrait) and (max-width: 700px) { .rotate-hint { display: block; } }

/* landscape phones: tighter */
@media (max-height: 500px) {
  .setup-card { padding: 12px 18px; border-width: 4px; }
  .tagline, .note-row { display: none; }
  #song-th { font-size: 28px; }
  .opts { gap: 6px; margin: 8px 0; grid-template-columns: 1fr 1fr; }
  .opt { grid-template-columns: 1fr; gap: 2px; }
  .opt-name { font-size: 14px; }
  .seg button { min-height: 38px; font-size: 15px; }
  .btn { min-height: 48px; font-size: 18px; }
  .actions { margin-top: 8px; }
  .logo { width: 64px; height: 64px; font-size: 14px; border-width: 4px; }
}

/* ---------- playing screen ---------- */
#play { padding: 0; display: grid; place-items: center; background: #fff4d6; overflow: hidden; }
#stage { display: block; touch-action: none; }
.btn-stop {
  position: absolute; left: max(10px, env(safe-area-inset-left)); top: 50%; transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.92); color: var(--red); border: 3px solid var(--red);
  border-radius: 999px; padding: 8px 14px; font-size: 16px;
}

/* ---------- score screen ---------- */
.result-card { border-color: var(--orange); box-shadow: 0 10px 0 rgba(255, 146, 43, 0.2); }
.result-top { display: flex; gap: 20px; align-items: center; justify-content: center; flex-wrap: wrap; }
.r-title { margin: 0; color: var(--muted); font-size: 16px; }
.stars { font-size: 34px; letter-spacing: 4px; color: #e5ddf0; line-height: 1; margin-top: 4px; }
.stars .lit { color: var(--yellow); text-shadow: 0 2px 0 #e0a800; }
.score { font-family: "Fredoka", sans-serif; font-size: 84px; color: var(--red); line-height: 1; }
.score small { font-size: 26px; color: var(--muted); }
.r-head { margin: 4px 0 0; font-size: 26px; color: var(--purple); }
.parts { display: grid; gap: 8px; min-width: 240px; text-align: left; }
.part-row { display: grid; grid-template-columns: 100px 1fr 54px; align-items: center; gap: 8px; font-size: 16px; }
.bar { height: 14px; background: #f0eaf4; border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 999px; }
.part-row b { font-family: "Fredoka", sans-serif; text-align: right; }

.note-map { margin: 14px 0 4px; display: grid; gap: 6px; }
.map-line { display: flex; gap: 5px; justify-content: center; flex-wrap: wrap; }
.dot-note {
  position: relative; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-family: "Fredoka", sans-serif; font-size: 17px;
  border: 3px solid transparent;
}
.dot-note.timing { border-color: var(--yellow); box-shadow: 0 0 0 2px #fff inset; }
.dot-note.wrong { background: #c9c2d6 !important; border-color: var(--red); }
.dot-note.wrong::after, .dot-note.missed::after {
  content: "✗"; position: absolute; right: -6px; top: -8px; font-size: 14px; color: var(--red);
  background: #fff; border-radius: 50%; width: 18px; height: 18px; display: grid; place-items: center; line-height: 1;
}
.dot-note.missed { background: #fff !important; color: #c9c2d6; border: 3px dashed #c9c2d6; }
.oct { position: absolute; left: 50%; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: currentColor; }
.oct.up { top: 2px; } .oct.up2 { top: -5px; } .oct.down { bottom: 2px; }
.legend { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend .dot-note { width: 18px; height: 18px; font-size: 0; border-width: 2px; }
.legend .dot-note::after { display: none; }

.tips { text-align: left; background: #f7f3fb; border-radius: 24px; padding: 10px 18px; margin-top: 12px; }
.tips h3 { margin: 4px 0; color: var(--pink); font-size: 20px; }
.tips ul { margin: 0; padding-left: 22px; }
.tips li { margin: 6px 0; font-size: 18px; line-height: 1.45; }
.r-end { margin: 10px 0 0; color: #3a86ff; font-size: 16px; }

/* ---------- popups ---------- */
.modal { position: fixed; inset: 0; background: rgba(60, 40, 120, 0.45); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-card { background: #fff; border-radius: 32px; padding: 22px; max-width: 460px; text-align: center; border: 5px solid var(--lilac); }
.modal-card h2 { margin: 6px 0; color: var(--purple); }
.modal-card p { font-size: 17px; line-height: 1.5; margin: 0; }
.mic-ico { font-size: 44px; }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 160%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 20px; font-size: 17px;
  max-width: calc(100% - 32px); text-align: center; transition: transform 0.25s, visibility 0.25s; z-index: 20;
  visibility: hidden;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }

/* ---------- learning / practice choice and speed slider ---------- */
.seg-big button { min-height: 52px; font-size: 20px; }
.seg-big button.on[data-value="learn"] { background: var(--green); box-shadow: 0 3px 0 #2f9a57; }
.seg-big button.on[data-value="practice"] { background: var(--orange); box-shadow: 0 3px 0 #d8431f; }
.mode-info { margin: -4px 0 0; color: var(--muted); font-size: 15px; }
body.learn .practice-only { display: none; }

.slider { display: flex; align-items: center; gap: 8px; background: #f0eaf4; border-radius: 999px; padding: 6px 14px; min-height: 54px; }
.slider input { flex: 1; min-width: 0; accent-color: var(--purple); height: 30px; }
.slider output { min-width: 86px; text-align: right; color: var(--purple); font-size: 17px; }

.btn-hear {
  position: absolute; right: max(10px, env(safe-area-inset-right)); top: 50%; transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.92); color: #3a86ff; border: 3px solid #3a86ff;
  border-radius: 999px; padding: 8px 14px; font-size: 16px;
}

.learned-card { border-color: var(--green); box-shadow: 0 10px 0 rgba(76, 201, 120, 0.25); max-width: 520px; }
.learned-card .score { color: var(--green); }
.big-star { font-size: 56px; line-height: 1; }

@media (max-height: 500px) {
  .opt-wide, .mode-info { grid-column: 1 / -1; }
  .mode-info { margin: 0; font-size: 13px; }
  .seg-big button { min-height: 40px; font-size: 16px; }
  .slider { min-height: 40px; padding: 2px 10px; }
  .slider output { min-width: 70px; font-size: 14px; }
}

/* narrow upright phones */
.opt > * { min-width: 0; }
.btn { white-space: nowrap; }
@media (max-width: 560px) {
  .setup-card { padding: 16px 14px; border-radius: 30px; }
  .opt { grid-template-columns: 1fr; gap: 4px; }
  .seg button { font-size: 16px; padding: 0 4px; }
  .slider output { min-width: 0; }
  .btn { font-size: 18px; padding: 0 16px; }
  .note-row span { min-width: 36px; height: 32px; padding: 0 7px; font-size: 15px; }
}
