/* ============================================================
   "Sveska" (notebook) visual direction.
   Leans into what this app fundamentally is: a digitized chord
   notebook. Warm ruled paper, fountain-pen-green ink for structure,
   red-pen for the one accent that should read as "active/annotation"
   (transpose value, chord-line tint). See the design pitch discussed
   with Nino for the two rejected directions (Vinska Karta, Ploča).

   Dark mode ("notebook at night"): light by default, switched only by
   the toggle button (static/js/theme-toggle.js), which sets
   data-bs-theme="dark" on <html> and persists the choice in
   localStorage -- reusing Bootstrap 5.3's own attribute (rather than
   inventing a separate one) means Bootstrap's own components repaint
   too, not just this file's custom rules. Deliberately does NOT also
   respond to prefers-color-scheme: an earlier version did, and it
   produced a confusing bug in practice -- a page with its own <head>
   (song.html, for SEO reasons) was missing the theme-restore script the
   other pages have, so it silently fell back to the OS preference
   instead of the visitor's actual stored choice, making the theme
   appear to "randomly" flip when navigating to a song page. Simpler and
   more predictable to have exactly one thing control this. Token
   indirection is what makes switching cheap regardless: every component
   rule below reads from the --paper/--ink/etc. custom properties (or
   the --bs-* aliases further down, which themselves read from those
   same tokens), never a literal color -- so only the token values need
   to change per mode, not every rule that uses them.

   Mobile-first: base rules target the smallest screen; the one
   width-based @media query widens things back up, it doesn't shrink
   them down.
   ============================================================ */

:root {
    --paper: #faf6ec;
    --paper-rule: #d9d2ba;
    --card: #fdfbf5;
    --ink: #2a2822;
    --ink-muted: #6b675c;
    --accent: #2f5d50;   /* fountain-pen green -- structure, links, primary actions */
    --accent-2: #a8402f; /* red pen -- the one "active/annotation" accent */
    --line: #d9d2ba;

    /* The navbar is deliberately always a dark "ink bar" in both modes
       (a permanent header, not something that inverts with the page) --
       kept as its own tokens rather than reusing --ink/--paper directly,
       since --ink flips to a *light* color in dark mode and would break
       this if the navbar rules referenced it. */
    --nav-bg: #2a2822;
    --nav-ink: #faf6ec;
    --nav-ink-muted: rgba(250, 246, 236, 0.75);

    /* Bootstrap 5.3 theming hooks: retint components through Bootstrap's
       own variables rather than fighting each utility class individually. */
    --bs-body-bg: var(--paper);
    --bs-body-color: var(--ink);
    --bs-emphasis-color: var(--ink);
    --bs-secondary-color: var(--ink-muted);
    --bs-tertiary-bg: var(--card);
    --bs-border-color: var(--line);
    --bs-link-color: var(--accent);
    --bs-link-hover-color: var(--accent-2);
    --bs-primary: var(--accent);
    --bs-primary-rgb: 47, 93, 80;
}

/* Explicit override via the toggle -- the only way this changes now
   (see the comment at the top of this file for why prefers-color-scheme
   auto-detection was removed). */
:root[data-bs-theme="dark"] {
    --paper: #201e19;
    --paper-rule: #38352c;
    --card: #2a2721;
    --ink: #ece7d9;
    --ink-muted: #a39d8c;
    --accent: #6fbf9f;
    --accent-2: #e0836b;
    --line: #38352c;
    --nav-bg: #14130f;
    --nav-ink: #ece7d9;
    --nav-ink-muted: rgba(236, 231, 217, 0.75);
    --bs-primary-rgb: 111, 191, 159;
}

body {
    padding-bottom: 2rem;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    /* Faint ruled-paper lines -- a background gradient, not an image, so
       it scales cleanly and costs nothing to load. */
    background-image: repeating-linear-gradient(var(--paper) 0 27px, var(--paper-rule) 27px 28px);
    background-color: var(--paper);
}

/* Manuscript serif for headings -- plays against the monospace chords
   rather than competing with it; system font stack only (the
   artifact/CSS here can't fetch a webfont, and this project already
   favors self-hosted-or-nothing over CDN dependencies -- see Bootstrap's
   own WebJar packaging). */
