:root {
  --bg: #fcfcfc;
  --surface: #f2f2f2;
  --surface-strong: #ffffff;
  --surface-border: #e4e4e4;
  --ink: #171717;
  --muted: #6a6a6a;
  --shadow: 0 14px 32px rgba(24, 24, 24, 0.08);
  --cell-width: 35.3px;
  --half-gap-extra: calc(var(--cell-width) * 0.7);
  --timeline-top: 84px;
}

:root[data-theme="dark"],
body[data-theme="dark"] {
  --bg: #0f1419;
  --surface: #171d24;
  --surface-strong: #121920;
  --surface-border: #2a3440;
  --ink: #eef3f8;
  --muted: #9eabb9;
  --shadow: 0 18px 36px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  font-family: "Trebuchet MS", "Gill Sans", "Avenir Next", sans-serif;
  transition: background 180ms ease, color 180ms ease;
}

button {
  font: inherit;
}

body,
button,
div,
span,
section,
header,
main,
article,
aside,
label,
h1,
h2,
h3,
h4,
h5,
h6,
p {
  -webkit-user-select: none;
  user-select: none;
}

input,
textarea,
[contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.app-shell {
  max-width: 1380px;
  margin: 0 auto;
  padding: 22px 18px 34px;
}

/* Keep the desktop editor compact without changing phone or tablet sizing. */
@media (min-width: 1100px) {
  .app-shell {
    width: min(calc(100% / 0.86), 1520px);
    max-width: none;
    zoom: 0.86;
  }
}

.page-header {
  position: sticky;
  top: 0;
  z-index: 60;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  min-height: 96px;
  padding: 10px 0 14px;
  margin: -10px 0 6px;
  isolation: isolate;
}

.page-header::before {
  content: "";
  position: absolute;
  inset: 0 -18px;
  z-index: -1;
  border-radius: 0 0 30px 30px;
  background: rgba(252, 252, 252, 0.88);
  backdrop-filter: blur(18px) saturate(1.05);
  -webkit-backdrop-filter: blur(18px) saturate(1.05);
  box-shadow: 0 10px 28px rgba(24, 24, 24, 0.05);
  border-bottom: 1px solid rgba(228, 228, 228, 0.72);
}

body[data-theme="dark"] .page-header::before {
  background: rgba(15, 20, 25, 0.9);
  border-bottom-color: rgba(54, 68, 82, 0.82);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3);
}

.header-audio-controls {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  align-self: center;
}

.toolbar-stack {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.header-actions {
  position: relative;
  display: flex;
  gap: 10px;
  align-self: center;
  flex-wrap: nowrap;
}

.mobile-view-button {
  display: none;
  font-size: 15px;
  font-weight: 700;
}

.mobile-undo-button {
  display: none;
}

.mobile-view-icon {
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
}

.mobile-view-icon i {
  display: block;
  width: 3px;
  height: 3px;
  border-radius: 999px;
  background: currentColor;
}

.mobile-view-icon--1 {
  grid-template-columns: 1fr;
}

.mobile-view-icon--4 {
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
}

.mobile-view-icon--16 {
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
}

.mobile-view-icon--16 i {
  width: 2px;
  height: 2px;
}

#account-button {
  order: 4;
}

.round-action-button--account-active {
  color: #3d8f63;
  border-color: rgba(61, 143, 99, 0.32);
}

.modal-card--auth {
  width: min(100%, 430px);
}

.modal-actions--split {
  justify-content: space-between;
}

.account-panel {
  display: grid;
  gap: 18px;
  padding-top: 8px;
}

.account-panel__identity {
  display: grid;
  gap: 5px;
}

.account-panel__identity strong {
  color: var(--ink);
  font-size: 18px;
}

.account-panel__identity span {
  color: var(--muted);
  font-size: 14px;
}

#theme-button {
  order: 1;
}

#library-button {
  order: 2;
}

#favorite-button {
  order: 3;
}

#theme-button .action-icon {
  display: block;
  width: 22px;
  height: 22px;
}

#theme-button .action-icon--moon {
  transform: translate(2px, -2px);
}

#theme-button .action-icon--sun {
  transform: translate(0, 0);
}

