*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #0a0a0f;
  --surface: #131320;
  --border:  #2a2a42;
  --accent:  #c8a84b;
  --accent2: #7b6fd0;
  --text:    #e8e8f0;
  --muted:   #6a6a88;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Hiragino Kaku Gothic Pro', 'Yu Gothic', 'Meiryo', sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ─── Screens ──────────────────────────────────────────────────────────────── */
#app { width: 100%; height: 100%; position: relative; }

.screen {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.4s ease;
}
.screen.active { opacity: 1; pointer-events: all; }

/* ─── Loading ──────────────────────────────────────────────────────────────── */
#loading-overlay {
  position: fixed; inset: 0; z-index: 9999;
  display: none; align-items: center; justify-content: center;
  flex-direction: column; gap: 14px;
  background: rgba(10,10,15,0.85); backdrop-filter: blur(6px);
}
#loading-overlay.active { display: flex; }
#loading-msg { font-size: 13px; color: var(--muted); letter-spacing: .08em; }
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Title ────────────────────────────────────────────────────────────────── */
#title-screen {
  background: radial-gradient(ellipse 80% 60% at 50% 30%, #1a1030, var(--bg) 70%);
  align-items: flex-start;
  justify-content: center;
  padding-top: 56px;
}
.title-wrap { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 32px; }
.title {
  font-size: clamp(2.2rem, 6vw, 4.2rem);
  font-weight: 300; letter-spacing: .3em;
  color: var(--accent);
  text-shadow: 0 0 40px rgba(200,168,75,.5), 0 0 80px rgba(200,168,75,.2);
}
.subtitle { font-size: .95rem; color: var(--muted); letter-spacing: .18em; margin-top: -20px; }

#song-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px; max-width: 820px; width: 90vw;
}
.song-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px 20px; cursor: pointer;
  display: flex; flex-direction: column; gap: 5px;
  transition: border-color .2s, transform .15s, box-shadow .2s;
  user-select: none;
}
.song-card:hover {
  border-color: var(--accent); transform: translateY(-3px);
  box-shadow: 0 8px 32px rgba(200,168,75,.15);
}
.song-card-top { display: flex; align-items: center; gap: 8px; }
.song-card-title { font-size: 1rem; font-weight: 500; flex: 1; }
.level-badge {
  font-size: .65rem; font-weight: 600; letter-spacing: .05em;
  padding: 2px 8px; border-radius: 10px; white-space: nowrap; flex-shrink: 0;
}
.level-badge.tutorial { background: rgba(123,111,208,.20); color: #a99cff; border: 1px solid rgba(123,111,208,.40); }
.level-badge.beginner { background: rgba(48,176,69,.18); color: #52d46a; border: 1px solid rgba(48,176,69,.35); }
.level-badge.advanced  { background: rgba(200,168,75,.18); color: var(--accent); border: 1px solid rgba(200,168,75,.35); }
.song-card-composer { font-size: .76rem; color: var(--muted); }
.song-card-desc { font-size: .72rem; color: var(--muted); opacity: .75; }
.song-card-events { font-size: .7rem; color: var(--accent2); margin-top: 4px; }

/* ─── Play screen ──────────────────────────────────────────────────────────── */
#play-screen {
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between; /* header pinned top, footer pinned bottom */
  background: var(--bg);
}

#effect-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none; z-index: 1;
}

.play-header {
  position: relative; z-index: 2;
  display: flex; align-items: center; gap: 14px;
  padding: 13px 22px;
  background: rgba(10,10,15,.75); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.song-name { font-size: .88rem; color: var(--muted); letter-spacing: .05em; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* BPM control */
.bpm-control {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
}
.bpm-btn {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); width: 26px; height: 26px; border-radius: 6px;
  font-size: 1rem; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: border-color .15s, color .15s; flex-shrink: 0;
}
.bpm-btn:hover { border-color: var(--accent); color: var(--accent); }
#bpm-display {
  font-size: .82rem; color: var(--accent); min-width: 30px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.bpm-label { font-size: .68rem; color: var(--muted); letter-spacing: .06em; }

.progress-bar-container { width: 130px; height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; flex-shrink: 0; }
.progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent2), var(--accent)); transition: width .2s ease; }
.progress-text { font-size: .76rem; color: var(--muted); width: 34px; text-align: right; flex-shrink: 0; }

/* ─── Typing text area — hidden; canvas falling-notes replaces it ──────────── */
#typing-area { display: none; }