h1, h2, h3 {
    font-family: Georgia, "Iowan Old Style", "Book Antiqua", Palatino, serif;
}

.navbar {
    background-color: var(--nav-bg);
}

.navbar .nav-link {
    /* "Home" (the leftmost link, replacing the old serif "Vino i gitare"
       brand mark) is a plain .nav-link too, not .navbar-brand -- styled
       identically to Genres/Chords/Admin rather than as a separate,
       differently-treated element. Padding set explicitly (matching
       Bootstrap's own resolved 0.5rem/0.5rem for .navbar-nav .nav-link,
       verified via computed styles) rather than relying on its
       .navbar-nav-scoped --bs-navbar-nav-link-padding-x variable, since
       this rule also has to reach a .nav-link that isn't nested inside
       a .navbar-nav. */
    padding: 0.5rem;
    color: var(--nav-ink-muted) !important;
}

.navbar .nav-link:hover,
.navbar .nav-link:focus {
    color: var(--nav-ink) !important;
}

@media (max-width: 767.98px) {
    /* Real bug found via a mobile screenshot: the search box was
       crushed to ~68px wide, cut off to "Searc", instead of moving to
       its own line below Home/Genres/Chords/Admin as the form's
       existing .mt-2 (mobile-only top margin) clearly intended.
       Root cause: .navbar-expand (used here so the nav links never
       collapse behind a hamburger button -- see the .container comment
       above) sets flex-wrap: nowrap *unconditionally*, not just above
       some breakpoint, so at any width where the row's content doesn't
       fit, items get flex-shrunk in place rather than wrapped. Restore
       wrapping below md, where there isn't room for everything on one
       line anyway. flex-basis: 100% on the form (Bootstrap's own trick,
       see .navbar-collapse in bootstrap.css) then guarantees it takes a
       full line to itself once wrapping is possible, rather than
       potentially sharing a partial one. */
    .navbar.navbar-expand {
        flex-wrap: wrap;
    }

    .navbar form {
        flex-basis: 100%;
    }
}

/* Live/performance view's slim top bar (song-live.html) -- same dark
   "ink bar" treatment as .navbar (reuses the same --nav-* tokens) but
   without a real <nav>, since this page deliberately has no navbar or
   search box. */
.live-bar {
    background-color: var(--nav-bg);
}

.live-bar-exit {
    color: var(--nav-ink-muted);
    text-decoration: none;
}

.live-bar-exit:hover,
.live-bar-exit:focus {
    color: var(--nav-ink);
}

/* Listing rows (artist index, genre browse, search results, admin table)
   styled like index cards -- a left accent rule instead of a full border,
   evoking a card-catalog drawer. Applied via .index-row, added to each
   <li> in the browse/search/genre templates. */
.index-row {
    background-color: var(--card);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: 0.25rem;
    padding: 0.5rem 0.85rem;
    list-style: none;
}

.index-row + .index-row {
    margin-top: 0.4rem;
}

.song-title {
    text-wrap: balance;
}

.song-artist {
    font-style: italic;
}

/* Chords-above-lyrics ASCII alignment only survives in a monospace font
   with whitespace preserved. On a narrow phone screen the natural failure
   mode is wrapping (which destroys the alignment) -- so we scroll
   horizontally instead of wrapping. */
.song-chords,
.song-chords-input {
    font-family: "Courier New", Consolas, monospace;
    white-space: pre;
    overflow-x: auto;
    font-size: 0.95rem;
    line-height: 1.4;
    background-color: var(--card);
    border: 1px solid var(--line);
    color: var(--ink);
    padding: 1rem;
    border-radius: 0.375rem;
}

/* Chord lines get the "different ink" treatment (com.vinoigitare.chords.
   ChordLineHighlighter on first render, static/js/transpose.js's JS
   mirror on every transpose click -- see both for why this can't just be
   done once server-side and left alone). */
.chord-line {
    color: var(--accent-2);
    font-weight: 700;
}

