@font-face {
  font-family: "Pacifico";
  src: url("fonts/pacifico.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "Fredoka";
  src: url("fonts/fredoka.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --bg: #1b1640;
  --panel: #2a2360;
  --panel-2: #342c74;
  --text: #fff8e7;
  --muted: #a79fd6;
  --inst: #ff5d73;
  --radius: 14px;
  font-family: "Fredoka", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
           max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  gap: 10px;
  background:
    radial-gradient(circle at 15% 0%, color-mix(in srgb, var(--inst) 22%, transparent), transparent 45%),
    var(--bg);
  transition: background 0.3s;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

/* ---------- header ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
h1 {
  margin: 0;
  font-size: clamp(24px, 3.4vw, 32px);
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
  line-height: 1.3;
  word-spacing: -0.1em;
}
h1 .by { color: var(--muted); font-weight: 500; font-size: 0.7em; }
h1 .logo { display: inline-block; position: relative; top: -0.08em; animation: wobble 3s ease-in-out infinite; }
h1 .ellis {
  font-family: "Pacifico", cursive;
  font-weight: 400;
  font-size: 1.2em;
  /* Pacifico's letters sit high in the line: drop them onto the same baseline as "Beats by" */
  display: inline-block;
  line-height: 1;
  position: relative;
  top: 0.14em;
  /* room so the rainbow fill reaches the swashes, without making the header taller */
  padding: 0.15em 0.15em 0.25em;
  margin: -0.15em 0 -0.25em -0.12em;
  background: linear-gradient(90deg, #ff5d73, #ff9f1c, #ffd23f, #3ddc97, #4cc9f0, #b388ff, #ff5d73);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: rainbow 6s linear infinite;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.35));
}

/* speed slider */
.speed {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border-radius: 999px;
  padding: 6px 14px;
  flex: 0 1 380px;
  min-width: 240px;
}
.speed-end { font-size: 24px; }
.speed-value {
  min-width: 2.4em;
  text-align: center;
  font-weight: 700;
  font-size: 18px;
  color: var(--muted);
}
#tempo {
  --pct: 40%;
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 0;
  height: 40px;
  background: transparent;
  touch-action: none;
}
#tempo::-webkit-slider-runnable-track {
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #3ddc97, #ffd23f, #ff5d73);
}
#tempo::-moz-range-track {
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #3ddc97, #ffd23f, #ff5d73);
}
#tempo::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 34px;
  height: 34px;
  margin-top: -11px;
  border-radius: 50%;
  background: #fff8e7;
  border: 4px solid var(--inst);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
}
#tempo::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff8e7;
  border: 4px solid var(--inst);
}

/* ---------- instrument tabs ---------- */
#tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.tab {
  position: relative;
  --c: #fff;
}
.tab-main {
  width: 100%;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.tab-emoji { font-size: 32px; }
.tab-name { font-size: 20px; font-weight: 800; }
.tab-dots {
  position: absolute;
  left: 10px;
  bottom: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--c);
}
.tab.active .tab-main {
  background: color-mix(in srgb, var(--c) 28%, var(--panel));
  border-color: var(--c);
}
.tab-main:active { transform: scale(0.96); }
.tab.bounce .tab-emoji { animation: bounce 0.2s ease-out; }
.tab-mute {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--panel-2);
  font-size: 16px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
.tab.muted .tab-main { opacity: 0.45; }
.tab.muted .tab-mute { background: #6b2340; }

/* save / my songs buttons */
.file-buttons { display: flex; gap: 8px; margin-left: auto; }
.head-btn {
  height: 52px;
  padding: 0 14px;
  border-radius: var(--radius);
  background: var(--panel);
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 16px;
}
.head-btn span { font-size: 24px; }
.head-btn:active { transform: scale(0.94); }

/* ---------- song parts ---------- */
#parts {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 58px;
}
#part-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px 2px;
  min-width: 0;
}
#part-list::-webkit-scrollbar { display: none; }
.part {
  position: relative;
  flex: none;
  display: flex;
  align-items: stretch;
  height: 50px;
  border-radius: 12px;
  background: var(--panel);
  border: 3px solid transparent;
  transition: border-color 0.15s, background 0.15s;
}
.part.active {
  border-color: #fff8e7;
  background: var(--panel-2);
}
.part.playing { box-shadow: 0 0 0 3px #3ddc97, 0 0 16px rgba(61, 220, 151, 0.6); }
.part.pop { animation: pop 0.3s ease-out; }
.part-main {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px 0 10px;
}
.part-num { font-size: 22px; font-weight: 700; min-width: 0.8em; }
.part-dots {
  display: grid;
  grid-template-columns: repeat(2, 9px);
  gap: 3px;
}
.part-dots i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
}
.part-dots i.has { background: var(--c); }
.part-repeat {
  margin: 5px 5px 5px 2px;
  padding: 0 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 16px;
  font-weight: 700;
  color: var(--muted);
}
body:not(.song-mode) .part-repeat { opacity: 0.45; }
.part-tool {
  flex: none;
  height: 50px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--panel);
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 4px;
}
.part-tool span { font-size: 20px; }
.part-tool:active { transform: scale(0.94); }
.part-tool:disabled { opacity: 0.3; }
.song-info {
  margin-left: auto;
  flex: 0 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 2px 4px 2px 8px;
  line-height: 1.2;
}
.song-name {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
  font-weight: 700;
}
.song-name.unsaved::after {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-left: 6px;
  border-radius: 50%;
  background: #ff9f1c;
  vertical-align: middle;
}
.song-length {
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
}

