/* T8 — Layout menu and presets (pages 3–7): the Layout button in the top bar
   (decision 39, DESIGN-CHANGES §4.19) and the Customize layout menu it opens
   (page 5). */

/* ---- Layout button ----------------------------------------------------------

   A fixed 168×40 box, so changing the layout never moves it or the menu. A
   24×18 picture of the layout (thumbs.ts, layoutPicture), "LAYOUT" over the
   layout's name, and a chevron. Keyboard focus is the global ring, 2px
   outside (controls.css). */

.lm-button {
  --lm-button-bg: var(--st-surface);
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 9px;
  box-sizing: border-box;
  width: 168px;
  height: 40px;
  padding: 0 10px 0 9px;
  border: 1px solid var(--st-line);
  border-radius: 10px;
  background: var(--lm-button-bg);
  color: var(--st-text);
  font: 600 13px/16px var(--st-font);
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.lm-button:not([aria-disabled='true']):hover { --lm-button-bg: var(--st-surface-2); border-color: var(--st-line-control); }
.lm-button[aria-expanded='true'],
.lm-button[aria-expanded='true']:hover { --lm-button-bg: var(--st-surface-2); border-color: var(--st-line-strong); }
/* No song open: it stays in place, dimmed, and still takes focus for its tooltip. */
.lm-button[aria-disabled='true'] { opacity: 0.45; cursor: default; }

.lm-button__art { position: relative; display: flex; flex: none; }
/* Unsaved changes ("Custom"): a dot on the picture's top-right corner. */
.lm-button__dot {
  position: absolute;
  top: -2px;
  right: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--st-accent);
  box-shadow: 0 0 0 1px var(--lm-button-bg);
}
.lm-button__dot[hidden] { display: none; }

.lm-button__text { display: flex; flex: 1 1 0; flex-direction: column; gap: 1px; min-width: 0; }
.lm-button__caption {
  color: var(--st-text-faint);
  font: 500 9px/11px var(--st-font-mono);
  letter-spacing: 1.1px;
  text-transform: uppercase;
}
/* A long saved layout's name stops short (its full name is the button's aria-label). */
.lm-button__label { overflow: hidden; text-overflow: ellipsis; }
.lm-button__chevron { flex: none; width: 14px; height: 14px; color: var(--st-text-faint); transition: transform 0.15s var(--ease); }
.lm-button[aria-expanded='true'] .lm-button__chevron { transform: rotate(180deg); }

/* The top bar's narrow rule (the same width at which it drops the Extract
   chips, shell.css): the picture and the chevron, 60px, in the same place. */
@container st-top (max-width: 1285px) {
  .lm-button { gap: 5px; width: 60px; padding: 0 8px 0 9px; }
  .lm-button__text { display: none; }
}

/* The tooltip: "Change layout · toggle panels" and the panel keys. */
.lm-tip:not([hidden]) { display: inline-flex; align-items: center; gap: 8px; }
.lm-tip__keys { display: inline-flex; gap: 3px; }
.lm-tip .st-kbd { padding: 1px 4px; border-radius: 3px; font-size: 9px; line-height: 11px; }

/* ---- The picture of the layout (24×18) ---------------------------------------- */

.lm-pic {
  --pic-l: 2px;
  --pic-r: 2px;
  --pic-b: 2px;
  position: relative;
  display: block;
  box-sizing: border-box;
  width: 24px;
  height: 18px;
  border: 1px solid var(--st-line-strong);
  border-radius: 4px;
  background: var(--st-panel);
}
.lm-pic--library { --pic-l: 8px; }
.lm-pic--sheet-right { --pic-r: 6px; }
.lm-pic--sheet-bottom { --pic-b: 7px; }
.lm-pic__block { position: absolute; border-radius: 1px; background: var(--st-neutral); }
.lm-pic__block--main { background: var(--st-accent); }
/* Where each panel sits inside the 22×16 */
.lm-pic__block--library { top: 2px; bottom: 2px; left: 2px; width: 4px; }
.lm-pic__block--sheet { top: 2px; right: 2px; bottom: 2px; width: 2px; }
.lm-pic__block--sheet-bottom { right: var(--pic-r); bottom: 2px; left: var(--pic-l); height: 3px; }
.lm-pic__block--sheet-float { right: 3px; bottom: 3px; width: 6px; height: 5px; box-shadow: 0 0 0 1px var(--st-panel); }
.lm-pic__block--live { top: 2px; right: var(--pic-r); left: var(--pic-l); height: 4px; }
.lm-pic__block--mixer { top: 8px; right: var(--pic-r); bottom: var(--pic-b); left: var(--pic-l); }
.lm-pic__block--live-wide,
.lm-pic__block--mixer-wide { top: 2px; right: var(--pic-r); bottom: var(--pic-b); left: var(--pic-l); }
.lm-pic__block--page { top: 2px; right: 2px; bottom: 2px; left: var(--pic-l); }
.lm-pic__block--line-1,
.lm-pic__block--line-2,
.lm-pic__block--line-3 { left: calc(var(--pic-l) + 3px); height: 1.5px; border-radius: 0; }
.lm-pic__block--line-1 { top: 5px; width: 11px; }
.lm-pic__block--line-2 { top: 8px; width: 13px; }
.lm-pic__block--line-3 { top: 11px; width: 9px; }

