:root{
  --pageMax: 980px;
  --radius: 18px;
  --radius2: 14px;
  --shadow: 0 18px 50px rgba(0,0,0,.24);
  --shadow2: 0 10px 26px rgba(0,0,0,.18);

  --text: rgba(255,255,255,.92);
  --muted: rgba(255,255,255,.70);
}

/* ---- THEME TOKENS ---- */
body[data-theme="piano"]{
  --bg1: #4b2a10;
  --bg2: #8a5a1c;
  --panel: rgba(255,235,170,.92);
  --panel2: rgba(255,235,170,.78);
  --panelBorder: rgba(255,215,120,.65);
  --frameOuter: #a56a1d;
  --frameInner: #2c2a26;
  --accent: #ffcc4a;
  --accent2: #b07a1e;
  --ink: #2a1706;
  --keyGlow: rgba(255,200,80,.22);
  --switchBg: rgba(255,255,255,.10);
  --switchBorder: rgba(255,255,255,.18);
  --switchActive: rgba(255,210,110,.30);
}
body[data-theme="synth"]{
  --bg1: #140a2a;
  --bg2: #5a1dd7;
  --panel: rgba(12,18,28,.86);
  --panel2: rgba(12,18,28,.70);
  --panelBorder: rgba(120,220,255,.35);
  --frameOuter: #2aa7c8;
  --frameInner: #0b0f1a;
  --accent: #7be6ff;
  --accent2: #7c3aed;
  --ink: #d8f7ff;
  --keyGlow: rgba(120,220,255,.20);
  --switchBg: rgba(0,0,0,.20);
  --switchBorder: rgba(123,230,255,.30);
  --switchActive: rgba(123,230,255,.18);
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  color: var(--text);
  background: radial-gradient(1200px 700px at 20% 10%, rgba(255,255,255,.10), transparent 50%),
              linear-gradient(180deg, var(--bg2), var(--bg1));
}

.page{
  max-width: var(--pageMax);
  margin: 0 auto;
  padding: 26px 16px 60px;
}

/* Theme switch (top-right) */
.themeSwitch{
  position: fixed;
  top: 14px;
  right: 14px;
  display:flex;
  gap: 8px;
  z-index: 50;
  padding: 6px;
  border-radius: 999px;
  background: var(--switchBg);
  border: 1px solid var(--switchBorder);
  backdrop-filter: blur(8px);
}
.switchBtn{
  display:flex;
  align-items:center;
  gap: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 999px;
  cursor:pointer;
  font-weight: 750;
  letter-spacing: .2px;
  transition: transform .06s ease, background .12s ease, border-color .12s ease;
}
.switchBtn .ico{ filter: drop-shadow(0 6px 10px rgba(0,0,0,.25)); }
.switchBtn:active{ transform: translateY(1px); }
.switchBtn.isActive{
  background: var(--switchActive);
  border-color: var(--switchBorder);
}

/* HERO */
.hero{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap: 16px;
  margin-top: 16px;
}
.heroBadge{
  width: 100%;
  background: rgba(0,0,0,.18);
  border: 2px solid rgba(255,255,255,.12);
  border-radius: var(--radius);
  padding: 16px;
  display:flex;
  align-items:center;
  gap: 14px;
  box-shadow: var(--shadow2);
}
.heroIcon{
  width: 48px; height:48px;
  border-radius: 14px;
  background:
    linear-gradient(135deg, var(--accent), rgba(255,255,255,.20));
  border: 2px solid rgba(0,0,0,.18);
  box-shadow: 0 14px 30px rgba(0,0,0,.25);
}
.heroTitle{
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 2px;
}
.heroSub{
  margin-top: 6px;
  font-style: italic;
  color: var(--muted);
}

.heroCard{
  width: 100%;
  background: rgba(0,0,0,.18);
  border: 2px solid rgba(255,255,255,.12);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow2);
}
.heroCardTitle{
  font-weight: 900;
  letter-spacing: .2px;
}
.heroCardSub{
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}
.mapping{
  margin-top: 10px;
  display:flex;
  gap: 10px;
  flex-wrap:wrap;
  font-size: 12px;
  color: var(--muted);
}
.mapping b{ color: rgba(255,255,255,.88); }