/* ---------- pop-up sheets ---------- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(10, 6, 30, 0.7);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: max(40px, env(safe-area-inset-top)) 16px 16px;
  animation: fade 0.15s ease-out;
}
#overlay[hidden] { display: none; }
.sheet {
  width: min(620px, 100%);
  max-height: calc(100% - 20px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--panel);
  border: 3px solid var(--panel-2);
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: rise 0.2s ease-out;
}
.sheet h2 { margin: 0; font-size: 26px; font-weight: 700; }
.sheet p { margin: 0; font-size: 18px; color: var(--muted); }
.sheet-head { display: flex; align-items: center; gap: 10px; }
.sheet-head h2 { flex: 1; }
.sheet-buttons { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

.btn {
  height: 52px;
  padding: 0 18px;
  border-radius: 14px;
  background: var(--panel-2);
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
}
.btn:active { transform: scale(0.95); }
.btn.primary { background: #3ddc97; color: #10301f; }
.btn.danger { background: #ff5d73; color: #3d0a14; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 2px var(--panel-2); }
.btn.small { height: 46px; padding: 0 14px; font-size: 16px; }
.btn.close { width: 52px; padding: 0; }

.name-row { display: flex; gap: 10px; }
#name-input {
  flex: 1;
  min-width: 0;
  height: 60px;
  border-radius: 14px;
  border: 3px solid var(--panel-2);
  background: #15112f;
  color: var(--text);
  font: inherit;
  font-size: 24px;
  font-weight: 600;
  padding: 0 16px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
#name-input:focus { border-color: #3ddc97; }
#name-input::placeholder { color: #6b63a8; }
.btn.dice { width: 60px; height: 60px; padding: 0; font-size: 30px; }

.song-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}
.song-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 16px;
  background: #3a3280;
  transition: opacity 0.25s, transform 0.25s;
}
.song-row.current { box-shadow: inset 0 0 0 3px #fff8e7; }
.song-row.gone { opacity: 0; transform: translateX(40px); }
.song-open {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 4px 6px;
}
.song-dots { display: grid; grid-template-columns: repeat(2, 12px); gap: 4px; flex: none; }
.song-dots i { width: 12px; height: 12px; border-radius: 50%; background: rgba(255, 255, 255, 0.14); }
.song-dots i.has { background: var(--c); }
.song-text { display: flex; flex-direction: column; min-width: 0; }
.song-title {
  font-size: 20px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.song-meta { font-size: 14px; color: var(--muted); font-weight: 500; }
.btn.del { width: 46px; padding: 0; }
.btn.del.armed { width: auto; padding: 0 12px; background: #ff5d73; color: #3d0a14; box-shadow: none; }
.empty { text-align: center; padding: 30px 0; line-height: 1.6; }

#toast {
  position: fixed;
  left: 50%;
  bottom: max(100px, calc(env(safe-area-inset-bottom) + 90px));
  z-index: 20;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  background: #fff8e7;
  color: #1b1640;
  font-size: 18px;
  font-weight: 700;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- grid ---------- */