/* ---- The menu ----------------------------------------------------------------- */

.lm-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  width: 380px;
  /* index.ts measures the room below the menu's top when it opens (and on
     resize); the fallback is the room under the design's header. */
  max-height: var(--lm-max-height, calc(100vh - 140px));
  border-radius: 14px;
  outline: 1px solid var(--st-line-strong);
  outline-offset: -0.5px;
  background: var(--st-menu-bg);
  box-shadow: 0 24px 60px color-mix(in srgb, var(--st-shadow) 80%, transparent), 0 2px 8px color-mix(in srgb, var(--st-shadow) 50%, transparent);
  overflow: hidden;
}
.lm-popover[hidden] { display: none; }

.lm-menu {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
/* In a short window the options scroll between the title row (Reset) and the
   footer (Save layout), which stay in view. At the design's size nothing
   scrolls. */
.lm-menu__options {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* Tab scrolls an option's focus ring fully into view. */
  scroll-padding-block: 6px;
}

.lm-head {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--st-line);
}
.lm-head__title { margin: 0; color: var(--st-text); font: 600 14px/17px var(--st-font); }

.lm-reset.st-btn {
  gap: 5px;
  /* A 24px target in the design's 18px of the title row. */
  height: 24px;
  margin: -3px -4px -3px 0;
  padding: 0 4px;
  border-radius: 5px;
  color: var(--st-text-faint);
  font-size: 12px;
  font-weight: 400;
}
.lm-reset.st-btn .st-icon { width: 12px; height: 12px; }

