/* --------------------------------------------------------------------------
 * Kanipad -- big targets, bright colors, no tiny text anywhere.
 * ----------------------------------------------------------------------- */

:root {
  --ink: #23262b;
  --paper: #fffdf7;
  --bg-1: #ffe2b0;
  --bg-2: #dccbff;
  --accent: #ffd23f;
  --rec: #ff3b3b;
  --shadow: 0 6px 0 rgba(0, 0, 0, .12);
  --radius: 22px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Comic Sans MS", "Chalkboard SE", "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(170deg, var(--bg-1), var(--bg-2));
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overflow: hidden;
}

.hidden { display: none !important; }

.screen {
  position: absolute;
  inset: 0;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}


/* ------------------------------------------------------------- menu screen */

#menu-screen,
#songs-screen,
#voice-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: max(20px, env(safe-area-inset-top)) 16px 24px;
  overflow-y: auto;
}

#songs-screen { justify-content: center; gap: 32px; padding-top: 90px; }

.title {
  margin: 4px 0 0;
  font-size: clamp(56px, 13vmin, 110px);
  line-height: 1;
  letter-spacing: .03em;
  color: #fff;
  -webkit-text-stroke: 4px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 rgba(0, 0, 0, .12);
  position: relative;
}

.corner-btn {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  z-index: 3;
  font-size: 26px;
  line-height: 1;
  width: 52px;
  height: 52px;
  padding: 0;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 50%;
  box-shadow: var(--shadow);
}

.corner-btn:active { transform: translateY(4px); box-shadow: none; }

.refresh-btn { right: 16px; opacity: .55; }
.refresh-btn:hover { opacity: 1; }

.corner-btn.home-btn { left: 16px; width: 64px; height: 64px; font-size: 32px; }

.gear-btn { left: 16px; opacity: .55; display: grid; place-items: center; }
.gear-btn:hover, .gear-btn.holding { opacity: 1; }
.gear-btn span { position: relative; }

/* the ring fills while a grown-up holds the gear; letting go snaps it back */
.gate-ring {
  position: absolute;
  inset: -8px;
  width: calc(100% + 16px);
  height: calc(100% + 16px);
  transform: rotate(-90deg);
  pointer-events: none;
}

.gate-ring circle {
  fill: none;
  stroke: #3a86ff;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
}

.gear-btn.holding .gate-ring circle {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 2s linear;
}

.levels {
  display: flex;
  gap: 14px;
  position: relative;
}

.level-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 104px;
  padding: 0;
  background: none;
  border: 0;
  opacity: .55;
  transition: opacity .15s;
}

.level-face {
  display: grid;
  place-items: center;
  font-size: 44px;
  width: 84px;
  height: 84px;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 50%;
  box-shadow: var(--shadow);
  transition: transform .15s;
}

.level-caption {
  font-size: 15px;
  line-height: 1.2;
  text-align: center;
}

.level-btn[aria-checked="true"] { opacity: 1; }

.level-btn[aria-checked="true"] .level-face {
  background: var(--accent);
  transform: scale(1.12);
}

.modes {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  width: 100%;
  max-width: 860px;
  position: relative;
}

.modes.songs { max-width: 860px; grid-template-columns: repeat(5, minmax(0, 1fr)); }

@media (max-width: 640px) {
  .modes, .modes.songs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
}

.mode-tile {
  aspect-ratio: 1 / 1;
  min-height: 120px;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6%;
}

.mode-tile:active { transform: translateY(4px); box-shadow: none; }

.tile-art { width: 100%; flex: 1; min-height: 0; }

.tile-emoji {
  font-size: clamp(36px, 9vmin, 72px);
  line-height: 1.15;
  text-align: center;
}

.songs .tile-emoji { font-size: clamp(44px, 10vmin, 76px); line-height: 1; }

.tile-caption {
  font-size: clamp(13px, 2.2vmin, 17px);
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
}

/* the menu's tiles are bigger, and so are their names */
.modes:not(.songs) .tile-caption { font-size: clamp(15px, 3vmin, 22px); }

