:root {
  color-scheme: dark;
  --app-bg: #101214;
  --surface: #1b1f23;
  --surface-strong: #24282d;
  --surface-soft: #15181c;
  --line: rgba(255, 255, 255, 0.14);
  --line-strong: rgba(255, 255, 255, 0.28);
  --text-soft: #b9c1cc;
  --accent: #d17a19;
  --playhead: #f0c859;
  --lane-label-width: 5rem;
  --step-width: 3.15rem;
  --lane-height: 2.15rem;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--app-bg);
}

.app-nav {
  position: relative;
  z-index: 1030;
  min-height: 2.65rem;
  border-bottom: 1px solid var(--line);
  background: #191c20;
}

.app-nav .container-fluid {
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 0.35rem !important;
  overflow: visible;
  padding-inline: 0.5rem !important;
}

.brand-mark {
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 0.3rem;
}

.navbar-brand {
  min-width: 0;
  margin-right: 0.15rem;
  gap: 0.35rem !important;
  font-size: 0.88rem;
  font-weight: 700;
  white-space: nowrap;
}

.app-nav .navbar-nav {
  flex: 0 0 auto;
}

.app-nav .btn-sm {
  --bs-btn-padding-y: 0.16rem;
  --bs-btn-padding-x: 0.42rem;
  --bs-btn-font-size: 0.78rem;
  --bs-btn-border-radius: 0.25rem;
  font-weight: 700;
}

.file-menu {
  position: relative;
  z-index: 1020;
  border-bottom: 1px solid var(--line);
  background: #14171b;
}

.file-menu-inner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  min-height: 2.35rem;
  padding: 0.28rem 0.5rem;
}

.file-menu .btn-sm {
  --bs-btn-padding-y: 0.16rem;
  --bs-btn-padding-x: 0.42rem;
  --bs-btn-font-size: 0.78rem;
  --bs-btn-border-radius: 0.25rem;
  font-weight: 700;
}

.share-menu-icon {
  width: 1rem;
  height: 1rem;
  margin-right: 0.45rem;
  vertical-align: -0.15rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.nav-clip-title {
  min-width: 0;
  flex: 1 1 10rem;
  max-width: 22rem;
}

.file-title {
  flex: 1 1 12rem;
  max-width: none;
}

.page-title {
  flex: 0 1 auto;
  min-width: 0;
  color: #fff;
  font-size: 0.86rem;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unsaved-changes-indicator {
  flex: 0 0 auto;
  color: #f0c859;
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.origin-bard-indicator {
  flex: 0 1 auto;
  min-width: 0;
  color: var(--text-soft);
  font-size: 0.76rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.origin-bard-indicator a {
  color: #f0c859;
  text-decoration: none;
}

.clip-stats {
  display: flex;
  flex: 1 1 14rem;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
  margin-left: auto;
  min-width: 0;
  color: var(--text-soft);
  font-size: 0.74rem;
  font-weight: 800;
  text-align: right;
}

.clip-stat-pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.35rem;
  padding: 0.08rem 0.38rem;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  background: rgba(255, 255, 255, 0.04);
  line-height: 1.1;
  white-space: nowrap;
}

.clip-stat-author {
  gap: 0.2rem;
  max-width: min(11rem, 44vw);
  overflow: hidden;
  text-overflow: ellipsis;
}

.clip-stat-author a {
  min-width: 0;
  overflow: hidden;
  color: #f0c859;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-title-label {
  display: block;
  min-width: 0;
  min-height: 1.95rem;
  padding: 0.18rem 0.42rem;
  color: #fff;
  overflow: hidden;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.55rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-title-label a {
  color: #f0c859;
  text-decoration: none;
}

.field .form-control:focus,
.field .form-select:focus,
#saveClipNameInput:focus {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 0.18rem rgba(209, 122, 25, 0.22);
}

.app-shell {
  min-height: calc(100vh - 2.65rem);
  display: flex;
  flex-direction: column;
}

.transport-band {
  display: block;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
}

.transport-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 0.25rem;
}

.transport-button {
  min-height: 2.05rem;
  padding: 0.24rem 0.48rem;
  border-radius: 0.28rem;
  font-size: 0.78rem;
  font-weight: 700;
}

.settings-cog-button {
  width: 2.05rem;
  min-width: 2.05rem;
  min-height: 2.05rem;
  padding-right: 0;
  padding-left: 0;
  font-size: 0.98rem;
  line-height: 1;
}

.step-record-button {
  display: grid;
  place-items: center;
  width: 2.35rem;
  min-width: 2.35rem;
  height: 2.35rem;
  min-height: 2.35rem;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0.32rem;
  color: #f8f9fa;
  background: rgba(255, 255, 255, 0.06);
}

.step-record-icon {
  width: 1rem;
  height: 1rem;
  border-radius: 999rem;
  background: rgba(255, 75, 67, 0.72);
  box-shadow: none;
}

.step-record-icon::before {
  content: none;
}

.step-record-icon::after {
  content: none;
}

.step-record-button.active {
  border-color: rgba(255, 110, 100, 0.95);
  background: #8d1e1b;
  box-shadow: 0 0 0 0.2rem rgba(255, 75, 67, 0.28);
}

.step-record-button.active .step-record-icon {
  background: #ff4b43;
  box-shadow: 0 0 0.7rem rgba(255, 75, 67, 0.55);
}

.play-icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 2.05rem;
  width: 2.05rem;
  padding-right: 0;
  padding-left: 0;
}

.play-icon {
  width: 0;
  height: 0;
  border-top: 0.46rem solid transparent;
  border-bottom: 0.46rem solid transparent;
  border-left: 0.72rem solid currentColor;
  transform: translateX(0.08rem);
}

.play-icon-button.active .play-icon {
  width: 0.72rem;
  height: 0.72rem;
  border: 0;
  background:
    linear-gradient(90deg, currentColor 0 35%, transparent 35% 65%, currentColor 65% 100%);
  transform: none;
}

.settings-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.field {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
  color: var(--text-soft);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
}

.field .form-control,
.field .form-select,
.output-control {
  min-height: 2.45rem;
  color: #fff;
  border-color: var(--line);
  background-color: rgba(255, 255, 255, 0.06);
  font-weight: 800;
}

.form-select {
  --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23d6dbe2' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
  color-scheme: dark;
  color: #fff;
  background-color: rgba(255, 255, 255, 0.06);
}

.form-select option,
.form-select optgroup {
  color: #fff;
  background-color: var(--surface-strong);
}

.output-control {
  display: flex;
  align-items: center;
}

.workspace {
  flex: 1;
  display: grid;
  gap: 0.75rem;
  min-width: 0;
  padding: 0.75rem;
}

.editor-wrap {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  overflow: hidden;
  background: var(--surface-soft);
}

.grid-scroller {
  overflow-x: auto;
  border-radius: 0.5rem;
}

.bindings-band {
  padding: 0 0.75rem 0.7rem;
}

.keyboard-bindings {
  display: grid;
  gap: 0.32rem;
  justify-items: center;
  overflow-x: auto;
  padding-bottom: 0.1rem;
}

.keyboard-bindings-row {
  display: flex;
  gap: 0.24rem;
  min-width: max-content;
}

.binding-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  width: 3.55rem;
  min-height: 3.35rem;
  padding: 0.3rem 0.2rem;
  border: 1px solid var(--line);
  border-radius: 0.28rem;
  background: rgba(255, 255, 255, 0.055);
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.72rem;
  font-weight: 800;
}

