/* Mobile-only Studio layout pass. Desktop and editor behavior stay untouched. */
@media screen and (max-width: 700px) {
  #app[data-page="studio"]:not(:has(> .shelves)) {
    min-width: 0;
    padding-inline: 12px;
  }

  #app[data-page="studio"]:not(:has(> .shelves)) .project-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px 44px;
    align-items: center;
    gap: 7px;
    padding-block: 9px;
  }
  #app[data-page="studio"]:not(:has(> .shelves)) .project-actions .etude-title-edit {
    min-width: 0;
    flex: initial;
    margin-inline-end: 0;
  }
  #app[data-page="studio"]:not(:has(> .shelves)) .project-actions .etude-title-input {
    font-size: 16px;
    min-width: 0;
    max-width: calc(100% - 38px);
    text-overflow: ellipsis;
  }

  #app[data-page="studio"] .score-heading {
    margin-block: 14px 10px;
    gap: 8px;
  }
  #app[data-page="studio"] .score-heading .signature-toggle {
    max-width: 100%;
    min-width: 0;
    white-space: normal;
  }
  #app[data-page="studio"] .score-heading .signature-toggle-label {
    white-space: normal;
  }

  /* Selection and notation tools: three consistently sized touch targets per row. */
  #app[data-page="studio"] .score-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
    gap: 7px;
    width: 100%;
  }
  #app[data-page="studio"] .score-actions > button {
    width: 100%;
    min-width: 0;
    min-height: 46px;
    margin: 0;
  }
  /* Playback, metronome and Record have a dedicated full-width row. */
  #app[data-page="studio"] .score-actions .score-transport-actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: stretch;
    gap: 7px;
    width: 100%;
    min-width: 0;
    margin: 2px 0 0;
  }
  #app[data-page="studio"] .score-transport-actions > button {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    padding: 8px;
    margin: 0;
  }
  #app[data-page="studio"] .score-transport-actions .score-audio-status {
    grid-column: 1 / -1;
    min-width: 0;
    margin: 0;
  }

  /* Keep the staff and piano horizontally scrollable without shrinking keys. */
  #app[data-page="studio"] .score,
  #app[data-page="studio"] .keys {
    max-width: 100%;
    min-width: 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
  }
  #app[data-page="studio"] .instrument {
    min-width: 0;
    padding: 10px;
    margin-block: 10px 14px;
  }
  #app[data-page="studio"] .instrument > .row {
    gap: 8px;
    justify-content: space-between;
  }
  #app[data-page="studio"] .board {
    height: 148px;
  }

  /* Note values, meter, measures and tempo are not squeezed into
     unpredictable flex rows on narrow devices. */
  #app[data-page="studio"] .score-below-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    gap: 9px;
    width: 100%;
    margin-block: 10px 14px;
  }
  #app[data-page="studio"] .score-below-actions > * {
    min-width: 0;
    max-width: 100%;
    margin: 0;
  }
  #app[data-page="studio"] .score-time-controls {
    display: grid;
    grid-template-columns: minmax(100px, 0.8fr) minmax(0, 1.2fr);
    align-items: stretch;
    width: 100%;
    gap: 8px;
  }
  #app[data-page="studio"] .score-time-controls > .score-meter-control {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 4px;
    flex-wrap: nowrap;
    min-width: 0;
    margin: 0;
  }
  #app[data-page="studio"] .score-time-controls > .score-meter-control select {
    width: 100%;
    min-width: 0;
    max-width: none;
    flex: 0 1 auto;
  }
  #app[data-page="studio"] .score-meter-control,
  #app[data-page="studio"] .score-pen-length,
  #app[data-page="studio"] .score-measure-count {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 44px;
  }
  #app[data-page="studio"] .score-meter-control select,
  #app[data-page="studio"] .score-pen-length select {
    flex: 1 1 160px;
    width: 100%;
    min-width: 0;
    max-width: none;
  }
  #app[data-page="studio"] .score-time-controls > .score-tempo {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-content: center;
    align-items: center;
    justify-content: stretch;
    column-gap: 4px;
    row-gap: 4px;
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 6px 7px;
  }
  #app[data-page="studio"] .score-time-controls .score-tempo-label {
    grid-column: 1 / -1;
  }
  #app[data-page="studio"] .score-time-controls .score-tempo-number {
    width: 100%;
    min-width: 0;
    padding-inline: 0;
  }
  #app[data-page="studio"] .score-meter-status {
    width: 100%;
    line-height: 1.55;
  }

  /* The Studio-only tuner and editor remain within the mobile viewport. */
  #app[data-page="studio"] .signature-editor-controls {
    min-width: 0;
  }
}

