:root {
  --bg: #16181d;
  --panel: #20232b;
  --text: #e9eaee;
  --muted: #9aa0ad;
  --accent: #f0a63a;
  --accent-black: #e0861a;
  --rec: #e5484d;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, textarea { font: inherit; color: inherit; }
button {
  background: #2d313b;
  border: 1px solid #3a3f4b;
  border-radius: 8px;
  padding: .45em .9em;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover { background: #363b47; }
button.primary { background: var(--accent); color: #1a1205; border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
input[type=text], input[type=number], textarea {
  background: #13151a;
  border: 1px solid #3a3f4b;
  border-radius: 8px;
  padding: .4em .6em;
}
input[type=number] { width: 5.2em; }
code, pre, kbd, textarea { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

/* header */
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
  padding: .7rem 1rem;
  border-bottom: 1px solid #2a2e37;
}
.top h1 { font-size: 1.2rem; margin: 0; letter-spacing: .02em; }
.tabs { display: flex; gap: .3rem; }
.tabs button[aria-selected=true] { background: var(--accent); color: #1a1205; border-color: var(--accent); }
.help-link { margin-left: auto; color: var(--muted); font-size: .9rem; }
.lang-switch { display: flex; gap: 2px; background: #2d313b; border-radius: 8px; padding: 2px; }
.lang-switch a {
  color: var(--muted); text-decoration: none; font-size: .8rem; font-weight: 600;
  padding: .2em .55em; border-radius: 6px;
}
.lang-switch a:hover { color: var(--text); }
.lang-switch a[aria-current=true] { background: var(--accent); color: #1a1205; }

main { max-width: 1400px; margin: 0 auto; padding: .8rem; }

/* stage + keyboard */
.stage-info { display: flex; align-items: baseline; gap: 1rem; min-height: 1.8rem; flex-wrap: wrap; }
.stage-info h2 { margin: 0; font-size: 1.1rem; }
.now { color: var(--accent); font-family: ui-monospace, Consolas, monospace; font-size: .95rem; }
.progress { height: 3px; background: #2a2e37; border-radius: 2px; margin: .4rem 0; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--accent); }

.keyboard-wrap { position: relative; }
.keyboard {
  overflow-x: auto;
  overflow-y: hidden;
  background: #0d0e11;
  border-radius: var(--radius);
  padding: 8px 0 0;
  scrollbar-width: thin;
}
.keys {
  --kw: 40px;
  position: relative;
  height: clamp(150px, 32vh, 260px);
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
body[data-mode=rec] .keys { touch-action: none; }
body[data-mode=rec] #melody-title, body[data-mode=rec] .progress { visibility: hidden; }
body[data-mode=play] .keys { touch-action: pan-x; }

.key {
  position: absolute;
  top: 0;
  left: calc(var(--x) * var(--kw));
  width: calc(var(--w) * var(--kw));
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  transition: transform .15s ease-out;
}
/* Color layer: its opacity is animated from JS to follow the sound (see js/envelope.js). */
.key .glow {
  position: absolute; inset: 0;
  border-radius: inherit;
  background: var(--accent);
  opacity: 0;
  pointer-events: none;
}
.key.black .glow { background: var(--accent-black); box-shadow: 0 0 14px rgba(240,166,58,.6); }
.key .label, .key .hint { position: relative; }
.key.white {
  height: 100%;
  background: linear-gradient(#f4f4f2, #fff 70%, #e9e9e6);
  border: 1px solid #b9b9b4;
  border-top: none;
  border-radius: 0 0 6px 6px;
  z-index: 1;
}
.key.black {
  height: 62%;
  background: linear-gradient(#2a2a2e, #111 80%);
  border-radius: 0 0 4px 4px;
  box-shadow: 0 2px 3px rgba(0,0,0,.6);
  z-index: 2;
}
/* held key: pressed in slightly; color comes from .glow */
.key.down { transform: translateY(1px); transition: none; }

.key .label { font-size: .7rem; color: #777; padding-bottom: 6px; pointer-events: none; }
.key .hint { font-size: .68rem; color: #999; order: -1; margin-bottom: auto; padding-top: 4px; pointer-events: none; }
.key.white .hint { margin-top: auto; margin-bottom: 0; padding-bottom: 2px; }
.key.black .hint { color: #bbb; margin-bottom: 0; margin-top: auto; padding-bottom: 4px; }
.key.white .label { order: 2; }
.key.white.down .label, .key.white.down .hint { color: #3b2603; }

/* covers the whole keyboard: a tap anywhere on it starts playback */
.start-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .6rem;
  background: rgba(13, 14, 17, .55);
  border-radius: var(--radius);
  cursor: pointer;
  z-index: 5;
}
.start-overlay[hidden] { display: none; }
.start-overlay button {
  font-size: 1.3rem; padding: .8em 1.6em;
  background: var(--accent); color: #1a1205; border: none; font-weight: 700;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.start-note { color: #fff; font-size: .9rem; text-shadow: 0 1px 3px #000; text-align: center; padding: 0 1rem; }
.sound-banner {
  margin-top: .5rem; padding: .5rem .8rem; border-radius: 8px;
  background: #3b2b10; color: #ffd28a; text-align: center;
}

/* panels */
.panel { margin-top: 1rem; background: var(--panel); border-radius: var(--radius); padding: .9rem; }
.row { display: flex; flex-wrap: wrap; gap: .5rem .7rem; align-items: center; }
.field { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); font-size: .92rem; }
.block-label { display: block; margin: .9rem 0 .3rem; color: var(--muted); font-size: .9rem; }
textarea { width: 100%; resize: vertical; min-height: 4.5em; }
.errors { color: #ff9a9a; font-size: .9rem; margin-top: .3rem; }
.link-row { margin-top: .6rem; }
.link-row input { flex: 1 1 220px; min-width: 0; color: var(--muted); font-size: .85rem; }
.examples { margin-top: .8rem; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; color: var(--muted); font-size: .9rem; }
.examples button { font-size: .85rem; padding: .3em .7em; }
.oct-label { min-width: 6.5em; text-align: center; color: var(--muted); font-size: .9rem; }
button.rec { margin-left: auto; color: #ffb3b5; border-color: #6b2b2e; }
button.rec.on { background: var(--rec); color: #fff; border-color: var(--rec); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .75; } }
.rec-time { color: var(--muted); font-size: .9rem; min-width: 5em; }
.rec-result p { margin: .8rem 0 0; }
.tip { color: var(--muted); font-size: .85rem; margin: .7rem 0 0; }
kbd { background: #2d313b; border-radius: 4px; padding: 0 .3em; font-size: .85em; }
@media (hover: none), (pointer: coarse) { .desktop-only { display: none; } }

/* readme */
.readme { margin-top: 1.2rem; }
.readme details { background: var(--panel); border-radius: var(--radius); margin-bottom: .6rem; }
.readme summary { cursor: pointer; padding: .7rem .9rem; font-weight: 600; }
.readme-body { padding: 0 1rem .8rem; font-size: .95rem; }
.readme-body li { margin: .3rem 0; }
.readme pre { background: #13151a; padding: .6rem; border-radius: 8px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; font-size: .85rem; }
.readme code { background: #13151a; padding: 0 .25em; border-radius: 4px; }
.noscript { text-align: center; color: var(--muted); }

@media (max-width: 600px) {
  .top { padding: .5rem .7rem; }
  .help-link { margin-left: 0; flex: 1; }
  main { padding: .5rem; }
  button.rec { margin-left: 0; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .keys { height: 55vh; }
  .top { padding: .3rem .7rem; }
}