/* music notes drifting up behind the menu */
.deco { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.deco span {
  position: absolute;
  bottom: -120px;
  font-size: 64px;
  color: rgba(255, 255, 255, .75);
  animation: drift 14s linear infinite;
}
.deco span:nth-child(1) { left: 6%;  animation-delay: 0s; }
.deco span:nth-child(2) { left: 24%; font-size: 44px; animation-delay: -5s; animation-duration: 11s; }
.deco span:nth-child(3) { left: 46%; font-size: 84px; animation-delay: -9s; animation-duration: 18s; }
.deco span:nth-child(4) { left: 66%; animation-delay: -2s; animation-duration: 13s; }
.deco span:nth-child(5) { left: 82%; font-size: 50px; animation-delay: -7s; }
.deco span:nth-child(6) { left: 92%; font-size: 40px; animation-delay: -11s; animation-duration: 10s; }

@keyframes drift {
  0%   { transform: translateY(0) rotate(-10deg); }
  50%  { transform: translateY(calc(-50vh - 80px)) rotate(10deg); }
  100% { transform: translateY(calc(-100vh - 160px)) rotate(-10deg); }
}


/* ------------------------------------------------------------ silly voices */

#voice-screen { justify-content: center; gap: 6vmin; padding-top: 90px; }

/* the big microphone: while recording it turns red, a ring fills up over the
   time it has, and it swells with how loud the voice is (--level, 0..1) */
.mic-btn {
  --level: 0;
  --max: 5s;
  position: relative;
  width: clamp(150px, 34vmin, 260px);
  aspect-ratio: 1;
  padding: 0;
  background: var(--paper);
  border: 5px solid var(--ink);
  border-radius: 50%;
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  transition: background .2s;
}

.mic-btn:active { transform: translateY(4px); box-shadow: none; }

.mic-face { font-size: clamp(70px, 16vmin, 130px); line-height: 1; }

.mic-btn.on {
  background: #ffe0e0;
  box-shadow: var(--shadow), 0 0 0 calc(var(--level) * 40px) rgba(255, 77, 77, .35);
  transform: scale(calc(1 + var(--level) * .12));
}

.mic-ring {
  position: absolute;
  inset: -16px;
  width: calc(100% + 32px);
  height: calc(100% + 32px);
  transform: rotate(-90deg);
  pointer-events: none;
}

.mic-ring circle {
  fill: none;
  stroke: var(--rec);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  opacity: 0;
}

.mic-btn.on .mic-ring circle {
  opacity: 1;
  animation: mic-fill var(--max) linear forwards;
}

@keyframes mic-fill { to { stroke-dashoffset: 0; } }

.pitches {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(10px, 2.5vmin, 22px);
  transition: opacity .2s;
}

.pitches.empty { opacity: .3; }

.pitch-btn {
  --c: #3cc85a;
  width: clamp(72px, 15vmin, 120px);
  aspect-ratio: 1;
  padding: 0;
  font-size: clamp(40px, 8vmin, 66px);
  line-height: 1;
  background: color-mix(in srgb, var(--c) 35%, var(--paper));
  border: 4px solid var(--ink);
  border-radius: 50%;
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  -webkit-touch-callout: none;
}

.pitches.empty .pitch-btn { cursor: default; }


/* ------------------------------------------------------------- play screen */

#play-screen {
  display: flex;
  flex-direction: column;
}

.play-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 6px
           max(14px, env(safe-area-inset-left));
}

.bar-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.transport { margin-left: auto; }

/* narrow screens: ⌂ and the tape (or song tools) on top, the instruments
   on a row of their own underneath */
@media (max-width: 600px) {
  #voices { order: 2; flex-basis: 100%; justify-content: center; }
}

.bar-btn {
  flex: none;
  width: 64px;
  height: 64px;
  padding: 0;
  font-size: 32px;
  line-height: 1;
  display: grid;
  place-items: center;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 50%;
  box-shadow: var(--shadow);
  transition: transform .12s, opacity .12s;
}

.bar-btn:active { transform: translateY(4px); box-shadow: none; }

.voice-btn { opacity: .55; }
.voice-btn[aria-checked="true"] { opacity: 1; background: var(--accent); transform: scale(1.1); }

/* record: a red dot; while recording, a square, and the button pulses */
.rec-btn i {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--rec);
}
.rec-btn.on { background: #ffe0e0; animation: pulse 1s ease-in-out infinite; }
.rec-btn.on i { border-radius: 4px; background: var(--ink); }

/* play: a triangle; while playing, a square */
.play-btn i {
  width: 0;
  height: 0;
  margin-left: 6px;
  border-style: solid;
  border-width: 14px 0 14px 24px;
  border-color: transparent transparent transparent #3cc85a;
}
.play-btn.on { background: #e0ffe6; }
.play-btn.on i { margin: 0; width: 24px; height: 24px; border: 0; border-radius: 4px; background: var(--ink); }
.play-btn.empty { opacity: .35; }

.loop-btn { opacity: .55; }
.loop-btn[aria-pressed="true"] { opacity: 1; background: var(--accent); }

@keyframes pulse {
  50% { transform: scale(1.1); }
}

.song-progress {
  width: clamp(120px, 30vw, 320px);
  height: 22px;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
}

#song-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #ff4d4d, #ffd23f, #3cc85a, #3a86ff, #9b5de5);
  transition: width .2s;
}

/* songs: the title, and the song on a staff with the note to play marked */
.song-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0 max(14px, env(safe-area-inset-right)) 4px max(14px, env(safe-area-inset-left));
}

.song-title {
  margin: 0;
  font-size: clamp(20px, 4vmin, 32px);
  line-height: 1.1;
  text-align: center;
}

.staff {
  width: 100%;
  max-width: 1000px;
  padding: 6px 8px 0;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.staff svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 34vh;
}