.primary-button,
.secondary-button,
.icon-button,
.round-action-button,
.add-pair-button,
.modal-primary-button,
.modal-secondary-button,
.library-load-button,
.modal-close-button {
  border: 0;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover,
.round-action-button:hover,
.add-pair-button:hover,
.modal-primary-button:hover,
.modal-secondary-button:hover,
.library-load-button:hover,
.modal-close-button:hover,
.instrument-token:hover {
  transform: translateY(-1px);
}

.primary-button {
  background: #121212;
  color: #ffffff;
  box-shadow: 0 10px 20px rgba(18, 18, 18, 0.16);
}

.secondary-button {
  background: #efefef;
  color: #171717;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 999px;
  background: #f3f3f3;
  color: #181818;
  font-size: 18px;
  line-height: 1;
}

.icon-button--danger {
  background: #fff2f2;
  color: #d53f3f;
}

.toolbar {
  padding: 12px 14px;
  border-radius: 28px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
}

.toolbar--lower {
  min-width: 470px;
}

.toolbar--upper {
  min-width: 272px;
}

.toolbar__label {
  display: none;
}

.instrument-bar {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
}

.toolbar--lower .instrument-bar {
  gap: 4px;
}

.instrument-bar--upper {
  gap: 5px;
}

.instrument-token {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 58px;
  min-height: 72px;
  padding: 4px 2px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  cursor: grab;
}

.toolbar--lower .instrument-token {
  min-width: 58px;
  min-height: 70px;
}

.instrument-token:active {
  cursor: grabbing;
}

.instrument-token__glyph {
  position: relative;
  width: 30px;
  height: 58px;
}

.instrument-token__text {
  font-size: 10px;
  line-height: 1.15;
  text-align: center;
  color: var(--muted);
  max-width: 62px;
}

.toolbar--lower .instrument-token__text {
  max-width: 60px;
  font-size: 9px;
  white-space: nowrap;
}

.board-section {
  margin-top: 18px;
}

.board-actions {
  display: flex;
  justify-content: center;
  margin-top: 18px;
}

.round-action-button,
.add-pair-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  padding: 0;
  border: 1px solid var(--surface-border);
  border-radius: 999px;
  background: var(--surface);
  color: #5a5a5a;
  box-shadow: var(--shadow);
  font-size: 36px;
  line-height: 1;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.round-action-button {
  color: #565656;
}

.round-action-button--theme-active {
  color: #6f8fdd;
  background: #edf3ff;
  border-color: #d5e2ff;
  box-shadow: 0 0 0 6px rgba(111, 143, 221, 0.08), var(--shadow);
}

.add-pair-button:hover {
  transform: translateY(-1px);
  background: #f6f6f6;
}

.round-action-button:hover {
  transform: translateY(-1px);
  background: #f6f6f6;
}

body[data-theme="dark"] .round-action-button,
body[data-theme="dark"] .add-pair-button {
  background: #171d24;
  border-color: #2a3440;
  color: #d4dce6;
}

body[data-theme="dark"] .round-action-button:hover,
body[data-theme="dark"] .add-pair-button:hover {
  background: #1d252e;
}

.round-action-button--active {
  color: #e34c4c;
  background: #fff3f3;
  border-color: #ffd9d9;
}

.round-action-button--active .heart-shape {
  fill: currentColor;
}

.action-icon {
  width: 25px;
  height: 25px;
}

.transport-panel {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 170px;
  padding: 8px 9px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
}

body[data-theme="dark"] .transport-panel {
  background: #171d24;
  border-color: #2a3440;
}

.transport-panel__divider {
  width: 1px;
  align-self: stretch;
  background: #dddddd;
  opacity: 0.95;
}

body[data-theme="dark"] .transport-panel__divider {
  background: #34414f;
}

.tempo-panel__control {
  display: grid;
  grid-template-columns: 46px 20px;
  grid-template-rows: 18px 14px;
  grid-template-areas:
    "input increase"
    "unit decrease";
  column-gap: 3px;
  row-gap: 2px;
  align-items: center;
}

.tempo-panel__unit {
  grid-area: unit;
  justify-self: center;
  margin: 0;
  font-size: 10px;
  color: #6b6b6b;
  letter-spacing: 0.04em;
}

body[data-theme="dark"] .tempo-panel__unit,
body[data-theme="dark"] .pulse-panel__unit {
  color: var(--muted);
}

.tempo-input {
  grid-area: input;
  width: 46px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #282828;
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
  text-align: center;
  outline: none;
  appearance: textfield;
  -moz-appearance: textfield;
}

body[data-theme="dark"] .tempo-input,
body[data-theme="dark"] .pulse-input {
  color: #eef3f8;
}

.tempo-input::-webkit-outer-spin-button,
.tempo-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.round-action-button--playing {
  background: #eef4ff;
  border-color: #d6e2ff;
  color: #3964c3;
  box-shadow: 0 0 0 6px rgba(57, 100, 195, 0.08), var(--shadow);
}

body[data-theme="dark"] .round-action-button--playing {
  background: #1b2430;
  border-color: #37507a;
  color: #8fb1ff;
}

.round-action-button--paused {
  background: #f5f5f5;
  border-color: #dfdfdf;
  color: #525252;
  box-shadow: var(--shadow);
}

body[data-theme="dark"] .round-action-button--paused {
  background: #1b2128;
  border-color: #303a46;
  color: #d6dee7;
}

.play-button-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
}

