:root {
  color-scheme: light;
  --ink: #202225;
  --muted: #68707a;
  --line: #d7dce2;
  --paper: #fbfaf6;
  --surface: #f0f4f7;
  --panel: #ffffff;
  --accent: #2563a8;
  --accent-dark: #184677;
  --blue: #2563a8;
  --shadow: 0 18px 44px rgba(32, 34, 37, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: auto;
  color: var(--ink);
  background: var(--surface);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

input {
  color: inherit;
}

.app {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #e8edf0;
  overflow-y: auto;
}

.brand {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 4px;
  order: 0;
}

.quick-tools {
  display: grid;
  grid-template-columns: repeat(2, 42px);
  gap: 8px;
  order: 1;
}

.sidebar .panel:nth-of-type(3) {
  order: 1;
}

.sidebar .panel:nth-of-type(6) {
  order: 7;
}

.sidebar .panel:nth-of-type(4) {
  order: 3;
}

.sidebar .panel:nth-of-type(1) {
  order: 4;
}

.sidebar .panel:nth-of-type(2) {
  order: 5;
}

.sidebar .panel:nth-of-type(5) {
  order: 6;
}

.sidebar .panel:nth-of-type(7) {
  order: 2;
}

.sidebar .panel:nth-of-type(8) {
  order: 8;
}

.sidebar .panel:nth-of-type(9) {
  order: 9;
}

.sidebar .panel:nth-of-type(10) {
  order: 10;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  font-weight: 800;
  font-size: 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 23px;
  line-height: 1.05;
  letter-spacing: 0;
}

.brand p,
.hint {
  color: var(--muted);
}

.panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(32, 34, 37, 0.05);
}

.panel h2 {
  margin-bottom: 12px;
  font-size: 13px;
  text-transform: uppercase;
  color: #4f5963;
}

.tool-grid {
  display: grid;
  gap: 8px;
}

.figure-grid {
  grid-template-columns: repeat(4, 42px);
  gap: 7px;
}

.edit-grid {
  grid-template-columns: repeat(4, 48px);
}

.clef-grid {
  grid-template-columns: repeat(3, 42px);
  gap: 7px;
}

.time-grid {
  grid-template-columns: repeat(4, 42px);
  gap: 7px;
  margin-top: 10px;
}

.accidental-grid {
  grid-template-columns: repeat(5, 42px);
  gap: 7px;
}

.bar-grid {
  grid-template-columns: repeat(4, 42px);
  gap: 7px;
}

.modifier-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.edit-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.tool-button,
.icon-command {
  display: grid;
  place-items: center;
  width: 48px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
  font-weight: 800;
}

.figure-button {
  width: 42px;
  height: 42px;
  padding: 0;
}

.modifier-button {
  width: 42px;
  height: 34px;
  padding-bottom: 8px;
  font-size: 28px;
  line-height: 1;
}

.time-button {
  width: 42px;
  height: 34px;
  padding: 0;
  font-size: 13px;
}

.bar-button {
  width: 42px;
  height: 34px;
  padding: 0;
  font-size: 15px;
}

.quick-tool-button {
  width: 42px;
  height: 34px;
  padding: 0;
  font-size: 14px;
}

.time-command {
  width: 100%;
  margin-top: 10px;
}

.time-controls,
.key-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.time-field {
  display: grid;
  gap: 5px;
  color: #434b54;
  font-size: 12px;
}

.time-field select {
  width: 100%;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  padding: 0 8px;
}

.music-symbol {
  display: block;
  width: auto;
  line-height: 1;
  font-family: Bravura, "Noto Music", "Segoe UI Symbol", "Apple Symbols", "Arial Unicode MS", serif;
  font-size: 28px;
  font-weight: 400;
  text-align: center;
}

.clef-symbol {
  font-size: 30px;
}

.accidental-symbol {
  font-size: 30px;
}

.tool-button:hover,
.icon-command:hover,
.command:hover {
  border-color: #a9b4be;
}

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

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

.field,
.toggle {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  color: #434b54;
  font-size: 14px;
}

.toggle {
  grid-template-columns: 18px 1fr;
  align-items: center;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.actions,
.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.command {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #fff;
  background: var(--blue);
  cursor: pointer;
  font-weight: 700;
}

.actions .command:last-child {
  background: #8b3c42;
}

.hint {
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.45;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 100vh;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 520px) minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.score-heading {
  display: grid;
  grid-column: 2;
  gap: 3px;
  min-width: 180px;
  max-width: 520px;
}

.piece-title,
.piece-subtitle {
  width: 100%;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  outline: 0;
  padding: 1px 0;
  text-align: center;
}

.piece-title {
  font-size: 19px;
  font-weight: 800;
  line-height: 1.15;
}

.piece-subtitle {
  font-size: 14px;
  color: var(--muted);
  text-align: right;
}

.piece-title:focus,
.piece-subtitle:focus {
  border-bottom-color: var(--accent);
}

.top-tools {
  display: flex;
  grid-column: 3;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  min-width: 0;
}

.canvas-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 24px;
  overflow: auto;
  background:
    linear-gradient(90deg, rgba(32, 34, 37, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(32, 34, 37, 0.04) 1px, transparent 1px),
    #dfe6ea;
  background-size: 28px 28px;
}

#scoreCanvas {
  display: block;
  width: 1120px;
  height: 1500px;
  border-radius: 4px;
  background: var(--paper);
  box-shadow: var(--shadow);
  touch-action: none;
  cursor: crosshair;
}

.canvas-text-editor {
  position: absolute;
  z-index: 2;
  height: 30px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1;
  padding: 2px 5px;
  outline: 0;
  box-shadow: 0 6px 16px rgba(32, 34, 37, 0.14);
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(620px, 1fr);
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .edit-grid {
    grid-template-columns: repeat(7, 42px);
  }

  .figure-grid {
    grid-template-columns: repeat(7, 42px);
  }

  .clef-grid {
    grid-template-columns: repeat(3, 42px);
  }

  .tool-button,
  .icon-command {
    width: 42px;
  }

  .topbar {
    display: flex;
    align-items: flex-start;
    flex-direction: column;
  }

  .score-heading,
  .top-tools {
    width: 100%;
    max-width: none;
  }

  .top-tools {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .canvas-wrap {
    padding: 12px;
  }
}