@media screen and (min-width: 480px) and (max-width: 700px) {
  #app[data-page="studio"] .score-below-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #app[data-page="studio"] .score-time-controls,
  #app[data-page="studio"] .score-pen-length,
  #app[data-page="studio"] .score-meter-status {
    grid-column: 1 / -1;
  }
}

/* Pen's mobile picker reuses the existing Etude Setup bottom sheet.
   Only its field styling is local to Score; no second dialog implementation. */
@media screen and (max-width: 700px),
       screen and (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
  #app[data-page="studio"] .score-pen-length {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  #app[data-page="studio"] .score-pen-length > .studio-native-music-select {
    display: none !important;
  }
  #app[data-page="studio"] .score-pen-length > .studio-mobile-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    min-width: 0;
    min-height: 49px;
    margin: 0;
    padding: 10px 13px;
    border: 1px solid var(--glass-border);
    border-radius: 11px;
    background: var(--dropdown-control-surface);
    color: var(--ink);
    font: inherit;
    font-weight: 500;
    text-align: start;
  }
  #app[data-page="studio"] .score-pen-length .studio-mobile-select-value {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #app[data-page="studio"] .score-pen-length .studio-mobile-select-chevron {
    flex: none;
    width: 9px;
    height: 9px;
    margin-inline: 3px;
    border-inline-end: 1.6px solid currentColor;
    border-bottom: 1.6px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
  }
}

@media screen and (max-width: 700px) and (orientation: landscape) and (max-height: 520px) {
  #app[data-page="studio"] .board {
    height: 104px;
  }
}


/* The added Settings tab/icons are not part of the desktop navbar. */
#nav .mobile-settings-tab,
#nav .mobile-nav-icon {
  display: none;
}