.play-button-label svg {
  width: 22px;
  height: 22px;
}

.tempo-step-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid #dddddd;
  border-radius: 999px;
  background: #fbfbfb;
  color: #5f5f5f;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease;
}

#tempo-increase-button {
  grid-area: increase;
}

#tempo-decrease-button {
  grid-area: decrease;
}

.tempo-step-button:hover {
  transform: translateY(-1px);
  background: #ffffff;
}

body[data-theme="dark"] .tempo-step-button,
body[data-theme="dark"] .pulse-step-button {
  border-color: #36414e;
  background: #202833;
  color: #d2dae3;
}

body[data-theme="dark"] .tempo-step-button:hover,
body[data-theme="dark"] .pulse-step-button:hover {
  background: #27313c;
}

.pulse-panel__control {
  display: grid;
  grid-template-columns: 32px 20px;
  grid-template-rows: 18px 14px;
  grid-template-areas:
    "input increase"
    "unit decrease";
  column-gap: 3px;
  row-gap: 2px;
  align-items: center;
}

.pulse-input {
  grid-area: input;
  width: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #282828;
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
  text-align: center;
  outline: none;
}

.pulse-panel__unit {
  grid-area: unit;
  justify-self: center;
  margin: 0;
  font-size: 10px;
  color: #6b6b6b;
  letter-spacing: 0.04em;
}

.pulse-step-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid #dddddd;
  border-radius: 999px;
  background: #fbfbfb;
  color: #5f5f5f;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease;
}

#pulse-increase-button {
  grid-area: increase;
}

#pulse-decrease-button {
  grid-area: decrease;
}

.pulse-step-button:hover {
  transform: translateY(-1px);
  background: #ffffff;
}

.measure-grid {
  display: grid;
  grid-template-columns: repeat(var(--measure-grid-columns, 2), minmax(0, 1fr));
  gap: var(--measure-grid-gap, 18px);
  position: relative;
  align-items: start;
  transition: gap 180ms ease;
}

.measure-card {
  position: relative;
  padding: 16px 16px 18px;
  border-radius: 28px;
  background: var(--surface-strong);
  border: 1px solid #ededed;
  box-shadow: var(--shadow);
  zoom: var(--measure-card-zoom, 1);
  transition: zoom 180ms ease;
}

body[data-theme="dark"] .measure-card {
  border-color: #26313c;
}

.measure-card__header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.measure-card__eyebrow {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.measure-title {
  margin: 2px 0 0;
  font-size: 28px;
}

.measure-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  padding-right: 36px;
}

.measure-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid #e5e5e5;
  border-radius: 999px;
  background: #ffffff;
  color: #545454;
  box-shadow: 0 6px 18px rgba(24, 24, 24, 0.06);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease, border-color 140ms ease,
    color 140ms ease;
}

body[data-theme="dark"] .measure-icon-button {
  border-color: #2a3440;
  background: #171d24;
  color: #d0d7e0;
}

.measure-icon-button:hover {
  transform: translateY(-1px);
  background: #fafafa;
}

body[data-theme="dark"] .measure-icon-button:hover {
  background: #1d252e;
}

