:root {
  color-scheme: light;
  --page: #f7f2e8;
  --text: #30372f;
  --muted: #596456;
  --surface: #fffdf8;
  --menu: rgba(245, 244, 241, 0.96);
  --border: #c8cabc;
  --hover: #eaece3;
  --pressed: #dbe1d3;
  --accent: #456747;
  --accent-text: #ffffff;
  --focus: #3478f6;
  --splitter: #d2c5ac;
  --splitter-hover: #8f7f61;
  --shadow: rgba(24, 32, 24, 0.2);
  --toast: #30372f;
  --toast-text: #fffdf8;
  --octave-filter: none;
  --syntax-chord: #8b3eb0;
  --syntax-pitch: #006a9b;
  --syntax-separator: #a34c14;
}

.chord-suggestions {
  position: fixed;
  z-index: 1100;
  min-width: 7rem;
  max-height: 12rem;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 4px 12px var(--shadow);
  font: 14px/1.5 monospace;
}
.chord-suggestions [role="option"] { padding: 2px 10px; cursor: pointer; }
.chord-suggestions [aria-selected="true"],
.chord-suggestions [role="option"]:hover { background: var(--pressed); }

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #1c211e;
  --text: #eceee4;
  --muted: #b6c0b2;
  --surface: #272e29;
  --menu: rgba(36, 40, 36, 0.96);
  --border: #667363;
  --hover: #333e34;
  --pressed: #435244;
  --accent: #b0cf9e;
  --accent-text: #1c211e;
  --focus: #adc8ff;
  --splitter: #414c42;
  --splitter-hover: #829b78;
  --shadow: rgba(0, 0, 0, 0.4);
  --toast: #eceee4;
  --toast-text: #1c211e;
  --octave-filter: invert(1);
  --syntax-chord: #d9a5f2;
  --syntax-pitch: #80d4f5;
  --syntax-separator: #ffc08b;
}

html {
  background: var(--page);
  padding: 0;
  margin: 0;
  color: var(--text);
  font-size: 25px;
  --main-font: 'Noto Sans SC', sans-serif;
  --menu-bar-height: 36px;
  font-family: var(--main-font);
}

h1 {
  font-size: 1.5rem;
  padding: 0;
  margin: 0;
  font-weight: bold;
}

label {
  user-select: none;
}

#chord-diagrams {
  margin-top: 1rem;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}

tab-maker-chord-diagram {
  transform: scale(0.9, 0.9);
}

#tab-body {
  font-size: calc(1rem * var(--tab-text-scale, 1));
}

#tab-body section {
  margin: 1em 0;
}

tab-maker-block {
  display: inline-block;
  margin: 0 0.1em;
}

tab-maker-measure {
  border-right: solid 2px var(--border);
  margin: .5em 0;
  padding: 0 .5em;
  display: inline-flex;
  min-width: 4em;
  flex-direction: row;
  align-items: flex-start;
  transition: background 1s;
  user-select: none;
}

tab-maker-measure:first-of-type {
  border-left: solid 2px var(--border);
}

tab-maker-measure:hover {
  background-color: var(--hover);
}

.tab-verse { margin: 1em 0; }
#tab-body .tab-line {
  display: grid;
  grid-template-columns: var(--measure-columns, minmax(0, 1fr));
  row-gap: 1em;
  margin: 1em 0;
}
.tab-line > tab-maker-measure {
  box-sizing: border-box;
  min-width: 0;
  margin: 0;
  flex-wrap: wrap;
  border-left: 0;
}
.tab-line > .measure-row-start { border-left: solid 2px var(--border); }
.tab-line tab-maker-block { max-width: calc(100% - 0.2em); overflow-wrap: anywhere; }
.tab-verse.measuring .tab-line { display: block; }
.tab-verse.measuring tab-maker-measure {
  display: inline-flex;
  width: max-content;
  min-width: 4em;
  flex-wrap: nowrap;
  border-left: solid 2px var(--border);
}
.tab-verse.measuring tab-maker-block { max-width: none; flex-shrink: 0; }
.tab-lyrics > tab-maker-measure {
  display: flex;
  flex-wrap: wrap;
  min-width: 0;
  border: 0;
  padding: 0;
  margin: 0;
}
.tab-lyrics tab-maker-block { max-width: 100%; overflow-wrap: anywhere; }

