/* WebPino — theme-aware styles. No frameworks, no external assets. */

* { box-sizing: border-box; }

:root {
  --radius: 14px;
}

html[data-theme="dark"] {
  --bg: #0f1115;
  --bg-soft: #161a21;
  --surface: #1b1f28;
  --surface-2: #232936;
  --text: #f2f3f5;
  --muted: #9aa3b2;
  --border: #2b3242;
  --accent: #e8b64c;
  --accent-text: #1a1405;
  --accent-soft: rgba(232, 182, 76, 0.16);
  --key-white: linear-gradient(#ffffff, #eceff1);
  --key-white-text: #222;
  --key-black: linear-gradient(#3a3a3f, #0a0a0c);
  --key-black-text: #cfd3da;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

html[data-theme="light"] {
  --bg: #f6f3ec;
  --bg-soft: #efece3;
  --surface: #ffffff;
  --surface-2: #f0ede4;
  --text: #1c1a16;
  --muted: #6b675c;
  --border: #ddd6c4;
  --accent: #9a6b12;
  --accent-text: #ffffff;
  --accent-soft: rgba(154, 107, 18, 0.14);
  --key-white: linear-gradient(#ffffff, #e9e7e0);
  --key-white-text: #222;
  --key-black: linear-gradient(#3a3a3f, #0a0a0c);
  --key-black-text: #cfd3da;
  --shadow: 0 10px 26px rgba(60, 50, 20, 0.16);
}

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  min-height: 100vh;
  transition: background 0.25s ease, color 0.25s ease;
}

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  max-width: 1100px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo-img {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: block;
}
.brand h1 { margin: 0; font-size: 28px; letter-spacing: 0.5px; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.header-actions { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 46px;
  height: 46px;
  font-size: 20px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease;
}
.icon-btn:hover { transform: scale(1.06); }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.icon-btn.vol-btn { width: 56px; height: 56px; font-size: 26px; }

/* Volume button + hover popup — big and easy to grab.
   The popup opens sideways (YouTube-style) so it never covers the controls below. */
.vol-wrap { position: relative; }
.vol-pop {
  display: none;
  position: absolute;
  top: 50%;
  right: calc(100% + 12px);
  transform: translateY(-50%);
  z-index: 60;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
  min-width: 340px;
  flex-direction: row;
  gap: 14px;
  align-items: center;
}
.vol-pop input[type="range"] { flex: 1; width: auto; height: 12px; }
.vol-pop input[type="range"]::-webkit-slider-runnable-track { height: 12px; border-radius: 6px; background: var(--surface-2); }
.vol-pop input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  cursor: pointer;
}
.vol-pop input[type="range"]::-moz-range-track { height: 12px; border-radius: 6px; background: var(--surface-2); }
.vol-pop input[type="range"]::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); cursor: pointer; }
.vol-pop .value { font-size: 18px; font-weight: 700; min-width: 52px; text-align: right; }
.vol-pop .btn.small { padding: 10px 16px; font-size: 14px; }
.vol-wrap:hover .vol-pop,
.vol-wrap:focus-within .vol-pop,
.vol-wrap.open .vol-pop { display: flex; }
.vol-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.vol-pop input[type="range"] { width: 100%; }

/* ---------- Main layout ---------- */
main { max-width: 1100px; margin: 0 auto; padding: 0 24px 32px; }

.now-playing {
  display: flex;
  align-items: baseline;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 14px;
  min-height: 66px;
}
.note-name { font-size: 30px; font-weight: 700; color: var(--accent); min-width: 84px; }
.note-info { color: var(--muted); font-size: 14px; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 28px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 14px;
}
.control { display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.control > label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.control .value { font-size: 13px; font-weight: 600; }
.control .hint { font-size: 12px; color: var(--muted); }
.octave { display: flex; align-items: center; gap: 10px; }
.bpm-row { display: flex; align-items: center; gap: 10px; }
.bpm-row input[type="range"] { width: 110px; }

.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.toggle[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.rec.recording { background: #c0392b; color: #fff; border-color: transparent; animation: pulse 1s infinite; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.small { padding: 6px 10px; font-size: 12px; }
@keyframes pulse { 50% { opacity: 0.65; } }

input[type="range"] { accent-color: var(--accent); width: 150px; }
select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 14px;
}

/* ---------- Piano ---------- */
.piano-wrap {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.piano {
  position: relative;
  display: flex;
  height: 250px;
  min-width: 640px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.key {
  position: relative;
  cursor: pointer;
  border: 1px solid #b9bcc2;
  border-top: none;
  border-radius: 0 0 8px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 10px;
  gap: 2px;
  transition: background 0.06s ease, box-shadow 0.06s ease;
}
.key.white {
  flex: 1 1 0;
  background: var(--key-white);
  color: var(--key-white-text);
  z-index: 1;
  box-shadow: inset 0 -4px 6px rgba(0, 0, 0, 0.08);
}
.key.black {
  position: absolute;
  top: 0;
  height: 62%;
  background: var(--key-black);
  color: var(--key-black-text);
  z-index: 2;
  border-color: #000;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 5px 8px rgba(0, 0, 0, 0.45), inset 0 -3px 4px rgba(255, 255, 255, 0.08);
}
/* The real keyboard button is the BIG label; the note name is small. */
.key .kbd-label {
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
}
.key .note-label {
  font-size: 10px;
  font-weight: 700;
  opacity: 0.55;
  pointer-events: none;
}
.key.black .kbd-label { font-size: 14px; }
.key.black .note-label { font-size: 9px; }
.key.white.active, .key.white.playing {
  background: linear-gradient(var(--accent), #f4cf7d);
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.15), 0 0 0 2px var(--accent);
  transform: translateY(1px);
}
.key.black.active, .key.black.playing {
  background: linear-gradient(#5a4630, var(--accent));
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), 0 0 0 2px var(--accent);
  transform: translateY(1px);
}
.key.next { animation: nextPulse 0.9s ease-in-out infinite; }
@keyframes nextPulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent), 0 0 18px var(--accent); }
  50% { box-shadow: 0 0 0 3px var(--accent), 0 0 4px var(--accent); }
}
.key.wrong { box-shadow: 0 0 0 3px #e74c3c !important; }
.piano.hide-notes .note-label { display: none; }

/* ---------- Learn panel ---------- */
.learn-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 14px;
}
.learn-top { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.learn-title { font-size: 15px; font-weight: 700; }
.learn-progress { font-size: 14px; font-weight: 700; color: var(--accent); }
.progress-bar { flex: 1 1 160px; height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
#progressFill { height: 100%; width: 0%; background: var(--accent); border-radius: 999px; transition: width 0.3s ease; }
.learn-score { font-size: 13px; font-weight: 600; color: var(--muted); }
.next-notes { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.nn-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 13px;
  color: var(--muted);
}
.nn-chip b { color: var(--text); font-size: 14px; }
.nn-chip.current { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 700; transform: scale(1.08); }
.nn-chip.current b { color: var(--accent-text); }
.learn-bottom { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 12px; }
.learn-best { font-size: 13px; color: var(--muted); }

/* ---------- Phone keyboard row + chords ---------- */
.phone-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  margin-bottom: 14px;
}
.phone-row .hint { font-size: 13px; color: var(--muted); }
.chords {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  margin-bottom: 14px;
}
.chords-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.chord-btn { min-width: 52px; font-size: 16px; }
.chords .hint { font-size: 12px; color: var(--muted); }

/* ---------- Player row ---------- */
.player-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 32px;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 14px;
}
.demo, .recorder { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.demo > label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

/* ---------- Help / footer ---------- */
.help {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.help h2 { margin: 0 0 8px; font-size: 17px; }
.help p { margin: 0 0 12px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.help p b { color: var(--text); }
kbd {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
}
.keymap { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--muted);
}
.chip b { color: var(--text); }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 16px 24px; }

/* ---------- Snow ---------- */
#snow { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
#snow span {
  position: absolute;
  top: -8%;
  color: #fff;
  opacity: 0.85;
  animation: snowfall linear infinite;
  font-size: 16px;
}
html[data-theme="light"] #snow span { color: #b9c4d6; }
@keyframes snowfall {
  0% { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(112vh) rotate(320deg); }
}

/* ---------- Hidden phone input (must stay focusable) ---------- */
#phoneInput {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 2px;
  height: 2px;
  opacity: 0.01;
  border: none;
  padding: 0;
  font-size: 16px; /* prevents iOS zoom on focus */
}

@media (max-width: 640px) {
  .topbar, main { padding-left: 14px; padding-right: 14px; }
  .brand h1 { font-size: 22px; }
  .logo-img { width: 44px; height: 44px; }
  .piano { height: 210px; min-width: 560px; }
  .note-name { font-size: 24px; min-width: 64px; }
  .vol-pop { position: fixed; top: auto; bottom: 90px; right: 14px; left: 14px; min-width: 0; transform: none; flex-direction: column; align-items: stretch; }
}
