:root {
  --bg: #0a0a0a;
  --card: #1f1f1f;
  --text: #fff;
  --text-dim: rgba(255, 255, 255, 0.38);
  --accent: rgb(71, 184, 255);
  --play: rgb(56, 133, 245);
  --save: rgb(56, 158, 97);
  --library-border: rgba(255, 165, 0, 0.55);
  --cell-off: #333;
  --cell-off-muted: #242424;
  --row-gap: 4px;
  --col-gap: 3px;
  --divider-w: 5px;
  --label-w: 88px;
  --mute-w: 36px;
}

[data-kit="0"] {
  --accent: rgb(71, 184, 255);
}
[data-kit="1"] {
  --accent: rgb(255, 107, 97);
}
[data-kit="2"] {
  --accent: rgb(184, 133, 250);
}

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

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app {
  min-height: 100%;
  padding: 12px 10px 24px;
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  max-width: 1100px;
  margin: 0 auto;
}

.top-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 14px;
  padding: 0 8px;
}

.top-bar__title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.kit-row {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  padding: 0 8px;
}

.kit-btn {
  flex: 1;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 9px 6px;
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.58);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  min-height: 44px;
}

.kit-btn[aria-selected="true"] {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border-width: 2px;
  border-color: color-mix(in srgb, var(--accent) 100%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 32%, transparent);
}

.studio-card {
  background: var(--card);
  border-radius: 12px;
  padding: 10px;
}

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