.tab-info {
  margin: .5rem;
  padding-top: 12px;
}

.tab-info ul {
  list-style: none;
  display: flex;
  flex-direction: row;
  align-items: center;
  margin: 0;
  padding: 0;
}

.tab-info ul li {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-right: 1rem;
}

.tab-info ul li:has(#key-select) {
  flex-wrap: wrap;
}

#capo-position {
  margin-inline-start: 0.25rem;
  color: var(--text);
  white-space: nowrap;
}

#key-select {
  background-color: var(--page);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.1rem 0.25rem;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

#key-select:hover {
  background-color: var(--hover);
  border-color: var(--border);
}

#tab-root {
  background-color: var(--page);
  overflow-y: scroll;
  padding: .25rem .5rem;
  min-width: 0;
}

#tab-script, #script-highlight {
  display: block;
  font-family: 'Sarasa Mono SC', 'Noto Sans Mono CJK SC', 'Noto Sans Mono CJK TC', 'Source Han Mono SC', 'Source Han Mono', Consolas, Menlo, 'DejaVu Sans Mono', 'NSimSun', 'MS Gothic', 'MingLiU', monospace;
  resize: none;
  line-height: 1.5;
  font-size: 16px;
  font-weight: normal;
  letter-spacing: normal;
  tab-size: 4;
  padding: 10px;
  margin: 0;
  border: 0;
  white-space: pre;
  overflow: scroll;
  width: 100%;
  height: 100%;
  min-height: 0;
  box-sizing: border-box;
}

.script-source {
  position: relative;
  min-height: 0;
  min-width: 0;
}

#script-highlight {
  position: absolute;
  inset: 0;
  pointer-events: none;
  color: var(--text);
}

#tab-script {
  position: relative;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
}

#tab-script::selection {
  background: var(--pressed);
  color: var(--text);
}

.syntax-chord { color: var(--syntax-chord); }
.syntax-pitch { color: var(--syntax-pitch); }
.syntax-separator { color: var(--syntax-separator); }

.editor-toolbar {
  display: flex;
  gap: 6px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}

.editor-toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-size: 14px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

.editor-toolbar button:hover { background: var(--hover); }
#split-lyrics, #dump-tab-data { width: auto; padding-inline: 10px; }
.editor-toolbar button:focus-visible { outline: 2px solid var(--focus); }
.editor-toolbar svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (forced-colors: active) {
  #tab-script { color: CanvasText; }
  #script-highlight { visibility: hidden; }
}

#tab-script.hidden {
  display: none;
}

button, input, select {
  font-family: var(--main-font);
  font-size: 1rem;
  color: var(--text);
}

input, select, textarea {
  border: var(--border) solid 1px;
  border-radius: 0;
  background-color: var(--surface);
  color: var(--muted);
  font-size: 1rem;
}

.landing {
  display: none;
  width: 100%;
  max-width: 580px;
  margin: 0 auto;
  padding: 48px 24px 32px;
  box-sizing: border-box;
  font-size: 16px;
}

