*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f11;
  --surface: #1a1a1f;
  --surface2: #25252d;
  --border: #2e2e38;
  --accent: #7c6af7;
  --accent-dim: #5a4fd6;
  --text: #e8e8f0;
  --text-dim: #8888aa;
  --green: #4ade80;
  --yellow: #facc15;
  --red: #f87171;
  --radius: 10px;
  --font-mono: "Fira Code", "Cascadia Code", "JetBrains Mono", Menlo, monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  padding: 2rem 1rem;
}

.container {
  max-width: 860px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.site-logo {
  display: block;
  width: 100%;        /* full-width on mobile */
  max-width: 480px;   /* cap on wider screens (covers all phones, ~256 px tall) */
  height: auto;
  margin: 0 auto .3rem;
  /* Blend the black logo background seamlessly into the page */
  mix-blend-mode: lighten;
}

.subtitle {
  color: var(--text-dim);
  margin-top: 0;
  font-size: .95rem;
}

/* Search mode toggle */
.search-mode-toggle {
  display: flex;
  margin-bottom: .7rem;
  width: fit-content;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.mode-btn {
  padding: .4rem 1.1rem;
  background: var(--surface);
  border: none;
  color: var(--text-dim);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s, background .15s;
}

.mode-btn + .mode-btn {
  border-left: 1px solid var(--border);
}

.mode-btn:hover { color: var(--text); background: var(--surface2); }

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

/* Form */
.input-row {
  display: flex;
  gap: .6rem;
}

/* Name-search fields: artist above, title+button below */
.name-fields {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

input[type="url"],
.name-fields input[type="text"] {
  padding: .75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .2s;
}

input[type="url"]:focus,
.name-fields input[type="text"]:focus {
  border-color: var(--accent);
}

/* flex: 1 only inside row-flex input-row — NOT on the standalone artist input */
.input-row input[type="url"],
.input-row input[type="text"] {
  flex: 1;
}

button[type="submit"] {
  padding: .75rem 1.5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
}

button[type="submit"]:hover { background: var(--accent-dim); }
button[type="submit"]:active { transform: scale(.97); }
button[type="submit"]:disabled { opacity: .5; cursor: not-allowed; }

/* Progress */
.progress {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 2rem;
  padding: 1.2rem 1.5rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

#progress-text { color: var(--text-dim); font-size: .95rem; }

/* Result */
.result {
  margin-top: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.song-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.song-header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.song-header h2 { font-size: 1.05rem; color: var(--text-dim); font-weight: 500; }
.song-header h3 { font-size: 1.5rem; font-weight: 700; margin-top: .2rem; }

.badges {
  display: flex;
  gap: .5rem;
  margin-top: .8rem;
  flex-wrap: wrap;
}

.badge {
  padding: .2rem .65rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  background: var(--surface2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.badge-warn { background: #3b2d00; color: var(--yellow); border-color: #6b4e00; }

.badge-db {
  padding: .25rem .45rem;
  color: var(--accent);
  border-color: var(--accent);
  background: #1e1a3a;
}

.badge-db svg {
  width: 13px;
  height: 13px;
  display: block;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
}

.tab-btn {
  padding: .7rem 1.1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-size: .9rem;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  margin-bottom: -1px;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Tab content */
.tab-content { display: none; padding: 1.5rem; }
.tab-content.active { display: block; }

/* ── Transpose bar ── */
.transpose-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .55rem .7rem;
  padding: .45rem 1rem;
  background: #141418;
  border-bottom: 1px solid var(--border);
}

.t-label {
  font-size: .75rem;
  color: var(--text-dim);
  white-space: nowrap;
  margin-right: .1rem;
}

.t-controls {
  display: flex;
  align-items: center;
  gap: .3rem;
}

.t-step {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, border-color .12s, color .12s;
}
.t-step:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

.t-offset {
  min-width: 2.5rem;
  text-align: center;
  font-size: .88rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  transition: color .15s;
}
.t-offset.active { color: var(--accent); }

.t-key-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface2)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238888aa'/%3E%3C/svg%3E")
    no-repeat right .55rem center;
  background-size: 8px 5px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: .82rem;
  font-weight: 600;
  padding: .22rem 1.6rem .22rem .6rem;
  cursor: pointer;
  transition: border-color .15s;
  min-width: 4.2rem;
}
.t-key-select:hover  { border-color: var(--accent); }
.t-key-select:focus  { outline: none; border-color: var(--accent); }
.t-key-select.active { border-color: var(--accent); color: var(--accent); }

.t-capo {
  font-size: .78rem;
  color: var(--green);
  white-space: nowrap;
}
.t-capo strong {
  font-variant-numeric: tabular-nums;
}

.t-reset {
  font-size: .73rem;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  padding: 0 .1rem;
  transition: color .12s;
}
.t-reset:hover { color: var(--text); }

pre {
  font-family: var(--font-mono);
  font-size: .88rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

/* Chord highlighting inside pre */
pre .chord {
  color: var(--accent);
  font-weight: 700;
  font-size: .82rem;
  vertical-align: super;
  line-height: 0;
}

/* Chord list pills */
#chords-list {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

.chord-pill {
  padding: .4rem .9rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}

/* Like / Dislike */
.like-bar {
  display: flex;
  gap: .4rem;
  align-items: center;
}

.like-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  transition: color .15s, background .15s, border-color .15s, transform .1s;
}

.like-btn svg {
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.like-btn:hover { color: var(--text); border-color: var(--accent); }
.like-btn:active { transform: scale(.92); }

.like-btn.active {
  color: var(--accent);
  background: #1e1a3a;
  border-color: var(--accent);
}

.like-btn.active svg { fill: var(--accent); stroke: var(--accent); }

.dislike-btn.active {
  color: var(--red);
  background: #2a1010;
  border-color: var(--red);
}

.dislike-btn.active svg { fill: var(--red); stroke: var(--red); }

.like-count {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-dim);
  min-width: 1ch;
  text-align: left;
}

/* Result footer */
.result-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: .5rem;
}

/* Sources */
.sources {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Print icon wrapper — inline in the like-bar */
.print-wrap {
  display: contents; /* renders children directly, no layout box */
}

/* Print options popover — positioned fixed by JS near the clicked button */
.print-options {
  position: fixed;
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  white-space: nowrap;
  padding: .5rem .7rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  z-index: 100;
}

.print-opt-label {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .85rem;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.print-opt-label input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.sources a {
  color: var(--text-dim);
  font-size: .82rem;
  text-decoration: none;
  transition: color .15s;
}
.sources a:hover { color: var(--accent); }

/* Fix bar */
.fix-bar {
  border-top: 1px solid var(--border);
  padding: .8rem 1.5rem;
}

.fix-toggle {
  display: flex;
  align-items: center;
  gap: .45rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: .85rem;
  cursor: pointer;
  padding: 0;
  transition: color .15s;
}

.fix-toggle:hover { color: var(--text); }

.fix-toggle svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.tab-fix-btn {
  margin-left: auto;
  padding: .7rem .9rem;
  border-bottom: 2px solid transparent;
  font-size: .85rem;
}

.fix-form {
  margin-top: .75rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.fix-form textarea {
  width: 100%;
  padding: .6rem .8rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: .88rem;
  resize: vertical;
  outline: none;
  transition: border-color .2s;
}

.fix-form textarea:focus { border-color: var(--accent); }

.fix-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.fix-submit-btn {
  padding: .4rem .9rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}

.fix-submit-btn:hover { background: var(--accent-dim); }
.fix-submit-btn:disabled { opacity: .5; cursor: not-allowed; }

.fix-status {
  font-size: .82rem;
  color: var(--text-dim);
}

.fix-status.error { color: var(--red); }

/* ── Chord diagram panel ──────────────────────────────────────────────────── */

/* Mobile (default): panel appears in document flow, below the song header */
.chord-panel {
  border-top: 1px solid var(--border);
  background: var(--surface);
  /* horizontally scrollable grid on small screens */
  overflow-x: auto;
}

.chord-panel-header {
  padding: .6rem .7rem .5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .45rem;
}

.chord-panel-title {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* Instrument switcher */
.chord-instrument-switcher {
  display: flex;
  gap: .25rem;
}

.chord-instr-btn {
  flex: 1;
  padding: .28rem .4rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  transition: color .15s, background .15s, border-color .15s;
  white-space: nowrap;
}

.chord-instr-btn:hover { color: var(--text); border-color: var(--accent); }

.chord-instr-btn.active {
  background: #1e1a3a;
  border-color: var(--accent);
  color: var(--accent);
}

/* Mobile grid: single horizontal row that wraps */
.chord-diagrams-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .15rem;
  padding: .5rem;
}

/* Piano: single column */
.chord-diagrams-grid.chord-diagrams-piano {
  flex-direction: column;
}

.chord-diagram-cell {
  display: flex;
  justify-content: center;
  padding: .3rem .2rem;
  border-radius: 6px;
  transition: background .15s;
  cursor: default;
}

.chord-diagram-cell:hover {
  background: var(--surface2);
}

.chord-diagram-cell svg {
  display: block;
  --chord-color: var(--accent);
  max-width: 100%;
  height: auto;
}

/* ── Desktop: CSS grid layout when chord panel is visible ─────────────────── */
@media (min-width: 681px) {
  .result.chord-panel-visible {
    display: grid;
    grid-template-columns: 1fr 236px;
    grid-template-areas:
      "song-header    chord-panel"
      "tabs           chord-panel"
      "transpose-bar  chord-panel"
      "result-body    chord-panel"
      "fix-bar        chord-panel"
      "result-footer  result-footer";
  }

  .result.chord-panel-visible .song-header    { grid-area: song-header; }
  .result.chord-panel-visible .tabs           { grid-area: tabs; }
  .result.chord-panel-visible .transpose-bar  { grid-area: transpose-bar; }
  .result.chord-panel-visible .result-body    { grid-area: result-body; }
  .result.chord-panel-visible .fix-bar        { grid-area: fix-bar; }
  .result.chord-panel-visible .result-footer  { grid-area: result-footer; }
  .result.chord-panel-visible #chord-panel    { grid-area: chord-panel; }

  /* Desktop panel style: left border, sticky, scrollable */
  .result.chord-panel-visible #chord-panel {
    border-top: none;
    border-left: 1px solid var(--border);
    position: sticky;
    top: 1rem;
    align-self: start;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
  }

  .result.chord-panel-visible #chord-panel::-webkit-scrollbar { width: 5px; }
  .result.chord-panel-visible #chord-panel::-webkit-scrollbar-track { background: transparent; }
  .result.chord-panel-visible #chord-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

  /* Desktop grid: 2 columns */
  .result.chord-panel-visible .chord-diagrams-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .result.chord-panel-visible .chord-diagrams-grid.chord-diagrams-piano {
    grid-template-columns: 1fr;
  }
}

/* Print: chord panel hidden by default, shown when body.print-with-diagrams */
@media print {
  .chord-panel { display: none !important; }
  body.print-with-diagrams .chord-panel { display: block !important; }
  .transpose-bar { display: none !important; }
}

/* Chords missing notice */
.chords-missing {
  padding: .7rem 1rem;
  margin-bottom: 1rem;
  background: #1e1a10;
  border: 1px solid #4a3a00;
  border-radius: var(--radius);
  color: var(--yellow);
  font-size: .88rem;
  line-height: 1.5;
}

/* Error */
.error {
  margin-top: 2rem;
  padding: 1rem 1.5rem;
  background: #2a1010;
  border: 1px solid #5a2020;
  border-radius: var(--radius);
  color: var(--red);
  font-size: .95rem;
}

/* Utility */
.hidden { display: none !important; }

/* ── Print ── */
#print-header { display: none; }

@media print {
  /* @page margin boxes: override browser-added date/time/URL/page-numbers.
     Works fully in Firefox and Safari. In Chrome: uncheck "Headers and footers"
     in the print dialog to get the same effect. */
  @page {
    margin: 1.2cm 1.5cm;
    /* Clear every browser-injected corner */
    @top-left    { content: none; }
    @top-right   { content: none; }
    @bottom-left { content: none; }
    @bottom-right{ content: none; }
    /* Our brand in the top center */
    @top-center {
      content: "AI Chords  ·  ai-chords.com";
      font-size: 7pt;
      color: #aaa;
    }
    /* Page number bottom center — only when there are multiple pages */
    @bottom-center {
      content: counter(page);
      font-size: 7.5pt;
      color: #aaa;
    }
  }
  /* Single-page: suppress the page number */
  @page :only {
    @bottom-center { content: none; }
  }

  /* @page margin boxes handle the brand (Firefox/Safari).
     Hide the HTML fallback div to avoid duplication. */
  #print-header { display: none !important; }

  /* Hide all screen-only UI */
  header,
  #search-form,
  #search-form-url,
  #search-form-name,
  .search-mode-toggle,
  #progress,
  #error-box,
  .tabs,
  .result-footer,
  .fix-bar,
  .badges,
  .song-header .like-bar { display: none !important; }

  body {
    background: #fff;
    color: #000;
    font-size: 10pt;
    padding: 0;
  }

  .container { max-width: none; }

  /* Reset grid layout – avoids phantom right-column left-margin */
  .result,
  .result.chord-panel-visible {
    display: block !important;
    border: none;
    margin: 0;
  }

  .song-header {
    border-bottom: none;
    padding: 0 0 .2cm;
    margin-bottom: .25cm;
  }

  /* Show artist + title; hide like bar */
  .song-header-top { display: block !important; }

  #song-artist {
    font-size: 9pt;
    font-weight: 400;
    color: #555;
    margin: 0;
  }

  #song-title {
    font-size: 15pt;
    font-weight: 700;
    color: #000;
    margin: .05cm 0 0;
  }

  /* Active tab content only */
  .tab-content { display: none !important; }
  .tab-content.active { display: block !important; padding: 0; }

  pre {
    font-size: 8.5pt;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    color: #000;
  }

  pre .chord {
    /* Indigo #4f46e5 — vivid in colour print; converts to ~13 % grey in B&W
       (clearly readable on white paper, clearly distinct from black body text) */
    color: #4f46e5;
    font-weight: 700;
    font-size: 7.5pt;
  }

  /* Two-column layout when JS detects long content */
  .print-2col .tab-content.active {
    columns: 2;
    column-gap: 1.2cm;
    column-fill: balance;
  }

  /* Compact mode: slightly smaller font + tighter spacing to absorb small overflow.
     Saves ≈ 12 % vertical space vs. normal (8.5pt/1.6 → 8pt/1.5).
     Applied by JS when content is close to or just over one page. */
  .print-compact pre {
    font-size: 8pt;
    line-height: 1.5;
  }
  .print-compact pre .chord {
    font-size: 7.2pt;
    color: #4f46e5;
  }
  .print-compact .song-header {
    padding-bottom: .15cm;
    margin-bottom: .2cm;
  }

  .chord-pill {
    border: 1px solid #999;
    color: #000;
    background: #f5f5f5;
  }

  /* ── Print WITH chord diagrams ── */
  /* Single-column: song header → diagrams → lyrics (natural flow order) */
  body.print-with-diagrams #chord-panel {
    display: block !important;
    border: none !important;
    position: static !important;
    max-height: none !important;
    overflow: visible !important;
    margin-bottom: .3cm;
  }

  body.print-with-diagrams .chord-panel-header {
    display: none; /* hide "AKORDY" label + switcher in print */
  }

  body.print-with-diagrams .chord-diagrams-grid {
    display: flex !important;
    flex-wrap: wrap;
    gap: .1rem;
    padding: .2rem .1rem;
  }

  body.print-with-diagrams .chord-diagram-cell {
    padding: .15rem .1rem;
  }

  body.print-with-diagrams .chord-diagram-cell svg {
    --chord-color: #4f46e5;
  }
}

/* ── Disambiguation panel ─────────────────────────────────────────────────── */

.disambig-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem 1rem;
  margin-bottom: 1.2rem;
  animation: fadeIn .2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.disambig-hint {
  font-size: .88rem;
  color: var(--text-dim);
  margin-bottom: .8rem;
}

.disambig-cards {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-bottom: .8rem;
}

.disambig-card {
  display: flex;
  align-items: center;
  gap: .9rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .65rem .9rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  text-align: left;
  width: 100%;
}

.disambig-card:hover,
.disambig-card:focus-visible {
  border-color: var(--accent);
  background: #25253a;
  outline: none;
}

.disambig-card-artist {
  font-weight: 600;
  font-size: .95rem;
  color: var(--text);
  line-height: 1.2;
}

.disambig-card-title {
  font-size: .82rem;
  color: var(--text-dim);
  margin-top: .1rem;
}

.disambig-card-rank {
  margin-left: auto;
  font-size: .75rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.disambig-custom {
  display: flex;
  gap: .5rem;
  margin-top: .6rem;
}

.disambig-custom input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: .55rem .8rem;
  font-size: .9rem;
}

.disambig-custom input:focus {
  outline: none;
  border-color: var(--accent);
}

.disambig-custom input::placeholder {
  color: var(--text-dim);
}
