@font-face {
  font-family: 'Nunito';
  src: url('fonts/nunito.woff2') format('woff2');
  font-weight: 200 1000;
  font-display: swap;
}

:root {
  --sky: #bfeafc;
  --sky-light: #eafaff;
  --panel: #fffdf6;
  --ink: #24324f;
  --muted: #5a6784;
  --line: #e9e4d6;
  --green: #178a47;
  --green-edge: #0f6a35;
  --red: #dc3f4d;
  --red-edge: #ad2a37;
  --purple: #6d4bd1;
  --purple-edge: #5233ab;
  --playhead: #ffe88a;
  --cell-h: clamp(38px, 5.4vh, 52px);
  --row-gap: 6px;
  --name-w: 104px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { background: var(--panel); }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(var(--sky), var(--sky-light) 62%);
  color: var(--ink);
  font-family: 'Nunito', ui-rounded, 'Segoe UI', system-ui, sans-serif;
  font-weight: 700;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

/* ---------- Schlagzeug: nimmt den Platz ein, den der Editor frei lässt ---------- */

.stage {
  position: relative;
  flex: 1 1 0;
  min-height: 200px;
}

#kit {
  position: absolute;
  inset: clamp(10px, 2.5vh, 26px) 16px 10px;
  width: calc(100% - 32px);
  height: calc(100% - clamp(10px, 2.5vh, 26px) - 10px);
  overflow: visible;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.piece { outline: none; }

.piece .hit {
  fill: transparent;
  stroke: none;
  cursor: pointer;
  touch-action: manipulation;
}

.piece .light {
  opacity: 0;
  pointer-events: none;
}

@media (hover: hover) {
  .piece:hover .light { opacity: 0.22; }
}

.piece:focus-visible .hit {
  stroke: var(--ink);
  stroke-width: 2;
  stroke-dasharray: 5 4;
}

/* ---------- Editor ---------- */

.editor {
  flex: none;
  background: var(--panel);
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -4px 18px rgba(36, 50, 79, 0.1);
  padding: 14px 16px 12px;
}

.editor.expanded {
  --cell-h: clamp(36px, 4.4vh, 46px);
  --row-gap: 5px;
}

.editor-inner {
  max-width: 900px;
  margin: 0 auto;
}

/* Bedienleiste */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.big {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 50px;
  padding: 0 18px 0 14px;
  border: 0;
  border-radius: 16px;
  font-size: 19px;
  font-weight: 800;
  color: #fff;
  transition: transform 0.06s, box-shadow 0.06s;
}

.big svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.big:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--edge);
}

.play { background: var(--green); --edge: var(--green-edge); box-shadow: 0 4px 0 var(--edge); }
.stop { background: var(--red); --edge: var(--red-edge); box-shadow: 0 4px 0 var(--edge); }

.play.active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--edge), 0 0 0 4px rgba(23, 138, 71, 0.25);
}

.loop {
  --edge: var(--purple-edge);
  background: #fff;
  color: var(--purple);
  box-shadow: inset 0 0 0 3px var(--purple), 0 4px 0 var(--edge);
}

.loop svg { fill: none; }

.loop[aria-pressed='true'] {
  background: var(--purple);
  color: #fff;
  box-shadow: 0 1px 0 var(--edge), 0 0 0 4px rgba(109, 75, 209, 0.25);
  transform: translateY(3px);
}

.tempo {
  flex: 1 1 260px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 17px;
}

.tempo-name { font-weight: 800; }
.tempo-icon { font-size: 22px; line-height: 1; }

.tempo output {
  min-width: 2.2em;
  text-align: right;
  font-size: 22px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

#tempo {
  flex: 1;
  min-width: 60px;
  height: 36px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

#tempo::-webkit-slider-runnable-track {
  height: 12px;
  border-radius: 6px;
  background: var(--line);
}

#tempo::-moz-range-track {
  height: 12px;
  border-radius: 6px;
  background: var(--line);
}

#tempo::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 30px;
  height: 30px;
  margin-top: -9px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 1px 4px rgba(36, 50, 79, 0.4);
}

#tempo::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 1px 4px rgba(36, 50, 79, 0.4);
}

/* Raster */

.grid,
.more-rows {
  display: grid;
  gap: var(--row-gap);
}

.more-rows { grid-column: 1 / -1; }

.row {
  display: grid;
  grid-template-columns: var(--name-w) repeat(4, 1fr);
  gap: 10px;
  align-items: stretch;
}

