:root {
  --sky: #dff3ff;
  --sky-deep: #7ec8e8;
  --ink: #1c2a33;
  --muted: #5a7180;
  --leaf: #3cb89a;
  --sun: #ffb703;
  --coral: #ff7a59;
  --white: #fffdf8;
  --key-w: #fffef9;
  --key-b: #243039;
  --shadow: 0 16px 40px rgba(28, 42, 51, 0.14);
  --font: "Nunito", "Apple SD Gothic Neo", sans-serif;
  --display: "Fredoka", "Nunito", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font);
  background:
    radial-gradient(900px 420px at 80% -10%, #ffe7c2 0%, transparent 55%),
    radial-gradient(700px 380px at 0% 0%, #c8ebff 0%, transparent 50%),
    linear-gradient(180deg, #f3fbff 0%, #e7f6ef 48%, #f7ffe8 100%);
}

button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 16px 28px;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.logo {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: 16px;
  background: linear-gradient(145deg, #fff7d6, #ffd27a);
  box-shadow: var(--shadow);
  font-size: 1.6rem;
}
.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.55rem;
  letter-spacing: 0.02em;
}
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 0.92rem; }

.mode-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: rgba(255,255,255,0.7);
  color: var(--muted);
  font-weight: 800;
  box-shadow: 0 2px 0 rgba(0,0,0,0.04);
}
.tab.active {
  background: linear-gradient(135deg, var(--leaf), #2a9d8f);
  color: white;
}

.banner, .guide-card, .song-list, .song-stage {
  background: rgba(255,253,248,0.9);
  border: 1px solid rgba(28,42,51,0.06);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.banner {
  padding: 16px 18px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.banner strong { font-family: var(--display); font-size: 1.15rem; }
.banner em { color: var(--coral); font-style: normal; font-weight: 800; }

.guide-card { padding: 20px; margin-bottom: 14px; line-height: 1.55; }
.guide-card h2 { margin: 0 0 8px; font-family: var(--display); }
.guide-map {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
  margin: 14px 0;
}
.guide-chip {
  background: #f4faf7;
  border-radius: 12px;
  padding: 10px;
  text-align: center;
  border: 1px solid rgba(60,184,154,0.25);
}
.guide-chip b { display: block; font-size: 1.15rem; color: var(--leaf); }
.guide-chip span { font-size: 0.82rem; color: var(--muted); }

.song-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 12px;
  margin-bottom: 14px;
  min-height: 280px;
}
.song-list { padding: 10px; overflow: auto; max-height: 360px; }
.song-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 14px;
  padding: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 700;
  color: var(--ink);
}
.song-item:hover, .song-item.active {
  background: linear-gradient(135deg, rgba(126,200,232,0.35), rgba(60,184,154,0.2));
}
.song-item .lv {
  font-size: 0.72rem;
  color: var(--sun);
  background: #fff6d8;
  padding: 2px 8px;
  border-radius: 999px;
}
.song-stage { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.song-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.song-head h2 { margin: 0; font-family: var(--display); font-size: 1.25rem; }
.song-head p { margin: 4px 0 0; }
.song-actions { display: flex; gap: 8px; }
.btn {
  border: 0;
  border-radius: 14px;
  padding: 11px 18px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--sun), #f4a261);
  color: #3a2508;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.ghost {
  background: white;
  border: 2px solid rgba(28,42,51,0.1);
  color: var(--muted);
}

.hud {
  display: grid;
  grid-template-columns: 1.4fr auto auto auto;
  gap: 8px;
  align-items: center;
}
.meter span { font-size: 0.75rem; color: var(--muted); font-weight: 800; }
.bar {
  height: 12px;
  border-radius: 999px;
  background: #e6eef2;
  overflow: hidden;
  margin-top: 4px;
}
.bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--leaf), var(--sky-deep));
  border-radius: inherit;
  transition: width 0.15s linear;
}
.score-box {
  background: #f3fbf8;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}
.score-box strong { color: var(--ink); font-size: 1.1rem; }
.stars { font-size: 1.35rem; letter-spacing: 2px; color: var(--sun); }

.lane {
  position: relative;
  height: 160px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(126,200,232,0.25), rgba(255,255,255,0.5));
  overflow: hidden;
  border: 1px dashed rgba(60,184,154,0.35);
}
.hit-line {
  position: absolute;
  left: 0; right: 0; bottom: 28px;
  height: 3px;
  background: var(--coral);
  box-shadow: 0 0 12px rgba(255,122,89,0.55);
  z-index: 2;
}
.falling { position: absolute; inset: 0; }
.fall-note {
  position: absolute;
  width: 42px;
  height: 42px;
  margin-left: -21px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.78rem;
  color: white;
  background: linear-gradient(145deg, var(--leaf), #2a9d8f);
  box-shadow: 0 6px 14px rgba(42,157,143,0.35);
  transform: translateY(-50px);
  transition: none;
  z-index: 1;
}
.fall-note.black {
  background: linear-gradient(145deg, #5b6b75, #243039);
  width: 34px;
  margin-left: -17px;
  font-size: 0.68rem;
}
.fall-note.hit { background: linear-gradient(145deg, #8fd36e, #3d9a3a); }
.fall-note.miss { opacity: 0.35; filter: grayscale(0.6); }

.hint {
  margin: 0;
  text-align: center;
  font-weight: 800;
  color: var(--coral);
  min-height: 1.4em;
}

.piano-wrap {
  margin-top: 8px;
  background: linear-gradient(180deg, #2f3d47, #1c2a33);
  border-radius: 24px;
  padding: 14px 14px 18px;
  box-shadow: var(--shadow);
}
.now-playing {
  text-align: center;
  color: #d7ece6;
  font-family: var(--display);
  font-size: 1.15rem;
  margin-bottom: 10px;
  min-height: 1.4em;
}
.piano {
  position: relative;
  display: flex;
  justify-content: center;
  height: 210px;
  user-select: none;
  touch-action: none;
}
.key {
  position: relative;
  border-radius: 0 0 10px 10px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 10px;
  gap: 2px;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.05s ease;
}
.key.white {
  width: min(68px, 9.2vw);
  height: 100%;
  background: linear-gradient(180deg, #fff, var(--key-w));
  border: 1px solid #c9d3da;
  margin: 0 1px;
  color: var(--ink);
  z-index: 1;
  box-shadow: inset 0 -8px 0 rgba(0,0,0,0.05);
}
.key.black {
  position: absolute;
  width: min(42px, 5.5vw);
  height: 62%;
  background: linear-gradient(180deg, #3b4a55, var(--key-b));
  color: #f0f4f6;
  z-index: 2;
  border: 0;
  box-shadow: 0 8px 12px rgba(0,0,0,0.35);
  padding-bottom: 8px;
}
.key .sol { font-weight: 800; font-size: 0.95rem; line-height: 1; }
.key .abc { font-size: 0.72rem; opacity: 0.75; font-weight: 700; }
.key .kb {
  margin-top: 4px;
  font-size: 0.7rem;
  font-weight: 800;
  background: rgba(60,184,154,0.18);
  color: #1f6f5c;
  padding: 2px 7px;
  border-radius: 999px;
}
.key.black .kb {
  background: rgba(255,183,3,0.25);
  color: #ffe7a0;
}
.key.active.white {
  background: linear-gradient(180deg, #e8fff6, #b8f0d8);
  transform: translateY(3px);
}
.key.active.black {
  background: linear-gradient(180deg, #5ecf8e, #2f6b4f);
  transform: translateY(2px);
}
.key.guide {
  outline: 3px solid var(--sun);
  outline-offset: -3px;
}
.key.white.guide { background: #fff4cc; }

.foot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 36, 0.45);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 16px;
}
.modal-card {
  background: var(--white);
  border-radius: 24px;
  padding: 28px 24px;
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow);
}
.big-stars { font-size: 2.2rem; color: var(--sun); letter-spacing: 4px; }
.modal-card h3 { margin: 8px 0; font-family: var(--display); font-size: 1.5rem; }
.modal-card p { color: var(--muted); line-height: 1.5; }

@media (max-width: 820px) {
  .song-layout { grid-template-columns: 1fr; }
  .song-list { max-height: 140px; display: flex; gap: 4px; overflow-x: auto; }
  .song-item { min-width: 140px; }
  .hud { grid-template-columns: 1fr 1fr; }
  .piano { height: 180px; }
  .key .abc { display: none; }
}