.measure-icon-button:disabled {
  opacity: 0.32;
  cursor: not-allowed;
  transform: none;
}

.measure-icon-button--armed {
  border-width: 2.5px;
  border-color: #46b265;
  background: #ffffff;
  color: #2b9850;
  box-shadow: 0 6px 18px rgba(24, 24, 24, 0.06);
}

.measure-icon-button--armed:hover {
  background: #ffffff;
  border-color: #389f56;
}

body[data-theme="dark"] .measure-icon-button--armed {
  border-width: 2.5px;
  border-color: #46b265;
  background: #171d24;
  color: #2b9850;
  box-shadow: 0 6px 18px rgba(24, 24, 24, 0.06);
}

body[data-theme="dark"] .measure-icon-button--armed:hover {
  background: #1d252e;
  border-color: #389f56;
  color: #2b9850;
}

.measure-icon-button--looping {
  border-width: 2.5px;
  border-color: #8c63ea;
  background: #ffffff;
  color: #7047c8;
  box-shadow: 0 6px 18px rgba(24, 24, 24, 0.06);
}

.measure-icon-button--looping:hover {
  background: #ffffff;
  border-color: #7e56df;
}

body[data-theme="dark"] .measure-icon-button--looping {
  border-width: 2.5px;
  border-color: #8c63ea;
  background: #171d24;
  color: #7047c8;
  box-shadow: 0 6px 18px rgba(24, 24, 24, 0.06);
}

body[data-theme="dark"] .measure-icon-button--looping:hover {
  background: #1d252e;
  border-color: #7e56df;
  color: #7047c8;
}

.measure-icon-button--danger {
  border-color: #e65b52;
  background: #e65b52;
  color: #ffffff;
  box-shadow: 0 10px 22px rgba(230, 91, 82, 0.22);
}

.measure-icon-button--danger:hover {
  background: #e1554b;
}

body[data-theme="dark"] .measure-icon-button--danger {
  border-color: #e65b52;
  background: #e65b52;
  color: #ffffff;
  box-shadow: 0 10px 22px rgba(230, 91, 82, 0.22);
}

body[data-theme="dark"] .measure-icon-button--danger:hover {
  background: #e1554b;
}

.measure-delete-button {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 22px;
  height: 22px;
  margin-left: 0;
  box-shadow: 0 5px 12px rgba(230, 91, 82, 0.18);
}

.measure-delete-button .measure-icon {
  width: 10px;
  height: 10px;
}

.measure-icon {
  width: 18px;
  height: 18px;
}

.measure-copy-button,
.measure-loop-button,
.measure-pulse-button {
  color: #4a4a4a;
}

.measure-copy-button.measure-icon-button--armed,
.measure-loop-button.measure-icon-button--looping {
  color: inherit;
}

.measure-delete-button {
  margin-left: 0;
}

.measure-pulse-button {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #282828;
}

body[data-theme="dark"] .measure-pulse-button {
  color: #eef3f8;
}

.notation-board {
  margin-top: 8px;
  min-height: 282px;
  overflow: hidden;
}

.notation-track {
  position: relative;
  width: calc(var(--cell-width) * 17 + var(--half-gap-extra));
  min-height: 266px;
  margin: 0 auto;
}

.playhead-dot {
  display: none;
}

.playhead-overlay-dot {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #3f77e0;
  box-shadow: 0 0 0 5px rgba(63, 119, 224, 0.12), 0 6px 16px rgba(63, 119, 224, 0.2);
  transform: translate(-50%, -50%);
  transition: opacity 120ms ease, box-shadow 180ms ease;
  will-change: left, top, opacity;
  opacity: 0;
  pointer-events: auto;
  cursor: grab;
  z-index: 20;
  --playhead-scale-value: var(--playhead-scale, 1);
}

.playhead-overlay-dot:active {
  cursor: grabbing;
}

.playhead-rail {
  position: absolute;
  left: 14px;
  right: 14px;
  top: 24px;
  height: 4px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: rgba(88, 180, 255, 0.14);
  pointer-events: auto;
  cursor: pointer;
  z-index: 3;
  transition: background 140ms ease, height 140ms ease;
}

.playhead-rail::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 18px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: transparent;
}

.playhead-rail:hover {
  background: rgba(88, 180, 255, 0.22);
  height: 12px;
}

