/* Phone layout. Loaded only while the "compact" media query on its <link>
   in index.html matches (narrow screens, or touch screens held landscape). */
:root {
  --cell-h: 42px;
  --cell-gap: 5px;
  --bar-gap: 10px;
  --num-h: 16px;
  --hit-pad: 5px;
  --hit-w: 5px;
  --label-w: 62px;
  --dock-h: 74px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --gutter-l: max(12px, env(safe-area-inset-left, 0px));
  --gutter-r: max(12px, env(safe-area-inset-right, 0px));
}
html { -webkit-text-size-adjust: 100%; }
body {
  align-items: stretch;
  padding: calc(10px + env(safe-area-inset-top, 0px)) var(--gutter-r) calc(var(--dock-h) + var(--safe-b) + 20px) var(--gutter-l);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
button:focus:not(:focus-visible), select:focus:not(:focus-visible) { outline: none; }

h1 { font-size: 15px; text-align: center; margin-bottom: 10px; }
.subtitle, .transport, .hint-desk { display: none; }

/* Visual order on phones: title, groove picker, beat bar, palette, grid, hint. */
.beat-bar { order: 1; }
.palette { order: 2; }
.sequencer { order: 3; }
.hint { order: 4; }

/* Chevron for restyled selects */
.m-preset select, .field select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  font-size: 16px;   /* below 16px iOS zooms the page on focus */
  background: var(--panel-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%239aa3b2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 14px center / 12px 8px;
  padding: 0 38px 0 14px;
  text-overflow: ellipsis;
}

/* ---------- Preset picker ---------- */
.m-preset { display: block; margin-bottom: 10px; }
.m-preset select { height: 46px; border-radius: 12px; font-weight: 600; }

/* ---------- Beat bar (long preset descriptions clamp; tap to expand) ---------- */
.beat-bar {
  position: relative;
  width: auto;
  margin: 0 0 10px;
  padding: 10px 12px;
  gap: 8px;
  font-size: 12.5px;
  line-height: 1.45;
  border-radius: 12px;
  cursor: pointer;
}
.bb-info { flex: 1 1 100%; flex-wrap: wrap; align-items: center; gap: 6px; }
.bb-text {
  flex-basis: 100%;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.beat-bar.expanded .bb-text { display: block; }
.bb-btn { padding: 8px 10px; font-size: 13px; }
/* Beats and Custom are already named in the picker above: drop the text line
   and let the tag and the buttons share a row when they fit. */
.beat-bar.kind-custom .bb-text,
.beat-bar.kind-beat:not(.missing) .bb-text { display: none; }
.beat-bar.kind-custom .bb-info,
.beat-bar.kind-beat:not(.missing) .bb-info { flex: 0 1 auto; }
.beat-bar.kind-preset::after {
  content: "More ▾";
  position: absolute;
  top: 11px;
  right: 12px;
  font-size: 11px;
  color: var(--text-dim);
}
.beat-bar.kind-preset.expanded::after { content: "Less ▴"; }

.toasts { bottom: calc(var(--dock-h) + var(--safe-b) + 12px); }

/* ---------- Palette ---------- */
.palette {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px 8px;
  margin-bottom: 10px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.palette .label { grid-area: 1 / 1; margin: 0; }
.glyph-preview { grid-area: 1 / 2; justify-self: start; padding: 3px 8px; transition: opacity .12s; }
.palette.erasing .glyph-preview { opacity: 0.3; }
.erase-toggle {
  grid-area: 1 / 3;
  display: block;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}
.erase-toggle.on { color: #ffb3b3; background: rgba(232,90,90,0.2); border-color: #e85a5a; }

.slot-families { grid-column: 1 / -1; display: flex; gap: 8px; }
.tool-group {
  flex: 4 1 0;
  min-width: 0;
  position: relative;
  gap: 5px;
  padding: 7px 6px 6px;
  border-radius: 11px;
}
.tool-group[data-grid="3"] { flex-grow: 3; }
/* Family name sits in the top border, like a fieldset legend. */
.tool-group .group-label {
  position: absolute;
  top: -7px;
  left: 9px;
  margin: 0;
  padding: 0 4px;
  font-size: 9.5px;
  line-height: 12px;
  background: var(--panel);
}
.tool-group.active-family .group-label { color: var(--accent); }
.slot-toggle { flex: 1 1 0; min-width: 0; height: 38px; padding: 0; font-size: 15px; }

/* ---------- Grid ---------- */
.sequencer { align-self: stretch; }
.seq-scroll {
  padding: 10px 10px 12px 0;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.seq-scroll::-webkit-scrollbar { display: none; }
.seq-inner { gap: 0; }

.row-labels {
  padding: calc(var(--num-h) + var(--cell-gap)) 6px 0 10px;
  transition: box-shadow .2s;
}
.sequencer.scrolled .row-labels { box-shadow: 10px 0 12px -10px rgba(0,0,0,0.8); }

/* The whole label is the mute toggle. */
.row-label {
  position: relative;
  width: var(--label-w);
  min-width: 0;
  justify-content: flex-start;
  padding: 0 4px 0 11px;
  border-radius: 9px;
  overflow: hidden;
  background: var(--panel-2);   /* fallback: color-mix needs iOS 16.2+ */
  background: color-mix(in srgb, var(--row-color) 9%, var(--panel-2));
  transition: background .15s;
}
.row-label .name { font-size: 11px; line-height: 1.15; white-space: normal; min-width: 0; }
.row-label .name .word { white-space: nowrap; }
.row-label .swatch { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; height: auto; border-radius: 0; }
.row-label .mute {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  z-index: 1;
  opacity: 0;
  border: 0;
  border-radius: 0;
}
.row-label.muted { background: #3a282c; }
.row-label.muted .name {
  color: var(--text-dim);
  text-decoration-line: line-through;
  text-decoration-color: #e85a5a;
  text-decoration-thickness: 1.5px;
}
.row-label.muted .swatch { background: #5a5f6b !important; }
.grid-row.muted .cell { opacity: 0.35; }

.beat-number { font-size: 10px; line-height: var(--num-h); }
.cell { border-radius: 9px; }
.cell.downbeat { border-left-width: 2px; }
.cell .hit { top: 5px; bottom: 5px; border-radius: 2px; }
.cell.tagged .hit { top: 14px; }
.cell .mode-tag { top: 1px; right: 5px; font-size: 8.5px; }

/* ---------- Bar navigator ---------- */
.bar-nav { display: flex; gap: 6px; padding: 0 10px 10px; }
.bar-chip {
  flex: 1;
  position: relative;
  overflow: hidden;
  padding: 6px 0 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  border-radius: 8px;
}
.bar-chip.in-view { color: var(--text); border-color: #5b6479; }
.bar-chip.playing { color: var(--accent); }
.bar-chip .fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
}

.hint { margin-top: 12px; line-height: 1.6; align-self: center; }
.hint-touch { display: inline; }

/* ---------- Bottom dock ---------- */
.dock {
  display: block;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  padding: 0 var(--gutter-r) var(--safe-b) var(--gutter-l);
  background: rgba(31, 35, 43, 0.92);   /* fallback: without it older iOS gets a see-through dock */
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 30px rgba(0,0,0,0.35);
}
.dock.sheet-open { border-radius: 18px 18px 0 0; }

.sheet {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height .28s ease, opacity .2s ease;
}
.dock.sheet-open .sheet { max-height: 70vh; opacity: 1; overflow-y: auto; }
.sheet-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; padding: 16px 2px 2px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.field-label b { color: var(--text); font-weight: 600; letter-spacing: 0; text-transform: none; font-variant-numeric: tabular-nums; }
.field select { height: 44px; border-radius: 11px; }

/* Bigger sliders: a tall (easy to grab) input with the track drawn in the middle. */
.dock input[type="range"] {
  width: 100%;
  height: 30px;
  background: linear-gradient(var(--border), var(--border)) center / 100% 6px no-repeat;
  border-radius: 3px;
}
.dock input[type="range"]::-webkit-slider-thumb { width: 26px; height: 26px; }
.dock input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; }

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 2px 14px;
}
.danger { padding: 10px 14px; font-weight: 600; color: #ff9b9b; background: #2e2327; border-color: #5c3a3a; }
.danger.armed { color: #fff; background: #a63c2d; border-color: #c8503e; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }

.dock-bar {
  height: var(--dock-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.setup-btn {
  width: 66px;
  height: 50px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 12px;
}
.setup-btn b { font-size: 15px; line-height: 1.1; }
.setup-btn small { font-size: 10px; color: var(--text-dim); }
.setup-btn[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }

.tempo { display: flex; align-items: center; gap: 4px; }
.nudge { width: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 22px; line-height: 1; }
.bpm-big {
  min-width: 74px;
  height: 50px;
  padding: 0 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-color: transparent;
}
.bpm-big b { font-size: 27px; line-height: 1; font-variant-numeric: tabular-nums; }
.bpm-big small { margin-top: 3px; font-size: 9px; letter-spacing: 0.16em; color: var(--text-dim); }
.bpm-big[aria-expanded="true"] b { color: var(--accent); }

.play-fab {
  position: relative;
  width: 60px;
  height: 60px;
  flex: none;
  padding: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, #3a9d5d, #2e7d4a);
  border-color: #2b6e42;
  box-shadow: 0 6px 18px rgba(46,125,74,0.4);
}
.play-fab::before {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 22px;
  height: 22px;
  background: #fff;
  clip-path: polygon(24% 6%, 24% 94%, 94% 50%);
}
.play-fab.playing {
  background: linear-gradient(180deg, #c8503e, #a63c2d);
  border-color: #8f3324;
  box-shadow: 0 6px 18px rgba(166,60,45,0.4);
}
.play-fab.playing::before { width: 18px; height: 18px; clip-path: inset(0 round 3px); }
.play-fab.pulse { animation: fab-pulse .3s ease-out; }
.play-fab.pulse-accent { animation: fab-pulse-accent .42s ease-out; }
@keyframes fab-pulse {
  from { box-shadow: 0 0 0 0 rgba(255,210,122,0.45); }
  to   { box-shadow: 0 0 0 10px rgba(255,210,122,0); }
}
@keyframes fab-pulse-accent {
  from { box-shadow: 0 0 0 0 rgba(255,210,122,0.85); transform: scale(1.06); }
  to   { box-shadow: 0 0 0 16px rgba(255,210,122,0); transform: scale(1); }
}

/* Very narrow phones */
@media (max-width: 359px) {
  :root { --label-w: 56px; }
  .nudge { width: 38px; height: 38px; }
  .bpm-big { min-width: 60px; }
  .setup-btn { width: 58px; }
}

/* Phones held landscape: short screen, so shrink rows, drop the title and
   put the whole palette on one line. */
@media (max-height: 520px) {
  :root { --cell-h: 34px; --dock-h: 62px; }
  h1 { display: none; }
  .m-preset select { height: 40px; }
  .palette { grid-template-columns: auto minmax(0, 1fr) auto auto; padding: 12px 10px 8px; }
  .slot-families { grid-area: 1 / 2; }
  .glyph-preview { grid-area: 1 / 3; }
  .erase-toggle { grid-area: 1 / 4; }
  .slot-toggle { height: 34px; }
  .play-fab { width: 50px; height: 50px; }
  .sheet-grid { grid-template-columns: repeat(4, 1fr); }
  .field.wide { grid-column: span 2; }
}