.binding-chip-spacer {
  width: 3.55rem;
  min-height: 3.35rem;
}

.binding-chip kbd {
  min-width: 1.55rem;
  padding: 0.1rem 0.24rem;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 0.2rem;
  background: #050607;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 900;
  text-align: center;
}

.binding-chip span {
  line-height: 1;
  text-align: center;
}

.binding-chip-action {
  border-color: rgba(209, 122, 25, 0.42);
  color: #ffd18f;
}

.clip-grid {
  position: relative;
  display: grid;
  grid-template-columns: var(--lane-label-width) repeat(var(--step-count), var(--step-width));
  width: max-content;
  min-width: 100%;
  background: var(--surface-soft);
}

.clip-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--playhead-left, var(--lane-label-width));
  z-index: 6;
  width: 2px;
  pointer-events: none;
  opacity: 0;
  background: var(--playhead);
  box-shadow: 0 0 0.65rem color-mix(in srgb, var(--playhead), transparent 20%);
  transform: translateX(-1px);
}

.clip-playhead::before {
  content: "";
  position: absolute;
  top: 0.18rem;
  left: 50%;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  background: var(--playhead);
  box-shadow: 0 0 0.65rem color-mix(in srgb, var(--playhead), transparent 20%);
  transform: translateX(-50%);
}

.clip-playhead.is-visible {
  opacity: 1;
}