.measure-bar {
  position: absolute;
  top: 70px;
  bottom: 0;
  width: 3px;
  background: #282828;
  border-radius: 999px;
}

.measure-bar--left {
  left: 0;
}

.measure-bar--right {
  right: 0;
}

.notation-grid {
  display: grid;
  grid-template-columns: repeat(8, var(--cell-width)) var(--half-gap-extra) repeat(8, var(--cell-width));
  justify-content: start;
  width: calc(var(--cell-width) * 16 + var(--half-gap-extra));
  min-height: 266px;
  margin: 0 auto;
}

.notation-cell {
  position: relative;
  width: var(--cell-width);
  min-height: 266px;
  border-radius: 14px;
}

.notation-cell--drop-target {
  background: rgba(0, 0, 0, 0.045);
}

.cross-mark {
  position: absolute;
  left: 50%;
  top: var(--timeline-top);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  line-height: 1;
  font-weight: 700;
  color: #282828;
}

body[data-theme="dark"] .cross-mark {
  color: #c3ccd6;
}

.subdivision-anchor-dot {
  position: absolute;
  left: 50%;
  top: calc(var(--timeline-top) + 11px);
  width: 3px;
  height: 3px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: rgba(40, 40, 40, 0.18);
  pointer-events: none;
}

body[data-theme="dark"] .subdivision-anchor-dot {
  background: rgba(195, 204, 214, 0.24);
}

.cross-mark--main {
  font-size: 26px;
}

.cross-mark--small {
  font-size: 14px;
  transform: translateX(-50%);
}

.cell-hit-area {
  position: absolute;
  inset: 0;
}

.measure-note {
  position: absolute;
  top: 0;
  left: 50%;
  width: 24px;
  height: 266px;
  transform: translateX(-50%);
  pointer-events: none;
}

.note-shape {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: filter 120ms ease, opacity 120ms ease;
  will-change: filter, opacity;
}

.measure-note--playing .note-shape {
  filter:
    brightness(1.05)
    drop-shadow(0 0 5px color-mix(in srgb, var(--note-glow, currentColor) 40%, transparent))
    drop-shadow(0 0 10px color-mix(in srgb, var(--note-glow, currentColor) 18%, transparent));
}

.measure-note--playing .note-shape__plus::before,
.measure-note--playing .note-shape__plus::after {
  box-shadow:
    0 0 6px color-mix(in srgb, var(--note-glow, currentColor) 46%, transparent),
    0 0 11px color-mix(in srgb, var(--note-glow, currentColor) 20%, transparent);
}

body[data-theme="dark"] .measure-note--playing .note-shape {
  filter:
    brightness(1.08)
    drop-shadow(0 0 6px color-mix(in srgb, var(--note-glow, currentColor) 48%, transparent))
    drop-shadow(0 0 12px color-mix(in srgb, var(--note-glow, currentColor) 22%, transparent));
}

body[data-theme="dark"] .measure-note--playing .note-shape__plus::before,
body[data-theme="dark"] .measure-note--playing .note-shape__plus::after {
  box-shadow:
    0 0 7px color-mix(in srgb, var(--note-glow, currentColor) 54%, transparent),
    0 0 13px color-mix(in srgb, var(--note-glow, currentColor) 24%, transparent);
}

.note-handle {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 999px;
  background: transparent;
  cursor: grab;
  pointer-events: auto;
}

.note-handle:active {
  cursor: grabbing;
}

.note-shape__line {
  display: none;
}

.note-shape__stem-svg {
  position: absolute;
  left: 50%;
  width: 6px;
  transform: translateX(-50%);
  pointer-events: none;
}

.note-shape__stem-svg svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.note-shape__stem-svg line {
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  shape-rendering: geometricPrecision;
  vector-effect: non-scaling-stroke;
}

.note-shape__head {
  position: absolute;
  left: 50%;
  width: 14px;
  height: 14px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: currentColor;
}

.note-shape__outline-circle {
  position: absolute;
  left: 50%;
  width: 14px;
  height: 14px;
  transform: translateX(-50%);
  border-radius: 999px;
  border: 3px solid currentColor;
}