/* Mobile-only header/navigation; desktop remains exactly as before. */
@media screen and (max-width: 700px),
       screen and (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
  body > header {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 62px;
    padding: 8px 14px;
    border: 0;
    border-bottom: 0;
    box-shadow: none;
    background: transparent;
    /* A backdrop filter on the header traps its fixed-position dock. */
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  body > header > .wordmark {
    width: 116px;
    height: 44px;
    object-fit: contain;
    margin: 0;
  }
  body > header > aside {
    display: none !important;
  }

  /* Higher specificity overrides Home's older mobile nav display:none. */
  body > header > #nav {
    position: fixed;
    --mobile-dock-gutter: 12px;
    inset: auto max(var(--mobile-dock-gutter), env(safe-area-inset-right))
           calc(8px + env(safe-area-inset-bottom))
           max(var(--mobile-dock-gutter), env(safe-area-inset-left));
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: stretch;
    gap: 3px;
    width: auto;
    max-width: 460px;
    padding: 4px;
    margin: 0 auto;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--panel);
    box-shadow: none;
    overflow: hidden;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  body > header > #nav > button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    min-height: 64px;
    margin: 0;
    padding: 4px 2px;
    border: 1px solid transparent;
    border-radius: 16px;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
    line-height: 17px;
    white-space: nowrap;
    text-align: center;
    overflow: hidden;
    box-shadow: none;
    transition: opacity .15s ease, background-color .15s ease, color .15s ease;
  }
  body > header > #nav > .mobile-settings-tab {
    display: flex;
    min-height: 59px;
    align-self: center;
    font-size: 10px;
    line-height: 14px;
  }
  body > header > #nav .mobile-nav-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  body > header > #nav .mobile-nav-icon {
    display: block;
    flex: none;
    width: 21px;
    height: 21px;
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    stroke-width: 1.7;
  }
  body > header > #nav > button:active {
    opacity: .7;
  }
  body {
    padding-bottom: calc(100px + env(safe-area-inset-bottom));
  }

  dialog.mobile-settings-dialog {
    position:fixed;
    inset:auto 12px calc(102px + env(safe-area-inset-bottom));
    box-sizing:border-box;
    width:min(390px,calc(100vw - 24px));
    max-width:calc(100vw - 24px);
    max-height:calc(100dvh - 120px - env(safe-area-inset-bottom));
    margin:0 auto;
    padding:18px;
    overflow-y:auto;
    overscroll-behavior:contain;
    border:1px solid var(--glass-border);
    border-radius:24px;
    background:var(--panel);
    color:var(--ink);
    box-shadow:0 18px 48px rgb(0 0 0 / 24%);
  }
  dialog.mobile-settings-dialog::backdrop {
    background:rgb(4 15 25 / 38%);
  }
  .mobile-settings-heading {
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:12px;
    margin-bottom:18px;
  }
  .mobile-settings-heading h2 {
    margin:0;
    font-size:18px;
    font-weight:700;
  }
  dialog.mobile-settings-dialog .mobile-settings-close {
    display:inline-grid;
    place-items:center;
    flex:none;
    width:36px;
    min-width:36px;
    height:36px;
    min-height:36px;
    padding:0;
    margin:0;
    border:1px solid var(--glass-border);
    border-radius:12px;
    background:var(--glass-control);
    color:var(--muted);
    font-size:23px;
    line-height:1;
    box-shadow:none;
  }
  dialog.mobile-settings-dialog .mobile-settings-group {
    display:block;
    margin:0;
    padding:0;
    border:0;
    border-radius:0;
    background:transparent;
    box-shadow:none;
  }
  dialog.mobile-settings-dialog .mobile-settings-group + .mobile-settings-group {margin-top:18px}
  .mobile-settings-group h3 {
    margin:0 0 8px;
    color:var(--muted);
    font-size:12px;
    font-weight:650;
  }
  .mobile-settings-choices {
    display:grid;
    grid-template-columns:repeat(2,minmax(0,1fr));
    gap:4px;
    padding:4px;
    background:var(--glass-control);
    border:1px solid var(--glass-border);
    border-radius:14px;
  }
  dialog.mobile-settings-dialog .mobile-settings-choice {
    position:relative;
    display:flex;
    align-items:center;
    justify-content:center;
    gap:8px;
    min-width:0;
    min-height:46px;
    margin:0;
    padding:8px 10px;
    border-radius:10px;
    border:1px solid transparent;
    background:transparent;
    color:var(--muted);
    font-size:13px;
    font-weight:600;
    box-shadow:none;
  }
  dialog.mobile-settings-dialog .mobile-settings-choice.active {
    border-color:var(--active-border);
    background:var(--active-fill);
    color:var(--active-ink);
  }
  dialog.mobile-settings-dialog .mobile-settings-choice.active::after {
    content:'';
    width:5px;
    height:9px;
    border:solid currentColor;
    border-width:0 1.7px 1.7px 0;
    transform:rotate(45deg);
    margin-inline-start:2px;
    flex:none;
  }
  
}

/* Mobile Home: the shared four-tab dock is the only bottom navigation.
   Show both dashboard sections in the normal scroll flow instead of hiding
   one behind the now-removed two-tab Etudes/Practice switcher. */
@media screen and (max-width: 699px) {
  body.home-screen > header > #nav {
    display: grid;
  }
  body.home-screen .g-home-tabs {
    display: none;
  }
  body.home-screen .g-dashboard-panel:not(.is-selected) {
    display: block;
  }
  body.home-screen .g-dashboard-panel + .g-dashboard-panel {
    margin-top: 16px;
  }
  body.home-screen,
  body.home-screen main {
    padding-bottom: calc(112px + env(safe-area-inset-bottom));
  }
}


/* Legacy WorkspaceBottomNav responsive gutter and label sizes. */
@media screen and (max-width: 399px) {
  body > header > #nav { --mobile-dock-gutter: 8px; }
}
@media screen and (max-width: 369px) {
  body > header > #nav > button { font-size: 10px; }
}

@media screen and (max-width: 700px) and (prefers-reduced-motion: reduce) {
  body > header > #nav > button,
  body > header > #nav .mobile-nav-icon {
    transition: none;
  }
}


/* Route text on the mobile dock only. Keep Desktop labels untouched. */
#nav .mobile-nav-label {display: none;}
@media screen and (max-width: 700px),
       screen and (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
  #nav .desktop-nav-label {display: none;}
  #nav .mobile-nav-label {display: inline;}
}


