:root {
  --bg1: #1d0b4a;
  --bg2: #4a3fb8;
  --bg3: #7597de;
  --pink: #ff5d8f;
  --yellow: #ffd23f;
  --green: #3bceac;
  --blue: #4ea8ff;
  --purple: #b77dff;
  --ink: #2b1055;
  --font: "Arial Rounded MT Bold", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --shadow: 0 10px 24px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: #fff;
  background: linear-gradient(160deg, var(--bg1), var(--bg2) 55%, var(--bg3));
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
body::before {
  content: "";
  position: fixed;
  inset: -20%;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 93, 143, .35), transparent 35%),
    radial-gradient(circle at 80% 15%, rgba(59, 206, 172, .3), transparent 35%),
    radial-gradient(circle at 50% 90%, rgba(255, 210, 63, .3), transparent 40%);
  animation: drift 18s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes drift { to { transform: translate(4%, 3%) rotate(3deg); } }

.screen {
  display: none;
  position: fixed;
  inset: 0;
  padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  text-align: center;
}
.screen.active { display: block; }
#play.screen { padding: 0; overflow: hidden; touch-action: none; }
.hidden { display: none !important; }

h1 { font-size: clamp(30px, 5vw, 56px); margin: 8px 0; text-shadow: 0 4px 0 rgba(0,0,0,.25); }
h2 { font-size: clamp(26px, 4.5vw, 44px); margin: 12px 0; text-shadow: 0 3px 0 rgba(0,0,0,.25); }
h3 { font-size: 26px; margin: 18px 0 10px; }
.subtitle { font-size: clamp(18px, 2.6vw, 26px); opacity: .9; margin: 4px 0 20px; }
.note { font-size: 14px; opacity: .7; }
.status { min-height: 1.4em; font-size: 18px; }
.status.error { color: #ffb3c6; }
.pill { background: rgba(0,0,0,.25); border-radius: 999px; padding: 8px 16px; font-size: 18px; white-space: nowrap; }

/* ---- shared controls ---- */
.big-btn {
  display: inline-block;
  border: none;
  border-radius: 22px;
  padding: 16px 28px;
  font: bold 22px var(--font);
  color: var(--ink);
  background: var(--yellow);
  box-shadow: 0 6px 0 #c99a00, var(--shadow);
  cursor: pointer;
  transition: transform .08s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #c99a00; }
.big-btn.alt { background: var(--green); box-shadow: 0 6px 0 #1f8a72, var(--shadow); }
.big-btn.alt:active { box-shadow: 0 2px 0 #1f8a72; }
.big-btn.ghost { background: rgba(255,255,255,.2); color: #fff; box-shadow: 0 6px 0 rgba(0,0,0,.25); }
.big-btn.ghost:active { box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.big-btn:disabled { opacity: .5; transform: none; }
.round-btn {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.22);
  color: #fff;
  font: bold 30px var(--font);
  cursor: pointer;
}
.round-btn:active { background: rgba(255,255,255,.4); }
.back-btn {
  border: none;
  background: rgba(255,255,255,.2);
  color: #fff;
  font: bold 24px var(--font);
  width: 60px; height: 60px;
  border-radius: 18px;
}
.panel {
  background: rgba(0,0,0,.22);
  border-radius: 24px;
  padding: 14px 18px;
  max-width: 720px;
  margin: 14px auto;
  backdrop-filter: blur(6px);
}
.add-row { display: flex; gap: 10px; justify-content: center; margin: 12px 0; flex-wrap: wrap; }
.add-row input {
  flex: 1 1 240px;
  font: 20px var(--font);
  padding: 14px 18px;
  border-radius: 18px;
  border: none;
  -webkit-user-select: text;
  user-select: text;
}
.file-btn input { display: none; }
.del {
  position: absolute;
  top: 8px; right: 10px;
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.3);
  color: #fff;
  font-size: 18px;
}
@keyframes bob { 50% { transform: translateY(-8px) rotate(-6deg); } }
@keyframes pop { from { transform: scale(0) rotate(-90deg); } }

/* ---- profiles ---- */
.profile-list { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; margin: 16px auto 20px; max-width: 1000px; }
.profile-card {
  position: relative;
  width: 200px;
  border: none;
  border-radius: 28px;
  padding: 22px 12px 18px;
  background: rgba(255,255,255,.14);
  color: #fff;
  font-family: var(--font);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .1s;
}
.profile-card:active { transform: scale(.95); }
.profile-card .avatar { display: block; font-size: 80px; animation: bob 1.4s ease-in-out infinite; }
.profile-card .name { display: block; font-size: 26px; font-weight: bold; margin-top: 6px; }
.profile-card .meta { display: block; font-size: 16px; opacity: .85; margin-top: 6px; }
.profile-create { display: none; }
.profile-create.open { display: block; }
.avatar-picker { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.avatar-btn { font-size: 40px; width: 68px; height: 68px; border-radius: 20px; border: 4px solid transparent; background: rgba(255,255,255,.12); }
.avatar-btn.chosen { border-color: var(--yellow); background: rgba(255,255,255,.3); transform: scale(1.1); }

/* ---- menu ---- */
.menu-header { display: flex; justify-content: center; margin-bottom: 6px; }
.who {
  display: flex; align-items: center; gap: 14px;
  border: none; border-radius: 999px;
  background: rgba(0,0,0,.25); color: #fff;
  padding: 10px 22px 10px 12px;
  font-family: var(--font);
  text-align: left;
}
.who .avatar { font-size: 44px; }
.who b { display: block; font-size: 22px; }
.who small { font-size: 15px; opacity: .85; }
.who .swap { margin-left: 8px; font-size: 15px; background: rgba(255,255,255,.2); padding: 6px 12px; border-radius: 999px; }
.menu-title { margin-top: 10px; }
.mode-cards, .menu-row { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; max-width: 1000px; margin: 0 auto 18px; }
.mode-card {
  position: relative;
  width: 250px;
  border: none;
  border-radius: 30px;
  padding: 22px 14px 18px;
  background: linear-gradient(160deg, var(--accent), color-mix(in srgb, var(--accent) 70%, black));
  color: #fff;
  font-family: var(--font);
  box-shadow: 0 8px 0 rgba(0,0,0,.25), var(--shadow);
  cursor: pointer;
  transition: transform .1s;
  overflow: hidden;
}
.mode-card:active { transform: translateY(6px) scale(.98); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.mode-card.wide { width: 330px; padding: 18px 14px; }
.mode-card .emoji { display: block; font-size: 64px; filter: drop-shadow(0 4px 4px rgba(0,0,0,.3)); animation: bob 1.6s ease-in-out infinite; }
.mode-card .title { display: block; font-size: 30px; font-weight: bold; text-shadow: 0 3px 0 rgba(0,0,0,.25); }
.mode-card .sub { display: block; font-size: 17px; opacity: .9; margin-top: 4px; }
.mode-card .bar { display: block; height: 12px; margin-top: 12px; background: rgba(0,0,0,.3); border-radius: 999px; overflow: hidden; }
.mode-card .bar span { display: block; height: 100%; background: #fff; border-radius: 999px; }
.view-row { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
.add-panel summary { font-size: 20px; cursor: pointer; padding: 6px; }

/* ---- headers / tabs ---- */
.bar-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 1100px; margin: 0 auto 10px; }
.bar-header h2 { margin: 0; }
.tabs { display: flex; gap: 10px; justify-content: center; margin-bottom: 16px; }
.tabs button, .chip {
  border: none; border-radius: 999px;
  padding: 12px 22px;
  font: bold 19px var(--font);
  color: #fff;
  background: rgba(255,255,255,.15);
  cursor: pointer;
}
.tabs button.active, .chip.active { background: var(--accent, var(--yellow)); color: var(--ink); box-shadow: var(--shadow); }
.chip { --accent: var(--yellow); }

/* ---- level map ---- */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
  max-width: 1100px;
  margin: 0 auto;
}
.level-node {
  position: relative;
  border: none;
  border-radius: 24px;
  padding: 14px 8px 12px;
  background: linear-gradient(160deg, var(--accent), color-mix(in srgb, var(--accent) 65%, black));
  color: #fff;
  font-family: var(--font);
  box-shadow: 0 6px 0 rgba(0,0,0,.25), var(--shadow);
  cursor: pointer;
  transition: transform .1s;
}
.level-node:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.level-node.locked { background: rgba(255,255,255,.1); box-shadow: none; opacity: .6; }
.level-node.cleared::after { content: "✔"; position: absolute; top: 8px; right: 10px; font-size: 18px; background: #fff; color: var(--ink); border-radius: 50%; width: 26px; height: 26px; line-height: 26px; }
.level-node .num { position: absolute; top: 8px; left: 12px; font-size: 18px; font-weight: bold; opacity: .9; }
.level-node .sticker { display: block; font-size: 52px; margin-top: 10px; }
.level-node .song { display: block; font-size: 18px; font-weight: bold; margin-top: 4px; }
.level-node .genre { display: block; font-size: 14px; opacity: .85; }
.level-node .stars { display: block; font-size: 16px; margin-top: 4px; min-height: 1.2em; letter-spacing: 2px; }

/* ---- free play ---- */
.song-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  max-width: 1100px;
  margin: 0 auto 10px;
}
.song-card {
  position: relative;
  border: 4px solid transparent;
  border-radius: 24px;
  padding: 14px 10px 12px;
  min-height: 120px;
  font: bold 18px var(--font);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0,0,0,.25), var(--shadow);
  transition: transform .1s;
  overflow-wrap: anywhere;
}
.song-card:active { transform: scale(.96); }
.song-card.chosen { border-color: #fff; transform: scale(1.04); }
.song-card .emoji { display: block; font-size: 46px; margin-bottom: 4px; }
.options { max-width: 1000px; }
.opt-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 8px 0; }
.opt-label { font-size: 20px; font-weight: bold; min-width: 56px; text-align: left; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper b { font-size: 40px; min-width: 60px; }
.stepper small { font-size: 16px; opacity: .85; }
.big-btn.start { width: 100%; margin-top: 10px; font-size: 24px; }

/* ---- stickers ---- */
.sticker-page { max-width: 1100px; margin: 0 auto 10px; }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.sticker-slot { background: rgba(255,255,255,.1); border-radius: 18px; padding: 10px 4px; }
.sticker-slot.got { background: rgba(255,255,255,.25); box-shadow: var(--shadow); }
.sticker-slot .face { display: block; font-size: 46px; }
.sticker-slot.got .face { animation: pop .5s backwards; }
.sticker-slot .label { font-size: 13px; opacity: .8; }

/* ---- loading / play ---- */
#loading { display: none; }
#loading.active { display: flex; flex-direction: column; justify-content: center; align-items: center; }
.spinner { font-size: 110px; animation: bob .8s ease-in-out infinite; }
#loading-text { font-size: 28px; }
#stage { width: 100%; height: 100%; display: block; touch-action: none; }
.play-controls {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  gap: 12px;
}

/* ---- result ---- */
.stars { font-size: clamp(70px, 12vw, 120px); letter-spacing: 10px; }
.stars span { display: inline-block; animation: pop .5s backwards; }
.stars span.off { filter: grayscale(1); opacity: .3; }
.reward { display: inline-flex; align-items: center; gap: 14px; background: rgba(255,255,255,.18); border-radius: 999px; padding: 10px 26px 10px 18px; margin-bottom: 12px; animation: pop .6s backwards .8s; }
.reward-label { font-size: 22px; font-weight: bold; }
.reward-face { font-size: 54px; }
.result-stats { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin: 16px 0 28px; }
.result-stats div { background: rgba(0,0,0,.22); border-radius: 18px; padding: 12px 18px; min-width: 110px; font-size: 18px; }
.result-stats b { display: block; font-size: 32px; color: var(--yellow); }
.result-actions { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