.lm-group {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--st-line);
}
.lm-group__title {
  margin: 0;
  color: var(--st-text-faint);
  font: 600 9.5px/11px var(--st-font-mono);
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

/* ---- Presets ------------------------------------------------------------------- */

.lm-presets { display: flex; gap: 8px; }

.lm-preset {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 6px;
  border: 0;
  border-radius: 9px;
  outline: 1px solid var(--st-line);
  outline-offset: -0.5px;
  background: var(--st-surface);
  color: var(--st-text-dim);
  font: 500 11.5px/normal var(--st-font);
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  transition: outline-color 0.15s, background 0.15s;
}
.lm-preset:hover { outline-color: var(--st-line-strong); }
.lm-preset[aria-pressed='true'] {
  outline: 1.5px solid var(--st-accent);
  outline-offset: -0.75px;
  background: var(--st-menu-chosen-bg);
  color: var(--st-menu-chosen-ink);
}
.lm-preset__name { overflow: hidden; text-overflow: ellipsis; }

.lm-thumb {
  position: relative;
  display: block;
  width: 100%;
  height: 44px;
  border-radius: 5px;
  background: var(--st-panel);
}
.lm-thumb__block { position: absolute; border-radius: 2px; }
.lm-thumb__block--base { background: var(--st-menu-thumb); }
.lm-thumb__block--strong { background: color-mix(in srgb, var(--st-menu-thumb-strong) 80%, transparent); }
.lm-preset[aria-pressed='true'] .lm-thumb__block--base { background: color-mix(in srgb, var(--st-accent) 35%, transparent); }
.lm-preset[aria-pressed='true'] .lm-thumb__block--strong { background: var(--st-accent); }

/* Where each panel sits in a 69×44 thumbnail; the panels start after the library when it shows */
.lm-thumb { --thumb-l: 4px; }
.lm-thumb--library { --thumb-l: 17px; }
.lm-thumb__block--library { top: 4px; bottom: 4px; left: 4px; width: 10px; }
.lm-thumb__block--sheet { top: 4px; right: 4px; bottom: 4px; width: 14px; }
.lm-thumb__block--live { top: 4px; right: 21px; left: var(--thumb-l); height: 11px; }
.lm-thumb__block--mixer { top: 18px; right: 21px; bottom: 4px; left: var(--thumb-l); }
.lm-thumb__block--mixer-wide { top: 4px; right: 4px; bottom: 4px; left: var(--thumb-l); }
.lm-thumb__block--live-wide { top: 4px; right: 21px; bottom: 4px; left: 4px; }
.lm-thumb__block--page { inset: 4px; }
.lm-thumb__block--line-1,
.lm-thumb__block--line-2,
.lm-thumb__block--line-3 { left: 9px; height: 3px; }
.lm-thumb__block--line-1 { top: 9px; width: 37px; background: var(--st-menu-thumb-strong); }
.lm-thumb__block--line-2 { top: 16px; width: 47px; opacity: 0.6; }
.lm-thumb__block--line-3 { top: 23px; width: 31px; opacity: 0.6; }

/* Saved layouts (Save layout adds one here) */
.lm-saved { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.lm-saved[hidden] { display: none; }
.lm-saved__title {
  color: var(--st-text-faint);
  font: 600 9.5px/normal var(--st-font-mono);
  letter-spacing: 1.2px;
  text-transform: uppercase;
}
.lm-saved__list { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.lm-saved__chip {
  max-width: 100%;
  height: 24px;
  padding: 0 9px;
  overflow: hidden;
  border: 0;
  border-radius: var(--st-radius-chip);
  outline: 1px solid var(--st-line);
  outline-offset: -0.5px;
  background: var(--st-surface);
  color: var(--st-text-dim);
  font: 500 11.5px/normal var(--st-font);
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.lm-saved__chip:hover { outline-color: var(--st-line-strong); color: var(--st-text); }
.lm-saved__chip[aria-pressed='true'] { outline-color: var(--st-accent); background: var(--st-menu-chosen-bg); color: var(--st-menu-chosen-ink); }

/* ---- Rows: panels and options ------------------------------------------------- */

.lm-row {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 28px;
  color: var(--st-text);
  font: 400 13px/normal var(--st-font);
}
label.lm-row { cursor: pointer; }
.lm-row__icon { width: 15px; height: 15px; color: var(--st-text-dim); }
.lm-row__label { flex: 1 1 0; min-width: 0; }
.lm-row .st-kbd { padding: 2px 6px; }

/* ---- Footer: Use for every song, Save layout ------------------------------------ */

.lm-foot {
  display: flex;
  flex: none;
  align-items: center;
  padding: 12px 16px;
  background: var(--st-menu-foot-bg);
}
.lm-foot__actions { display: flex; flex: 1; align-items: center; gap: 8px; min-width: 0; }
.lm-foot__actions[hidden] { display: none; }

.lm-check {
  position: relative;
  display: flex;
  flex: 1 1 0;
  align-items: center;
  gap: 7px;
  min-width: 0;
  min-height: 24px;
  color: var(--st-text-dim);
  font: 400 12px/normal var(--st-font);
  cursor: pointer;
}
/* The hidden checkbox covers the whole row, so the target is the row (24px tall). */
.lm-check__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.lm-check__box {
  display: grid;
  flex: none;
  place-items: center;
  width: 15px;
  height: 15px;
  border-radius: 4px;
  outline: 1px solid var(--st-line-strong);
  outline-offset: -0.5px;
  color: var(--st-on-accent);
}
.lm-check__icon { width: 11px; height: 11px; visibility: hidden; stroke-width: 3; }
.lm-check__input:checked + .lm-check__box { outline-color: var(--st-accent); background: var(--st-accent); }
.lm-check__input:checked + .lm-check__box .lm-check__icon { visibility: visible; }
.lm-check__input:focus-visible + .lm-check__box { outline: 2px solid var(--st-accent); outline-offset: 2px; }

.lm-save.st-btn { font-size: 12.5px; }
.lm-save.st-btn .st-icon { width: 13px; height: 13px; }

.lm-name { display: flex; flex: 1; align-items: center; gap: 8px; min-width: 0; }
.lm-name[hidden] { display: none; }
.lm-name__input {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--st-line-strong);
  border-radius: 8px;
  background: var(--st-panel);
  color: var(--st-text);
  font: 400 13px/normal var(--st-font);
}
/* The ring sits over the field's own border, so the focused field shows one ring, not a border and a ring. */
.lm-name__input:focus-visible { border-color: var(--st-accent); outline: 2px solid var(--st-accent); outline-offset: -1px; }

/* ---- Keyboard focus inside the menu -------------------------------------------- */

.lm-menu :where(.lm-preset, .lm-saved__chip, .st-btn, .st-switch, .st-seg__item):focus-visible {
  outline: 2px solid var(--st-accent);
  outline-offset: 1px;
}