/* Mobile Settings: sun/moon choices, keeping the original theme handler. */
@media screen and (max-width: 700px),
       screen and (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
  .mobile-settings-appearance-choice {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
  }
  .mobile-settings-appearance-choice .mobile-appearance-icon {
    display: block;
    flex: none;
    width: 22px;
    height: 22px;
    color: currentColor;
  }
}


/* Mobile Etude Studio editor: preserve its compact content gutters.
   The navigation uses the same fixed bottom dock as every other page. */
@media screen and (max-width: 700px),
       screen and (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
  /* One clear phone-edge gutter rather than main > section > instrument
     each independently consuming large chunks of the available width. */
  #app[data-page="studio"]:not(:has(> .shelves)) {
    padding-inline: 10px;
  }
  #app[data-page="studio"]:not(:has(> .shelves)) > section:has(.instrument) {
    min-width: 0;
    margin-inline: 0;
    padding-inline: 8px;
    border-top: 0;
  }
  #app[data-page="studio"]:not(:has(> .shelves)) > section > .instrument {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding-inline: 6px;
  }
  #app[data-page="studio"]:not(:has(> .shelves)) .keys {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding-inline: 0;
  }
  #app[data-page="studio"]:not(:has(> .shelves)) .score,
  #app[data-page="studio"]:not(:has(> .shelves)) .board {
    max-width: 100%;
  }
}


/* Phone touch: suppress the browser's transient blue tap overlay.
   Focus-visible and intentional pressed/selected states remain intact. */
@media screen and (max-width: 700px),
       screen and (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
  button,
  a,
  summary,
  label,
  input,
  select,
  textarea,
  [role="button"] {
    -webkit-tap-highlight-color: transparent;
  }
}


/* Studio editor visual zones: piano and full Score-to-tempo region.
   The wrapper is layout-neutral on Desktop; the mobile card does NOT
   nest another phone-edge gutter or change the piano's note widths. */
#app[data-page="studio"] .studio-score-surface {
  display: contents;
}
/* Give the desktop piano card and the Score toolbar their own breathing room. */
@media screen and (min-width: 701px) {
  #app[data-page="studio"] .studio-score-surface > .score-actions {
    margin-block-start: 18px;
  }
}
@media screen and (max-width: 700px) {
  #app[data-page="studio"]:not(:has(> .shelves)) > section:has(.instrument) {
    background: var(--glass-surface);
  }
  #app[data-page="studio"]:not(:has(> .shelves)) .instrument {
    margin-block: 7px 13px;
    padding: 10px 8px 9px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: var(--glass-control);
    box-shadow: var(--glass-soft-shadow);
  }
  #app[data-page="studio"]:not(:has(> .shelves)) .instrument > .row {
    margin-bottom: 6px;
    padding-bottom: 7px;
    border-bottom: 1px solid color-mix(in srgb, var(--line) 65%, transparent);
  }
  #app[data-page="studio"]:not(:has(> .shelves)) .studio-score-surface {
    display: block;
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    min-width: 0;
    margin-block: 14px 4px;
    padding: 12px 9px 10px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: var(--glass-surface);
    box-shadow: var(--glass-soft-shadow);
  }
  #app[data-page="studio"]:not(:has(> .shelves)) .studio-score-surface > .score-heading {
    margin: 0 0 11px;
    padding: 0 2px 9px;
    border-bottom: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
  }
  #app[data-page="studio"]:not(:has(> .shelves)) .studio-score-surface > .score-actions {
    min-width: 0;
    margin-block: 0;
  }
  #app[data-page="studio"]:not(:has(> .shelves)) .studio-score-surface > .score {
    min-width: 0;
    margin-block: 11px 8px;
  }
  #app[data-page="studio"]:not(:has(> .shelves)) .studio-score-surface > .score-below-actions:not([hidden]) {
    margin: 0;
    padding-top: 12px;
    border-top: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
  }
}