.grid-corner,
.step-header,
.lane-label,
.note-cell {
  min-width: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.grid-corner,
.step-header {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 2rem;
  background: var(--surface-strong);
}

.grid-corner {
  left: 0;
  z-index: 7;
  display: grid;
  place-items: center;
}

.step-header {
  display: grid;
  place-items: center;
  color: var(--text-soft);
  font-size: 0.72rem;
  font-weight: 800;
}

.step-header.is-bar-start {
  border-left: 1px solid var(--line-strong);
  color: #fff;
}

.lane-label {
  position: sticky;
  left: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  min-height: var(--lane-height);
  padding-inline: 0.35rem;
  color: #fff;
  background: var(--surface);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
}

.lane-label.is-chromatic {
  color: #d6dbe2;
}

.lane-label.is-step-record-octave {
  color: #fff;
  background:
    linear-gradient(90deg, rgba(240, 200, 89, 0.3), rgba(240, 200, 89, 0.08)),
    var(--surface);
  box-shadow: inset 0.2rem 0 0 rgba(240, 200, 89, 0.86);
}

.note-cell {
  position: relative;
  min-height: var(--lane-height);
  padding: 0;
  touch-action: manipulation;
  background:
    linear-gradient(90deg, transparent calc(100% - 1px), rgba(255, 255, 255, 0.08) calc(100% - 1px)),
    rgba(255, 255, 255, 0.015);
}

.note-cell.is-bar-start {
  border-left: 1px solid var(--line-strong);
}

.lane-label.is-octave-boundary,
.note-cell.is-octave-boundary {
  border-top: 1px solid var(--line-strong);
  box-shadow: inset 0 1px 0 var(--line-strong);
}

.note-cell.is-active::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  border: 1px solid color-mix(in srgb, var(--note-color), white 30%);
  border-radius: 0;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--note-color), white 10%), var(--note-color));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), 0 0.35rem 0.8rem rgba(0, 0, 0, 0.24);
}

.note-cell.is-note-start::after {
  border-top-left-radius: 0.25rem;
  border-bottom-left-radius: 0.25rem;
}

.note-cell.is-note-end::after {
  border-top-right-radius: 0.25rem;
  border-bottom-right-radius: 0.25rem;
}

.note-cell.is-active:not(.is-note-start)::after {
  border-left-color: transparent;
}

.note-cell.is-active:not(.is-note-end)::after {
  border-right-color: transparent;
}

.note-resize-handle {
  position: absolute;
  top: 0.18rem;
  bottom: 0.18rem;
  z-index: 2;
  width: 0.7rem;
  cursor: ew-resize;
  touch-action: none;
}

.note-resize-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 0.16rem;
  height: 56%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  transform: translateY(-50%);
}

.note-resize-handle.is-left {
  left: -0.08rem;
}

.note-resize-handle.is-left::after {
  left: 0.18rem;
}

.note-resize-handle.is-right {
  right: -0.08rem;
}

.note-resize-handle.is-right::after {
  right: 0.18rem;
}

.note-resize-handle:hover::after,
.note-resize-handle:focus-visible::after {
  background: #fff;
}

.note-cell:focus-visible {
  outline: 0.16rem solid rgba(240, 200, 89, 0.72);
  outline-offset: -0.2rem;
}

.note-cell:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.step-header.is-step-record-column,
.note-cell.is-step-record-column {
  background:
    linear-gradient(90deg, rgba(240, 200, 89, 0.16), rgba(240, 200, 89, 0.08)),
    rgba(255, 255, 255, 0.015);
  box-shadow: inset 0.16rem 0 0 rgba(240, 200, 89, 0.76), inset -0.16rem 0 0 rgba(240, 200, 89, 0.34);
}

.clip-grid-footer {
  position: sticky;
  bottom: 0;
  z-index: 8;
  min-height: 2.15rem;
  display: grid;
  grid-template-columns: var(--lane-label-width) repeat(var(--step-count), var(--step-width));
  align-items: center;
  width: max-content;
  min-width: 100%;
  padding: 0;
  border-top: 1px solid var(--line);
  border-bottom-right-radius: 0.5rem;
  border-bottom-left-radius: 0.5rem;
  color: var(--text-soft);
  background: var(--surface-strong);
  font-size: 0.78rem;
  font-weight: 800;
}

.clip-grid-footer.is-active {
  color: #fff;
}

.clip-grid-footer-spacer {
  min-width: 0;
}

.clip-grid-footer-status {
  grid-column: 2 / -1;
  min-width: 0;
  padding: 0.42rem 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-stack {
  display: grid;
  gap: 1.25rem;
}

.settings-section {
  display: grid;
  gap: 0.85rem;
}

.settings-section-title {
  margin: 0;
  color: var(--text-strong);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0;
}

.settings-help-text {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.84rem;
  line-height: 1.35;
}

.save-modal-stack {
  display: grid;
  gap: 1rem;
}

.clip-list-table {
  overflow-x: hidden;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}

.open-clip-dialog .clip-list-table {
  max-height: min(22rem, 58vh);
  overflow: auto;
}

.open-clip-dialog .clip-list-rows {
  max-height: none;
  overflow: visible;
}

.clip-list-header,
.clip-list-row {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(4.5rem, 0.6fr) minmax(6rem, 0.8fr) minmax(6.5rem, 0.8fr);
  align-items: center;
  gap: 0.55rem;
}

.clip-list-header.has-preview,
.clip-list-row.has-preview {
  grid-template-columns: 4rem minmax(0, 1.7fr) minmax(4.5rem, 0.6fr) minmax(6rem, 0.8fr) minmax(6.5rem, 0.8fr);
}

.clip-list-header {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
}

.clip-sort-button {
  padding: 0;
  border: 0;
  color: var(--text-muted);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-align: left;
  text-transform: uppercase;
}

.clip-sort-button.is-active {
  color: var(--text-strong);
}

.clip-sort-button.is-active::after {
  content: "  \25be";
}

.clip-sort-button.is-active[aria-sort="ascending"]::after {
  content: "  \25b4";
}

.save-options {
  display: grid;
  gap: 0.6rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.035);
}