.note-shape__diamond {
  position: absolute;
  left: 50%;
  width: 24px;
  height: 24px;
  transform: translateX(-50%) rotate(45deg);
  background: currentColor;
}

.note-shape__plus {
  position: absolute;
  left: 50%;
  width: 18px;
  height: 18px;
  transform: translateX(-50%);
}

.note-shape__plus::before,
.note-shape__plus::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: currentColor;
  border-radius: 999px;
}

.note-shape__plus::before {
  width: 18px;
  height: 3px;
}

.note-shape__plus::after {
  width: 3px;
  height: 18px;
}

.note-shape__x-cross {
  position: absolute;
  left: 50%;
  width: 22px;
  height: 22px;
  transform: translateX(-50%);
  pointer-events: none;
}

.note-shape__x-cross::before,
.note-shape__x-cross::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3px;
  height: 100%;
  transform-origin: center;
  background: currentColor;
  border-radius: 999px;
}

.note-shape__x-cross::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.note-shape__x-cross::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.note-shape__x-cross--palette {
  top: 16px;
  width: 20px;
  height: 20px;
}

.note-shape__x-cross--measure {
  top: 81px;
  width: 21px;
  height: 21px;
}

.note-shape__x-cross--measure-main {
  top: 79px;
  width: 21px;
  height: 21px;
}

.note-shape__x-cross--measure-small {
  top: 85px;
  width: 13px;
  height: 13px;
}

.note-shape__x-cross--measure-small::before,
.note-shape__x-cross--measure-small::after {
  width: 2.4px;
}

.note-shape__timeline-cross {
  color: currentColor;
}

.note-shape__ghost {
  position: absolute;
  left: 50%;
  width: 30px;
  height: 22px;
  transform: translateX(-50%);
  pointer-events: none;
}

.note-shape__ghost svg {
  display: block;
  width: 100%;
  height: 100%;
}

.note-shape__ghost path {
  fill: none;
  stroke: currentColor;
  stroke-width: 3.2;
  stroke-linecap: round;
}

.note-shape__ghost circle {
  fill: currentColor;
}

.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9999;
  width: 64px;
  height: 64px;
  padding: 8px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--surface-border);
  box-shadow: 0 16px 26px rgba(0, 0, 0, 0.12);
  pointer-events: none;
}

.drag-ghost .instrument-token__glyph {
  margin: 0 auto;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(16, 16, 16, 0.16);
  backdrop-filter: blur(8px);
  z-index: 1000;
}

#library-modal {
  z-index: 1000;
}

#save-modal,
#confirm-replace-modal,
#confirm-delete-modal {
  z-index: 1010;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: min(100%, 440px);
  max-height: calc(100vh - 48px);
  padding: 22px;
  display: flex;
  flex-direction: column;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--surface-border);
  box-shadow: 0 24px 60px rgba(24, 24, 24, 0.18);
  overflow: hidden;
}

body[data-theme="dark"] .modal-card {
  background: rgba(18, 25, 32, 0.96);
  border-color: #2a3440;
}

.modal-card--wide {
  width: min(100%, 620px);
  position: relative;
}

.modal-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-card__header--library {
  min-height: 24px;
  padding-right: 0;
  align-items: center;
}

.modal-title {
  margin: 0;
  font-size: 28px;
}

.modal-card__header--library .modal-title {
  font-size: 21px;
  line-height: 1;
  margin-top: -2px;
  margin-left: 18px;
}

.modal-text {
  margin: 14px 0 0;
  color: #4f4f4f;
}

body[data-theme="dark"] .modal-text {
  color: var(--muted);
}

.modal-form {
  margin-top: 18px;
}

.modal-input {
  width: 100%;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid var(--surface-border);
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  outline: none;
}

body[data-theme="dark"] .modal-input {
  background: #141b22;
  border-color: #2a3440;
  color: #eef3f8;
}

.modal-input:focus {
  border-color: #cfcfcf;
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.04);
}

.modal-input--error {
  border-color: #e16a6a;
  box-shadow: 0 0 0 4px rgba(225, 106, 106, 0.08);
}

.modal-error {
  margin-top: 10px;
  color: #d34d4d;
  font-size: 13px;
}

.modal-inline-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.modal-primary-button,
.modal-secondary-button,
.library-load-button {
  padding: 12px 18px;
  border-radius: 999px;
}