/* Dark/light toggle (static/js/theme-toggle.js sets its glyph/aria-label).
   Sits in the always-dark nav bar in both modes, so it's styled against
   --nav-ink rather than the page's --ink, which would be invisible-ish on
   a dark navbar in light mode. */
.theme-toggle-btn {
    color: var(--nav-ink);
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.25rem 0.5rem;
}

.theme-toggle-btn:hover,
.theme-toggle-btn:focus {
    color: var(--nav-ink);
    opacity: 0.8;
}

/* Song page control rows (Transpose/Zoom/Auto-scroll): real feedback --
   the -/+ buttons looked "jagged" across the three rows, each one glued
   immediately to the end of its own label, so they landed at a
   different x position per row ("Transpose:" vs "Zoom:" vs
   "Auto-scroll:" are all different lengths, and the Zoom buttons show
   an extra "A" -- "A-"/"A+" vs plain "-"/"+"). Giving the label and the
   step buttons a shared fixed width turns both into real columns: labels
   stay left-aligned (unchanged), but now the buttons after them start
   -- and, being the same width themselves, end -- at the same x on
   every row. */
.control-label {
    display: inline-block;
    min-width: 6.5rem;
}

.control-step-btn {
    min-width: 2.25rem;
}

/* Login page (admin-auth plan, step 2) -- same card treatment as
   .index-row/.chord-diagram-card (--card/--line tokens), just narrower
   and centered, since a login form has exactly one thing to look at. */
.login-card {
    max-width: 24rem;
    background-color: var(--card);
    border: 1px solid var(--line);
    border-radius: 0.375rem;
    padding: 1.5rem;
    margin-top: 2rem;
}

/* Homepage artist tree -- rethinking the main page for scale (hundreds of
   artists, thousands of songs), replacing the old flat list. Artists as
   "folders" (serif-adjacent, like everything else that isn't chords),
   songs as "files" (monospace, echoing the chords block's own typewriter
   feel). Verified first as a standalone mockup before building this for
   real -- see SongBrowseController's class Javadoc. */
.tree-card {
    background-color: var(--card);
    border: 1px solid var(--line);
    border-radius: 0.5rem;
    overflow: hidden;
}

.tree-scroll {
    max-height: 70vh;
    overflow-y: auto;
}

.letter-heading {
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: var(--card);
    color: var(--ink-muted);
    font-family: Georgia, "Iowan Old Style", "Book Antiqua", Palatino, serif;
    font-style: italic;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    padding: 0.35rem 1rem;
    border-bottom: 1px solid var(--line);
    border-top: 1px solid var(--line);
}

.letter-heading:first-child {
    border-top: none;
}

.artist-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.5rem 1rem 0.5rem 0.75rem;
    cursor: pointer;
    user-select: none;
}

.artist-row:hover {
    background-color: color-mix(in srgb, var(--accent) 7%, transparent);
}

.artist-row:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.twisty {
    width: 0.9rem;
    flex: none;
    color: var(--accent);
    font-size: 0.7rem;
    transition: transform 0.15s ease;
    display: inline-block;
}

.artist-row[aria-expanded="true"] .twisty {
    transform: rotate(90deg);
}

.folder-icon {
    flex: none;
    color: var(--accent);
    opacity: 0.85;
}