.landing-active .landing { display: block; }
.landing-active .tab-info,
.landing-active #tab-body { display: none; }
.landing h1 { font-size: 28px; font-weight: 500; margin: 0 0 10px; }
.landing p { font-size: 14px; color: var(--muted); margin: 0 0 25px; }
.landing-search {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  margin-bottom: 25px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted);
}
.landing-search > span { font-size: 24px; }
.landing-search input {
  width: 100%;
  min-width: 0;
  border: 0;
  padding: 13px 0;
  background: transparent;
  color: var(--text);
  font: inherit;
}
.landing-search input::placeholder { color: var(--muted); opacity: 1; }
.landing-list-heading { display: flex; justify-content: space-between; padding-bottom: 10px; font-size: 12px; color: var(--muted); }
.landing-songs { margin: 0; padding: 0; list-style: none; }
.landing-songs button {
  width: 100%;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 4px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.landing-songs button:hover { background: var(--hover); }
.landing-songs button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.landing-songs small { display: block; font-size: 12px; color: var(--muted); margin-top: 5px; }
.landing-songs button > span:last-child { color: var(--accent); }
@media (max-width: 768px) {
  .landing { padding: 32px 12px 24px; }
  .landing h1 { font-size: 25px; }
}

.root {
  --editor-width: 38vw;
  position: absolute;
  left: 0;
  right: 0;
  top: var(--menu-bar-height);
  bottom: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 8px minmax(18rem, var(--editor-width));
  grid-template-rows: minmax(0, 1fr);
}

.editor {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
}

.root.editor-closed {
  grid-template-columns: minmax(0, 1fr) 0 0;
}

.root.editor-closed .editor,
.root.editor-closed #editor-splitter {
  display: none;
}

#editor-splitter {
  background: var(--splitter);
  cursor: col-resize;
  transition: background 0.15s ease;
}

#editor-splitter:hover,
body.resizing-editor #editor-splitter {
  background: var(--splitter-hover);
}

body.resizing-editor {
  cursor: col-resize;
  user-select: none;
}

/* Compact menu bar inspired by macOS. */
.tabs-menu-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--menu-bar-height);
  box-sizing: border-box;
  padding: 0 8px;
  z-index: 1000;
  display: flex;
  gap: 2px;
  align-items: center;
  background: var(--menu);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--pressed);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.tabs-menu-toggle {
  background: transparent;
  color: var(--text);
  padding: 4px 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  font-size: 14px;
  line-height: 20px;
  white-space: nowrap;
  transition: background-color 0.15s ease;
}

.tabs-menu-brand {
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-right: 8px;
  color: var(--accent);
  font-family: 'Fredoka', 'Noto Sans SC', sans-serif;
  font-size: 21px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.tabs-menu-brand:hover { background: var(--hover); }
.tabs-menu-brand:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.tabs-menu-brand img {
  display: block;
  object-fit: contain;
}

.tabs-menu-toggle:hover {
  background-color: var(--hover);
}

.tabs-menu-toggle:active,
.tabs-menu-toggle[aria-pressed="true"] {
  background-color: var(--pressed);
}

.tabs-menu-toggle:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.tabs-menu-toggle:disabled {
  opacity: 0.4;
  cursor: default;
  background: transparent;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  z-index: 1100;
  transform: translate(-50%, 0.5rem);
  padding: 0.45rem 0.8rem;
  border-radius: 4px;
  background: var(--toast);
  color: var(--toast-text);
  font-size: 0.8rem;
  line-height: 1.2;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Keep the desktop score size, but fit controls and notation on phones. */
@media (max-width: 768px) {
  html {
    font-size: 14px;
    --menu-bar-height: 44px;
  }

  /* Keep text fields readable and avoid automatic zoom when focused on phones. */
  input, select, textarea {
    font-size: 16px;
  }

  .root {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }

  .root.editor-closed {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  #editor-splitter {
    display: none;
  }

  .editor {
    border-top: 1px solid var(--splitter);
  }

  .tabs-menu-toggle {
    padding: 10px 6px;
    min-height: 44px;
  }

  .tabs-menu-brand {
    min-height: 44px;
    min-width: 44px;
    justify-content: center;
    gap: 4px;
    margin-right: 4px;
    font-size: 18px;
  }

  .tabs-menu-brand img {
    width: 26px;
    height: 26px;
  }

.tab-info {
    margin: .25rem;
    padding-top: 8px;
  }

  .tab-info ul {
    flex-wrap: wrap;
    gap: .5rem 1rem;
    align-items: center;
  }

  .tab-info ul li {
    margin-right: 0;
  }
}

@media (max-width: 480px) {
  html {
    --menu-bar-height: 88px;
  }

  .tabs-menu-header {
    flex-wrap: wrap;
    align-content: center;
    row-gap: 0;
  }

  .tabs-menu-brand span {
    display: none;
  }
}

input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}
