:root {
  color-scheme: light dark;

  /* Chassis */
  --bg: light-dark(#e4e6eb, #0b0c10);
  --chassis: light-dark(#f4f5f8, #14161c);
  --surface: light-dark(#ffffff, #1b1e26);
  --surface-hover: light-dark(#f1f3f7, #242833);
  --text: light-dark(#151821, #e6e8ef);
  --muted: light-dark(#5b6172, #8b91a3);
  --border: light-dark(#c3c7d1, #2a2f3b);

  /* Unlit pad (rubber) */
  --pad-off: light-dark(#dcdfe6, #23262e);
  --pad-off-edge: light-dark(#b8bcc7, #0f1014);

  /* Cat identity (thumbnail glyph, library LED) */
  --cat-marty: #f59e0b;
  --cat-sprout: #22c55e;

  /* Pad hues by tag — RGB-launchpad palette */
  --hue-meow: #ff7a1a;
  --hue-chirp: #22d3ee;
  --hue-purr: #a855f7;
  --hue-squeak: #facc15;
  --hue-greeting: #f43f5e;
  --accent: light-dark(#4f46e5, #7c8cff);
  --accent-text: #ffffff;
  --danger: light-dark(#dc2626, #ef4444);

  --radius: 6px;
  --radius-sm: 6px;
  --pad-gap: 8px;
}

[data-theme="light"] { color-scheme: light; }
[data-theme="dark"]  { color-scheme: dark; }

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  max-width: 100vw;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Header / scene buttons ---------- */

.app-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px 8px;
  min-width: 0;
  width: 100%;
  background: var(--chassis);
  border-bottom: 1px solid var(--border);
}

.app-header nav {
  min-width: 0;
  width: 100%;
}

.app-header h1 {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

#bank-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  padding: 2px 0 4px;
  min-width: 0;
  width: 100%;
}
#bank-tabs::-webkit-scrollbar { display: none; }

[role="tab"], .tab-add {
  flex-shrink: 0;
  min-height: 30px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--pad-off-edge);
  background: var(--pad-off);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  scroll-snap-align: center;
  user-select: none;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .06), 0 1px 0 rgb(0 0 0 / .35);
  transition: background-color .12s, color .12s, box-shadow .12s;
}

[role="tab"][aria-selected="true"] {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 70%, transparent),
              0 0 22px color-mix(in srgb, var(--accent) 35%, transparent);
}

/* ---------- Grid ---------- */

main {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow-y: auto;
  padding: 12px;
  min-width: 0;
  width: 100%;
}

#pad-grid {
  width: 100%;
  min-width: 0;
  display: flex;
  justify-content: center;
}

.pads {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--pad-gap);
  width: 100%;
  padding: var(--pad-gap);
  background: var(--chassis);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / .25), 0 12px 30px rgb(0 0 0 / .35);
  touch-action: manipulation;
}

@media (min-width: 640px) {
  .pads {
    grid-template-columns: repeat(4, 1fr);
    max-width: 620px;
    --pad-gap: 10px;
  }
}

@media (min-width: 1024px) {
  .pads {
    max-width: 720px;
    --pad-gap: 12px;
  }
}

@media (max-height: 480px) and (orientation: landscape) {
  .pads {
    grid-template-columns: repeat(6, 1fr);
    max-width: 900px;
    --pad-gap: 6px;
  }
}

.pads li { min-width: 0; }

/* ---------- Pads ---------- */

.pad {
  --pad-accent: var(--accent);
  aspect-ratio: 1;
  width: 100%;
  display: grid;
  place-items: end center;
  position: relative;
  overflow: hidden;
  padding: 6px;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  color: light-dark(#1a1a1a, #f6f6f6);
  transition: color .08s ease;
  /* dim-lit: cat color mixed down toward the rubber */
  background: color-mix(in srgb, var(--pad-accent) 42%, var(--pad-off));
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / .10),
    inset 0 -3px 0 rgb(0 0 0 / .35),
    0 2px 0 var(--pad-off-edge);
  transition: transform .05s ease, background-color .08s ease, box-shadow .08s ease;
}

.pad[data-hue="meow"]     { --pad-accent: var(--hue-meow); }
.pad[data-hue="chirp"]    { --pad-accent: var(--hue-chirp); }
.pad[data-hue="purr"]     { --pad-accent: var(--hue-purr); }
.pad[data-hue="squeak"]   { --pad-accent: var(--hue-squeak); }
.pad[data-hue="greeting"] { --pad-accent: var(--hue-greeting); }

.pad__thumb {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22%;
  max-width: 28px;
  aspect-ratio: 1;
  object-fit: contain;
  opacity: .9;
  filter: drop-shadow(0 1px 1px rgb(0 0 0 / .5));
  pointer-events: none;
}

.pad__label {
  font-size: clamp(0.55rem, 2vw, 0.7rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 1px rgb(0 0 0 / .25);
  pointer-events: none;
}

/* Pressed: pad physically sinks */
.pad:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / .10),
    inset 0 -1px 0 rgb(0 0 0 / .35),
    0 0 0 var(--pad-off-edge);
}

/* Lit: full-saturation glow that decays over the clip */
.pad.is-playing {
  background: var(--pad-accent);
  color: #1a1a1a; /* lit pads are always bright; dark text passes AA on every hue */
  animation: lit var(--dur, 0.6s) linear forwards;
}
.pad.is-playing .pad__label { text-shadow: none; }

@keyframes lit {
  0%, 35% {
    background-color: color-mix(in srgb, var(--pad-accent) 100%, white 25%);
    color: #1a1a1a;
    box-shadow:
      inset 0 1px 0 rgb(255 255 255 / .35),
      0 0 14px var(--pad-accent),
      0 0 34px color-mix(in srgb, var(--pad-accent) 65%, transparent);
  }
  100% {
    background-color: color-mix(in srgb, var(--pad-accent) 42%, var(--pad-off));
    color: light-dark(#1a1a1a, #f6f6f6);
    box-shadow:
      inset 0 1px 0 rgb(255 255 255 / .10),
      inset 0 -3px 0 rgb(0 0 0 / .35),
      0 2px 0 var(--pad-off-edge);
  }
}

/* Unlit rubber */
.pad--empty {
  background: var(--pad-off);
  color: var(--muted);
  cursor: default;
}
.pad--empty .pad__thumb { display: none; }
.pad--empty .pad__label {
  font-size: 1.3rem;
  font-weight: 300;
  opacity: .5;
}

/* Edit mode: pads show a thin ring, empty ones pulse softly */
body[data-editing] .pad {
  cursor: pointer;
  box-shadow:
    inset 0 0 0 2px color-mix(in srgb, var(--accent) 70%, transparent),
    inset 0 -3px 0 rgb(0 0 0 / .35),
    0 2px 0 var(--pad-off-edge);
}
body[data-editing] .pad--empty {
  animation: breathe 1.6s ease-in-out infinite alternate;
}
@keyframes breathe {
  from { background-color: var(--pad-off); }
  to   { background-color: color-mix(in srgb, var(--accent) 22%, var(--pad-off)); }
}

@media (prefers-reduced-motion: reduce) {
  *, ::after, ::before {
    animation: none !important;
    transition: none !important;
  }
  .pad.is-playing { background: var(--pad-accent); }
}

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  min-width: 0;
  width: 100%;
  background: var(--chassis);
  border-top: 1px solid var(--border);
}

.toolbar button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--pad-off-edge);
  background: var(--pad-off);
  color: var(--text);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .06), 0 1px 0 rgb(0 0 0 / .35);
}
.toolbar button:hover { background: var(--surface-hover); }
.toolbar button:disabled { opacity: .4; cursor: default; }