.staff-line, .ledger { stroke: var(--ink); stroke-width: 1.4; }
.clef { font-size: 58px; fill: var(--ink); font-family: "Apple Symbols", "Noto Music", "Segoe UI Symbol", serif; }

.note { transition: opacity .25s; }
.note .stem { stroke: var(--ink); stroke-width: 1.6; }
.note .head { fill: var(--c); stroke: var(--ink); stroke-width: 1.6; }
.note.open .head { fill: var(--paper); stroke: var(--c); stroke-width: 3; }
.note.done { opacity: .3; }
.note.now .head { stroke-width: 2.6; }

/* the glowing ball under the note to play */
.ball { transition: opacity .2s; }
.ball.glide { transition: transform .3s cubic-bezier(.3, 1.4, .6, 1), opacity .2s; }
.ball.hidden-ball { opacity: 0; }
.ball-glow { fill: var(--c); opacity: .8; transform-box: fill-box; transform-origin: center;
             animation: ball-pulse .7s ease-in-out infinite alternate; }
.ball-core { fill: color-mix(in srgb, var(--c) 45%, #fff); stroke: var(--c); stroke-width: 1.5; }

@keyframes ball-pulse {
  from { transform: scale(.8); opacity: .55; }
  to   { transform: scale(1.25); opacity: .95; }
}


.stage {
  flex: 1;
  min-height: 0;
  padding: 10px max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom))
           max(14px, env(safe-area-inset-left));
  touch-action: none;
  border-radius: var(--radius);
  transition: box-shadow .2s;
}

body.recording .stage { box-shadow: inset 0 0 0 6px var(--rec); }


/* -------------------------------------------------------------------- pads
 *
 * Xylophone bars: low on the left, getting shorter as they go up. In
 * portrait they stack instead, low at the bottom. --len is set per pad.
 * ----------------------------------------------------------------------- */

.stage.pads {
  display: flex;
  align-items: center;
  gap: 1.4vmin;
}

.pad {
  --c: #3a86ff;
  position: relative;
  flex: 1;
  height: var(--len);
  min-width: 0;
  border: 4px solid var(--ink);
  border-radius: 18px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--c) 70%, #fff), var(--c) 55%,
                              color-mix(in srgb, var(--c) 82%, #000));
  box-shadow: var(--shadow);
}

/* the two pegs that hold a xylophone bar */
.pad i {
  position: absolute;
  left: 50%;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .7);
  border: 3px solid rgba(0, 0, 0, .25);
}
.pad i:first-child { top: 12%; }
.pad i:last-child { bottom: 12%; }

/* songs: the pad to tap next */
.pad.next {
  box-shadow: 0 0 0 6px #fff, 0 0 28px 14px var(--c);
  animation: glow .8s ease-in-out infinite alternate;
  z-index: 1;
}

@keyframes glow {
  from { filter: brightness(1); }
  to   { filter: brightness(1.3); }
}

@media (orientation: portrait) {
  .stage.pads { flex-direction: column-reverse; }
  .pad { width: var(--len); height: auto; flex: 1; min-height: 0; }
  .pad i { top: 50% !important; bottom: auto !important; left: auto; margin: -7px 0 0; }
  .pad i:first-child { left: 8%; }
  .pad i:last-child { right: 8%; }
}


/* ------------------------------------------------------------------- drums */

.stage.drums {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 2vmin;
}

@media (orientation: portrait) {
  .stage.drums {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
  }
}

.drum-cell {
  container-type: size;
  display: grid;
  place-items: center;
  min-height: 0;
}

.drum {
  --c: #3a86ff;
  --d: min(100cqw, 100cqh);
  width: var(--d);
  height: var(--d);
  display: grid;
  place-items: center;
  font-size: calc(var(--d) * .42);
  line-height: 1;
  border-radius: 50%;
  border: 4px solid var(--ink);
  background: radial-gradient(circle, #fffdf7 0 52%, color-mix(in srgb, var(--c) 30%, #fff) 53% 62%,
                              var(--c) 63%);
  box-shadow: var(--shadow);
}


/* ------------------------------------------------------- grown-up settings */

.settings {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(35, 38, 43, .45);
}

.settings-card {
  width: min(420px, 100%);
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 20px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  -webkit-user-select: text;
  user-select: text;
}

.settings-card h2 { margin: 0; font-size: 28px; }

.settings-note { margin: 0; font-size: 15px; opacity: .7; }

.small-btn {
  align-self: flex-start;
  font-size: 19px;
  padding: 6px 14px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .12);
}

.small-btn:active { transform: translateY(4px); box-shadow: none; }
.small-btn:disabled { opacity: .4; cursor: default; }

.big-btn {
  font-size: 24px;
  padding: 10px;
  background: var(--accent);
  border: 4px solid var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.big-btn:active { transform: translateY(4px); box-shadow: none; }