.modal-primary-button {
  background: #3f77e0;
  color: #ffffff;
}

.modal-primary-button:hover {
  background: #3066c9;
}

#logout-button {
  background: #3f77e0;
  color: #ffffff;
}

#logout-button:hover {
  background: #3066c9;
}

.modal-primary-button--danger {
  background: #e35a52;
  color: #ffffff;
}

.modal-secondary-button,
.library-load-button {
  background: #efefef;
  color: #171717;
}

body[data-theme="dark"] .modal-secondary-button,
body[data-theme="dark"] .library-load-button {
  background: #1d252e;
  color: #e3eaf2;
}

.modal-close-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 999px;
  background: #e65b52;
  color: #ffffff;
  font-size: 16px;
  line-height: 1;
  box-shadow: 0 5px 12px rgba(230, 91, 82, 0.18);
}

.modal-close-button:hover {
  background: #de5349;
}

body[data-theme="dark"] .modal-close-button {
  background: #e65b52;
  color: #ffffff;
  box-shadow: 0 5px 12px rgba(230, 91, 82, 0.18);
}

body[data-theme="dark"] .modal-close-button:hover {
  background: #de5349;
}

button:focus,
button:focus-visible,
.library-item:focus,
.library-item:focus-visible {
  outline: none;
}

button::-moz-focus-inner {
  border: 0;
}

.modal-card__header--library .modal-close-button {
  position: absolute;
  top: 22px;
  right: 22px;
  z-index: 2;
}

.library-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
  min-height: 0;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-right: 6px;
}

.library-toolbar {
  position: absolute;
  top: 22px;
  right: 68px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: nowrap;
}

.library-toolbar__button {
  min-height: 20px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.library-empty {
  padding: 20px 4px 6px;
  color: #6a6a6a;
}

body[data-theme="dark"] .library-empty {
  color: var(--muted);
}

.library-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-radius: 22px;
  background: #f7f7f7;
  border: 1px solid #ececec;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

body[data-theme="dark"] .library-item {
  background: #141b22;
  border-color: #2a3440;
}

.library-item:hover {
  transform: translateY(-1px);
  background: #fafafa;
  box-shadow: 0 8px 18px rgba(24, 24, 24, 0.06);
}

body[data-theme="dark"] .library-item:hover {
  background: #1a222b;
}

.library-item:focus-visible {
  box-shadow: 0 8px 18px rgba(24, 24, 24, 0.06);
}

.library-item__meta {
  min-width: 0;
}

.library-item__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.library-item__name {
  font-size: 18px;
  font-weight: 600;
  color: #191919;
}

body[data-theme="dark"] .library-item__name {
  color: #eef3f8;
}

.library-item__details {
  margin-top: 4px;
  color: #6a6a6a;
  font-size: 13px;
}

body[data-theme="dark"] .library-item__details {
  color: var(--muted);
}

.library-delete-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #fff1f1;
  color: #d34d4d;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease;
}

.library-delete-button:hover {
  transform: translateY(-1px);
  background: #ffe5e5;
}

.library-load-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #efefef;
  color: #666666;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease;
}

.library-load-button:hover {
  transform: translateY(-1px);
  background: #e4e4e4;
}

body[data-theme="dark"] .library-load-button:hover {
  background: #27313b;
}

.library-export-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #eef5ff;
  color: #5a7db8;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease;
}

body[data-theme="dark"] .library-export-button {
  background: #1a2637;
  color: #83a7e0;
}

.library-export-button:hover {
  transform: translateY(-1px);
  background: #e1edff;
}

body[data-theme="dark"] .library-export-button:hover {
  background: #213249;
}

.library-export-icon {
  width: 24px;
  height: 24px;
  display: block;
}

