/* style.css
   Layout: the page is a column that fills the window.
     header         fixed height
     main           pad grid + pad editor, as tall as the grid
     #timelineCard  takes all the remaining height, and scrolls inside itself */

:root {
  --bg: #15161a;
  --panel: #1f2127;
  --line: #30333c;
  --text: #e8e9ee;
  --muted: #8b8f9c;
  --accent: #6c8cff;
  --rec: #ff4d4d;
  --go: #5fe08a;
  --field: #2c2f38;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  height: 100vh;
  min-height: 620px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 -apple-system, system-ui, sans-serif;
}

/* ---------- shared controls ---------- */

button,
select,
input[type=number],
input[type=text] {
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #363a45;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

input[type=number] {
  width: 62px;
  padding: 5px 6px;
}

input[type=number].narrow {
  width: 50px;
}

input[type=range] {
  width: 100%;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.spacer {
  flex: 1;
}

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

/* ---------- header ---------- */

header {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}

h1 {
  font-size: 16px;
  margin: 0;
}

header .check {
  color: var(--muted);
}

header select {
  max-width: 150px;
}

header button,
header select {
  padding: 4px 8px;
}

#midiStatus {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

#midiStatus.ok {
  color: var(--go);
}

/* ---------- pad grid ---------- */

main {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 14px;
  padding: 12px 16px;
}

#padArea {
  flex: none;
  max-width: 100%;
}

#pageButtons {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

#pageButtons button {
  padding: 2px 10px;
}

#pageButtons button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  width: min(var(--pad-size, 300px), 100%);
}

.pad {
  aspect-ratio: 1;
  min-width: 0;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  padding: 2px;
  border: 2px solid transparent;
  border-radius: 5px;
  background: #272a32;
  color: var(--text);
  font-size: 9px;
  line-height: 1.15;
  text-align: left;
  word-break: break-word;
  cursor: pointer;
  user-select: none;
  touch-action: none;
}

/* --glow is set per pad from its resting-glow setting */
.pad.loaded {
  background: color-mix(in srgb, var(--c) var(--glow, 30%), #1a1b20);
}

.pad.hit {
  background: var(--c, #555);
  color: #000;
}

/* Every selected pad gets a white border; the one shown in the editor is drawn solid */
.pad.selected {
  border-color: #fff;
  border-style: dashed;
}

.pad.selected.primary {
  border-style: solid;
}

.pad.drop {
  border-color: var(--accent);
  border-style: dashed;
}

/* ---------- pad editor ---------- */

#padEditor {
  flex: 1 1 420px;
  min-width: 0;
}

.editorHead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#padName {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#wave {
  display: block;
  width: 100%;
  height: 36px;
  margin: 10px 0 6px;
  background: #1a1b20;
  border-radius: 4px;
}

.editorColumns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0 24px;
}

.row {
  display: grid;
  grid-template-columns: 56px 1fr 50px;
  align-items: center;
  gap: 8px;
  margin: 5px 0;
}

.row select {
  grid-column: 2 / 4;
  min-width: 0;
}

.row output {
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#swatches,
#patternColors {
  display: flex;
  gap: 6px;
  grid-column: 2 / 4;
}

#swatches button,
#patternColors button {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  font-size: 10px;
}

#swatches button.on,
#patternColors button.on {
  border-color: #fff;
}

#selectTools {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

header input[type=range] {
  width: 80px;
}

#micButton.on,
#recordButton.on {
  background: var(--rec);
  border-color: var(--rec);
  color: #000;
}

#playButton.on {
  background: var(--go);
  border-color: var(--go);
  color: #000;
}

/* ---------- timeline card ---------- */

#timelineCard {
  flex: 1 1 0;
  min-height: 240px;
  margin: 0 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toolbar {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

.toolbar input[type=range] {
  width: 90px;
}

.divider {
  width: 1px;
  height: 20px;
  background: var(--line);
}

#clock {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  min-width: 64px;
}

#recordInfo {
  color: var(--muted);
  font-size: 12px;
}

#timeline {
  flex: 1 1 0;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #1a1b20;
}

#timeline .empty {
  margin: 0;
  padding: 12px;
  color: var(--muted);
}

/* ---------- inside the timeline ---------- */

.tl-inner {
  position: relative;
}

.tl-row {
  display: flex;
  height: 22px;
  border-bottom: 1px solid #262830;
}

.tl-ruler {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #1a1b20;
}