/* Mobile Studio Score: one transport row above seven editing controls. */
@media screen and (max-width: 700px),
       screen and (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
  #app[data-page="studio"]:not(:has(> .shelves)) .studio-score-surface > .score-actions {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    grid-template-rows: auto auto;
    align-items: stretch;
    gap: 6px 4px;
    min-width: 0;
    width: 100%;
  }
  #app[data-page="studio"]:not(:has(> .shelves)) .studio-score-surface > .score-actions > button {
    grid-row: 2;
    min-width: 0;
    width: 100%;
    min-height: 44px;
    margin: 0;
    padding: 7px 2px;
    font-size: 16px;
    line-height: 1;
  }
  #app[data-page="studio"]:not(:has(> .shelves)) .studio-score-surface > .score-actions > button svg {
    width: 18px;
    height: 18px;
    max-width: 100%;
  }
  #app[data-page="studio"]:not(:has(> .shelves)) .studio-score-surface > .score-actions > .score-transport-actions {
    grid-column: 1 / -1;
    grid-row: 1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    min-width: 0;
    width: 100%;
    gap: 6px;
    margin: 0;
  }
  /* When there is no time signature, metronome is hidden. */
  #app[data-page="studio"]:not(:has(> .shelves)) .studio-score-surface > .score-actions > .score-transport-actions:has(.score-metronome[hidden]) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}


/* Free-meter note-length timeline and per-row score playhead (Studio only). */
#app[data-page="studio"] .score-free-timeline-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 13px;
  background: transparent;
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  cursor: pointer;
}
#app[data-page="studio"] .score-free-timeline-toggle[hidden],
#app[data-page="studio"] .score-free-timeline[hidden] {
  display: none !important;
}
#app[data-page="studio"] .score-free-timeline-toggle.active {
  color: var(--accent);
  border-color: var(--accent);
}
#app[data-page="studio"] .score-free-timeline-toggle svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}
#app[data-page="studio"] .score-free-timeline {
  min-width: 0;
  margin: 14px 0;
  padding: 14px;
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  background: var(--glass-surface);
}
#app[data-page="studio"] .free-timeline-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 9px 16px;
  margin-bottom: 12px;
}
#app[data-page="studio"] .free-timeline-heading strong {
  font-size: .95rem;
}
#app[data-page="studio"] .free-timeline-heading small {
  color: var(--ink);
  opacity: .76;
}
#app[data-page="studio"] .free-timeline-empty {
  margin: 0;
  opacity: .72;
}
#app[data-page="studio"] .free-timeline-scroll {
  width: 100%;
  overflow: auto hidden;
  scrollbar-width: none;
  direction: ltr;
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  background: var(--glass-control);
}
#app[data-page="studio"] .free-timeline-scroll::-webkit-scrollbar {
  display: none;
}
/* Desktop editor scrolling: the global scrollbar reset must not hide
   the Score and Timeline handles. Mouse wheel pans horizontal overflow;
   trackpads and draggable scrollbars retain their native behavior. */
@media screen and (pointer:fine) {
  #app[data-page="studio"] .studio-score-surface > .score:not([hidden]),
  #app[data-page="studio"] .free-timeline-scroll {
    scrollbar-width:thin;
    scrollbar-color:color-mix(in srgb,var(--accent) 42%,transparent) transparent;
  }
  #app[data-page="studio"] .studio-score-surface > .score:not([hidden])::-webkit-scrollbar,
  #app[data-page="studio"] .free-timeline-scroll::-webkit-scrollbar {
    display:block;
    width:7px;
    height:7px;
  }
  #app[data-page="studio"] .studio-score-surface > .score:not([hidden])::-webkit-scrollbar-thumb,
  #app[data-page="studio"] .free-timeline-scroll::-webkit-scrollbar-thumb {
    border-radius:7px;
    background:color-mix(in srgb,var(--accent) 42%,transparent);
  }
}

#app[data-page="studio"] .free-timeline-track {
  position: relative;
  min-width: 100%;
}
/* Compact ruler, matching the Score's small/fifth longer divisions.
   The existing seconds ticks remain to preserve temporal orientation. */