main {
  flex: 1;
  min-height: 0;
  background: var(--panel);
  border-radius: 20px;
  padding: 10px;
  border: 3px solid color-mix(in srgb, var(--inst) 55%, transparent);
  transition: border-color 0.3s;
}
#grid {
  height: 100%;
  display: grid;
  grid-template-columns: clamp(52px, 8vw, 84px) repeat(16, 1fr);
  grid-template-rows: repeat(var(--rows, 4), 1fr);
  gap: 5px;
  touch-action: none;
}
.row-label {
  border-radius: 10px;
  background: color-mix(in srgb, var(--note) 25%, var(--panel-2));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.05;
  margin-right: 4px;
}
.row-label:active { transform: scale(0.94); }
.row-label.boing { animation: bounce 0.25s ease-out; }
.lbl-emoji { font-size: clamp(18px, 2.6vw, 26px); }
.lbl-text { font-size: 13px; font-weight: 800; }
.lbl-note {
  font-size: clamp(18px, 2.6vw, 26px);
  font-weight: 900;
  color: var(--note);
}

.cell {
  border-radius: 9px;
  background: #3a3280;
  transition: background 0.08s, transform 0.08s, box-shadow 0.08s;
}
.cell.beat-a { background: #453c93; }
.cell.on {
  background: var(--note);
  box-shadow: 0 3px 0 color-mix(in srgb, var(--note) 60%, black), 0 0 14px color-mix(in srgb, var(--note) 55%, transparent);
}
.cell.now:not(.on) { background: #5e55b5; }
.cell.now.on { transform: scale(1.1); filter: brightness(1.2); }
.cell.pop { animation: pop 0.2s ease-out; }
.cell.hit { animation: hit 0.18s ease-out; }

/* ---------- footer controls ---------- */
footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.tool {
  width: 84px;
  height: 66px;
  border-radius: var(--radius);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform 0.1s, opacity 0.15s;
}
.tool span { font-size: 26px; }
.tool small { font-size: 13px; font-weight: 700; color: var(--muted); }
.tool:active { transform: scale(0.93); }
.tool:disabled { opacity: 0.35; }
#surprise.spin span { display: inline-block; animation: spin 0.45s ease-out; }

.mode {
  display: flex;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 4px;
  gap: 4px;
}
.mode button {
  width: 72px;
  height: 58px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  transition: opacity 0.15s, background 0.15s;
}
.mode button span { font-size: 24px; }
.mode button small { font-size: 13px; font-weight: 700; }
.mode button.active {
  opacity: 1;
  background: var(--panel-2);
  box-shadow: inset 0 0 0 2px #fff8e7;
}

#play {
  height: 72px;
  min-width: 190px;
  padding: 0 26px;
  border-radius: 999px;
  background: #3ddc97;
  color: #10301f;
  font-size: 28px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  box-shadow: 0 5px 0 #23935f;
  transition: transform 0.08s, box-shadow 0.08s, background 0.15s;
}
#play:active { transform: translateY(4px); box-shadow: 0 1px 0 #23935f; }
.play-icon {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 13px 0 13px 22px;
  border-color: transparent transparent transparent currentColor;
}
#play.playing { background: #ff5d73; color: #3d0a14; box-shadow: 0 5px 0 #b8344a; }
#play.playing .play-icon {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 4px;
  background: currentColor;
}

/* ---------- portrait iPad ---------- */
@media (orientation: portrait) {
  .tab-main { flex-direction: column; gap: 0; height: 84px; }
  .tab-name { font-size: 16px; }
  #grid { gap: 4px; }
  .tool { width: 70px; }
  #play { min-width: 150px; }
  footer { gap: 10px; }
  /* narrow screen: icon-only buttons, shorter slider */
  .head-btn small { display: none; }
  .head-btn { padding: 0 12px; }
  .speed { min-width: 200px; flex-basis: 260px; }
  .speed-value { display: none; }
  .song-name { max-width: 150px; }
}

/* ---------- animations ---------- */
@keyframes pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes hit { 0% { transform: scale(1.22); } 100% { transform: scale(1.1); } }
@keyframes bounce { 0% { transform: translateY(0); } 40% { transform: translateY(-5px) scale(1.12); } 100% { transform: translateY(0); } }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
@keyframes rainbow { from { background-position: 0% 0; } to { background-position: 200% 0; } }
@keyframes wobble { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }

/* ---------- older browsers (e.g. an out-of-date Silk on a Fire tablet) ---------- */
@supports not (color: color-mix(in srgb, red, blue)) {
  body { background: var(--bg); }
  .tab.active .tab-main { background: var(--panel-2); }
  .row-label { background: var(--panel-2); }
  main { border-color: var(--inst); }
  .cell.on { box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
