/* Layout: a song list on the left, a ruled chart sheet on the right. Every bar is one equal grid cell, so chords can never drift out of line. */
:root {
  --bg: #eef2ee;
  --paper: #fbfcfa;
  --ink: #12241b;
  --muted: #5a6c62;
  --line: #cdd8d0;
  --bar: #2b4a3b;
  --accent: #b3261e;
  --accent-ink: #ffffff;
  --focus: #f6e3df;
  --font-display: 'Newsreader', Georgia, serif;
  --font-body: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1913; --paper: #14241b; --ink: #e7f0e9; --muted: #93a89b; --line: #2a4136;
    --bar: #8fb5a0; --accent: #f08a80; --accent-ink: #2a0f0c; --focus: #3a2623;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1913; --paper: #14241b; --ink: #e7f0e9; --muted: #93a89b; --line: #2a4136;
  --bar: #8fb5a0; --accent: #f08a80; --accent-ink: #2a0f0c; --focus: #3a2623;
  color-scheme: dark;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  margin: 0;
  padding-block: 24px 56px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  max-width: 1080px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

/* Song list */
.book { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.book-title {
  width: 100%;
  box-sizing: border-box;
  background: transparent;
  border: 0;
  border-bottom: 1px solid transparent;
  padding: 2px 0;
  font-family: var(--font-display);
  font-size: 26px;
  line-height: 1.2;
  font-weight: 500;
  text-wrap: balance;
}
.book-title:hover, .book-title:focus { border-bottom-color: var(--line); outline: none; }
.count { margin: 0; color: var(--muted); font-size: 13px; letter-spacing: 0.02em; }
.songs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.song {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 8px 10px;
  overflow-wrap: anywhere;
}
.song:hover { background: var(--paper); }
.song[aria-current="true"] {
  background: var(--paper);
  border-color: var(--line);
  font-weight: 600;
  color: var(--accent);
}

/* Buttons */
.btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 12px;
  line-height: 1.3;
}
.btn:hover { border-color: var(--bar); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.quiet { border-color: transparent; color: var(--muted); }
.btn.quiet:hover { color: var(--accent); border-color: var(--line); }
.btn.square { min-width: 36px; padding-inline: 0; font-family: var(--font-mono); font-size: 16px; }

/* Chart sheet */
.sheet {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 28px;
  min-width: 0;
}
.song-title {
  width: 100%;
  box-sizing: border-box;
  background: transparent;
  border: 0;
  border-bottom: 1px solid transparent;
  padding: 0;
  font-family: var(--font-display);
  font-size: 40px;
  line-height: 1.15;
  font-weight: 500;
  font-style: italic;
  text-wrap: balance;
}
.song-title:hover, .song-title:focus { border-bottom-color: var(--line); outline: none; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-top: 14px; }
.tool-group { display: flex; align-items: center; gap: 6px; }
.tool-label { color: var(--muted); font-size: 13px; letter-spacing: 0.04em; text-transform: uppercase; margin-right: 4px; }
.hint { color: var(--muted); font-size: 13px; margin: 14px 0 0; max-width: 62ch; }

.export {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.export p { margin: 0; color: var(--muted); font-size: 13px; max-width: 62ch; }
.export textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 190px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px;
  white-space: pre;
  overflow: auto;
}
.export-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Sections */
.section { margin-top: 34px; }
.sec-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 12px; }
.sec-name {
  flex: 1 1 140px;
  min-width: 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid transparent;
  padding: 2px 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--bar);
}
.sec-name:hover, .sec-name:focus { border-bottom-color: var(--line); outline: none; }
.per { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.per select {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 6px;
}
.scroller { overflow-x: auto; padding-bottom: 4px; }
.rows { display: flex; flex-direction: column; gap: 8px; min-width: calc(var(--cols) * 64px + 44px); }
.row { display: flex; align-items: stretch; gap: 8px; }
.cells {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  border-right: 2px solid var(--bar);
}
.chord {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  text-align: center;
  background: transparent;
  border: 0;
  border-left: 2px solid var(--bar);
  border-radius: 0;
  padding: 14px 4px;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 22px;
  line-height: 1.2;
  color: var(--ink);
}
.chord.hold { color: var(--muted); }
.chord:hover { background: var(--bg); }
.chord:focus { outline: none; background: var(--focus); box-shadow: inset 0 0 0 2px var(--accent); }
.x {
  width: 32px;
  flex: none;
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  opacity: 0.6;
}
.x:hover { opacity: 1; color: var(--accent); background: var(--bg); }
.empty-rows { color: var(--muted); margin: 0 0 8px; }
.add-row { margin-top: 10px; }
.add-section { margin-top: 30px; }

.empty { padding: 48px 12px; color: var(--muted); }
.empty h2 { font-family: var(--font-display); font-weight: 500; font-size: 26px; margin: 0 0 6px; color: var(--ink); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 4px;
  padding: 8px 8px 8px 14px;
  font-size: 14px;
  z-index: 20;
  max-width: calc(100vw - 32px);
}
.toast button {
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 3px 10px;
}

@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .songs { flex-direction: row; flex-wrap: wrap; }
  .song { width: auto; border-color: var(--line); }
  .sheet { padding: 18px 14px; }
  .song-title { font-size: 32px; }
  .chord { font-size: 19px; padding-block: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
[hidden] { display: none !important; }