/* INSTRUMENT FRAME */
.instrument{ margin-top: 18px; }

.frame{
  width: 100%;
  border-radius: 24px;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
  border: 4px solid rgba(0,0,0,.18);
  box-shadow: var(--shadow);
  position:relative;
}
.frame::before{
  content:"";
  position:absolute;
  inset: 8px;
  border-radius: 20px;
  border: 4px solid rgba(0,0,0,.16);
  pointer-events:none;
  opacity:.8;
}
.frameTop{
  display:flex;
  justify-content:center;
  margin-top: -10px;
}
.tag{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding: 8px 16px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(0,0,0,.22));
  border: 2px solid rgba(255,255,255,.12);
  font-weight: 900;
  letter-spacing: .7px;
  text-transform: uppercase;
  box-shadow: var(--shadow2);
}
body[data-theme="piano"] .tag{ color: #2a1706; background: linear-gradient(180deg, #ffd46d, #c88a1e); border-color: rgba(255,210,110,.55); }
body[data-theme="synth"] .tag{ color: #07131b; background: linear-gradient(180deg, #7be6ff, #7c3aed); border-color: rgba(123,230,255,.55); }

.pianoWell{
  margin-top: 12px;
  border-radius: 18px;
  padding: 18px 14px;
  background: linear-gradient(180deg, rgba(0,0,0,.55), rgba(0,0,0,.35));
  border: 2px solid rgba(255,255,255,.10);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.25);

  overflow: hidden;
}

.frameBottom{
  margin-top: 16px;
  display:flex;
  justify-content:center;
}
.ribbon{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding: 12px 18px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.18);
  font-weight: 900;
  letter-spacing: .6px;
  text-transform: uppercase;
}
body[data-theme="piano"] .ribbon{
  background: linear-gradient(90deg, rgba(255,175,55,.25), rgba(0,0,0,.12));
}
body[data-theme="synth"] .ribbon{
  background: linear-gradient(90deg, rgba(123,230,255,.20), rgba(124,58,237,.18));
}

/* PIANO KEYS */
.keys{
  transform-origin: center bottom;
  position:relative;
  height: 250px;
  display:flex;
  align-items:flex-end;
  gap: 10px;
  justify-content:center;
  user-select:none;
  touch-action: manipulation;
}

.key{
  position:relative;
  border-radius: 14px;
  border: 2px solid rgba(0,0,0,.22);
  box-shadow: 0 14px 28px rgba(0,0,0,.45);
  display:flex;
  align-items:flex-end;
  justify-content:center;
  padding-bottom: 10px;
  transition: transform .06s ease, filter .06s ease, box-shadow .08s ease;
  will-change: transform, filter;
}
.key.white{
  width: 64px;
  height: 220px;
  background: linear-gradient(180deg, #ffffff, #eaeaea);
}
.key.black{
  width: 44px;
  height: 140px;
  background: linear-gradient(180deg, #1b1b1e, #0b0b0d);
  border: 2px solid rgba(255,255,255,.10);
  position:absolute;
  top: 18px;
  z-index: 3;
  box-shadow: 0 18px 28px rgba(0,0,0,.65);
}
body[data-theme="synth"] .key.white{
  box-shadow: 0 16px 30px rgba(0,0,0,.55), 0 0 0 2px rgba(123,230,255,.18);
}
body[data-theme="synth"] .key.black{
  box-shadow: 0 18px 28px rgba(0,0,0,.65), 0 0 0 2px rgba(123,230,255,.10);
}

.key:active{ transform: translateY(2px) scale(.995); }
.key.active{
  transform: translateY(2px) scale(.995);
  filter: brightness(1.01) contrast(1.05);
  box-shadow: 0 20px 36px rgba(0,0,0,.55), 0 0 0 6px var(--keyGlow);
}


/* Extra feedback for black keys (more visible press) */
.key.black:active{
  transform: translateY(3px) scale(.99);
  filter: brightness(1.05) contrast(1.08);
}
.key.black.active{
  transform: translateY(3px) scale(.99);
  filter: brightness(1.07) contrast(1.10);
  box-shadow: 0 22px 36px rgba(0,0,0,.70), 0 0 0 7px var(--keyGlow);
}
.key.black.active::after{
  content:"";
  position:absolute;
  inset: 6px 6px 18px 6px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255,255,255,.16), transparent 55%);
  pointer-events:none;
}
.key .label{
  width: calc(100% - 14px);
  text-align:center;
  font-size: 11px;
  letter-spacing: .2px;
  color: rgba(20,24,33,.70);
  background: rgba(255,255,255,.78);
  padding: 7px 8px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,.08);
  display:flex;
  flex-direction:column;
  gap: 2px;
}
.key.black .label{
  color: rgba(255,255,255,.88);
  background: rgba(255,255,255,.10);
  border-color: rgba(255,255,255,.12);
}
.label .note{
  font-weight: 800;
}
.label .kbd{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  opacity: .9;
}