.save-options .form-check {
  min-height: 1.5rem;
  margin: 0;
}

.shared-save-info {
  margin: -0.2rem 0 0;
  color: var(--text-soft);
  font-size: 0.8rem;
  font-weight: 700;
}

#saveClipNameInput {
  min-height: 2.6rem;
  color: #fff;
  border-color: var(--line);
  background-color: rgba(255, 255, 255, 0.06);
  font-weight: 800;
}

#saveClipNameInput.is-duplicate {
  border-color: #f0c859;
  box-shadow: 0 0 0 0.18rem rgba(240, 200, 89, 0.18);
}

.duplicate-save-message {
  min-height: 1.2rem;
  color: #f0c859;
  font-weight: 700;
}

.clip-list-rows {
  max-height: 15rem;
  overflow-y: auto;
  border-radius: 0;
}

.clip-list-rows .list-group-item.active {
  border-color: rgba(209, 122, 25, 0.86);
  background: rgba(209, 122, 25, 0.22) !important;
}

.open-clip-dialog .clip-list-rows .list-group-item.is-selected {
  border-color: rgba(240, 200, 89, 0.72);
  background: rgba(240, 200, 89, 0.12) !important;
  box-shadow: inset 3px 0 0 rgba(240, 200, 89, 0.86);
}

.clip-list-rows .list-group-item {
  border-right: 0;
  border-left: 0;
}

.clip-list-rows .list-group-item:first-child {
  border-top: 0;
}

.clip-list-rows .list-group-item:last-child {
  border-bottom: 0;
}

.clip-list-row {
  padding: 0.65rem 0.75rem;
  text-align: left;
}

.clip-list-cell {
  display: block;
  min-width: 0;
  overflow: hidden;
  font-size: 0.86rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clip-list-title-cell {
  color: var(--text-strong);
}

.clip-list-title-wrap {
  display: grid;
  min-width: 0;
  gap: 0.2rem;
}

.clip-list-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.55rem;
  color: var(--text-soft);
  font-size: 0.72rem;
  font-weight: 700;
}

.clip-list-preview-cell {
  display: block;
  width: 4rem;
  min-width: 0;
}

.clip-list-preview {
  position: relative;
  display: block;
  width: 4rem;
  height: 2.25rem;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 0.35rem;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 25%),
    rgba(255, 255, 255, 0.04);
}

.clip-list-preview-note {
  position: absolute;
  min-width: 2px;
  border-radius: 999px;
  background: var(--note-color);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28);
}

.access-chip {
  display: inline-block;
  max-width: 100%;
  margin-right: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.access-chip.is-read-only {
  color: #ffd18f;
  font-weight: 800;
}

.octave-stepper {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 4.5rem minmax(0, 1fr);
  gap: 0.5rem;
}

.octave-stepper .btn {
  min-height: 2.5rem;
  font-weight: 700;
}

.octave-stepper output {
  justify-content: center;
}

@media (max-width: 420px) {
  .page-title {
    display: none;
  }

  .bindings-band {
    padding-inline: 0.35rem;
  }

  .keyboard-bindings {
    justify-items: start;
  }

  .binding-chip,
  .binding-chip-spacer {
    width: 3.15rem;
    min-height: 3.05rem;
  }

  .binding-chip {
    font-size: 0.67rem;
  }

  .clip-list-header.has-preview,
  .clip-list-row.has-preview {
    grid-template-columns: 4rem minmax(0, 1fr) minmax(5.8rem, 0.7fr);
  }

  .clip-list-header.has-preview > :nth-child(3),
  .clip-list-header.has-preview > :nth-child(4),
  .clip-list-row.has-preview > :nth-child(3),
  .clip-list-row.has-preview > :nth-child(4) {
    display: none;
  }
}

@media (min-width: 720px) {
  :root {
    --step-width: 3.65rem;
    --lane-label-width: 5.4rem;
  }

  .settings-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .open-clip-dialog,
  .save-clip-dialog {
    max-width: min(92vw, 860px);
  }
}