/* ─── Footer ───────────────────────────────────────────────────────────────── */
.play-footer {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 22px;
  background: rgba(10,10,15,.75); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}
.key-hint { font-size: .78rem; color: var(--muted); letter-spacing: .1em; animation: pulse 2s ease-in-out infinite; }
.key-hint.tutorial-hint {
  color: #a99cff; font-size: .9rem; letter-spacing: .04em; animation: none;
  font-weight: 500;
}
@keyframes pulse { 0%,100%{opacity:.45} 50%{opacity:1} }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.back-btn, .complete-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); padding: 7px 16px; border-radius: 8px;
  font-size: .8rem; cursor: pointer; letter-spacing: .05em;
  transition: border-color .2s, color .2s; font-family: inherit;
}
.back-btn:hover, .complete-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ─── Complete ─────────────────────────────────────────────────────────────── */
#complete-screen { background: radial-gradient(ellipse 70% 50% at 50% 40%, #1a2040, var(--bg) 70%); }
.complete-content { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.complete-content h2 {
  font-size: 2.2rem; font-weight: 300; letter-spacing: .2em;
  color: var(--accent); text-shadow: 0 0 30px rgba(200,168,75,.5);
}
#complete-song-name { font-size: .95rem; color: var(--muted); letter-spacing: .1em; }
.complete-actions { display: flex; gap: 12px; margin-top: 6px; }

/* ─── Home Position Overlay ───────────────────────────────────────────────── */
#homepos-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: none; align-items: center; justify-content: center;
  background: rgba(10,10,15,0.94); backdrop-filter: blur(12px);
}
#homepos-overlay.active { display: flex; }

.homepos-panel {
  display: flex; flex-direction: column; align-items: center;
  gap: 20px; padding: 36px 44px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; max-width: 560px; width: 90vw; text-align: center;
}

.homepos-title {
  font-size: 1.4rem; font-weight: 300; letter-spacing: .22em;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(200,168,75,.4);
}

.homepos-sub {
  font-size: .88rem; color: var(--muted); letter-spacing: .06em; margin-top: -6px;
}

.homepos-kb { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }

.homepos-keys { display: flex; gap: 7px; }

.hk {
  width: 54px; height: 54px; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 1.05rem; font-weight: 600;
  border: 2px solid transparent;
}
.hk small {
  font-size: .52rem; font-weight: 400; opacity: .9; margin-top: 2px; letter-spacing: 0;
}
.hp-dim    { background: var(--bg);                  border-color: var(--border);           color: var(--muted); }
.hp-pinky-l{ background: rgba(220,80,70,.16);  border-color: rgba(220,80,70,.55);  color: #e87070; }
.hp-ring-l { background: rgba(220,130,50,.16); border-color: rgba(220,130,50,.55); color: #e8a060; }
.hp-mid-l  { background: rgba(200,168,75,.16); border-color: rgba(200,168,75,.55); color: var(--accent); }
.hp-idx-l  { background: rgba(70,180,100,.16); border-color: rgba(70,180,100,.55); color: #60d080; }
.hp-idx-r  { background: rgba(60,180,160,.16); border-color: rgba(60,180,160,.55); color: #50c8b0; }
.hp-mid-r  { background: rgba(80,130,220,.16); border-color: rgba(80,130,220,.55); color: #7090e8; }
.hp-ring-r { background: rgba(130,80,200,.16); border-color: rgba(130,80,200,.55); color: #a060d8; }

.homepos-labels {
  display: flex; justify-content: space-between; width: 100%;
  font-size: .7rem; color: var(--muted); padding: 0 2px;
}

.homepos-tip {
  font-size: .81rem; color: var(--muted); line-height: 1.75;
  padding: 12px 16px;
  background: rgba(255,255,255,.035); border-radius: 10px;
  border: 1px solid var(--border);
}

#homepos-start-btn {
  background: var(--accent); color: #0a0a0f;
  border: none; border-radius: 12px;
  padding: 13px 36px; font-size: .96rem; font-weight: 700;
  cursor: pointer; letter-spacing: .1em; font-family: inherit;
  transition: opacity .2s, transform .15s;
  margin-top: 4px;
}
#homepos-start-btn:hover { opacity: .85; transform: translateY(-2px); }

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #song-list { grid-template-columns: 1fr; }
  .progress-bar-container { width: 100px; }
  #typing-text { font-size: .9rem; }
}