.artist-name {
    /* Plain text, not a link -- see index.html's comment on .artist-row:
       a link filling this much of the row left nowhere comfortable to
       click for the row's real job, toggling. */
    flex: 1 1 auto;
    font-weight: 600;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.artist-name mark,
.song-title mark {
    background-color: color-mix(in srgb, var(--accent-2) 30%, transparent);
    color: inherit;
    border-radius: 0.15rem;
    padding: 0 0.1rem;
}

.song-count {
    flex: none;
    color: var(--ink-muted);
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.artist-open-link {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.4rem;
    height: 1.4rem;
    color: var(--ink-muted);
    text-decoration: none;
    border-radius: 0.25rem;
    font-size: 0.85rem;
}

.artist-open-link:hover,
.artist-open-link:focus-visible {
    color: var(--accent);
    background-color: color-mix(in srgb, var(--accent) 12%, transparent);
}

/* No hide-class present = visible -- the no-JS default (see
   SongBrowseController's Javadoc and index.html's comment on this).
   static/js/artist-tree.js toggles Bootstrap's own .d-none to drive the
   interactive tree, rather than a bespoke class doing the same thing. */

.song-row {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
    padding: 0.4rem 1rem 0.4rem 2.35rem;
    text-decoration: none;
    color: var(--ink);
}

.song-row:hover {
    background-color: color-mix(in srgb, var(--accent) 7%, transparent);
}

.song-row:hover .song-title {
    color: var(--accent);
}

.file-icon {
    flex: none;
    color: var(--ink-muted);
    font-family: "Courier New", Consolas, monospace;
    font-size: 0.85rem;
}

.song-title {
    flex: 1 1 auto;
    font-family: "Courier New", Consolas, monospace;
    font-size: 0.92rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.song-views {
    flex: none;
    color: var(--ink-muted);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

.tree-empty-state {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--ink-muted);
}

/* Toolbar above the tree: search box (filters the tree, static/js/
   artist-tree.js) + expand/collapse-all buttons. */
.tree-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.tree-search-box {
    flex: 1 1 14rem;
    position: relative;
}

.tree-search-box input {
    width: 100%;
    padding-left: 2rem;
}

.tree-search-box::before {
    content: "";
    position: absolute;
    left: 0.65rem;
    top: 50%;
    width: 0.65rem;
    height: 0.65rem;
    border: 1.5px solid var(--ink-muted);
    border-radius: 50%;
    transform: translateY(-65%);
    pointer-events: none;
}

.tree-search-box::after {
    content: "";
    position: absolute;
    left: 1.22rem;
    top: 50%;
    width: 0.4rem;
    height: 1.5px;
    background: var(--ink-muted);
    transform: translateY(40%) rotate(45deg);
    transform-origin: left center;
    pointer-events: none;
}

/* Chord-diagram reference page (com.vinoigitare.chords.ChordDiagramRenderer
   builds the actual <svg> per diagram; this is just the card/grid layout
   and the SVG's stroke/fill colors, which have to be set here since an
   inline SVG's shapes don't otherwise inherit the page's CSS custom
   properties by default the way HTML text does). */
.chord-diagram-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.75rem;
}

.chord-diagram-card {
    background-color: var(--card);
    border: 1px solid var(--line);
    border-radius: 0.375rem;
    padding: 0.5rem;
    text-align: center;
}

.chord-diagram-name {
    font-family: Georgia, "Iowan Old Style", "Book Antiqua", Palatino, serif;
    font-weight: 700;
    font-style: italic;
    margin-bottom: 0.25rem;
}

.chord-diagram-svg {
    width: 100%;
    height: auto;
}

.chord-diagram-string,
.chord-diagram-fret {
    stroke: var(--ink-muted);
    stroke-width: 1;
}

.chord-diagram-nut {
    stroke: var(--ink);
    stroke-width: 2.5;
}

.chord-diagram-dot {
    fill: var(--accent);
}

.chord-diagram-barre {
    stroke: var(--accent);
    stroke-width: 8;
    stroke-linecap: round;
    opacity: 0.55;
}

.chord-diagram-marker {
    fill: var(--ink-muted);
    font-size: 10px;
}

@media (max-width: 576px) {
    .song-chords,
    .song-chords-input {
        font-size: 0.85rem;
        padding: 0.75rem;
    }
}

/* Browser-native printing (the "Print" button / Ctrl+P) -- the free
   sibling feature to the PDF download, per the migration plan. Hides chrome
   that only makes sense on screen (navbar, back link, the download/print
   buttons themselves) and strips the on-screen chords block's background
   and border, which look wrong on paper. The actual PDF download uses its
   own standalone template (song-pdf.html) with its own print CSS, so this
   only affects Ctrl+P / window.print() on the on-screen page. */
@media print {
    nav,
    .no-print {
        display: none !important;
    }

    body {
        padding-bottom: 0;
        background-image: none;
    }

    .song-chords {
        background: none;
        border: none;
        padding: 0;
        font-size: 11pt;
    }

    .chord-line {
        color: inherit;
    }
}