/* GUIDE */
.guide{
  margin-top: 18px;
  border-radius: 22px;
  padding: 18px;
  background: var(--panel);
  border: 2px solid var(--panelBorder);
  box-shadow: var(--shadow);
  color: var(--ink);
}
.guideTitle{
  margin: 0 0 14px;
  text-align:center;
  font-size: 26px;
  letter-spacing: .6px;
  font-weight: 900;
}
.guideGrid{
  display:grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.miniCard{
  background: var(--panel2);
  border: 2px solid var(--panelBorder);
  border-radius: 16px;
  padding: 12px;
}
.miniTitle{
  font-weight: 900;
  letter-spacing: .2px;
}
.miniText{
  margin-top: 8px;
  color: rgba(0,0,0,.62);
  font-size: 13px;
}
body[data-theme="synth"] .miniText{ color: rgba(216,247,255,.75); }
body[data-theme="synth"] .guide{ color: var(--ink); }

.bankRow{
  margin-top: 12px;
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.bank{
  border-radius: 16px;
  padding: 12px;
  border: 2px solid var(--panelBorder);
  background: linear-gradient(90deg, rgba(0,0,0,.06), rgba(0,0,0,.02));
}
body[data-theme="synth"] .bank{
  background: linear-gradient(90deg, rgba(123,230,255,.12), rgba(124,58,237,.10));
}
.bankTitle{
  font-weight: 900;
}
.bankMap{
  margin-top: 8px;
  font-size: 12px;
  color: rgba(0,0,0,.65);
}
body[data-theme="synth"] .bankMap{ color: rgba(216,247,255,.78); }

.controlsPanel{
  margin-top: 14px;
  padding-top: 14px;
  border-top: 2px solid rgba(0,0,0,.10);
  display:flex;
  flex-wrap:wrap;
  gap: 12px 16px;
  align-items:flex-end;
}
.ctrl{
  display:flex;
  flex-direction:column;
  gap: 8px;
  min-width: 220px;
}
.ctrl label{
  font-weight: 900;
  letter-spacing:.2px;
}
.ctrl input{ width: 100%; }

.check{
  display:flex;
  align-items:center;
  gap: 10px;
  font-weight: 900;
}
.check input{ accent-color: var(--accent2); }

.kbdHints{
  display:flex;
  flex-wrap:wrap;
  gap: 10px;
  align-items:center;
  margin-left:auto;
}
.pill{
  border-radius: 999px;
  padding: 9px 12px;
  border: 2px solid rgba(0,0,0,.12);
  background: rgba(255,255,255,.60);
  font-weight: 900;
  font-size: 12px;
}
.pill.subtle{
  opacity: .8;
  font-weight: 750;
}
.pill.btn{
  cursor:pointer;
}
body[data-theme="synth"] .pill{
  background: rgba(12,18,28,.72);
  border-color: rgba(123,230,255,.22);
  color: rgba(216,247,255,.92);
}
body[data-theme="synth"] .pill.subtle{ opacity:.85; }

.fineprint{
  margin-top: 16px;
  text-align:center;
  color: rgba(0,0,0,.55);
  font-style: italic;
}
body[data-theme="synth"] .fineprint{ color: rgba(216,247,255,.62); }

/* Responsive */
@media (max-width: 980px){
  .guideGrid{ grid-template-columns: 1fr; }
  .bankRow{ grid-template-columns: 1fr; }
  .kbdHints{ margin-left: 0; width:100%; }
  .key.white{ width: 54px; }
}
@media (max-width: 560px){
  .heroTitle{ font-size: 26px; }
  .key.white{ width: 48px; }
  .page{ padding-top: 70px; }
}



/* Responsive fine-tuning */
@media (max-width: 820px){
  :root{ --pageMax: 920px; }
  .page{ padding: 22px 14px 48px; }
  .heroBadge, .heroCard{ padding: 14px; }
  .frame{ padding: 14px; }
  .pianoWell{ padding: 14px 10px; }
  .mapping{ font-size: 11px; }
}
@media (max-width: 640px){
  .themeSwitch{ top: 10px; right: 10px; padding: 5px; }
  .switchBtn{ padding: 9px 10px; font-size: 12px; }
  .heroTitle{ font-size: 24px; letter-spacing: 1.2px; }
  .heroIcon{ width: 40px; height: 40px; border-radius: 12px; }
  .guide{ padding: 14px; }
  .guideTitle{ font-size: 22px; }
  .ctrl{ min-width: 170px; }
  .keys{ gap: 8px; height: 235px; }
  .key.white{ width: 46px; height: 205px; border-radius: 12px; }
  .key.black{ width: 34px; height: 128px; border-radius: 12px; }
  .key .label{ font-size: 10px; padding: 6px 6px; }
}
@media (max-width: 420px){
  .page{ padding: 70px 10px 40px; } /* leave room for fixed theme switch */
  .heroBadge, .heroCard{ border-radius: 16px; }
  .frame{ border-radius: 18px; }
  .pianoWell{ border-radius: 14px; }
  .keys{ height: 220px; }
}


/* Melodies / Catalog */
.melodies{
  margin-top: 18px;
  border-radius: 22px;
  padding: 18px;
  background: rgba(0,0,0,.18);
  border: 2px solid rgba(255,255,255,.12);
  box-shadow: var(--shadow2);
}
.melodyTop{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap: 12px;
  flex-wrap:wrap;
  margin-bottom: 12px;
}
.melodyTitle{
  margin: 0;
  text-align:left;
  font-size: 24px;
  letter-spacing: .6px;
  font-weight: 900;
}
.melodyControls{
  display:flex;
  gap: 10px;
  flex-wrap:wrap;
  align-items:center;
}
.melodySearch{
  width: min(360px, 78vw);
  padding: 10px 12px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.20);
  color: var(--text);
  outline: none;
}
.melodySearch::placeholder{ color: rgba(255,255,255,.65); }
.melodyFilter{
  padding: 10px 12px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.20);
  color: var(--text);
  outline:none;
  cursor:pointer;
}
body[data-theme="synth"] .melodySearch,
body[data-theme="synth"] .melodyFilter{
  border-color: rgba(123,230,255,.25);
  background: rgba(12,18,28,.50);
}