@media (max-width: 1280px) and (min-width: 861px) {
  .page-header {
    grid-template-columns: auto auto;
  }

  .toolbar-stack {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

@media (max-width: 860px) {
  :root {
    --cell-width: 18px;
    --half-gap-extra: calc(var(--cell-width) * 0.7);
  }

  body.is-dragging {
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
  }

  .app-shell {
    padding: 10px 10px 184px;
  }

  .measure-card__header {
    flex-direction: row;
    align-items: flex-start;
  }

  .page-header {
    position: sticky;
    top: 0;
    display: block;
    min-height: 64px;
    margin: 0 0 10px;
    padding: 8px 0;
  }

  .toolbar-stack {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 90;
    width: 100%;
    padding: 7px 9px calc(7px + env(safe-area-inset-bottom));
    gap: 6px;
    flex-direction: column;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    border-top: 1px solid var(--surface-border);
    box-shadow: 0 -12px 28px rgba(24, 24, 24, 0.08);
    backdrop-filter: blur(18px) saturate(1.05);
    -webkit-backdrop-filter: blur(18px) saturate(1.05);
  }

  .header-actions {
    position: static;
    width: 100%;
    justify-content: flex-end;
    transform: none;
  }

  .header-actions .round-action-button {
    width: 44px;
    height: 44px;
  }

  .mobile-view-button {
    display: inline-flex;
  }

  .mobile-undo-button {
    display: inline-flex;
    margin-right: auto;
  }

  .measure-grid {
    grid-template-columns: repeat(var(--measure-grid-columns, 1), minmax(0, 1fr));
    gap: var(--measure-grid-gap, 14px);
  }

  .measure-grid[data-view="1"] {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 0 2px 8px;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .measure-grid[data-view="1"]::-webkit-scrollbar {
    display: none;
  }

  .measure-grid[data-view="1"] .measure-card {
    flex: 0 0 calc(100% - 4px);
    scroll-snap-align: center;
    scroll-snap-stop: always;
  }

  .measure-grid[data-view="4"],
  .measure-grid[data-view="16"] {
    display: grid;
    overflow: visible;
    padding: 0;
  }

  .measure-card {
    zoom: var(--measure-card-zoom, 1);
  }

  .header-audio-controls {
    position: fixed;
    right: 10px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    z-index: 92;
    width: 158px;
    gap: 4px;
    justify-content: flex-end;
    margin: 0;
  }

  .transport-panel {
    min-width: 110px;
    padding: 4px 5px;
    gap: 3px;
    border-radius: 16px;
  }

  .toolbar--lower,
  .toolbar--upper {
    min-width: unset;
    padding: 4px 5px;
    border-radius: 18px;
    box-shadow: none;
  }

  .toolbar--lower {
    width: 100%;
  }

  .toolbar--upper {
    align-self: flex-start;
    width: calc(100% - 166px);
  }

  .instrument-bar {
    flex-wrap: nowrap;
    gap: 1px;
    justify-content: space-evenly;
  }

  .instrument-token,
  .toolbar--lower .instrument-token {
    flex: 1 1 0;
    min-width: 0;
    min-height: 56px;
    padding: 1px 0;
    gap: 2px;
    touch-action: none;
  }

  .toolbar--lower .instrument-token {
    min-height: 62px;
  }

  .instrument-token__glyph {
    width: 22px;
    height: 42px;
    transform: scale(0.82);
    transform-origin: center;
  }

  .instrument-token__text,
  .toolbar--lower .instrument-token__text {
    max-width: 48px;
    font-size: 7px;
    line-height: 1.1;
    white-space: nowrap;
  }

  .toolbar--upper .instrument-token__glyph {
    height: 35px;
  }

  .toolbar--upper .instrument-token__text {
    font-size: 7px;
  }

  .header-audio-controls .round-action-button {
    width: 42px;
    height: 42px;
  }

  .header-audio-controls .play-button-label,
  .header-audio-controls .play-button-label svg {
    width: 18px;
    height: 18px;
  }

  .tempo-panel__control {
    grid-template-columns: 32px 16px;
    grid-template-rows: 15px 11px;
    column-gap: 1px;
    row-gap: 0;
  }

  .pulse-panel__control {
    grid-template-columns: 22px 16px;
    grid-template-rows: 15px 11px;
    column-gap: 1px;
    row-gap: 0;
  }

  .tempo-input,
  .pulse-input {
    width: auto;
    font-size: 14px;
  }

  .tempo-panel__unit,
  .pulse-panel__unit {
    font-size: 7px;
  }

  .tempo-step-button,
  .pulse-step-button {
    width: 16px;
    height: 16px;
    font-size: 7px;
  }

  .note-handle {
    touch-action: none;
  }

  .notation-track {
    margin: 0 auto;
  }
}