.beat {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

/* Achtel-Ansicht: Zwischenplätze ausblenden. Sechzehntel: 4 Plätze pro Schlag */
.editor:not(.fine) .sub { display: none; }

.editor.fine .editor-inner { max-width: 1100px; }

.editor.fine .beat {
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
}

.editor.fine .row { gap: 8px; }
.editor.fine .cell { border-radius: 9px; }
.editor.fine .cell.on::after { width: 10px; height: 10px; margin: -7px 0 0 -5px; }

.count {
  border-radius: 8px;
  text-align: center;
  font-size: 15px;
  line-height: 22px;
  color: var(--muted);
}

.count.main {
  font-size: 18px;
  font-weight: 900;
  color: var(--ink);
}

.count.now { background: var(--playhead); }

.name {
  height: var(--cell-h);
  padding: 0 6px;
  border: 0;
  border-radius: 12px;
  background: var(--soft);
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  white-space: nowrap;
}

.cell {
  position: relative;
  height: var(--cell-h);
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--soft);
  transition: transform 0.08s;
}

.cell.on {
  background: var(--c);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2);
}

/* Punkt im aktiven Kästchen: Der Zustand ist so auch ohne Farbe erkennbar */
.cell.on::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  margin: -9px 0 0 -7px;
  border-radius: 50%;
  background: #fff;
}

.cell.now:not(.on) { background: var(--playhead); }
.cell.on.now { transform: scale(1.07); }

@media (hover: hover) {
  .name:hover { filter: brightness(0.95); }
  .cell:not(.on):hover { filter: brightness(0.93); }
}

.row[data-piece='kick'] { --c: #e0434f; --soft: #fde4e4; }
.row[data-piece='snare'] { --c: #ef7d1a; --soft: #fdebd9; }
.row[data-piece='hihat'] { --c: #dca400; --soft: #fbf1c8; }
.row[data-piece='tomHigh'] { --c: #2fa84f; --soft: #dcf3e1; }
.row[data-piece='tomMid'] { --c: #0f9f90; --soft: #d6f2ee; }
.row[data-piece='tomFloor'] { --c: #2f80ed; --soft: #dfecfd; }
.row[data-piece='crash'] { --c: #8e5bd9; --soft: #ece3fa; }
.row[data-piece='ride'] { --c: #dd4f9f; --soft: #fbe2f0; }

/* Fußzeile */

.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 14px;
  margin-top: 8px;
}

.small {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px 0 8px;
  border: 0;
  border-radius: 12px;
  background: var(--line);
  font-size: 16px;
  font-weight: 800;
}

.small svg {
  width: 20px;
  height: 20px;
  flex: none;
  transition: transform 0.15s;
}

.small:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Achtel / Sechzehntel */

.resolution {
  display: inline-flex;
  margin-left: auto;
  padding: 3px;
  border-radius: 12px;
  background: var(--line);
}

.resolution button {
  position: relative;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-size: 15px;
  font-weight: 800;
  color: var(--muted);
}

.resolution button[aria-pressed='true'] {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(36, 50, 79, 0.18);
}

.badge {
  position: absolute;
  top: -8px;
  right: -6px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--purple);
  color: #fff;
  font-size: 12px;
  line-height: 20px;
}

/* Pattern-Leiste */

.patterns {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-bottom: 8px;
}

.patterns-name { font-size: 17px; font-weight: 800; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tab {
  position: relative;
  width: 42px;
  height: 38px;
  border: 0;
  border-radius: 12px;
  background: var(--line);
  font-size: 18px;
  font-weight: 900;
}

.tab[aria-pressed='true'] {
  background: var(--ink);
  color: #fff;
}

/* Grüner Punkt: dieses Pattern spielt gerade */
.tab.playing::after {
  content: '';
  position: absolute;
  top: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  border: 3px solid var(--panel);
  border-radius: 50%;
  background: var(--green);
}

.pattern-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pattern-tools .small { height: 38px; }

.more[aria-expanded='true'] svg { transform: rotate(180deg); }

.hint {
  margin: 0;
  font-size: 16px;
  color: var(--muted);
}

/* ---------- Schmale Bildschirme ---------- */

@media (max-width: 560px) {
  :root { --name-w: 74px; }

  .editor { padding: 12px 10px 10px; }
  .row { gap: 6px; }
  .beat { gap: 3px; }
  .name { font-size: 13px; padding: 0 2px; }
  .big { height: 46px; font-size: 17px; padding: 0 14px 0 10px; }
  .controls { gap: 8px; }
  .tempo { flex-basis: 100%; }
  .hint { order: 1; flex-basis: 100%; }

  .patterns-name { display: none; }
  .tab { width: 38px; }
  .pattern-tools .small { padding: 0 10px 0 6px; font-size: 15px; }

  .editor.fine { --name-w: 62px; }
  .editor.fine .name { font-size: 11px; }
  .editor.fine .row { gap: 4px; }
  .editor.fine .beat { gap: 2px; }
  .editor.fine .cell { border-radius: 6px; }
  .editor.fine .cell.on::after { width: 8px; height: 8px; margin: -6px 0 0 -4px; }
  .editor.fine .count { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .big, .cell, .more svg { transition: none; }
  .cell.on.now { transform: none; outline: 3px solid var(--ink); }
}