.melodyGrid{
  display:grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.melodyCard{
  border-radius: 16px;
  padding: 12px;
  background: rgba(0,0,0,.18);
  border: 2px solid rgba(255,255,255,.12);
  display:flex;
  flex-direction:column;
  gap: 10px;
}
body[data-theme="synth"] .melodyCard{
  background: rgba(12,18,28,.55);
  border-color: rgba(123,230,255,.22);
}
.melodyMeta{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
}
.melodyName{ font-weight: 900; letter-spacing: .2px; }
.melodyTags{ display:flex; flex-wrap:wrap; gap: 8px; justify-content:flex-end; }
.tagChip{
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.08);
}
body[data-theme="piano"] .tagChip{ background: rgba(255,210,110,.10); }
body[data-theme="synth"] .tagChip{ border-color: rgba(123,230,255,.22); background: rgba(123,230,255,.10); }

.melodySeq{
  margin-top: 2px;
  padding: 10px 10px;
  border-radius: 14px;
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.14);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  letter-spacing: 1px;
  font-size: 13px;
  white-space: pre-wrap;
  line-height: 1.5;
}
.melodySeq.muted{ opacity: .78; }
body[data-theme="piano"] .melodySeq{ background: rgba(255,210,110,.10); }
body[data-theme="synth"] .melodySeq{ background: linear-gradient(90deg, rgba(123,230,255,.14), rgba(124,58,237,.12)); }