#app[data-page="studio"] .free-timeline-ruler {
  position:absolute;
  top:13px;
  height:10px;
  border-top:1px solid color-mix(in srgb,var(--accent) 42%,transparent);
  background-image:
    repeating-linear-gradient(to right,
      color-mix(in srgb,var(--accent) 40%,transparent) 0 1px,
      transparent 1px 13px),
    repeating-linear-gradient(to right,
      color-mix(in srgb,var(--accent) 53%,transparent) 0 1px,
      transparent 1px 65px);
  background-size:100% 3px,100% 6px;
  background-repeat:repeat-x;
  background-position:left top,left top;
  pointer-events:none;
}
#app[data-page="studio"] .free-timeline-playhead {
  position:absolute;
  z-index:2;
  top:8px;
  bottom:5px;
  width:1.5px;
  background:repeating-linear-gradient(to bottom,
    color-mix(in srgb,var(--accent) 70%,transparent) 0 3px,
    transparent 3px 6px);
  transform:translateX(-50%);
  pointer-events:none;
}
#app[data-page="studio"] .free-timeline-playhead::before {
  content:'';
  position:absolute;
  top:0;
  left:50%;
  width:0;
  height:0;
  border-left:5px solid transparent;
  border-right:5px solid transparent;
  border-top:8px solid var(--accent);
  transform:translateX(-50%);
}
/* Active playback is a raised outlined state, NOT a brighter note color.
   Leave sizing and the draggable resize handle unchanged. */
#app[data-page="studio"] .free-timeline-note.is-playing {
  z-index:3;
  outline:2px solid var(--accent);
  outline-offset:1px;
  box-shadow:0 0 0 3px color-mix(in srgb,var(--accent) 18%,transparent),
    0 4px 12px rgb(0 0 0 / 16%);
}
#app[data-page="studio"] .free-timeline-note.is-playing::before {
  content:'';
  position:absolute;
  top:0;
  bottom:0;
  left:0;
  width:3px;
  background:var(--accent);
  pointer-events:none;
}
#app[data-page="studio"] .free-timeline-tick {
  position: absolute;
  top: 15px;
  bottom: 4px;
  width: 1px;
  background: color-mix(in srgb, var(--line) 50%, transparent);
  pointer-events: none;
}
#app[data-page="studio"] .free-timeline-tick span {
  position: absolute;
  top: -13px;
  left: 4px;
  font-size: 10px;
  white-space: nowrap;
  color: var(--ink);
  opacity: .78;
}
#app[data-page="studio"] .free-timeline-drop-marker:not([hidden]) {
  position:absolute;
  z-index:5;
  top:30px;
  bottom:5px;
  width:2px;
  background:var(--accent);
  pointer-events:none;
}
#app[data-page="studio"] .free-timeline-drop-marker[hidden] {
  display:none!important;
}
#app[data-page="studio"] .free-timeline-drop-marker::before {
  content:'';
  position:absolute;
  top:-6px;
  left:50%;
  border-left:5px solid transparent;
  border-right:5px solid transparent;
  border-top:6px solid var(--accent);
  transform:translateX(-50%);
}
#app[data-page="studio"] .free-timeline-note {
  touch-action:none;
  user-select:none;
  -webkit-user-select:none;
  cursor:grab;
  position: absolute;
  display: flex;
  align-items: center;
  overflow: hidden;
  gap: 7px;
  height: 33px;
  padding: 0 14px 0 9px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  color: var(--ink);
  background: var(--glass-selected);
  box-shadow: var(--glass-soft-shadow);
  direction: ltr;
  white-space: nowrap;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
#app[data-page="studio"] .free-timeline-note.is-dragging {
  z-index:4;
  opacity:.85;
  cursor:grabbing;
}
#app[data-page="studio"] .free-timeline-note-name {
  font-weight: 750;
  flex: 0 0 auto;
}
#app[data-page="studio"] .free-timeline-note-duration {
  overflow: hidden;
  opacity: .85;
  text-overflow: ellipsis;
}
#app[data-page="studio"] .free-timeline-resize {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 13px;
  min-width: 13px;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--accent);
  border-radius: 0 6px 6px 0;
  background: var(--glass-elevated);
  color: var(--accent);
  cursor: ew-resize;
  touch-action: none;
}
#app[data-page="studio"] .free-timeline-resize::after {
  content: '';
  display: block;
  width: 3px;
  height: 15px;
  border-inline: 1px solid currentColor;
  margin: auto;
}

#app[data-page="studio"] .score svg [data-score-seek] {
  cursor: pointer !important;
  touch-action: none;
}
@media print {
  #app[data-page="studio"] .score-free-timeline,
  #app[data-page="studio"] .score-free-timeline-toggle,
  #app[data-page="studio"] .score .score-ruler-art {
    display: none !important;
  }
}
@media screen and (max-width: 700px) {
  #app[data-page="studio"] .score-free-timeline {
    padding: 10px;
  }
  #app[data-page="studio"] .free-timeline-heading {
    gap: 4px;
  }
  #app[data-page="studio"] .free-timeline-heading small {
    flex-basis: 100%;
  }
}

