/* Music Maker — chunky plastic toy.
   Everything is rounded, saturated and has a bottom edge that presses down.
   Colour carries meaning: each Instrument and each Pattern has its own hue. */

:root {
  --display: "Baloo 2", "Trebuchet MS", sans-serif;
  --body: "Nunito", "Trebuchet MS", sans-serif;
  --paper: #fdf3e3;
  --paper-deep: #f3e2c7;
  --ink: #3b2a1e;
  --ink-soft: #8a7361;
  --panel: #fffaf0;
  --shadow: rgba(59, 42, 30, .22);
  --radius: 16px;
  --press: 4px;
  --row-gap: 5px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--body);
  font-weight: 800;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, #ffe9b8 0%, transparent 45%),
    radial-gradient(circle at 85% 100%, #cdeeff 0%, transparent 45%),
    var(--paper);
  touch-action: manipulation;
  user-select: none;
}

button, input { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:disabled { opacity: .35; cursor: default; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

/* ---------- Loading ------------------------------------------------------ */

#loading {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; background: var(--paper);
}
.loading-note { font-size: 72px; animation: bob 1.1s ease-in-out infinite; }
#loading h1 { font-family: var(--display); font-size: 34px; letter-spacing: .5px; }
.loading-track { width: min(320px, 60vw); height: 16px; border-radius: 99px; background: var(--paper-deep); overflow: hidden; }
#loading-bar { height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, #ffb03b, #ff6f61); transition: width .2s ease; }
#loading-text { color: var(--ink-soft); font-size: 15px; text-align: center; max-width: 32ch; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-6deg); } 50% { transform: translateY(-12px) rotate(6deg); } }

/* ---------- Shell -------------------------------------------------------- */

#app { display: flex; flex-direction: column; height: 100dvh; padding: 8px 10px 10px; gap: 8px; }
.stage { flex: 1; display: flex; flex-direction: column; gap: 8px; min-height: 0; }

/* Reusable chunky button: a coloured face with a darker bottom edge. */
.big, .play, .card, .slot, .step, .tile, .inst, .mute, .clear, .open, .back {
  --hue: 30;
  --sat: 78%;
  --lit: 62%;
  border-radius: var(--radius);
  background: hsl(var(--hue) var(--sat) var(--lit));
  box-shadow: 0 var(--press) 0 hsl(var(--hue) var(--sat) calc(var(--lit) - 16%)),
              0 6px 10px var(--shadow);
  transition: transform .06s ease, box-shadow .06s ease, background .12s ease;
}
.big:active:not(:disabled), .play:active:not(:disabled), .card:active, .slot:active,
.step:active, .tile:active, .inst:active, .mute:active, .clear:active, .open:active, .back:active {
  transform: translateY(var(--press));
  box-shadow: 0 0 0 hsl(var(--hue) var(--sat) calc(var(--lit) - 16%)), 0 2px 4px var(--shadow);
}

/* ---------- Top bar ------------------------------------------------------ */

.topbar { display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 8px; margin-right: auto; }
.brand-icon { font-size: 30px; }
.brand-name { font-family: var(--display); font-size: 24px; letter-spacing: .3px; }

.speed { display: flex; align-items: center; gap: 8px; background: var(--panel); padding: 6px 14px; border-radius: 99px; box-shadow: 0 3px 0 var(--paper-deep); }
.speed-end { font-size: 22px; }
.bpm { font-size: 13px; font-weight: 700; color: var(--ink-soft); min-width: 56px; }
.tempo { -webkit-appearance: none; appearance: none; width: clamp(110px, 18vw, 220px); height: 12px; border-radius: 99px; background: linear-gradient(90deg, #9ad7ff, #ffcf5c, #ff8a5c); }
.tempo::-webkit-slider-thumb { -webkit-appearance: none; width: 30px; height: 30px; border-radius: 50%; background: #fff; box-shadow: 0 3px 0 #d8c4a4, 0 4px 8px var(--shadow); }
.tempo::-moz-range-thumb { width: 30px; height: 30px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 3px 0 #d8c4a4; }

.big { display: flex; align-items: center; gap: 8px; padding: 9px 16px; min-height: 46px; }
.big .icon { font-size: 22px; line-height: 1; }
.big .label { font-size: 15px; }
.undo { --hue: 205; }
.new { --hue: 275; }
.new.armed { --hue: 355; animation: nudge .5s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: rotate(-1.5deg); } 50% { transform: rotate(1.5deg); } }

/* ---------- Song strip --------------------------------------------------- */

.strip { display: flex; gap: 10px; align-items: stretch; }
.strip-left, .strip-right { background: var(--panel); border-radius: var(--radius); padding: 6px 10px 8px; box-shadow: 0 4px 0 var(--paper-deep); }
.strip-right { flex: 1; min-width: 0; }
.strip-title { font-size: 12px; letter-spacing: .8px; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 4px; }
.strip-row { display: flex; align-items: center; gap: 10px; }

.cards { display: flex; gap: 6px; align-items: center; }
.card { position: relative; width: 46px; height: 46px; display: grid; place-items: center; --lit: 66%; }
.card-number { font-size: 20px; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.18); }
.card.selected { --lit: 56%; outline: 4px solid var(--ink); outline-offset: 3px; }
.card.add { --hue: 0; --sat: 0%; --lit: 88%; font-size: 22px; }
.card-delete { position: absolute; top: -9px; right: -9px; width: 24px; height: 24px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-size: 12px; box-shadow: 0 2px 4px var(--shadow); }

.play { --hue: 140; --lit: 48%; width: 58px; height: 44px; font-size: 22px; color: #fff; display: grid; place-items: center; flex: none; }
.play.active { --hue: 355; }

.slots { flex: 1; display: grid; grid-template-columns: repeat(16, 1fr); gap: 5px; min-width: 0; }
.slot { height: 46px; --sat: 0%; --lit: 90%; font-size: 17px; color: #fff; }
.slot.filled { --sat: 78%; --lit: 62%; }
.slot:not(.filled) { box-shadow: inset 0 3px 0 rgba(0,0,0,.06); }
.slot.now { outline: 4px solid var(--ink); outline-offset: 2px; }

/* ---------- Pattern board ------------------------------------------------ */

.board { position: relative; flex: 1; min-height: 0; background: var(--panel); border-radius: var(--radius); padding: 8px 10px 10px; box-shadow: 0 4px 0 var(--paper-deep); display: flex; flex-direction: column; gap: 6px; }

.patternbar { display: flex; align-items: center; gap: 10px; }
.pattern-label { --hue: 30; font-size: 16px; padding: 5px 14px; border-radius: 99px; color: #fff; background: hsl(var(--hue) 78% 58%); }

.tracks { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: var(--row-gap); overflow-y: auto; }

.track {
  --hue: 30;
  flex: 1 1 0; min-height: 34px;
  display: grid;
  grid-template-columns: 132px 44px 1fr auto auto;
  gap: 6px; align-items: stretch;
}
.track.muted { opacity: .42; }

.inst { --sat: 62%; --lit: 52%; display: flex; align-items: center; gap: 7px; padding: 0 10px; overflow: hidden; }
.inst .icon { font-size: 21px; flex: none; }
.inst .label { font-size: 13px; color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,.15); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.mute, .clear, .open { --sat: 0%; --lit: 92%; font-size: 17px; display: grid; place-items: center; }
.mute { width: 44px; }
.clear, .open { width: 44px; }
.hidden-keep-space { visibility: hidden; pointer-events: none; }

.steps { display: grid; grid-template-columns: repeat(16, 1fr); gap: 5px; min-width: 0; }

.step {
  --sat: 0%; --lit: 91%;
  --press: 3px;
  border-radius: 11px;
  box-shadow: inset 0 3px 0 rgba(0,0,0,.05);
}
.step.beat { --lit: 84%; }
/* Steps and labels take their colour from the Track (or the Melody Editor)
   they sit in, rather than the shared button default. */
.track .step, .roll .step, .track .inst { --hue: inherit; }
.step.on {
  --sat: 80%; --lit: 58%;
  background: hsl(var(--hue) var(--sat) var(--lit));
  box-shadow: 0 3px 0 hsl(var(--hue) var(--sat) 44%), 0 3px 7px var(--shadow);
}
.step.chord::after { content: ''; display: block; width: 6px; height: 6px; margin: 0 auto; border-radius: 50%; background: rgba(255,255,255,.85); }
.step.now { outline: 3px solid var(--ink); outline-offset: 1px; }
.step.pop { animation: pop .22s ease-out; }
@keyframes pop {
  0% { transform: scale(1); filter: brightness(1); }
  35% { transform: scale(1.35); filter: brightness(1.6); }
  100% { transform: scale(1); filter: brightness(1); }
}

/* ---------- Melody editor (overlay) -------------------------------------- */

.melody {
  --hue: 210;
  position: absolute; inset: 0; z-index: 10;
  background: var(--panel); border-radius: var(--radius);
  padding: 8px 10px 10px;
  display: flex; flex-direction: column; gap: 6px;
  animation: slide-up .18s ease-out;
}
.melody[hidden] { display: none; }
@keyframes slide-up { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

.melody-head { display: flex; align-items: center; gap: 10px; }
.back { --hue: 30; --sat: 0%; --lit: 90%; width: 58px; height: 46px; font-size: 20px; display: grid; place-items: center; }
.melody-title { display: flex; align-items: center; gap: 8px; margin-right: auto; padding: 5px 14px; border-radius: 99px; background: hsl(var(--hue) 70% 90%); }
.melody-title .icon { font-size: 24px; }
.melody-title .label { font-size: 17px; }
.melody .clear { width: 58px; height: 46px; }

.roll { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; padding-right: 2px; }

/* Every row is one semitone. 29 of them do not fit at a tappable size, so the
   roll scrolls and opens centred on the middle of the keyboard. */
.roll-row {
  flex: 1 0 30px;
  display: grid; grid-template-columns: 62px repeat(16, 1fr);
  gap: 4px; align-items: stretch;
}
.roll-row.black .step { --lit: 84%; }
.roll-row.black .step.beat { --lit: 78%; }
.roll-row.root .step { --lit: 93%; }
.roll-row.root .step.beat { --lit: 86%; }
.roll-row .step.on { --lit: 58%; }

/* The keyboard down the side: white keys full width, black keys short and dark,
   the way they sit on a real piano. */
.key {
  --press: 2px;
  position: relative;
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 7px;
  font-size: 11px; font-weight: 800; color: #6b5947;
  background: linear-gradient(180deg, #ffffff 0%, #f1e7d8 100%);
  border-radius: 5px 9px 9px 5px;
  box-shadow: inset -3px 0 0 rgba(0, 0, 0, .07), 0 2px 0 #d9c8ae;
  transition: background .08s ease, transform .08s ease, box-shadow .08s ease;
}
.key-black {
  width: 68%;
  background: linear-gradient(180deg, #4a3b30 0%, #2c211a 100%);
  box-shadow: inset -3px 0 0 rgba(0, 0, 0, .35), 0 2px 0 #1b1310;
  border-radius: 4px 8px 8px 4px;
}
.key:active, .key.lit {
  transform: translateX(3px);
  box-shadow: inset -1px 0 0 rgba(0, 0, 0, .12), 0 0 0 #d9c8ae;
  background: hsl(var(--hue) 85% 62%);
  color: #fff;
}
.key-black.lit, .key-black:active {
  background: hsl(var(--hue) 80% 44%);
}

/* ---------- Instrument picker -------------------------------------------- */

.picker { position: fixed; inset: 0; z-index: 30; background: rgba(59, 42, 30, .45); display: grid; place-items: center; padding: 16px; }
.picker[hidden] { display: none; }
.picker-box { width: min(900px, 96vw); max-height: 92dvh; overflow-y: auto; background: var(--paper); border-radius: 26px; padding: 14px 18px 20px; box-shadow: 0 12px 0 rgba(0,0,0,.16); animation: slide-up .18s ease-out; }
.picker-head { display: flex; align-items: center; gap: 10px; }
.picker-title { font-family: var(--display); font-size: 24px; margin-right: auto; }
.picker-hint { font-size: 14px; font-weight: 700; color: var(--ink-soft); margin: 2px 0 12px; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 10px; }
.tile { --lit: 66%; padding: 10px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tile .icon { font-size: 34px; }
.tile .label { font-size: 13px; color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,.18); }
.tile.current { outline: 4px solid var(--ink); outline-offset: 3px; }
.tile.previewed { animation: nudge .5s ease-in-out infinite; --lit: 56%; }

/* ---------- Portrait ------------------------------------------------------ */

#rotate { display: none; }
@media (orientation: portrait) and (max-width: 900px) {
  #app, #loading { display: none; }
  #rotate {
    position: fixed; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 18px; text-align: center; padding: 24px;
  }
  .rotate-icon { font-size: 84px; animation: turn 1.6s ease-in-out infinite; }
  #rotate p { font-size: 22px; max-width: 16ch; }
  @keyframes turn { 0%, 40% { transform: rotate(0); } 70%, 100% { transform: rotate(90deg); } }
}
