:root {
  --app-width: 1500px;
  --fit-scale: 1;
  --bg-0: #060a12;
  --bg-1: #0b1323;
  --panel-1: #0d1628;
  --panel-2: #14203a;
  --panel-3: #1a2744;
  --text: #e6edf8;
  --muted: #92a0bb;
  --accent: #f09244;
  --accent-soft: #ffd6a8;
  --border: #2a3957;
  --step-off: #374766;
  --step-half: #8f693f;
  --step-full: #ef8a39;
  --playhead: #fce6bf;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-family: "Avenir Next", "SF Pro Text", "Segoe UI", sans-serif;
  background:
    radial-gradient(1100px 600px at 18% -10%, #1e2f53 0%, transparent 60%),
    radial-gradient(900px 700px at 88% -20%, #1c2a47 0%, transparent 58%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
}

.app-shell {
  position: fixed;
  left: 50%;
  top: 50%;
  width: var(--app-width);
  transform: translate(-50%, -50%) scale(var(--fit-scale));
  transform-origin: center center;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 10px;
  padding: 8px;
  border-radius: 18px;
  border: 1px solid #243651;
  background: linear-gradient(180deg, rgba(14, 23, 40, 0.94) 0%, rgba(8, 13, 24, 0.96) 100%);
  box-shadow:
    0 14px 48px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.grid-wrap {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(180deg, #101a2d 0%, #0b1220 100%);
}

.grid-header,
.lane-row {
  display: grid;
  grid-template-columns: 392px repeat(16, minmax(0, 1fr));
  gap: 5px;
  align-items: center;
  min-width: 0;
}

.grid-header {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #1a2742 0%, #16233b 100%);
}

.grid-header .step-head {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  letter-spacing: 0.02em;
}

.grid-header .step-head:first-child {
  text-align: left;
  padding-left: 8px;
  color: #b9c5db;
  font-size: 13px;
  letter-spacing: 0.01em;
}

.lanes {
  display: grid;
  gap: 3px;
  padding: 6px;
}

.lane-row {
  min-height: 32px;
  padding: 2px;
  border: 1px solid #22314e;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(23, 34, 56, 0.7) 0%, rgba(16, 25, 42, 0.72) 100%);
}

.lane-row.lane-muted {
  opacity: 0.58;
}

.lane-row.lane-solo {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--lane-color, #f09244) 72%, #ffffff 28%);
}

.lane-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px 56px 24px 24px 24px 24px 24px;
  gap: 5px;
  align-items: center;
}

.lane-select,
.lane-swing-select,
.lane-length-input,
#kitSelect,
#mappingSelect,
#bpmInput,
#masterStepsInput,
button {
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel-3);
  color: var(--text);
  font-size: 12px;
}

.lane-select {
  min-width: 0;
  width: 100%;
  padding: 0 8px;
}

.lane-swing-select {
  min-width: 0;
  width: 100%;
  padding: 0 2px;
  text-align: center;
}

.lane-length-input {
  width: 56px;
  min-width: 56px;
  text-align: center;
  padding: 0 4px;
}

.lane-toggle-btn,
.lane-color-btn {
  width: 24px;
  min-width: 24px;
  height: 24px;
  border-radius: 8px;
  padding: 0;
}

.lane-toggle-btn {
  border: 1px solid #34507a;
  background: #162741;
  color: #a2b4d1;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.lane-toggle-btn.active {
  border-color: color-mix(in srgb, var(--lane-color, #f09244) 78%, #ffffff 22%);
  background: color-mix(in srgb, var(--lane-color, #f09244) 26%, #13233d 74%);
  color: #f6ede5;
}

.lane-color-btn {
  border: 1px solid #41608f;
  background:
    radial-gradient(circle at 35% 32%, color-mix(in srgb, var(--swatch, #f09244) 78%, #ffffff 22%) 0%, var(--swatch, #f09244) 42%, color-mix(in srgb, var(--swatch, #f09244) 34%, #000000 66%) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.step-btn {
  width: 100%;
  min-width: 0;
  height: 18px;
  border: 1px solid #25385a;
  border-radius: 4px;
  background: var(--step-off);
  padding: 0;
  flex: 1 1 auto;
  touch-action: none;
  transition: filter 80ms linear;
}

.step-btn.vel-1 {
  background: linear-gradient(180deg, color-mix(in srgb, var(--lane-color-mid, var(--step-half)) 84%, #0e1526 16%) 0%, var(--lane-color-mid, var(--step-half)) 100%);
}

.step-btn.vel-2 {
  background: linear-gradient(180deg, color-mix(in srgb, var(--lane-color, var(--step-full)) 82%, #121a2d 18%) 0%, var(--lane-color, var(--step-full)) 100%);
}

.step-btn.inactive {
  opacity: 0.28;
  filter: saturate(0.58);
}

.step-btn.playhead {
  box-shadow: inset 0 0 0 2px var(--playhead);
}

.bottom-dock {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(180deg, #172641 0%, #111b2f 100%);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.page-tab {
  width: 68px;
  min-width: 68px;
  height: 30px;
  border: 1px solid #314565;
  border-radius: 11px;
  background: #1a2946;
  color: var(--muted);
  font-size: 11px;
}

.page-tab.active {
  border-color: var(--accent);
  color: var(--accent-soft);
}

.page-tab.dimmed {
  opacity: 0.33;
}

.page-tab.copy-source {
  border-color: #ffaa00;
  background: color-mix(in srgb, #ffaa00 15%, #1a2946 85%);
  color: #ffcc44;
}

.page-tab.copy-dest {
  border-color: #44ff44;
  background: color-mix(in srgb, #44ff44 15%, #1a2946 85%);
  color: #aaffaa;
}

.controls-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 10px;
  width: 100%;
}

.controls-left,
.controls-center,
.controls-right {
  display: flex;
  align-items: end;
  gap: 8px;
  min-width: 0;
}

.controls-left {
  justify-content: flex-start;
}

.controls-center {
  justify-content: center;
}

.controls-right {
  justify-content: flex-end;
}

label {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  min-height: 44px;
  font-size: 11px;
  line-height: 1;
  color: var(--muted);
  flex: 0 0 auto;
  align-items: center;
  text-align: center;
}

#kitSelect {
  width: 120px;
}

#mappingSelect {
  width: 140px;
}

#bpmInput {
  width: 52px;
  text-align: center;
  padding: 0;
  font-variant-numeric: tabular-nums;
  appearance: textfield;
  -moz-appearance: textfield;
}

#masterStepsInput {
  width: 58px;
  text-align: center;
  padding: 0;
  font-variant-numeric: tabular-nums;
  appearance: textfield;
  -moz-appearance: textfield;
}

#bpmInput::-webkit-inner-spin-button,
#bpmInput::-webkit-outer-spin-button,
#masterStepsInput::-webkit-inner-spin-button,
#masterStepsInput::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.check-label {
  min-width: 84px;
  align-items: center;
}

.check-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 6px auto 6px;
}

button {
  min-width: 74px;
  padding: 0 8px;
  cursor: pointer;
  flex: 0 0 auto;
}

button.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 24%, var(--panel-3) 76%);
  color: var(--accent);
}

.page-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.page-row-left,
.page-row-right {
  display: flex;
  gap: 6px;
  align-items: center;
}

.page-row-left {
  justify-content: flex-start;
}

.page-row-left #pageTabsLeft {
  margin-left: auto;
}

.page-row-right {
  justify-content: flex-end;
}

.page-row-right #pageTabsRight {
  margin-right: auto;
}

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

#pageTabsLeft {
  justify-content: flex-end;
}

#pageTabsRight {
  justify-content: flex-start;
}

.page-follow {
  min-width: 92px;
}

@keyframes blink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

#copyPageBtn.copy-blink {
  animation: blink 600ms ease-in-out infinite;
}

#pastePageBtn.paste-blink {
  animation: blink 600ms ease-in-out infinite;
}

.page-follow input[type="checkbox"] {
  margin: 4px auto 2px;
}

#playBtn,
#stopBtn {
  min-width: 62px;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

.drag-field {
  cursor: ns-resize;
  user-select: none;
}

.drag-field:focus {
  outline: 1px solid #496594;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon {
  width: 12px;
  height: 12px;
  display: inline-block;
  position: relative;
}

.play-icon::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 1px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 8px solid var(--accent-soft);
}

.stop-icon::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 1px;
  width: 10px;
  height: 10px;
  border: 2px solid var(--accent-soft);
  background: transparent;
}

.export-popup-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(2, 6, 14, 0.62);
  z-index: 1000;
}

.export-popup-panel {
  width: 260px;
  border: 1px solid #36507c;
  border-radius: 12px;
  padding: 10px;
  background: linear-gradient(180deg, #162540 0%, #111b30 100%);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  display: grid;
  gap: 8px;
}

.export-popup-title {
  margin: 0;
  font-size: 13px;
  color: #d8e5fb;
  font-weight: 700;
}

.export-popup-label {
  display: grid;
  gap: 4px;
  font-size: 11px;
  color: #9db0d0;
}

.export-popup-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: end;
}

.export-popup-input {
  width: 100%;
  height: 28px;
  border: 1px solid #37537f;
  border-radius: 8px;
  background: #1a2b49;
  color: var(--text);
  padding: 0 8px;
  font-size: 12px;
}

.export-popup-check {
  display: grid;
  grid-template-columns: auto 1fr 64px;
  gap: 6px;
  align-items: center;
  font-size: 11px;
  color: #9db0d0;
}

.export-popup-tail:disabled {
  opacity: 0.45;
}

.export-popup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}
