/* assets/chordy-ui.css
   Chordy design tokens, shared by every page (loaded through build_common.get_nav_assets_html and the
   song / artist pages). One primary colour (和弦藍) for buttons, links and chords; a slightly blue-grey
   neutral scale; light and dark themes. Every text pair here is at least 4.5:1.

   Themes: the <html data-theme> attribute is "day-blue" (light) or "night-green" (dark). The names are
   kept for stored preferences; what users see is 淺色 / 深色.

   The second half maps the variables each page still defines in its own <style> (--bg-page, --accent,
   --chord-color, ...) onto these tokens. The `html:root` / `html[data-theme=...]` selectors are more
   specific than the pages' `:root` / `[data-theme=...]` blocks, so the tokens win wherever this file loads. */

html:root {
    /* colour */
    --c-bg: #f7f8fa;
    --c-surface: #ffffff;
    --c-surface-glass: rgba(255, 255, 255, 0.94);
    --c-soft: #eef1f5;
    --c-line: #dfe3e8;
    --c-line-strong: #c5ccd5;
    --c-fg: #141a22;
    --c-fg-2: #3d4754;
    --c-muted: #55606e;
    --c-primary: #0a64a0;
    --c-primary-hover: #08578b;
    --c-on-primary: #ffffff;
    --c-primary-soft: #e3eff8;
    --c-star: #b7791f;
    --c-danger: #b42318;
    --c-danger-soft: #fdecea;
    --c-hero: linear-gradient(160deg, #0f2b42 0%, #0b1d2d 100%);
    --c-on-hero: #f2f6fa;
    --c-on-hero-2: #c3d2e0;
    --c-scrim: rgba(10, 16, 24, 0.55);
    --c-focus: #0a64a0;

    /* type */
    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", Roboto, Arial, sans-serif;
    --font-chord: Menlo, Monaco, Consolas, "Courier New", monospace;
    --fs-xs: 12px; --fs-sm: 14px; --fs-md: 16px; --fs-lg: 18px; --fs-xl: 22px; --fs-2xl: 28px; --fs-3xl: 36px;

    /* space, shape, depth */
    --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;
    --r-sm: 6px; --r-md: 10px; --r-pill: 999px;
    --shadow-raise: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
    --shadow-pop: 0 12px 32px rgba(16, 24, 40, 0.18);
    --tap: 44px;

    color-scheme: light;
}

html[data-theme="night-green"] {
    --c-bg: #0f1318;
    --c-surface: #171c23;
    --c-surface-glass: rgba(23, 28, 35, 0.94);
    --c-soft: #1f2630;
    --c-line: #2a313b;
    --c-line-strong: #3a4350;
    --c-fg: #e7ecf2;
    --c-fg-2: #c2cbd6;
    --c-muted: #9aa5b3;
    --c-primary: #6cc0f5;
    --c-primary-hover: #8ccff8;
    --c-on-primary: #06223a;
    --c-primary-soft: #10283b;
    --c-star: #f2c14e;
    --c-danger: #ff8a80;
    --c-danger-soft: #3a1d1b;
    --c-hero: linear-gradient(160deg, #10283b 0%, #0b1620 100%);
    --c-on-hero: #f2f6fa;
    --c-on-hero-2: #b6c6d6;
    --c-scrim: rgba(0, 0, 0, 0.7);
    --c-focus: #6cc0f5;
    --shadow-raise: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.55);

    color-scheme: dark;
}

/* ---- the pages' own variables, mapped onto the tokens (same block for both themes: tokens switch) ---- */
html:root, html[data-theme="night-green"] {
    --bg-page: var(--c-bg);
    --bg-card: var(--c-surface);
    --bg-sheet: var(--c-surface);
    --bg-toolbar: var(--c-surface);
    --bg-panel: var(--c-soft);
    --bg-nav: var(--c-surface-glass);
    --badge-bg: var(--c-soft);
    --border-color: var(--c-line);
    --border-hover: var(--c-line-strong);
    --text-title: var(--c-fg);
    --text-primary: var(--c-fg);
    --text-secondary: var(--c-fg-2);
    --text-muted: var(--c-muted);
    --lyric-color: var(--c-fg);
    --primary: var(--c-primary);
    --primary-light: var(--c-primary-soft);
    --accent: var(--c-primary);
    --accent-text: var(--c-on-primary);
    --chord-color: var(--c-primary);
    --chord-bg: var(--c-primary-soft);
    --setup-banner-bg: var(--c-primary-soft);
    --sidebar-bg: var(--c-surface);
    --sidebar-text: var(--c-fg);
    --sidebar-chord-dot: var(--c-primary);
    --sidebar-card-border: var(--c-line);
    --modal-bg: var(--c-surface);
    --modal-overlay: var(--c-scrim);
    --hero-bg: var(--c-hero);
    --shadow-sm: var(--shadow-raise);
    --shadow-md: var(--shadow-raise);
    --shadow-card: var(--shadow-raise);
    --shadow-hover: var(--shadow-pop);
    /* song / artist pages (src/seo/site.mjs) */
    --text: var(--c-fg);
    --text-2: var(--c-muted);
    --border: var(--c-line);
    --chord: var(--c-primary);
    --lyric: var(--c-fg);
    --accent-hover: var(--c-primary-hover);
    /* chordy-nav.css */
    --cn-text: var(--c-fg);
    --cn-muted: var(--c-muted);
    --cn-border: var(--c-line);
    --cn-field: var(--c-soft);
    --cn-surface: var(--c-surface-glass);
    --cn-accent: var(--c-primary);
    --cn-accent-soft: var(--c-primary-soft);
}

/* ---- base ---- */
html:root body { font-family: var(--font-ui); }
:focus-visible { outline: 3px solid var(--c-focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* ---- icons (inline SVG from build_common.icon / ChordyIcons) ---- */
.ci { width: 1.15em; height: 1.15em; flex: 0 0 auto; vertical-align: -0.2em; stroke: currentColor; fill: none;
      stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ci-fill { fill: currentColor; }

/* ---- phase 0 fixes on the existing pages: tap targets of at least 44px, text of at least 12px ----
   `html body` outranks the single-class rules in each page's own <style>. The reader's controls are left
   out: the reader is rebuilt in phase 1. */
html body .btn-fav-drawer, html body .btn-nav-account, html body .btn-theme-toggle, html body .btn-search-trigger {
    min-height: var(--tap); min-width: var(--tap); display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
html body .brand-logo, html body .nav-brand-link { min-height: var(--tap); display: inline-flex; align-items: center; }
html body .sort-select { min-height: var(--tap); }
html body .cat-pill, html body .home-tab-btn, html body .btn-search-go, html body .btn-surprise-song,
html body .section-more-link, html body .btn-open-sheet, html body .btn-load-more {
    min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
html body .alpha-btn { min-width: var(--tap); min-height: var(--tap); }
html body .btn-star-fav { min-width: var(--tap); min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center; color: var(--c-muted); }
html body .btn-star-fav.starred { color: var(--c-star); }
html body .card-key, html body .essentials-key-pill, html body .section-badge, html body .artist-count-badge,
html body .curated-star { font-size: var(--fs-xs); }
html body .account-icon .ci, html body .account-avatar-fallback .ci { width: 18px; height: 18px; }

/* ---- phase 2: one entry per destination. Phones have 收藏 in the bottom tab bar (<= 768px). ---- */
@media (max-width: 768px) {
    html body .btn-fav-drawer { display: none; }
}

/* ---- phase 3: a song row (catalog .song-card, homepage .essentials-item) opens the sheet anywhere on it.
   The title link is stretched over the whole row; the artist link, 開譜 and the star sit above it. ---- */
html body .song-card, html body .essentials-item { position: relative; cursor: pointer; }
html body .song-card .card-title::after, html body .essentials-item .essentials-title::after {
    content: ""; position: absolute; inset: 0; border-radius: inherit; z-index: 0;
}
html body .song-card .card-artist, html body .essentials-item .essentials-artist-link,
html body .song-card .card-right, html body .essentials-item .essentials-right { position: relative; z-index: 1; }
/* the artist link gets a taller hit area without changing the row's height */
html body .song-card .card-artist, html body .essentials-item .essentials-artist-link {
    display: inline-block; padding-block: 10px; margin-block: -10px;
}
html body .song-card:focus-within, html body .essentials-item:focus-within { outline: 2px solid var(--c-focus); outline-offset: 2px; }

/* ---- offline library: header icon and its panel (assets/chordy-offline.js) ---- */
html body .btn-offline {
    min-width: var(--tap); min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--c-line); border-radius: var(--r-md); background: var(--c-surface); color: var(--c-fg);
    cursor: pointer; padding: 0; flex: 0 0 auto;
}
html body .btn-offline:hover { border-color: var(--c-primary); color: var(--c-primary); }
html body .btn-offline[data-state="ready"] { color: var(--c-primary); border-color: var(--c-primary); }
html body .btn-offline[data-state="busy"] .ci { animation: chordy-pulse 1.2s ease-in-out infinite; }
@keyframes chordy-pulse { 50% { opacity: .35; } }
.offline-panel {
    position: fixed; z-index: 1300; top: calc(64px + env(safe-area-inset-top, 0px)); right: 16px;
    width: min(380px, calc(100vw - 24px)); max-height: calc(100vh - 96px); overflow-y: auto;
    background: var(--c-surface); color: var(--c-fg); border: 1px solid var(--c-line); border-radius: 14px;
    box-shadow: var(--shadow-pop); font-family: var(--font-ui);
}
.offline-panel[hidden] { display: none; }
.offline-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 4px 18px; }
.offline-head h2 { margin: 0; font-size: var(--fs-lg); font-weight: 700; }
.offline-close { min-width: var(--tap); min-height: var(--tap); border: 0; background: none; color: var(--c-muted); cursor: pointer; border-radius: var(--r-md); }
.offline-close:hover { color: var(--c-fg); background: var(--c-soft); }
.offline-body { padding: 4px 18px 18px; display: flex; flex-direction: column; gap: 10px; }
.offline-body p { margin: 0; }
.offline-text { font-size: var(--fs-sm); line-height: 1.6; color: var(--c-fg-2); }
.offline-small { font-size: var(--fs-xs); color: var(--c-muted); font-variant-numeric: tabular-nums; }
.offline-status { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--c-primary); }
.offline-error { font-size: var(--fs-sm); color: var(--c-danger); background: var(--c-danger-soft); border-radius: var(--r-sm); padding: 8px 10px; }
.offline-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.offline-btn {
    min-height: var(--tap); padding: 0 14px; display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid var(--c-line); border-radius: var(--r-md); background: var(--c-surface); color: var(--c-fg);
    font: 600 var(--fs-sm)/1 var(--font-ui); cursor: pointer;
}
.offline-btn:hover { border-color: var(--c-primary); }
.offline-btn:disabled { opacity: .5; cursor: default; }
.offline-btn.offline-primary { background: var(--c-primary); border-color: var(--c-primary); color: var(--c-on-primary); }
.offline-btn.offline-danger { border-color: var(--c-danger); color: var(--c-danger); }
.offline-bar { height: 8px; border-radius: var(--r-pill); background: var(--c-soft); overflow: hidden; }
.offline-bar span { display: block; height: 100%; background: var(--c-primary); transition: width .3s ease; }
.offline-install { border-top: 1px solid var(--c-line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.offline-steps { margin: 0; padding-left: 1.3em; font-size: var(--fs-sm); color: var(--c-fg-2); display: grid; gap: 2px; }
@media (max-width: 640px) { .offline-panel { right: 12px; top: calc(60px + env(safe-area-inset-top, 0px)); } }

/* ---- utilities ---- */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