/* Score settings below the staff: a consistent desktop control bar.
   Presentation only; keep the canonical tempo, meter, note value and
   timeline inputs and every existing event handler unchanged. */
@media screen and (min-width:701px) and (pointer:fine) {
  #app[data-page="studio"] .studio-score-surface > .score-below-actions:not([hidden]) {
    display:flex;
    align-items:flex-end;
    flex-wrap:wrap;
    column-gap:18px;
    row-gap:12px;
    margin:15px 0 3px;
    padding:14px 16px;
    border:1px solid var(--glass-border);
    border-radius:14px;
    background:color-mix(in srgb,var(--panel) 68%,var(--glass-surface));
    box-shadow:inset 0 1px 0 color-mix(in srgb,var(--panel) 80%,transparent);
    direction:ltr;
  }
  #app[data-page="studio"] .score-below-actions > .score-time-controls {
    display:inline-flex;
    align-items:flex-end;
    gap:16px;
    min-width:0;
  }
  #app[data-page="studio"] .score-time-controls > .score-tempo,
  #app[data-page="studio"] .score-time-controls > .score-meter-control,
  #app[data-page="studio"] .score-below-actions > .score-pen-length,
  #app[data-page="studio"] .score-below-actions > .score-measure-count {
    display:flex;
    flex-direction:column;
    align-items:stretch;
    justify-content:flex-end;
    gap:7px;
    min-width:0;
    min-height:0;
    margin:0;
    padding:0;
    border:0;
    border-radius:0;
    background:transparent;
    box-shadow:none;
  }
  #app[data-page="studio"] .score-tempo-label,
  #app[data-page="studio"] .score-meter-control > span,
  #app[data-page="studio"] .score-pen-length > span,
  #app[data-page="studio"] .score-measure-count > span {
    display:block;
    margin:0;
    padding:0;
    color:var(--muted);
    font-size:12px;
    font-weight:650;
    line-height:1.3;
    text-align:start;
    direction:rtl;
    white-space:nowrap;
  }
  #app[data-page="studio"] .score-time-controls > .score-tempo {
    position:relative;
    display:grid;
    grid-template-columns:minmax(35px,1fr) auto;
    grid-template-rows:auto 42px;
    column-gap:4px;
    width:118px;
  }
  #app[data-page="studio"] .score-tempo-label {
    grid-column:1/-1;
  }
  #app[data-page="studio"] .score-tempo-number {
    grid-column:1;
    grid-row:2;
    width:100%;
    min-width:0;
    min-height:42px;
    padding:0 4px 0 10px;
    border:1px solid var(--glass-border);
    border-inline-end:0;
    border-radius:10px 0 0 10px;
    background:var(--dropdown-control-surface);
    color:var(--ink);
    font-size:15px;
    font-weight:700;
    text-align:center;
  }
  #app[data-page="studio"] .score-tempo-unit {
    display:grid;
    grid-column:2;
    grid-row:2;
    align-items:center;
    min-height:42px;
    padding-inline:6px 9px;
    border:1px solid var(--glass-border);
    border-inline-start:0;
    border-radius:0 10px 10px 0;
    background:var(--dropdown-control-surface);
    color:var(--muted);
    font-size:10.5px;
    font-weight:650;
  }
  #app[data-page="studio"] .score-meter-control > select,
  #app[data-page="studio"] .score-pen-length > select,
  #app[data-page="studio"] .score-measure-count > input {
    width:auto;
    max-width:none;
    height:42px;
    min-height:42px;
    margin:0;
    padding:0 12px;
    border:1px solid var(--glass-border);
    border-radius:10px;
    background:var(--dropdown-control-surface);
    color:var(--ink);
    box-shadow:none;
    font:inherit;
    font-size:13px;
    font-weight:600;
  }
  #app[data-page="studio"] .score-meter-control > select {min-width:172px;max-width:218px}
  #app[data-page="studio"] .score-pen-length > select {min-width:126px;max-width:190px}
  #app[data-page="studio"] .score-measure-count > input {width:90px;text-align:center}
  #app[data-page="studio"] .score-below-actions > .score-free-timeline-toggle:not([hidden]) {
    align-self:flex-end;
    min-height:42px;
    margin:0;
    padding:0 15px;
    border:1px solid var(--glass-border);
    border-radius:10px;
    background:var(--glass-control);
    box-shadow:none;
    color:var(--ink);
    font-size:13px;
    font-weight:600;
  }
  #app[data-page="studio"] .score-below-actions > .score-free-timeline-toggle.active {
    border-color:color-mix(in srgb,var(--accent) 38%,var(--glass-border));
    background:color-mix(in srgb,var(--accent) 11%,var(--panel));
    color:var(--ink);
  }
  #app[data-page="studio"] .score-below-actions > .score-meter-status:not([hidden]) {
    margin:0;
    flex-basis:100%;
  }
}