.toolbar button[aria-pressed="true"] {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 70%, transparent);
}

.volume {
  flex: 1 1 120px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 0;
}
.volume input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

@media (max-width: 639px) {
  .volume__label {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

/* ---------- Dialogs ---------- */

dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--chassis);
  color: var(--text);
  width: min(100% - 24px, 560px);
  max-height: 85dvh;
  padding: 16px;
  margin: auto;
  box-shadow: 0 24px 48px rgb(0 0 0 / .5);
}
dialog::backdrop {
  background: rgb(0 0 0 / .65);
  backdrop-filter: blur(2px);
}

@media (max-width: 639px) {
  dialog {
    margin-block-end: 0;
    margin-inline: 0;
    border-end-start-radius: 0;
    border-end-end-radius: 0;
    width: 100%;
    max-height: 90dvh;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  }
}

.dialog__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.dialog__header h2 {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.dialog__close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.dialog__close:hover { color: var(--text); }

.dialog__body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-block: 12px;
  overflow-y: auto;
  max-height: calc(85dvh - 130px);
}

.dialog__field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.dialog__field input,
.dialog__search input {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}
.dialog__search { display: block; width: 100%; }

.chip-group {
  border: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chip-group legend {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0;
}
.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip { display: inline-flex; cursor: pointer; }
.chip input {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.chip span {
  display: inline-block;
  padding: 5px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--pad-off-edge);
  background: var(--pad-off);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  user-select: none;
  transition: background-color .12s, color .12s, box-shadow .12s;
}
.chip:has(:checked) span {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
  box-shadow: 0 0 8px color-mix(in srgb, var(--accent) 70%, transparent);
}

/* Sound list */
.sound-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  max-height: 280px;
  overflow-y: auto;
}
.sound {
  display: grid;
  grid-template-columns: 6px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.sound:last-child { border-bottom: none; }
.sound[aria-current="true"] {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

/* LED strip in the pad hue; the row's --pad-accent is set via data-hue */
.sound[data-hue="meow"]     { --pad-accent: var(--hue-meow); }
.sound[data-hue="chirp"]    { --pad-accent: var(--hue-chirp); }
.sound[data-hue="purr"]     { --pad-accent: var(--hue-purr); }
.sound[data-hue="squeak"]   { --pad-accent: var(--hue-squeak); }
.sound[data-hue="greeting"] { --pad-accent: var(--hue-greeting); }

.sound__thumb {
  width: 6px;
  height: 28px;
  border-radius: 3px;
  background: var(--pad-accent, var(--muted));
  box-shadow: 0 0 6px var(--pad-accent, transparent);
}

.sound__info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sound__name {
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sound__meta {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sound__preview,
.sound__assign {
  min-height: 30px;
  padding: 0 10px;
  border-radius: var(--radius);
  border: 1px solid var(--pad-off-edge);
  background: var(--pad-off);
  color: var(--text);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
.sound__preview:hover,
.sound__assign:hover { background: var(--surface-hover); }
.sound__assign {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
}

.sound--none {
  display: block;
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.875rem;
}

.dialog__footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.btn--danger {
  min-height: 32px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--danger);
  background: transparent;
  color: var(--danger);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
.btn--danger:hover { background: var(--danger); color: #fff; }

.setting-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  cursor: pointer;
}
.setting-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}
.settings__actions {
  padding-top: 8px;
  display: flex;
}