.melodyHint{ font-size: 12px; color: var(--muted); }
.melodyBtns{ display:flex; gap: 8px; flex-wrap:wrap; }

.mBtn.play{
  border-color: rgba(255,255,255,.24);
  background: linear-gradient(180deg, rgba(255,255,255,.14), rgba(255,255,255,.06));
}
.mBtn.play.playing{
  border-color: rgba(255,255,255,.30);
  box-shadow: 0 14px 26px rgba(0,0,0,.25);
}
.mBtn:disabled{
  opacity: .55;
  cursor:not-allowed;
}
body[data-theme="piano"] .mBtn.play{
  background: linear-gradient(180deg, rgba(255,210,110,.22), rgba(0,0,0,.10));
}
body[data-theme="synth"] .mBtn.play{
  border-color: rgba(123,230,255,.26);
  background: linear-gradient(90deg, rgba(123,230,255,.18), rgba(124,58,237,.12));
}

.melodyNote{
  margin-top: 14px;
  text-align:center;
  color: var(--muted);
  font-style: italic;
  font-size: 12px;
}

@media (max-width: 980px){
  .melodyGrid{ grid-template-columns: 1fr; }
}

/* Modal */
.modalBackdrop{
  position: fixed;
  inset: 0;
  display:none;
  align-items:center;
  justify-content:center;
  padding: 18px;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
  z-index: 80;
}
.modalBackdrop.open{ display:flex; }
.modal{
  width: min(760px, 96vw);
  border-radius: 18px;
  padding: 14px;
  border: 2px solid rgba(255,255,255,.14);
  background: rgba(12,18,28,.88);
  color: rgba(255,255,255,.92);
  box-shadow: 0 24px 70px rgba(0,0,0,.55);
}
body[data-theme="piano"] .modal{ background: rgba(34,20,8,.88); }
.modalHead{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.modalTitle{ font-weight: 900; font-size: 16px; }
.modalSub{ margin-top: 4px; font-size: 12px; opacity: .82; }
.modalTextarea{
  width: 100%;
  min-height: 150px;
  resize: vertical;
  border-radius: 16px;
  padding: 12px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(0,0,0,.22);
  color: rgba(255,255,255,.92);
  outline: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  line-height: 1.5;
}
.modalTextarea::placeholder{ color: rgba(255,255,255,.55); }
.modalFoot{
  margin-top: 12px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 12px;
  flex-wrap:wrap;
}
.modalHint{ font-size: 12px; opacity: .82; }
.modalBtns{ display:flex; gap: 8px; flex-wrap:wrap; }


/* Melody buttons polish (match the original pill buttons) */
.melodyBtns .mBtn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  font-weight: 900;
  letter-spacing: .2px;
  transition: transform .08s ease, filter .15s ease, box-shadow .15s ease, background .2s ease, border-color .2s ease;
}
.melodyBtns .mBtn:hover{
  filter: brightness(1.06);
}
.melodyBtns .mBtn:active{
  transform: translateY(1px);
}
.melodyBtns .mBtn.play{
  border-width: 2px;
}
.melodyBtns .mBtn.play.playing{
  filter: brightness(1.08);
}
.melodyBtns .mBtn[disabled]{
  opacity: .55;
  filter: grayscale(.15);
  box-shadow: none;
}

/* Make Edit/Copy visually secondary */
.melodyBtns .mBtn:not(.play){
  background: rgba(255,255,255,.06);
}
body[data-theme="synth"] .melodyBtns .mBtn:not(.play){
  background: rgba(12,18,28,.26);
}

/* Slightly tighter layout on small screens */
@media (max-width: 640px){
  .melodyBtns{ gap: 6px; }
  .melodyBtns .mBtn{ height: 34px; padding: 0 12px; font-size: 12px; }
}