/* Studio piano: individual, understated glass icon controls, without an
   old-fashioned segmented outer frame. Existing button handlers stay intact. */
:is(#app[data-page="studio"],body) .instrument .studio-piano-view-controls {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  flex:0 0 auto;
  gap:6px;
  margin-inline-start:auto;
  padding:0;
  border:0;
  border-radius:0;
  background:transparent;
  box-shadow:none;
}
:is(#app[data-page="studio"],body) .instrument .studio-piano-view-controls > button {
  display:inline-grid;
  place-items:center;
  flex:0 0 36px;
  width:36px;
  min-width:36px;
  height:36px;
  min-height:36px;
  margin:0;
  padding:0;
  border:1px solid color-mix(in srgb,var(--glass-border) 80%,transparent);
  border-radius:11px;
  background:color-mix(in srgb,var(--glass-control) 80%,transparent);
  color:var(--ink);
  box-shadow:inset 0 1px 0 color-mix(in srgb,var(--panel) 55%,transparent);
  cursor:pointer;
  transition:background-color 160ms ease,color 160ms ease,
    box-shadow 160ms ease,border-color 160ms ease,transform 160ms ease;
}
:is(#app[data-page="studio"],body) .instrument .studio-piano-view-controls > button svg {
  display:block;
  width:18px;
  height:18px;
}
:is(#app[data-page="studio"],body) .instrument .studio-piano-view-controls > button:hover {
  border-color:color-mix(in srgb,var(--accent) 34%,var(--glass-border));
  background:color-mix(in srgb,var(--accent) 8%,var(--glass-control));
  color:var(--accent);
  box-shadow:0 3px 12px color-mix(in srgb,var(--ink) 7%,transparent);
  transform:translateY(-1px);
}
:is(#app[data-page="studio"],body) .instrument .studio-piano-view-controls > button:active {
  transform:translateY(0);
  box-shadow:none;
}

:is(#app[data-page="studio"],body) .instrument .studio-piano-view-controls > .studio-piano-fullscreen-toggle[aria-pressed="true"] {
  border-color:color-mix(in srgb,var(--accent) 40%,var(--glass-border));
  background:color-mix(in srgb,var(--accent) 11%,var(--glass-control));
  color:var(--accent);
}
:is(#app[data-page="studio"],body) .instrument .studio-piano-view-controls > .studio-piano-toggle[aria-expanded="true"] svg {
  transform:rotate(180deg);
}
/* Full size is a mobile-only action. Keep it available on actual landscape
   phones even when their long edge exceeds 700 CSS pixels. */
:is(#app[data-page="studio"],body) .instrument .studio-piano-view-controls > .studio-piano-fullscreen-toggle {
  display:none;
}
@media screen and (max-width:700px),
       screen and (pointer:coarse) and (orientation:landscape) and (max-height:520px) {
  :is(#app[data-page="studio"],body) .instrument .studio-piano-view-controls > .studio-piano-fullscreen-toggle {
    display:inline-grid;
  }
  :is(#app[data-page="studio"],body) .instrument > .row {
    gap:6px;
  }
  :is(#app[data-page="studio"],body) .instrument > .row > strong {
    font-size:14px;
    font-weight:650;
    line-height:1.25;
  }
  :is(#app[data-page="studio"],body) .instrument .studio-piano-view-controls {
    gap:5px;
  }
  :is(#app[data-page="studio"],body) .instrument .studio-piano-view-controls > button {
    flex-basis:34px;
    width:34px;
    min-width:34px;
    height:34px;
    min-height:34px;
    border-radius:10px;
  }
  :is(#app[data-page="studio"],body) .instrument .studio-piano-view-controls > button svg {
    width:17px;
    height:17px;
  }
}