/* The row-name column stays put while the lanes scroll sideways. Its width matches
   TIMELINE_LABEL_WIDTH in timeline.js. */
.tl-label {
  position: sticky;
  left: 0;
  z-index: 3;
  flex: 0 0 132px;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0 4px 0 6px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  border-left: 4px solid var(--c, transparent);
  font-size: 11px;
  line-height: 22px;
}

.tl-name {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tl-ms {
  flex: none;
  width: 16px;
  height: 16px;
  padding: 0;
  font-size: 10px;
  line-height: 1;
  border-radius: 4px;
}

.tl-ms.onM {
  background: var(--rec);
  border-color: var(--rec);
  color: #000;
}

.tl-ms.onS {
  background: #ffe14d;
  border-color: #ffe14d;
  color: #000;
}

.tl-lane {
  position: relative;
  flex: none;
  background-image: var(--grid);
}

.tl-ruler .tl-lane {
  background-image: none;
  cursor: pointer;
  touch-action: none;
}

.tl-ruler .tl-lane span {
  position: absolute;
  top: 0;
  padding-left: 3px;
  border-left: 1px solid #3d414d;
  color: var(--muted);
  font-size: 10px;
  line-height: 22px;
}

/* A recorded hit */
.ev {
  position: absolute;
  top: 2px;
  bottom: 2px;
  border-radius: 3px;
  background: var(--c);
  cursor: grab;
  touch-action: none;
}

.ev::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  cursor: ew-resize;
}

.ev.sel {
  outline: 2px solid #fff;
  z-index: 1;
}

/* Looped hits are striped */
.ev.lp {
  background-image: repeating-linear-gradient(90deg, transparent 0 10px, rgba(0, 0, 0, 0.25) 10px 12px);
}

.tl-row.silent .ev {
  filter: grayscale(1) brightness(0.6);
}

/* Full-height overlays: repeat sections, the ruler selection, the box select, and marker lines */
.tl-sec,
.tl-range,
.tl-box,
.tl-start,
.tl-head,
.tl-end {
  position: absolute;
  top: 0;
  bottom: 0;
}

.tl-sec,
.tl-range,
.tl-box,
.tl-start,
.tl-head {
  pointer-events: none;
}

.tl-sec {
  z-index: 1;
  background: rgba(108, 140, 255, 0.13);
  border: solid var(--accent);
  border-width: 0 2px;
}

.tl-range {
  z-index: 1;
  background: rgba(255, 255, 255, 0.1);
}

.tl-box {
  bottom: auto;
  z-index: 4;
  border: 1px solid #fff;
  background: rgba(255, 255, 255, 0.12);
}

.tl-start {
  z-index: 2;
  width: 2px;
  background: var(--go);
}

.tl-head {
  z-index: 2;
  width: 2px;
  background: #fff;
}

.tl-end {
  z-index: 2;
  width: 5px;
  margin-left: -2px;
  background: var(--rec);
  cursor: ew-resize;
  touch-action: none;
}

/* Repeat-section controls on the ruler */
.tl-secbtn {
  position: absolute;
  top: 3px;
  width: 34px;
  height: 16px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
}

.tl-secx {
  width: 18px;
  background: #4a5068;
}

.tl-sechandle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 7px;
  border-radius: 2px;
  background: var(--accent);
  cursor: ew-resize;
  touch-action: none;
}

/* ---------- dialogs ---------- */

dialog {
  max-width: 360px;
  padding: 18px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
}

dialog.wide {
  max-width: 600px;
}

dialog::backdrop {
  background: rgba(10, 10, 12, 0.7);
}

dialog h2 {
  font-size: 15px;
  margin: 0 0 12px;
}

dialog h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 14px 0 4px;
}

dialog p {
  margin: 4px 0;
}

dialog > * + * {
  margin-top: 10px;
}

dialog input[type=range] {
  width: 140px;
}

#patternGrid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  width: 264px;
  touch-action: none;
  user-select: none;
}

#patternGrid div {
  aspect-ratio: 1;
  border-radius: 4px;
  background: #272a32;
  cursor: crosshair;
}

/* ---------- start overlay ---------- */

#startOverlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  text-align: center;
  background: rgba(10, 10, 12, 0.92);
}

#startOverlay button {
  padding: 14px 28px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
}

#startOverlay p {
  max-width: 420px;
  margin: 0;
  color: var(--muted);
}