.toolbar__pattern-title {
  font: 600 13px ui-monospace, monospace;
  color: var(--accent);
  width: 100px;
  min-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar__steps {
  display: flex;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.seg {
  width: 48px;
  min-height: 36px;
  border: none;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.55);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.seg--43 {
  width: auto;
  min-width: 48px;
  padding: 0 8px;
  font-size: 12px;
}

.seg--active {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.bpm-block {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  user-select: none;
  touch-action: pan-y;
}

.bpm-block__label {
  font-size: 9px;
  font-weight: 500;
  color: var(--text-dim);
  min-width: 28px;
}

.bpm-arrow {
  width: 34px;
  height: 32px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.92);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.bpm-arrow:disabled {
  color: rgba(255, 255, 255, 0.3);
  cursor: default;
}

.bpm-block__value {
  font: 700 16px ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  width: 52px;
  text-align: center;
}

.toolbar__grow {
  flex: 1;
  min-width: 8px;
}

.toolbar__grow--sm {
  flex: 0;
  min-width: 4px;
}

.btn-play {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: var(--play);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.btn-play__icon {
  font-size: 11px;
  margin-left: 2px;
}

.btn-clear {
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 7px 12px;
  min-height: 36px;
  cursor: pointer;
  white-space: nowrap;
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.28);
}

.btn-clear:hover {
  border-color: rgba(255, 120, 120, 0.55);
  color: rgb(255, 170, 170);
}

.btn-save,
.btn-export,
.btn-library {
  font-size: 12px;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  padding: 7px 14px;
  min-height: 36px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-save {
  background: var(--save);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.btn-export {
  background: rgb(45, 55, 72);
  color: rgba(255, 255, 255, 0.92);
  box-shadow: inset 0 0 0 1px rgba(120, 160, 255, 0.45);
}

.btn-library {
  background: rgb(51, 51, 51);
  color: rgba(255, 255, 255, 0.92);
  box-shadow: inset 0 0 0 1.2px var(--library-border);
}

.export-modal__hint code {
  font-size: 11px;
  opacity: 0.9;
}

.export-modal__actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.btn-export-choice {
  width: 100%;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
}

.btn-export-choice:hover {
  background: rgba(255, 255, 255, 0.12);
}

.grid-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.sequencer {
  padding: 4px 0;
  min-width: min-content;
}

.seq-row {
  display: flex;
  align-items: center;
  gap: var(--col-gap);
  margin-bottom: var(--row-gap);
}

.seq-row--header {
  margin-bottom: var(--row-gap);
}

.seq-label {
  width: var(--label-w);
  min-width: var(--label-w);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  color: var(--accent);
  line-height: 1.15;
  word-break: break-word;
  flex-shrink: 0;
}

.seq-label--muted {
  opacity: 0.4;
}

.seq-label--header {
  height: 12px;
  min-height: 12px;
}

.seq-step-num {
  width: var(--cell, 24px);
  min-width: var(--cell, 24px);
  height: 12px;
  font-size: 9px;
  font-weight: 500;
  font-family: ui-monospace, monospace;
  color: var(--text-dim);
  text-align: center;
  line-height: 12px;
  flex-shrink: 0;
}

.seq-divider {
  width: var(--divider-w);
  min-width: var(--divider-w);
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  align-self: stretch;
}

.seq-divider::after {
  content: "";
  width: 1.5px;
  background: rgba(255, 255, 255, 0.78);
  border-radius: 1px;
  margin: 1px 0;
}

.seq-divider--header {
  height: 12px;
  align-self: auto;
}

.seq-divider--header::after {
  margin: 0;
  height: 10px;
}

.seq-cell {
  width: var(--cell, 24px);
  min-width: var(--cell, 24px);
  height: var(--cell, 24px);
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--cell-off);
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
}

.seq-cell--on {
  background: color-mix(in srgb, var(--accent) 88%, transparent);
  border-color: rgba(255, 255, 255, 0.15);
}

.seq-cell--on.seq-cell--track-muted {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
}

.seq-cell--track-muted:not(.seq-cell--on) {
  background: var(--cell-off-muted);
}

.seq-cell--playhead {
  border-width: 2px;
  border-color: #fff;
}

.seq-mute-head {
  width: var(--mute-w);
  min-width: var(--mute-w);
  font-size: 7px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.25);
  text-align: center;
  flex-shrink: 0;
}

.seq-mute {
  width: var(--mute-w);
  min-width: var(--mute-w);
  height: var(--cell, 24px);
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  font-size: 14px;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
}

.seq-mute--active {
  color: rgba(255, 80, 80, 0.95);
}

/* Modal */
.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

.modal__panel {
  position: relative;
  background: #2a2a2a;
  border-radius: 14px;
  padding: 20px;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.modal__panel--wide {
  max-width: 420px;
  max-height: min(80vh, 560px);
  display: flex;
  flex-direction: column;
}

.modal__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal__head h2 {
  margin: 0;
  font-size: 17px;
}

.btn-close-lib {
  border: none;
  background: transparent;
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

.modal__hint {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-dim);
}

.modal__input {
  width: 100%;
  font: 600 18px ui-monospace, monospace;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: #1a1a1a;
  color: #fff;
  margin-bottom: 16px;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-ghost {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 15px;
  cursor: pointer;
  padding: 8px 12px;
}

.btn-primary {
  background: var(--save);
  border: none;
  color: #fff;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
}

.library-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.library-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.library-item__main {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0;
}

.library-item__title {
  font-size: 16px;
  font-weight: 600;
  display: block;
}

.library-item__sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

.library-item__check {
  color: #ff9500;
  font-size: 18px;
}

.library-item__del {
  border: none;
  background: rgba(255, 59, 48, 0.2);
  color: #ff6b6b;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}

.library-empty {
  text-align: center;
  padding: 24px 12px;
  color: var(--text-dim);
}

.library-empty__title {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  margin: 0 0 8px;
}

.library-empty__hint {
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
}

/* Smartphone quer: kompaktere Toolbar, kleinere Zellen wenn nötig */
@media (max-height: 480px) and (orientation: landscape) {
  .app {
    padding-top: 6px;
    padding-bottom: 12px;
  }

  .top-bar {
    margin-bottom: 8px;
  }

  .top-bar__title {
    font-size: 16px;
  }

  .kit-row {
    margin-bottom: 8px;
  }

  .kit-btn {
    padding: 6px 4px;
    min-height: 40px;
    font-size: 11px;
  }

  .studio-card {
    padding: 8px;
  }

  .toolbar__pattern-title {
    width: 72px;
    font-size: 11px;
  }

  .seg {
    width: 40px;
    min-height: 32px;
    font-size: 12px;
  }

  .bpm-block__value {
    font-size: 14px;
    width: 46px;
  }

  :root {
    --label-w: 72px;
    --mute-w: 32px;
  }

  .seq-label {
    font-size: 10px;
  }
}

@media (max-width: 520px) {
  .toolbar {
    gap: 6px;
  }

  .toolbar__grow {
    flex-basis: 100%;
    height: 0;
    min-height: 0;
  }

  .toolbar__grow--sm {
    display: none;
  }
}
