/* =================================================================
   DAS KARLPITAL ★ Cartoon Comrades
   A Marx-themed Saturday-morning-cartoon party for a book catalog.
   Display: Modak · Body: Mulish · Mono: JetBrains Mono
   ================================================================= */

[data-theme="steampunk"] {
    --paper:       #2A1E14;
    --paper-soft:  #3A2A1D;
    --paper-deep:  #1E1410;

    --ink:         #E8D2A0;
    --ink-mid:     #A89070;
    --ink-soft:    #6D5A3F;

    --red:         #9A3618;
    --red-deep:    #6F2410;
    --gold:        #D9A455;
    --gold-deep:   #A88242;
    --cyan:        #5C8F8C;
    --neon:        #D9A455;
    --magenta:     #A85B3E;
    --hot-pink:    #C9663C;
    --purple:      #5E4A6B;
    --olive:       #7E6D44;
    --brass:       #B5723B;
    --copper:      #A85928;
    --amber:       #E0B868;
    --verdigris:   #5C8F8C;

    /* Button tokens — kept as named pairs (rather than inline var()s in the
       .btn rules below) so the WCAG contrast regression test
       (library/tests/test_button_contrast.py) can read "what colour is a
       button" straight out of this token block, without parsing gradients
       out of arbitrary rule bodies. --btn-bg-1/-2 are a gradient's two
       stops (equal for a flat fill); both must independently meet the
       contrast ratio against --btn-text, since either can be the one under
       the text depending on button height. */
    --btn-bg-1:          var(--brass);
    --btn-bg-2:          var(--gold-deep);
    --btn-text:          var(--paper-deep);
    --btn-red-bg-1:      var(--red);
    --btn-red-bg-2:      var(--red-deep);
    --btn-red-text:      var(--ink);
    --btn-ghost-text:    var(--amber);
    --btn-ghost-border:  var(--brass);
    --btn-focus-ring:    var(--ink);

    --rule:        rgba(217, 164, 85, 0.34);
    --rule-soft:   rgba(217, 164, 85, 0.16);

    --shadow-1:    0 2px 0 rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    --shadow-2:    0 4px 0 rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.10);
    --shadow-soft: 0 1px 0 rgba(0, 0, 0, 0.4);

    --r:           4px;
    --r-pill:      999px;
    --max:         1180px;

    --display:     "Cinzel", "Trajan Pro", "Times New Roman", serif;
    --brand:       "Pirata One", "Cinzel", "Times New Roman", serif;
    --body:        "Crimson Text", "EB Garamond", "Georgia", serif;
    --mono:        "Special Elite", "VT323", "Courier New", monospace;
}

[data-theme="karlpital"] {
    --paper:       #FFF7E1;
    --paper-soft:  #FFEFC4;
    --paper-deep:  #FFE190;

    --ink:         #1A0F0F;
    --ink-mid:     #4A3A2A;
    --ink-soft:    #7C6E5C;

    --red:         #D31E1E;
    --red-deep:    #8B0F0F;
    --gold:        #FFC830;
    --gold-deep:   #C99100;
    --cyan:        #3FB6E2;
    --purple:      #8B4FB8;
    --olive:       #6BA94A;

    /* See the steampunk block above for why these exist. Karlpital's own
       .btn is flat (not a gradient), so --btn-bg-1/-2 are equal. */
    --btn-bg-1:          var(--gold);
    --btn-bg-2:          var(--gold);
    --btn-text:          var(--ink);
    --btn-red-bg-1:      var(--red);
    --btn-red-bg-2:      var(--red);
    --btn-red-text:      var(--paper);
    --btn-ghost-text:    var(--ink);
    --btn-ghost-border:  var(--ink);
    --btn-focus-ring:    var(--ink);

    --rule:        rgba(26, 15, 15, 0.18);
    --rule-soft:   rgba(26, 15, 15, 0.10);

    --shadow-1:    4px 4px 0 var(--ink);
    --shadow-2:    6px 6px 0 var(--ink);
    --shadow-soft: 0 2px 0 rgba(26, 15, 15, 0.15);

    --r:           18px;
    --r-pill:      999px;
    --max:         1180px;

    --display:     "Fredoka", "Trebuchet MS", system-ui, sans-serif;
    --brand:       "Modak", "Bowlby One SC", "Fredoka", system-ui, sans-serif;
    --body:        "Mulish", "Trebuchet MS", system-ui, sans-serif;
    --mono:        "JetBrains Mono", "Menlo", monospace;
}

:root,
[data-theme="elven"] {
    /* Biblioteca del Bosque Élfico: a library inside an ancient forest at night.
       Moss and bark surfaces, moonlit-silver ink, gold-leaf ornament.
       :root lives here (not on steampunk) because ELVEN is the default theme;
       every page sets data-theme explicitly, so this only matters if that
       ever stops being true. */
    --paper:       #0F1F17;   /* forest floor at night */
    --paper-soft:  #172C21;   /* moss-lit panel */
    --paper-deep:  #09140E;   /* deep canopy shade */

    --ink:         #ECEBDD;   /* moonlit vellum */
    --ink-mid:     #BFCBB6;   /* silver sage */
    --ink-soft:    #9DB097;   /* lichen */

    --red:         #E6A27D;   /* rowan berry (text-safe accent) */
    --red-deep:    #F2BFA1;
    --gold:        #D9B860;   /* gold leaf */
    --gold-deep:   #B08F3C;
    --cyan:        #93C4B7;   /* moon on water */
    --neon:        #D9B860;
    --purple:      #B3A1D3;   /* bluebell */
    --olive:       #97B86E;   /* fern */
    --moss:        #5E8248;
    --bark:        #6E4B30;
    --silver:      #C9D3D6;

    /* See the steampunk block above for why these exist. Elven's .btn/
       .btn--red were hand-tuned gradients in raw hex (not other tokens),
       so these are the first named tokens for those colours. */
    --btn-bg-1:          #E7CB7A;
    --btn-bg-2:          #C9A64D;
    --btn-text:          #13261B;
    --btn-red-bg-1:      #A84A3B;
    --btn-red-bg-2:      #8A3629;
    --btn-red-text:      #FBF0E4;
    --btn-ghost-text:    var(--ink);
    --btn-ghost-border:  var(--silver);
    --btn-focus-ring:    var(--gold);

    --rule:        rgba(217, 184, 96, 0.38);
    --rule-soft:   rgba(217, 184, 96, 0.16);

    --shadow-1:    0 1px 0 rgba(0, 0, 0, 0.5), 0 10px 26px -12px rgba(0, 0, 0, 0.7);
    --shadow-2:    0 2px 0 rgba(0, 0, 0, 0.5), 0 16px 34px -12px rgba(0, 0, 0, 0.8);
    --shadow-soft: 0 1px 0 rgba(0, 0, 0, 0.4);

    --r:           4px 22px 4px 22px;   /* leaf-shaped corners */
    --r-pill:      999px;
    --max:         1180px;

    --display:     "Cormorant Garamond", "EB Garamond", "Georgia", serif;
    --brand:       "Uncial Antiqua", "Cormorant Garamond", "Georgia", serif;
    --body:        "Alegreya", "EB Garamond", "Georgia", serif;
    --mono:        "Alegreya SC", "Alegreya", "Georgia", serif;
    --initial:     "Uncial Antiqua", "Cormorant Garamond", serif;
}

/* ---- Reset & base ---------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }

body {
    background: var(--paper);
    color: var(--ink);
    font-family: var(--body);
    font-size: 17px;
    line-height: 1.55;
    font-weight: 500;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    background-image:
        radial-gradient(circle at 10% 12%, rgba(255, 200, 48, 0.18) 0 14px, transparent 16px),
        radial-gradient(circle at 88% 22%, rgba(63, 182, 226, 0.18) 0 10px, transparent 12px),
        radial-gradient(circle at 22% 78%, rgba(211, 30, 30, 0.10) 0 18px, transparent 20px),
        radial-gradient(circle at 80% 88%, rgba(139, 79, 184, 0.16) 0 12px, transparent 14px),
        radial-gradient(circle at 55% 50%, rgba(107, 169, 74, 0.10) 0 8px, transparent 10px);
    background-size: 540px 540px;
    background-attachment: fixed;
}

/* paper grain */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.06;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='320' height='320'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
    background-size: 320px 320px;
}

::selection { background: var(--red); color: var(--paper); }

/* ---- Typography ------------------------------------------------- */
h1, h2, h3, h4 {
    font-family: var(--display);
    font-weight: 700;
    margin: 0 0 0.6rem;
    line-height: 1.02;
    letter-spacing: -0.005em;
    color: var(--ink);
}

h1 {
    font-size: clamp(2.4rem, 5.5vw, 4.25rem);
    font-weight: 700;
    text-shadow:
        3px 3px 0 var(--gold),
        5px 5px 0 var(--ink);
    color: var(--red);
}
h2 { font-size: clamp(1.65rem, 2.8vw, 2.3rem); font-weight: 700; color: var(--ink); }
h3 { font-size: 1.3rem; font-weight: 600; color: var(--ink); }

p { margin: 0 0 1em; max-width: 64ch; }

a {
    color: var(--red);
    text-decoration: none;
    font-weight: 800;
    transition: color 160ms ease, transform 160ms ease;
}
a:hover { color: var(--red-deep); }

.mono, .stamp {
    font-family: var(--mono);
    font-size: 0.74rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-mid);
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    font-family: var(--mono);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: var(--red);
    background: var(--gold);
    padding: 0.32rem 0.85rem 0.28rem;
    border: 2px solid var(--ink);
    border-radius: var(--r-pill);
    box-shadow: var(--shadow-1);
    transform: rotate(-1.5deg);
}
.eyebrow::before { content: "★"; color: var(--ink); }

.ink-soft { color: var(--ink-soft); font-weight: 500; }
.ink-mid  { color: var(--ink-mid); }

/* ---- Layout ---------------------------------------------------- */
.shell {
    width: 100%;
    max-width: var(--max);
    margin-inline: auto;
    padding-inline: clamp(1.25rem, 4vw, 2.5rem);
}

main {
    flex: 1 0 auto;
    padding-block: clamp(2rem, 5vw, 4rem);
    position: relative;
}

/* ---- Top bar --------------------------------------------------- */
.topbar {
    background: var(--red);
    color: var(--paper);
    border-bottom: 4px solid var(--ink);
    position: relative;
    z-index: 10;
    box-shadow: 0 4px 0 var(--ink);
}
.topbar__inner {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding-block: 1.1rem;
    flex-wrap: wrap;
}

.brand {
    font-family: var(--brand);
    font-size: clamp(1.7rem, 3vw, 2.3rem);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--paper);
    -webkit-text-stroke: 2px var(--ink);
    text-shadow:
        2px 2px 0 var(--gold),
        4px 4px 0 var(--ink);
    transition: transform 200ms ease;
    line-height: 1;
    text-decoration: none;
    font-weight: 400;
}
.brand:hover { transform: rotate(-2deg); color: var(--paper); }
.brand sup {
    font-family: var(--mono);
    font-size: 0.55rem;
    letter-spacing: 0.2em;
    margin-left: 0.5rem;
    text-shadow: none;
    -webkit-text-stroke: 0;
    color: var(--gold);
    background: var(--ink);
    padding: 0.12rem 0.45rem;
    border-radius: var(--r-pill);
    vertical-align: middle;
    font-weight: 600;
}

.topbar__nav {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    font-family: var(--mono);
    font-size: 0.78rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-weight: 600;
    flex-wrap: wrap;
}
.topbar__nav a, .topbar__nav button {
    background: var(--gold);
    color: var(--ink);
    border: 2px solid var(--ink);
    border-radius: var(--r-pill);
    padding: 0.45rem 0.9rem 0.4rem;
    font: inherit;
    cursor: pointer;
    box-shadow: 3px 3px 0 var(--ink);
    transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
    text-decoration: none;
}
.topbar__nav a:hover, .topbar__nav button:hover {
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 var(--ink);
    background: var(--paper);
    color: var(--ink);
}
.topbar__nav form { display: inline; margin: 0; }
.topbar__nav span[aria-hidden] { color: var(--paper); opacity: 0.6; }

/* ---- Buttons --------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.7rem 1.3rem;
    border: 3px solid var(--ink);
    background: var(--btn-bg-1);
    color: var(--btn-text);
    font-family: var(--display);
    font-weight: 700;
    font-size: 0.98rem;
    letter-spacing: 0.02em;
    cursor: pointer;
    border-radius: var(--r-pill);
    box-shadow: var(--shadow-1);
    transition: transform 150ms cubic-bezier(0.2, 1.4, 0.4, 1), box-shadow 150ms ease;
    text-decoration: none;
}
.btn:hover {
    transform: translate(-2px, -2px) rotate(-1deg);
    box-shadow: var(--shadow-2);
    color: var(--ink);
    background: var(--paper);
}
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }

.btn--ghost {
    background: var(--paper);
    color: var(--btn-ghost-text);
    border-color: var(--btn-ghost-border);
}
.btn--ghost:hover { background: var(--cyan); color: var(--ink); }

.btn--red {
    background: var(--btn-red-bg-1);
    color: var(--btn-red-text);
}
.btn--red:hover { background: var(--gold); color: var(--ink); }

.btn[disabled], .btn[aria-disabled="true"] {
    opacity: 0.5; cursor: not-allowed; pointer-events: none;
}

/* ---- Focus ring (WCAG 2.2 non-text contrast, every theme but elven) ---
   Karlpital and Steampunk had no explicit :focus-visible rule at all and
   fell back to the browser default outline, which headless/older Chromium
   renders as `outline-style: auto` with a used colour that doesn't reliably
   contrast against either theme's surfaces. `var(--ink)` always contrasts
   >= 4.5:1 against this site's own paper/panel tones in every theme (it's
   the primary body-text colour), so one rule covers Karlpital's default
   look and Steampunk (elven keeps its own gold ring below, which already
   passes and matches its own character more). */
a:focus-visible,
button:focus-visible,
summary:focus-visible,
[role="button"]:focus-visible {
    outline: 3px solid var(--btn-focus-ring);
    outline-offset: 3px;
}

.linkish {
    background: none; border: 0; padding: 0; cursor: pointer; font: inherit;
    color: var(--red); font-weight: 800;
}
.linkish:hover { color: var(--red-deep); }

/* ---- Forms ----------------------------------------------------- */
form .field { display: block; margin-bottom: 1.3rem; }
form label, form .field-label, form legend {
    display: block;
    font-family: var(--mono);
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--ink);
    margin-bottom: 0.5rem;
    padding: 0;
}
form input[type="text"],
form input[type="email"],
form input[type="password"],
form input[type="number"],
form input[type="search"],
form input[type="date"],
form input[type="file"],
form select,
form textarea {
    width: 100%;
    background: var(--paper);
    border: 3px solid var(--ink);
    border-radius: 12px;
    padding: 0.75rem 0.9rem;
    font: 500 1.02rem var(--body);
    color: var(--ink);
    outline: none;
    box-shadow: 3px 3px 0 var(--ink);
    transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
form input:focus,
form select:focus,
form textarea:focus {
    background: var(--paper-soft);
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 var(--ink);
}
form input::placeholder, form textarea::placeholder { color: var(--ink-soft); font-style: italic; }
form select {
    -webkit-appearance: none;
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%),
                      linear-gradient(135deg, var(--ink) 50%, transparent 50%);
    background-position: right 0.95rem center, right 0.65rem center;
    background-size: 7px 7px;
    background-repeat: no-repeat;
    padding-right: 1.8rem;
}
form textarea { resize: vertical; min-height: 5rem; }

.form-helper {
    font-family: var(--body);
    font-size: 0.86rem;
    color: var(--ink-mid);
    margin-top: 0.35rem;
    font-weight: 500;
}
.form-grid { display: grid; gap: 1.25rem 1.5rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.form-actions {
    margin-top: 2rem;
    display: flex; gap: 0.9rem; justify-content: flex-end; align-items: center;
}

/* ---- Save-on-change field status (Detalles panel) --------------- */
.detail-status {
    display: block;
    min-height: 1.1em;
    margin-top: 0.35rem;
    font-family: var(--body);
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--olive);
}
.detail-status--error { color: var(--red); }
.errorlist {
    list-style: none; margin: 0 0 0.4rem; padding: 0;
    color: var(--red-deep);
    font-family: var(--mono);
    font-size: 0.78rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    font-weight: 600;
}

/* ---- Notices --------------------------------------------------- */
.notice {
    border: 3px solid var(--ink);
    border-radius: var(--r);
    padding: 1rem 1.1rem;
    background: var(--gold);
    color: var(--ink);
    box-shadow: var(--shadow-1);
    margin-bottom: 1.5rem;
    font-weight: 600;
}
.notice--success { background: var(--olive); color: var(--paper); }
.notice--info    { background: var(--cyan); color: var(--ink); }
.notice--warning { background: var(--red); color: var(--paper); }

/* ---- Page header (editorial) ---------------------------------- */
.page-header { margin-bottom: 3rem; display: grid; gap: 1.25rem; position: relative; }
.page-header__row {
    display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1.5rem;
}
.page-header h1 { margin: 0; max-width: 14ch; }
.page-header .lede {
    font-family: var(--body);
    font-style: italic;
    font-size: clamp(1.05rem, 1.5vw, 1.2rem);
    color: var(--ink-mid);
    max-width: 44ch;
    margin: 0;
    font-weight: 600;
}

/* ---- Speech bubble ---- */
.speech {
    position: relative;
    background: var(--paper-soft);
    border: 3px solid var(--ink);
    border-radius: 22px;
    padding: 1rem 1.2rem;
    box-shadow: var(--shadow-1);
    font-family: var(--body);
    font-weight: 600;
    color: var(--ink);
    max-width: 32ch;
}
.speech::before {
    content: "";
    position: absolute;
    left: -18px; top: 22px;
    width: 28px; height: 22px;
    background: var(--paper-soft);
    border-left: 3px solid var(--ink);
    border-bottom: 3px solid var(--ink);
    clip-path: polygon(0 0, 100% 100%, 100% 0);
    transform: rotate(15deg);
}
.speech strong { color: var(--red); }

/* ---- Mascot wrapper ---- */
.mascot {
    width: 110px; height: 110px;
    flex-shrink: 0;
    filter: drop-shadow(3px 3px 0 var(--ink));
}
.mascot--lg { width: 160px; height: 160px; }
.mascot--sm { width: 72px; height: 72px; }

.mascot-block {
    display: flex;
    align-items: center;
    gap: 1.2rem;
    margin: 1.5rem 0 2rem;
}
@media (max-width: 540px) {
    .mascot-block { flex-wrap: wrap; }
}

/* dividers */
.divider {
    border: 0;
    height: 4px;
    background:
        repeating-linear-gradient(90deg,
            var(--red) 0 18px,
            var(--gold) 18px 36px);
    margin-block: clamp(2rem, 5vw, 3.5rem);
    border-radius: var(--r-pill);
}
.divider--stars {
    display: flex; align-items: center; gap: 1rem;
    background: none; height: auto;
    font-family: var(--display);
    color: var(--gold-deep);
    font-size: 1.8rem;
    justify-content: center;
}
.divider--stars::before, .divider--stars::after {
    content: "";
    flex: 1; height: 4px;
    border-radius: var(--r-pill);
    background: repeating-linear-gradient(90deg, var(--red) 0 14px, var(--gold) 14px 28px);
}

/* ---- Library list & toolbar ----------------------------------- */
.library-toolbar {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1.6fr repeat(2, 1fr) auto;
    align-items: end;
    padding: 1.4rem;
    background: var(--paper-soft);
    border: 3px solid var(--ink);
    border-radius: var(--r);
    box-shadow: var(--shadow-1);
    margin-bottom: 2.5rem;
}
@media (max-width: 760px) { .library-toolbar { grid-template-columns: 1fr; } }
.library-toolbar .field { margin-bottom: 0; }
.library-toolbar input,
.library-toolbar select { box-shadow: 2px 2px 0 var(--ink); }

/* ---- Card grid ------------------------------------------------- */
.cardgrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 1.6rem 1.5rem;
}

.bookcard {
    position: relative;
    padding: 1.2rem 1.2rem 1.1rem;
    background: var(--paper);
    border: 3px solid var(--ink);
    border-radius: var(--r);
    color: var(--ink);
    text-decoration: none;
    box-shadow: var(--shadow-1);
    transition: transform 220ms cubic-bezier(0.2, 1.4, 0.4, 1), box-shadow 220ms ease, background 220ms ease;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    min-height: 12rem;
}
.bookcard:hover {
    transform: translate(-3px, -3px) rotate(-1deg);
    box-shadow: var(--shadow-2);
    background: var(--paper-soft);
    color: var(--ink);
}
.bookcard:nth-child(3n)    { transform: rotate(0.6deg); }
.bookcard:nth-child(3n+1)  { transform: rotate(-0.5deg); }
.bookcard:nth-child(4n+2)  { transform: rotate(0.3deg); }

.bookcard__stamp {
    position: absolute;
    top: -10px; right: 1rem;
    font-family: var(--mono);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--paper);
    background: var(--red);
    border: 2px solid var(--ink);
    padding: 0.22rem 0.55rem;
    border-radius: var(--r-pill);
    box-shadow: 2px 2px 0 var(--ink);
    transform: rotate(3deg);
}
.bookcard__title {
    font-family: var(--display);
    font-weight: 700;
    font-size: 1.25rem;
    line-height: 1.1;
    margin: 0.8rem 0 0;
    padding-right: 1.5rem;
    color: var(--ink);
}
.bookcard__authors {
    font-family: var(--body);
    font-style: italic;
    font-weight: 700;
    color: var(--ink-mid);
    font-size: 1rem;
    margin: 0;
}
.bookcard__meta {
    margin-top: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding-top: 0.85rem;
    border-top: 2px dashed var(--rule);
}

/* ---- Tags ------------------------------------------------------ */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.22rem 0.6rem 0.18rem;
    font-family: var(--mono);
    font-size: 0.64rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink);
    background: var(--paper-deep);
    border: 2px solid var(--ink);
    border-radius: var(--r-pill);
    box-shadow: 2px 2px 0 var(--ink);
}
.tag--read       { background: var(--olive); color: var(--paper); }
.tag--reading    { background: var(--red); color: var(--paper); }
.tag--want       { background: var(--paper-deep); color: var(--ink); }
.tag--location   { background: var(--cyan); color: var(--ink); }
.tag--sale       { background: var(--red); color: var(--paper); }
.tag--trade      { background: var(--purple); color: var(--paper); }
.tag--loaned     { background: var(--gold); color: var(--ink); }

/* ---- Avatars ---------------------------------------------------- */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 50%;
    border: 2px solid var(--ink);
    overflow: hidden;
    object-fit: cover;
    background: var(--paper-deep);
    color: var(--ink);
    font-family: var(--display);
    font-weight: 700;
    letter-spacing: 0.02em;
}
.avatar--initials { background: var(--red); color: var(--paper); }
.avatar--sm { width: 1.8rem;  height: 1.8rem;  font-size: 0.7rem; }
.avatar--md { width: 2.8rem;  height: 2.8rem;  font-size: 1rem; }
.avatar--lg { width: 5.5rem;  height: 5.5rem;  font-size: 1.9rem; border-width: 3px; }

/* ---- Empty state ---------------------------------------------- */
.empty-state {
    display: flex;
    gap: 2.5rem;
    align-items: center;
    flex-wrap: wrap;
    padding-block: clamp(2rem, 6vw, 4rem);
    max-width: 64rem;
}
.empty-state__text { flex: 1 1 24rem; }
.empty-state h2 {
    font-size: clamp(2.2rem, 5vw, 3.6rem);
    margin: 0 0 0.8rem;
    font-weight: 700;
    text-shadow: 3px 3px 0 var(--gold), 5px 5px 0 var(--ink);
    color: var(--red);
}
.empty-state .lede {
    font-family: var(--body);
    font-style: italic;
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--ink-mid);
    margin: 0 0 2rem;
}

/* ---- Choice list (numbered options) --------------------------- */
.choice-list {
    display: grid;
    gap: 1rem;
    list-style: none;
    padding: 0;
    margin: 0;
}
.choice {
    display: grid;
    grid-template-columns: 4rem 1fr 2.5rem;
    align-items: center;
    gap: 1.2rem;
    padding: 1.4rem 1.4rem;
    background: var(--paper);
    border: 3px solid var(--ink);
    border-radius: var(--r);
    color: var(--ink);
    text-decoration: none;
    box-shadow: var(--shadow-1);
    transition: transform 220ms cubic-bezier(0.2, 1.4, 0.4, 1), box-shadow 220ms ease, background 220ms ease;
}
.choice:hover {
    transform: translate(-3px, -3px) rotate(-0.5deg);
    box-shadow: var(--shadow-2);
    background: var(--paper-soft);
    color: var(--ink);
}
.choice__num {
    font-family: var(--brand);
    font-weight: 400;
    font-size: 1.9rem;
    color: var(--paper);
    background: var(--red);
    border: 3px solid var(--ink);
    border-radius: 50%;
    width: 3.4rem; height: 3.4rem;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 2px 2px 0 var(--ink);
    transform: rotate(-6deg);
    line-height: 1;
    padding-top: 0.2rem;
}
.choice:nth-child(2) .choice__num { background: var(--gold); color: var(--ink); transform: rotate(4deg); }
.choice:nth-child(3) .choice__num { background: var(--cyan); color: var(--ink); transform: rotate(-3deg); }
.choice:nth-child(4) .choice__num { background: var(--purple); color: var(--paper); transform: rotate(5deg); }
.choice__title {
    font-family: var(--display);
    font-weight: 700;
    font-size: clamp(1.35rem, 2.2vw, 1.75rem);
    line-height: 1.05;
    margin: 0 0 0.2rem;
    color: var(--ink);
}
.choice__sub { color: var(--ink-mid); margin: 0; max-width: 56ch; font-weight: 600; }
.choice__arrow {
    font-family: var(--display);
    font-weight: 700;
    font-size: 1.8rem;
    color: var(--red);
    text-align: right;
    transition: transform 220ms cubic-bezier(0.2, 1.4, 0.4, 1);
}
.choice:hover .choice__arrow { transform: translateX(0.6rem) rotate(-8deg); color: var(--red-deep); }
@media (max-width: 600px) {
    .choice { grid-template-columns: 3rem 1fr; }
    .choice__arrow { display: none; }
}

/* ---- Places tree (Ubicaciones list) ---------------------------- */
.tree-list {
    display: grid;
    gap: 0.55rem;
    list-style: none;
    padding: 0;
    margin: 0;
}
.place-row {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.85rem 1rem;
    background: var(--paper);
    border: 2px solid var(--rule);
    border-radius: var(--r);
    color: var(--ink);
}
.place-row--root {
    border-color: var(--ink);
    box-shadow: var(--shadow-1);
}
.tree-connectors {
    display: flex;
    align-self: stretch;
    flex: 0 0 auto;
}
.tree-guide,
.tree-branch {
    width: 1.1rem;
    flex: 0 0 auto;
    align-self: stretch;
    position: relative;
}
.tree-guide {
    border-left: 2px solid transparent;
}
.tree-guide--on {
    border-left-color: var(--ink-mid);
}
.tree-branch::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    height: 50%;
    border-left: 2px solid var(--ink-mid);
}
.tree-branch:not(.tree-branch--last)::before {
    height: 100%;
}
.tree-branch::after {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    width: 0.6rem;
    border-top: 2px solid var(--ink-mid);
}
.place-row__icon {
    flex: 0 0 auto;
    align-self: center;
    color: var(--gold-deep);
}
.place-row__body {
    /* A zero basis (not "auto") keeps the body on the same line as the
       connectors even when its content (e.g. a long name or parent path)
       would otherwise be wide enough to force a wrap in a flex-wrap row. */
    flex: 1 1 0;
    min-width: 0;
}
.place-row__name {
    margin: 0 0 0.15rem;
    font-family: var(--display);
    font-weight: 700;
    color: var(--ink);
}
.place-row__name--root { font-size: 1.2rem; }
.place-row__name--nested { font-size: 0.98rem; }
.place-row__parent {
    margin: 0 0 0.15rem;
    color: var(--ink-mid);
    font-size: 0.82rem;
    font-weight: 600;
}
.place-row__counts {
    margin: 0;
    color: var(--ink-mid);
    font-size: 0.85rem;
    font-weight: 600;
}
.place-row__actions {
    flex: 0 0 auto;
    align-self: center;
    display: flex;
    gap: 0.5rem;
}
@media (max-width: 480px) {
    .place-row { flex-wrap: wrap; }
    .place-row__icon { display: none; }
    .place-row__actions { flex-basis: 100%; justify-content: flex-end; }
    .tree-guide, .tree-branch { width: 0.8rem; }
}

/* ---- Panels (forms etc.) -------------------------------------- */
.panel {
    background: var(--paper);
    border: 3px solid var(--ink);
    border-radius: var(--r);
    padding: clamp(1.5rem, 3vw, 2.25rem);
    box-shadow: var(--shadow-1);
    max-width: 640px;
}
.panel--narrow { max-width: 480px; }
.panel--tight  { padding: 1.25rem; }
.panel--gold   { background: var(--paper-soft); }

/* ---- Native <dialog> (the "+ New place" popup) ------------------ */
dialog {
    background: var(--paper);
    color: var(--ink);
    border: 3px solid var(--ink);
    border-radius: var(--r);
    padding: clamp(1.25rem, 3vw, 2rem);
    box-shadow: var(--shadow-1);
    max-width: 420px;
    width: calc(100% - 2rem);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }

[x-cloak] { display: none !important; }

/* ---- Theme picker (profile page) ------------------------------- */
.theme-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr)); gap: 1rem; }
.theme-picker__card { cursor: pointer; }
.theme-picker__input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.theme-picker__panel {
    outline: 3px solid transparent;
    outline-offset: 3px;
    transition: outline-color 150ms ease;
}
.theme-picker__input:checked + .theme-picker__panel {
    outline-color: var(--gold);
}
.theme-picker__input:focus-visible + .theme-picker__panel {
    outline: 3px dashed var(--ink);
    outline-offset: 3px;
}
.theme-picker .theme-picker__panel h3 {
    font-size: 0.92rem;
    line-height: 1.2;
    overflow-wrap: break-word;
    /* Cards keep their own brand voice: don't let the active theme's global
       heading transform (e.g. Steampunk's uppercase + wide letter-spacing)
       widen these titles past the card and force a mid-word break. Extra
       specificity here (vs. [data-theme="x"] h1,h2,h3,h4) is intentional. */
    text-transform: none;
    letter-spacing: normal;
}
.theme-picker__title--elven { overflow-wrap: anywhere; }

/* ---- Scan page ------------------------------------------------ */
.scan-frame {
    background: var(--ink);
    aspect-ratio: 4 / 3;
    border: 4px solid var(--ink);
    border-radius: var(--r);
    margin-bottom: 1.4rem;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-1);
}
.scan-frame video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame::before, .scan-frame::after, .scan-frame > .scan-corner {
    content: "";
    position: absolute;
    width: 32px; height: 32px;
    border: 3px solid var(--gold);
    pointer-events: none;
}
.scan-frame::before { top: 12px; left: 12px; border-right: 0; border-bottom: 0; border-top-left-radius: 8px; }
.scan-frame::after  { top: 12px; right: 12px; border-left: 0; border-bottom: 0; border-top-right-radius: 8px; }
.scan-frame .scan-corner.bl { bottom: 12px; left: 12px; border-right: 0; border-top: 0; border-bottom-left-radius: 8px; }
.scan-frame .scan-corner.br { bottom: 12px; right: 12px; border-left: 0; border-top: 0; border-bottom-right-radius: 8px; }
.scan-row {
    display: grid; grid-template-columns: 1fr auto;
    gap: 0.8rem; align-items: end;
}
.scan-row .field { margin-bottom: 0; }

/* ---- Copy detail ---------------------------------------------- */
.book-detail {
    display: grid;
    grid-template-columns: minmax(220px, 280px) 1fr;
    gap: clamp(1.5rem, 4vw, 3rem);
    margin-top: 2rem;
}
@media (max-width: 720px) { .book-detail { grid-template-columns: 1fr; } }

.home-grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 2rem;
}
@media (max-width: 720px) { .home-grid { grid-template-columns: 1fr; } }

/* ---- Landing page (logged-out visitors) ------------------------ */
.landing-hero__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    flex-wrap: wrap;
}
.landing-hero__copy { max-width: 46ch; }
.landing-hero__copy h1 { max-width: none; }
.landing-hero__actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}
.landing-section { margin-bottom: 3rem; }
.landing-section > .eyebrow { display: block; margin-bottom: 1.25rem; }
.landing-feature {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    text-align: left;
}
.landing-feature .mascot { margin-bottom: 0.2rem; }
.landing-feature h3 { margin: 0; }
.landing-feature p { margin: 0; color: var(--ink-mid); }
.landing-step {
    grid-template-columns: 4rem 1fr;
}
.landing-themes { margin-bottom: 1rem; }
.landing-themes__caption {
    font-style: italic;
    font-weight: 600;
}
.landing-cta {
    text-align: center;
    display: grid;
    gap: 1.25rem;
    justify-content: center;
    /* Without this, the single-column grid item (the "Sign up" button)
       defaults to justify-self: stretch and fills the whole panel width. */
    justify-items: center;
    margin: 0 auto;
}
@media (max-width: 720px) {
    .landing-hero__row { flex-direction: column; align-items: flex-start; }
    .landing-hero__copy { max-width: none; }
}

.book-detail__cover {
    background: var(--gold);
    aspect-ratio: 2 / 3;
    border: 4px solid var(--ink);
    border-radius: var(--r);
    box-shadow: var(--shadow-2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--brand);
    font-size: 6rem;
    color: var(--red);
    -webkit-text-stroke: 2px var(--ink);
    text-transform: uppercase;
    transform: rotate(-1.5deg);
}

.book-detail__title {
    font-size: clamp(2rem, 4vw, 3.2rem);
    /* The eyebrow above (e.g. "De la biblioteca de …") isn't in a grid row
       here, so on narrow screens where it wraps to two lines it would
       otherwise touch this title — a fixed top margin keeps them apart
       regardless of how many lines the eyebrow takes. */
    margin: 0.5rem 0 0.4rem;
    font-weight: 700;
    text-shadow: 3px 3px 0 var(--gold), 5px 5px 0 var(--ink);
    color: var(--red);
}
.book-detail__authors {
    font-family: var(--body);
    font-style: italic;
    font-weight: 800;
    color: var(--ink-mid);
    font-size: 1.3rem;
    margin: 0 0 1.5rem;
}

.dl {
    display: grid;
    grid-template-columns: minmax(120px, 14ch) 1fr;
    column-gap: 1.5rem;
    row-gap: 0.65rem;
    margin: 0;
    padding-top: 1rem;
    border-top: 3px dashed var(--rule);
}
.dl dt {
    font-family: var(--mono);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--red);
    margin: 0;
    align-self: baseline;
}
.dl dd { margin: 0; font-weight: 600; }

.backlink {
    display: inline-block;
    font-family: var(--mono);
    font-size: 0.78rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--paper);
    background: var(--ink);
    padding: 0.4rem 0.85rem;
    border-radius: var(--r-pill);
    border: 2px solid var(--ink);
    box-shadow: 2px 2px 0 var(--ink);
}
.backlink:hover { background: var(--red); color: var(--paper); }

/* ---- Footer ---------------------------------------------------- */
.colophon {
    border-top: 4px solid var(--ink);
    background: var(--ink);
    color: var(--gold);
    padding-block: 1.6rem;
    margin-top: 4rem;
}
.colophon__inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-family: var(--mono);
    font-size: 0.74rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    font-weight: 700;
}
.colophon__inner .ribbon {
    font-family: var(--display);
    font-weight: 700;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--red);
    background: var(--gold);
    padding: 0.3rem 0.85rem;
    border-radius: var(--r-pill);
    border: 2px solid var(--ink);
}

/* ---- Animations ----------------------------------------------- */
@keyframes pop-in {
    from { opacity: 0; transform: translateY(12px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
main > * { animation: pop-in 520ms cubic-bezier(0.2, 1.3, 0.3, 1) both; }
main > *:nth-child(1) { animation-delay: 0ms; }
main > *:nth-child(2) { animation-delay: 70ms; }
main > *:nth-child(3) { animation-delay: 130ms; }
main > *:nth-child(4) { animation-delay: 190ms; }
main > *:nth-child(5) { animation-delay: 240ms; }

@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-3deg); }
    75% { transform: rotate(3deg); }
}
.mascot { animation: wiggle 5s ease-in-out infinite; transform-origin: 50% 90%; }
.mascot:nth-of-type(2) { animation-duration: 6.2s; animation-delay: -1s; }

@media (prefers-reduced-motion: reduce) {
    main > *, .mascot { animation: none; }
}

/* ---- Marquee ribbon -------------------------------------------- */
.marquee {
    overflow: hidden;
    background: var(--red);
    color: var(--gold);
    border-block: 3px solid var(--ink);
    padding-block: 0.5rem;
    font-family: var(--display);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.marquee__track {
    display: inline-flex;
    gap: 3rem;
    white-space: nowrap;
    animation: marquee 28s linear infinite;
    /* No initial padding-left: 100% — that started the track fully
       off-screen, so the ribbon looked like an empty band for the many
       seconds (up to half the animation's duration) it took the first
       saying to scroll into view, most noticeable on the landing page
       where it's the first thing under the header. The content is
       duplicated (two laps), so translating by -50% still loops
       seamlessly — it just starts visible instead of starting blank. */
}
.marquee__track span::before { content: "✦"; color: var(--paper); margin-right: 0.8rem; }
@keyframes marquee {
    from { transform: translateX(0); }
    to   { transform: translateX(-50%); }
}

/* ---- Allauth gentle override ---------------------------------- */
.allauth-form {
    max-width: 460px;
    margin: 2rem auto;
    background: var(--paper);
    padding: 1.6rem;
    border: 3px solid var(--ink);
    border-radius: var(--r);
    box-shadow: var(--shadow-1);
}
.allauth-form ul { padding-left: 1.2rem; }
.allauth-form h1 {
    color: var(--red);
    text-shadow: 3px 3px 0 var(--gold), 5px 5px 0 var(--ink);
    font-size: clamp(1.8rem, 3.5vw, 2.6rem);
    margin-bottom: 1rem;
    font-weight: 700;
}

/* ============================================================
   Steampunk Librarian — component overrides
   ============================================================ */

body[data-theme="steampunk"] {
    background-image:
        radial-gradient(circle at 20% 18%, rgba(168, 89, 40, 0.08) 0%, transparent 35%),
        radial-gradient(circle at 78% 82%, rgba(217, 164, 85, 0.06) 0%, transparent 35%),
        radial-gradient(circle at 50% 50%, rgba(94, 74, 107, 0.04) 0%, transparent 50%);
    background-size: 100% 100%, 100% 100%, 100% 100%;
    background-attachment: fixed;
}

body[data-theme="steampunk"]::before {
    opacity: 0.10;
}

body[data-theme="steampunk"]::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1001;
    background:
        radial-gradient(ellipse at center,
            transparent 50%,
            rgba(20, 14, 8, 0.65) 100%);
}

[data-theme="steampunk"] h1,
[data-theme="steampunk"] h2,
[data-theme="steampunk"] h3,
[data-theme="steampunk"] h4 {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--amber);
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6), 0 0 8px rgba(217, 164, 85, 0.25);
}

[data-theme="steampunk"] h1 {
    text-shadow:
        0 2px 0 rgba(0, 0, 0, 0.7),
        0 0 10px rgba(217, 164, 85, 0.30),
        2px 2px 0 var(--red-deep);
}

[data-theme="steampunk"] a {
    color: var(--amber);
    text-decoration: underline;
    text-decoration-color: rgba(217, 164, 85, 0.4);
    text-underline-offset: 3px;
}
[data-theme="steampunk"] a:hover {
    color: var(--copper);
    text-decoration-color: var(--copper);
}

[data-theme="steampunk"] .topbar {
    background: linear-gradient(180deg, #3A2A1D 0%, #2A1E14 100%);
    border-bottom: 2px solid var(--brass);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(217, 164, 85, 0.15);
}
[data-theme="steampunk"] .brand {
    color: var(--amber);
    -webkit-text-stroke: 0;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.7), 0 0 6px rgba(217, 164, 85, 0.30);
}
[data-theme="steampunk"] .brand sup {
    background: var(--brass);
    color: var(--paper-deep);
    border: 1px solid var(--paper);
}

[data-theme="steampunk"] .topbar__nav a,
[data-theme="steampunk"] .topbar__nav button {
    background: linear-gradient(180deg, #5A3F26 0%, #3A2A1D 100%);
    color: var(--amber);
    border: 1px solid var(--brass);
    box-shadow: inset 0 1px 0 rgba(217, 164, 85, 0.2), 0 1px 0 rgba(0, 0, 0, 0.5);
}
[data-theme="steampunk"] .topbar__nav a:hover,
[data-theme="steampunk"] .topbar__nav button:hover {
    /* Same --btn-bg-1/-2 gradient as .btn below, same reason (its previous
       copper stop under paper-deep text only cleared 4.1:1). */
    background: linear-gradient(180deg, var(--btn-bg-1) 0%, var(--btn-bg-2) 100%);
    color: var(--btn-text);
    transform: translateY(-1px);
}
[data-theme="steampunk"] .topbar__nav span[aria-hidden] { color: var(--ink-soft); }

[data-theme="steampunk"] .marquee {
    background: var(--paper-deep);
    color: var(--amber);
    border-block: 2px solid var(--brass);
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
}
[data-theme="steampunk"] .marquee__track span::before {
    content: "⚙";
    color: var(--copper);
    margin-right: 0.8rem;
}

[data-theme="steampunk"] .btn {
    /* --btn-bg-1/-2 (brass -> gold-deep, not copper): --btn-text needs
       >= 4.5:1 against *both* gradient stops (WCAG AA); copper's stop only
       cleared 3.55:1. */
    background: linear-gradient(180deg, var(--btn-bg-1) 0%, var(--btn-bg-2) 100%);
    color: var(--btn-text);
    border: 2px solid #5A3818;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.25),
        inset 0 -2px 0 rgba(0, 0, 0, 0.20),
        0 2px 0 rgba(0, 0, 0, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-family: var(--display);
}
[data-theme="steampunk"] .btn:hover {
    transform: translateY(-1px);
    background: linear-gradient(180deg, var(--amber) 0%, var(--brass) 100%);
    color: var(--paper-deep);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.35),
        inset 0 -2px 0 rgba(0, 0, 0, 0.25),
        0 4px 0 rgba(0, 0, 0, 0.5);
}
[data-theme="steampunk"] .btn:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.6); }
[data-theme="steampunk"] .btn--ghost {
    background: transparent;
    color: var(--btn-ghost-text);
    border-color: var(--btn-ghost-border);
    box-shadow: inset 0 0 0 1px rgba(217, 164, 85, 0.25);
}
[data-theme="steampunk"] .btn--ghost:hover {
    background: rgba(181, 114, 59, 0.18);
    color: var(--amber);
}
[data-theme="steampunk"] .btn--red {
    /* --btn-red-bg-1/-2 (red -> red-deep, not the brighter #C24A28):
       --btn-red-text needs >= 4.5:1 against *both* stops; the brighter one
       only cleared 3.29:1. */
    background: linear-gradient(180deg, var(--btn-red-bg-1) 0%, var(--btn-red-bg-2) 100%);
    color: var(--btn-red-text);
    border-color: #5A1F0F;
}

[data-theme="steampunk"] .eyebrow {
    background: var(--paper-soft);
    color: var(--amber);
    border: 1px solid var(--brass);
    box-shadow: inset 0 1px 0 rgba(217, 164, 85, 0.2), 0 1px 0 rgba(0, 0, 0, 0.4);
    transform: none;
    font-family: var(--mono);
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
}
[data-theme="steampunk"] .eyebrow::before { content: "❦"; color: var(--copper); }

[data-theme="steampunk"] form input,
[data-theme="steampunk"] form select,
[data-theme="steampunk"] form textarea {
    background: var(--paper-deep);
    color: var(--ink);
    border: 2px solid var(--brass);
    box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.3);
    border-radius: 3px;
}
[data-theme="steampunk"] form input:focus,
[data-theme="steampunk"] form select:focus,
[data-theme="steampunk"] form textarea:focus {
    background: var(--paper-soft);
    border-color: var(--amber);
    box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.3), 0 0 0 2px rgba(217, 164, 85, 0.20);
    transform: none;
}
[data-theme="steampunk"] form label,
[data-theme="steampunk"] form .field-label {
    color: var(--amber);
    font-family: var(--mono);
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
}

[data-theme="steampunk"] .panel {
    background: linear-gradient(180deg, var(--paper-soft) 0%, var(--paper) 100%);
    border: 2px solid var(--brass);
    border-radius: 4px;
    box-shadow:
        inset 0 1px 0 rgba(217, 164, 85, 0.15),
        0 2px 0 rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(0, 0, 0, 0.3);
    position: relative;
}
[data-theme="steampunk"] .panel--gold { background: var(--paper-deep); border-color: var(--copper); }

[data-theme="steampunk"] .speech {
    background: var(--paper-soft);
    border: 2px solid var(--brass);
    border-radius: 6px;
    color: var(--ink);
    box-shadow: inset 0 1px 0 rgba(217, 164, 85, 0.15), 0 2px 0 rgba(0, 0, 0, 0.5);
}
[data-theme="steampunk"] .speech::before {
    background: var(--paper-soft);
    border-color: var(--brass);
}
[data-theme="steampunk"] .speech strong { color: var(--amber); text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5); }

[data-theme="steampunk"] .bookcard {
    background: linear-gradient(180deg, var(--paper-soft) 0%, var(--paper) 100%);
    border: 2px solid var(--brass);
    border-radius: 4px;
    color: var(--ink);
    box-shadow:
        inset 0 1px 0 rgba(217, 164, 85, 0.18),
        0 3px 0 rgba(0, 0, 0, 0.55),
        0 0 0 1px rgba(0, 0, 0, 0.3);
    transform: none !important;
}
[data-theme="steampunk"] .bookcard:hover {
    transform: translateY(-2px) !important;
    border-color: var(--amber);
    box-shadow:
        inset 0 1px 0 rgba(217, 164, 85, 0.25),
        0 5px 0 rgba(0, 0, 0, 0.55),
        0 0 0 1px rgba(0, 0, 0, 0.3);
    background: linear-gradient(180deg, #4A3520 0%, var(--paper-soft) 100%);
}
[data-theme="steampunk"] .bookcard__stamp {
    background: var(--brass);
    color: var(--paper-deep);
    border: 1px solid #5A3818;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transform: none;
}
[data-theme="steampunk"] .bookcard__title {
    color: var(--amber);
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
}
[data-theme="steampunk"] .bookcard__authors { color: var(--ink-mid); font-style: italic; font-family: var(--body); }
[data-theme="steampunk"] .bookcard__meta { border-top: 1px dashed var(--rule); }

[data-theme="steampunk"] .tag {
    background: var(--paper-deep);
    color: var(--amber);
    border-color: var(--brass);
    box-shadow: inset 0 1px 0 rgba(217, 164, 85, 0.15);
    font-family: var(--mono);
}
[data-theme="steampunk"] .tag--read     { background: var(--olive); color: var(--paper-deep); border-color: var(--olive); }
[data-theme="steampunk"] .tag--reading  { background: var(--brass); color: var(--paper-deep); border-color: var(--brass); }
[data-theme="steampunk"] .tag--sale     { background: var(--red); color: var(--ink); border-color: #5A1F0F; }
[data-theme="steampunk"] .tag--trade    { background: var(--purple); color: var(--ink); border-color: #2E1F3C; }
[data-theme="steampunk"] .tag--loaned   { background: var(--gold-deep); color: var(--paper-deep); border-color: var(--gold-deep); }
[data-theme="steampunk"] .tag--location { background: var(--verdigris); color: var(--paper-deep); border-color: var(--verdigris); }

[data-theme="steampunk"] .choice {
    background: linear-gradient(180deg, var(--paper-soft) 0%, var(--paper) 100%);
    border: 2px solid var(--brass);
    border-radius: 4px;
    box-shadow:
        inset 0 1px 0 rgba(217, 164, 85, 0.18),
        0 2px 0 rgba(0, 0, 0, 0.5);
}
[data-theme="steampunk"] .choice:hover {
    border-color: var(--amber);
    box-shadow:
        inset 0 1px 0 rgba(217, 164, 85, 0.25),
        0 4px 0 rgba(0, 0, 0, 0.5);
    transform: translate(-2px, -2px);
}
[data-theme="steampunk"] .choice__num {
    background: linear-gradient(180deg, var(--brass) 0%, var(--copper) 100%);
    color: var(--paper-deep);
    border: 2px solid #5A3818;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 2px 0 rgba(0, 0, 0, 0.5);
    transform: rotate(0);
    font-family: var(--display);
}
[data-theme="steampunk"] .choice__title { color: var(--amber); text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5); }
[data-theme="steampunk"] .choice__arrow { color: var(--copper); text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5); }

[data-theme="steampunk"] .empty-state h2 {
    color: var(--amber);
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.7), 0 0 12px rgba(217, 164, 85, 0.30), 2px 2px 0 var(--red-deep);
    -webkit-text-stroke: 0;
}

[data-theme="steampunk"] .divider {
    background:
        repeating-linear-gradient(90deg,
            var(--brass) 0 14px,
            var(--copper) 14px 28px);
    height: 3px;
}

[data-theme="steampunk"] .colophon {
    background: var(--paper-deep);
    border-top: 2px solid var(--brass);
    color: var(--amber);
    box-shadow: inset 0 1px 0 rgba(217, 164, 85, 0.15);
}
[data-theme="steampunk"] .colophon__inner .ribbon {
    background: var(--brass);
    color: var(--paper-deep);
    border-color: #5A3818;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
    font-family: var(--display);
}

[data-theme="steampunk"] .notice {
    background: var(--paper-soft);
    border: 2px solid var(--brass);
    border-left: 6px solid var(--brass);
    color: var(--ink);
    box-shadow: inset 0 1px 0 rgba(217, 164, 85, 0.15);
}
[data-theme="steampunk"] .notice--success { border-left-color: var(--olive); }
[data-theme="steampunk"] .notice--info    { border-left-color: var(--verdigris); }
[data-theme="steampunk"] .notice--warning { border-left-color: var(--red); }

[data-theme="steampunk"] .backlink {
    background: var(--paper-deep);
    color: var(--amber);
    border: 1px solid var(--brass);
    box-shadow: inset 0 1px 0 rgba(217, 164, 85, 0.20);
    font-family: var(--mono);
}
[data-theme="steampunk"] .backlink:hover { background: var(--brass); color: var(--paper-deep); }

[data-theme="steampunk"] .mascot { animation: none; }

/* ============================================================
   Biblioteca del Bosque Élfico — component overrides
   Night forest, moonlit ink, gold-leaf illumination.
   Small caps (Alegreya SC) replace the all-caps mono labels.
   ============================================================ */

body[data-theme="elven"] {
    font-weight: 400;
    font-size: 18px;
    line-height: 1.6;
    background-color: var(--paper);
    background-image:
        radial-gradient(ellipse 60% 45% at 88% -8%, rgba(201, 211, 214, 0.17) 0%, transparent 70%),
        radial-gradient(ellipse 55% 50% at -5% 105%, rgba(94, 130, 72, 0.22) 0%, transparent 70%),
        radial-gradient(circle at 14% 22%, rgba(217, 184, 96, 0.55) 0 1.2px, transparent 2.2px),
        radial-gradient(circle at 71% 64%, rgba(217, 184, 96, 0.45) 0 1px, transparent 2px),
        radial-gradient(circle at 42% 88%, rgba(201, 211, 214, 0.40) 0 1px, transparent 2px),
        radial-gradient(circle at 90% 38%, rgba(217, 184, 96, 0.35) 0 1.4px, transparent 2.4px);
    background-size: 100% 100%, 100% 100%, 610px 610px, 470px 470px, 530px 530px, 690px 690px;
    background-attachment: fixed;
}

/* faint gold vine tracery instead of the paper grain */
body[data-theme="elven"]::before {
    opacity: 0.05;
    mix-blend-mode: normal;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><g fill='none' stroke='%23D9B860' stroke-width='1.2' stroke-linecap='round'><path d='M10 210 C60 170 70 120 120 100 S190 40 214 8'/><path d='M60 164 q-22 -6 -30 -26 q22 2 30 26z'/><path d='M96 112 q4 -24 24 -32 q-2 22 -24 32z'/><path d='M150 70 q-20 -10 -24 -30 q20 6 24 30z'/><path d='M184 34 q14 -4 22 6 q-12 8 -22 -6z'/></g></svg>");
    background-size: 220px 220px;
}

/* canopy vignette */
body[data-theme="elven"]::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1001;
    background: radial-gradient(ellipse at center, transparent 58%, rgba(4, 10, 6, 0.55) 100%);
}

[data-theme="elven"] ::selection { background: var(--gold); color: var(--paper-deep); }

/* ---- Typography ---- */
[data-theme="elven"] h1,
[data-theme="elven"] h2,
[data-theme="elven"] h3,
[data-theme="elven"] h4 {
    font-family: var(--display);
    font-weight: 600;
    letter-spacing: 0.005em;
    text-transform: none;
    color: #EFE6C8;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.55);
    line-height: 1.08;
}
[data-theme="elven"] h1 {
    font-weight: 700;
    font-size: clamp(2.6rem, 6vw, 4.6rem);
    color: #F3EBD0;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6), 0 0 28px rgba(201, 211, 214, 0.12);
}
/* the illuminated initial — the one bold gesture of the theme */
[data-theme="elven"] h1::first-letter,
[data-theme="elven"] .empty-state h2::first-letter,
[data-theme="elven"] .book-detail__title::first-letter {
    font-family: var(--initial);
    font-weight: 400;
    font-size: 1.22em;
    color: var(--gold);
    text-shadow:
        0 1px 0 #6B5320,
        0 0 18px rgba(217, 184, 96, 0.45);
    padding-right: 0.03em;
}
[data-theme="elven"] h2 { color: #EAE0BF; }
[data-theme="elven"] h3 { color: var(--ink); font-weight: 700; }

[data-theme="elven"] a {
    color: #E8CD7E;
    font-weight: 600;
    text-decoration: underline;
    text-decoration-color: rgba(217, 184, 96, 0.45);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}
[data-theme="elven"] a:hover {
    color: #F6F1E0;
    text-decoration-color: var(--silver);
}
[data-theme="elven"] a:focus-visible,
[data-theme="elven"] button:focus-visible,
[data-theme="elven"] summary:focus-visible {
    outline: 2px solid var(--btn-focus-ring);
    outline-offset: 3px;
}

/* Alegreya SC sets much smaller than the other themes' mono faces, so the
   tiny inline sizes some templates put on .mono would drop below legibility. */
[data-theme="elven"] .mono,
[data-theme="elven"] .stamp {
    font-family: var(--mono);
    font-size: 0.82rem !important;
    letter-spacing: 0.06em;
    text-transform: lowercase;
    color: var(--ink-mid);
}
[data-theme="elven"] .page-header .lede,
[data-theme="elven"] .empty-state .lede {
    font-weight: 400;
    color: var(--ink-mid);
}
[data-theme="elven"] .linkish { color: #E8CD7E; font-weight: 600; }
[data-theme="elven"] .linkish:hover { color: #F6F1E0; }

/* ---- Eyebrow: a gilded rubric between fine rules ---- */
[data-theme="elven"] .eyebrow {
    background: none;
    color: var(--gold);
    border: 0;
    border-block: 1px solid var(--rule);
    border-radius: 0;
    box-shadow: none;
    transform: none;
    padding: 0.28rem 0.15rem 0.24rem;
    font-family: var(--mono);
    font-size: 0.92rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: lowercase;
    text-shadow: none;
}
[data-theme="elven"] .eyebrow::before { content: "❧"; color: var(--olive); font-size: 1.05em; }

/* ---- Top bar: bark and canopy, with a hanging vine ---- */
[data-theme="elven"] .topbar {
    background:
        linear-gradient(180deg, rgba(201, 211, 214, 0.05) 0%, transparent 60%),
        linear-gradient(180deg, #1B3526 0%, #112419 100%);
    border-bottom: 1px solid var(--gold-deep);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
}
[data-theme="elven"] .topbar::after {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: -9px;
    height: 9px;
    pointer-events: none;
    opacity: 0.8;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='64' height='9'><path d='M0 1 Q16 7 32 1 T64 1' fill='none' stroke='%23B08F3C' stroke-width='1'/><path d='M14 4 q3 5 7 4 q-2 -4 -7 -4z M46 4 q-3 5 -7 4 q2 -4 7 -4z' fill='%235E8248'/></svg>") repeat-x;
}
[data-theme="elven"] .topbar__inner {
    flex-wrap: wrap;
}
@media (min-width: 880px) {
    [data-theme="elven"] .topbar__inner { flex-wrap: nowrap; }
    [data-theme="elven"] .topbar__nav { flex-shrink: 1; min-width: 0; }
}
[data-theme="elven"] .brand {
    font-family: var(--brand);
    font-size: clamp(1.35rem, 2vw, 1.8rem);
    color: #E9EEEA;
    -webkit-text-stroke: 0;
    text-transform: none;
    letter-spacing: 0.04em;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.7), 0 0 14px rgba(201, 211, 214, 0.35);
    flex-shrink: 0;
}
[data-theme="elven"] .brand:hover { transform: none; color: #FFFFFF; text-decoration: none; }
[data-theme="elven"] .brand::first-letter { color: var(--gold); }
[data-theme="elven"] .brand sup {
    font-family: var(--mono);
    font-size: 0.62rem;
    letter-spacing: 0.1em;
    background: none;
    color: var(--gold);
    border: 1px solid var(--rule);
    border-radius: var(--r-pill);
}
[data-theme="elven"] .topbar__nav {
    font-family: var(--mono);
    font-size: 0.95rem;
    letter-spacing: 0.05em;
    text-transform: lowercase;
    font-weight: 500;
    gap: 0.5rem;
}
[data-theme="elven"] .topbar__nav a,
[data-theme="elven"] .topbar__nav button {
    text-transform: lowercase;
    background: rgba(9, 20, 14, 0.45);
    color: var(--ink);
    border: 1px solid rgba(217, 184, 96, 0.40);
    box-shadow: none;
    text-decoration: none;
    padding: 0.36rem 0.7rem 0.4rem;
    white-space: nowrap;
}
@media (min-width: 880px) and (max-width: 1300px) {
    [data-theme="elven"] .topbar__nav { font-size: 0.8rem; letter-spacing: 0.02em; gap: 0.4rem; }
    [data-theme="elven"] .topbar__nav a,
    [data-theme="elven"] .topbar__nav button { padding: 0.32rem 0.55rem 0.36rem; }
}
[data-theme="elven"] .topbar__nav a:hover,
[data-theme="elven"] .topbar__nav button:hover {
    background: var(--gold);
    border-color: var(--gold);
    color: var(--paper-deep);
    transform: none;
    box-shadow: 0 0 14px rgba(217, 184, 96, 0.35);
}
[data-theme="elven"] .topbar__nav span[aria-hidden] { color: var(--ink-soft); opacity: 1; }

/* ---- Marquee: a quiet ribbon of forest sayings ---- */
[data-theme="elven"] .marquee {
    background: var(--paper-deep);
    color: var(--ink-mid);
    border-block: 1px solid var(--rule-soft);
    font-family: var(--display);
    font-style: italic;
    font-weight: 500;
    font-size: 1.08rem;
    letter-spacing: 0.02em;
    text-transform: none;
    padding-block: 0.55rem 0.45rem;
    margin-top: 9px;
}
[data-theme="elven"] .marquee__track { animation-duration: 46s; }
[data-theme="elven"] .marquee__track span::before {
    content: "❦";
    font-style: normal;
    color: var(--gold);
    margin-right: 0.9rem;
}

/* ---- Buttons: gold leaf ---- */
[data-theme="elven"] .btn {
    background: linear-gradient(180deg, var(--btn-bg-1) 0%, var(--btn-bg-2) 100%);
    color: var(--btn-text);
    border: 1px solid #8C6E2A;
    border-radius: 3px 16px 3px 16px;
    box-shadow: inset 0 1px 0 rgba(255, 250, 225, 0.55), 0 2px 0 rgba(0, 0, 0, 0.45);
    font-family: var(--display);
    font-weight: 700;
    font-size: 1.08rem;
    letter-spacing: 0.02em;
    text-transform: none;
    text-decoration: none;
    transition: background 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}
[data-theme="elven"] .btn:hover {
    background: linear-gradient(180deg, #F2DC98 0%, #D9B860 100%);
    color: #0B1A11;
    transform: translateY(-1px);
    box-shadow: inset 0 1px 0 rgba(255, 250, 225, 0.6), 0 3px 0 rgba(0, 0, 0, 0.45), 0 0 18px rgba(217, 184, 96, 0.3);
}
[data-theme="elven"] .btn:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.5); }
[data-theme="elven"] .btn--ghost {
    background: rgba(9, 20, 14, 0.35);
    color: var(--btn-ghost-text);
    /* Opaque (was rgba(201, 211, 214, 0.55)): a translucent border blends
       toward whatever sits behind it, which is exactly what a stable
       border-vs-background token/test can't safely represent — and it's
       an unnecessary 0.55 alpha to begin with, since the hover state
       already uses the opaque form. */
    border-color: var(--btn-ghost-border);
    box-shadow: none;
}
[data-theme="elven"] .btn--ghost:hover {
    background: rgba(201, 211, 214, 0.12);
    color: #FFFFFF;
    border-color: var(--silver);
    box-shadow: 0 0 14px rgba(201, 211, 214, 0.18);
}
[data-theme="elven"] .btn--red {
    background: linear-gradient(180deg, var(--btn-red-bg-1) 0%, var(--btn-red-bg-2) 100%);
    color: var(--btn-red-text);
    border-color: #5E2118;
    box-shadow: inset 0 1px 0 rgba(255, 220, 200, 0.3), 0 2px 0 rgba(0, 0, 0, 0.45);
}
[data-theme="elven"] .btn--red:hover {
    background: linear-gradient(180deg, #BA5A48 0%, #9A4032 100%);
    color: #FFFFFF;
}

/* ---- Forms ---- */
[data-theme="elven"] form input,
[data-theme="elven"] form select,
[data-theme="elven"] form textarea {
    background-color: var(--paper-deep);
    color: var(--ink);
    border: 1px solid rgba(217, 184, 96, 0.42);
    border-radius: 6px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.45);
    font-family: var(--body);
}
[data-theme="elven"] form input:focus,
[data-theme="elven"] form select:focus,
[data-theme="elven"] form textarea:focus {
    background-color: #0E1C14;
    border-color: var(--gold);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.45), 0 0 0 3px rgba(217, 184, 96, 0.22);
    transform: none;
}
[data-theme="elven"] form input::placeholder,
[data-theme="elven"] form textarea::placeholder { color: var(--ink-soft); }
[data-theme="elven"] form label,
[data-theme="elven"] form .field-label {
    font-family: var(--mono);
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: lowercase;
    color: #E3CF92;
}
/* theme picker cards live inside a <label>: keep them in their own voice */
[data-theme="elven"] form label > .panel {
    font-family: var(--body);
    font-size: 1rem;
    letter-spacing: normal;
    text-transform: none;
    height: 100%;
    box-shadow: none;
}
[data-theme="elven"] .form-helper { color: var(--ink-mid); font-style: italic; }
[data-theme="elven"] .errorlist {
    color: #F4B39A;
    font-family: var(--mono);
    font-size: 0.92rem;
    letter-spacing: 0.04em;
    text-transform: lowercase;
}

/* ---- Panels: a leaf-cornered folio with a double gilt rule ---- */
[data-theme="elven"] .panel,
[data-theme="elven"] .library-toolbar,
[data-theme="elven"] .allauth-form {
    background: linear-gradient(180deg, #1A3124 0%, var(--paper-soft) 100%);
    border: 1px solid rgba(217, 184, 96, 0.55);
    border-radius: var(--r);
    box-shadow:
        inset 0 0 0 4px var(--paper-soft),
        inset 0 0 0 5px rgba(217, 184, 96, 0.18),
        var(--shadow-1);
    color: var(--ink);
    position: relative;
}
[data-theme="elven"] .panel--gold {
    background: linear-gradient(180deg, #213A2A 0%, #1A3124 100%);
    border-color: var(--gold);
}
[data-theme="elven"] .panel:not(.panel--tight)::after {
    content: "❦";
    position: absolute;
    top: -0.78em;
    left: 1.4rem;
    padding: 0 0.4rem;
    font-size: 1.3rem;
    line-height: 1.2;
    color: var(--gold);
    background: var(--paper);
    border-radius: 50%;
    pointer-events: none;
}
[data-theme="elven"] .library-toolbar input,
[data-theme="elven"] .library-toolbar select { box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.45); }

/* ---- Speech bubble: a whispered note ---- */
[data-theme="elven"] .speech {
    background: var(--paper-soft);
    border: 1px solid rgba(217, 184, 96, 0.5);
    border-radius: 18px 18px 18px 4px;
    color: var(--ink);
    box-shadow: var(--shadow-1);
    font-weight: 400;
    font-size: 1.02rem;
    max-width: 38ch;
}
[data-theme="elven"] .speech::before {
    background: var(--paper-soft);
    border-left: 1px solid rgba(217, 184, 96, 0.5);
    border-bottom: 1px solid rgba(217, 184, 96, 0.5);
}
[data-theme="elven"] .speech strong {
    color: var(--gold);
    font-family: var(--display);
    font-weight: 700;
    font-size: 1.1em;
}
[data-theme="elven"] .speech em { color: #E4E9DE; }

/* ---- Book cards ---- */
[data-theme="elven"] .bookcard {
    background: linear-gradient(180deg, #1A3124 0%, var(--paper-soft) 100%);
    border: 1px solid rgba(217, 184, 96, 0.45);
    border-radius: var(--r);
    color: var(--ink);
    text-decoration: none;
    box-shadow: inset 0 0 0 4px var(--paper-soft), inset 0 0 0 5px rgba(217, 184, 96, 0.14), var(--shadow-1);
    transform: none !important;
    transition: transform 220ms ease, box-shadow 220ms ease, border-color 220ms ease;
}
[data-theme="elven"] .bookcard:hover {
    transform: translateY(-3px) !important;
    border-color: var(--gold);
    background: linear-gradient(180deg, #1F3A2A 0%, #1A3124 100%);
    box-shadow: inset 0 0 0 4px #1C3527, inset 0 0 0 5px rgba(217, 184, 96, 0.28), var(--shadow-2), 0 0 22px rgba(217, 184, 96, 0.12);
    color: var(--ink);
}
[data-theme="elven"] .bookcard__stamp {
    background: var(--gold);
    color: var(--paper-deep);
    border: 1px solid #8C6E2A;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    border-radius: 3px 10px 3px 10px;
    font-family: var(--mono);
    font-size: 0.78rem;
    letter-spacing: 0.05em;
    text-transform: lowercase;
    transform: none;
}
[data-theme="elven"] .bookcard__title { color: #F0E6C4; font-size: 1.4rem; text-decoration: none; }
[data-theme="elven"] .bookcard__authors { color: var(--ink-mid); font-weight: 400; }
[data-theme="elven"] .bookcard__meta { border-top: 1px dotted var(--rule); }

/* ---- Tags: pressed-flower labels ---- */
[data-theme="elven"] .tag {
    font-family: var(--mono);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: lowercase;
    background: var(--paper-deep);
    color: var(--ink);
    border: 1px solid rgba(217, 184, 96, 0.4);
    border-radius: 3px 10px 3px 10px;
    box-shadow: none;
}
[data-theme="elven"] .tag--read     { background: var(--olive);  color: #0B1A11; border-color: #6E8E4B; }
[data-theme="elven"] .tag--reading  { background: var(--gold);   color: #0B1A11; border-color: #8C6E2A; }
[data-theme="elven"] .tag--want     { background: var(--paper-deep); color: var(--ink); }
[data-theme="elven"] .tag--location { background: var(--cyan);   color: #0B1A11; border-color: #5F9587; }
[data-theme="elven"] .tag--sale     { background: var(--red);    color: #0B1A11; border-color: #A86A4B; }
[data-theme="elven"] .tag--trade    { background: var(--purple); color: #0B1A11; border-color: #7D6AA0; }
[data-theme="elven"] .tag--loaned   { background: var(--silver); color: #0B1A11; border-color: #8C9A9E; }

/* ---- Choice list ---- */
[data-theme="elven"] .choice {
    background: linear-gradient(180deg, #1A3124 0%, var(--paper-soft) 100%);
    border: 1px solid rgba(217, 184, 96, 0.45);
    border-radius: var(--r);
    color: var(--ink);
    text-decoration: none;
    box-shadow: inset 0 0 0 4px var(--paper-soft), inset 0 0 0 5px rgba(217, 184, 96, 0.14), var(--shadow-1);
}
[data-theme="elven"] .choice:hover {
    transform: translateY(-2px);
    border-color: var(--gold);
    background: linear-gradient(180deg, #1F3A2A 0%, #1A3124 100%);
    box-shadow: inset 0 0 0 4px #1C3527, inset 0 0 0 5px rgba(217, 184, 96, 0.28), var(--shadow-2);
    color: var(--ink);
}
[data-theme="elven"] .choice:nth-child(n) .choice__num {
    background: radial-gradient(circle at 35% 30%, #F2DC98 0%, var(--gold) 55%, var(--gold-deep) 100%);
    color: #13261B;
    border: 1px solid #8C6E2A;
    box-shadow: 0 0 0 3px var(--paper-soft), 0 0 0 4px rgba(217, 184, 96, 0.4);
    font-family: var(--initial);
    font-size: 1.7rem;
    transform: none;
    padding-top: 0;
}
[data-theme="elven"] .choice__title { color: #F0E6C4; }
[data-theme="elven"] .choice__sub { color: var(--ink-mid); font-weight: 400; }
[data-theme="elven"] .choice__arrow { color: var(--gold); }
[data-theme="elven"] .choice:hover .choice__arrow { color: #F2DC98; transform: translateX(0.4rem); }

/* ---- Empty state ---- */
[data-theme="elven"] .empty-state h2 {
    color: #F3EBD0;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
    -webkit-text-stroke: 0;
}

/* ---- Rules and ornaments ---- */
[data-theme="elven"] .divider,
[data-theme="elven"] .divider--ornament {
    border: 0;
    height: 1px;
    overflow: visible;
    border-radius: 0;
    background: linear-gradient(90deg, transparent 0%, var(--gold-deep) 20%, var(--gold) 50%, var(--gold-deep) 80%, transparent 100%);
    margin-block: clamp(2rem, 5vw, 3.5rem);
    position: relative;
    text-align: center;
}
[data-theme="elven"] .divider::after,
[data-theme="elven"] .divider--ornament::after {
    content: "❦";
    position: relative;
    top: -0.8em;
    padding: 0 0.6rem;
    color: var(--gold);
    background: var(--paper);
    font-size: 1.15rem;
    line-height: 1;
}
[data-theme="elven"] .divider--stars { color: var(--gold); font-family: var(--initial); }
[data-theme="elven"] .divider--stars::before,
[data-theme="elven"] .divider--stars::after {
    height: 1px;
    border-radius: 0;
    background: linear-gradient(90deg, transparent, var(--gold-deep));
}
[data-theme="elven"] .divider--stars::after { background: linear-gradient(90deg, var(--gold-deep), transparent); }

/* ---- Copy detail ---- */
[data-theme="elven"] .book-detail__cover {
    background:
        radial-gradient(circle at 50% 40%, rgba(217, 184, 96, 0.18) 0%, transparent 60%),
        linear-gradient(160deg, #214030 0%, #10231A 100%);
    border: 1px solid var(--gold);
    border-radius: var(--r);
    box-shadow: inset 0 0 0 6px #163024, inset 0 0 0 7px rgba(217, 184, 96, 0.45), var(--shadow-2);
    font-family: var(--initial);
    color: var(--gold);
    -webkit-text-stroke: 0;
    text-shadow: 0 0 22px rgba(217, 184, 96, 0.45);
    text-transform: none;
    transform: none;
}
[data-theme="elven"] .book-detail__title {
    color: #F3EBD0;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
}
[data-theme="elven"] .book-detail__authors { color: var(--ink-mid); font-weight: 400; }
[data-theme="elven"] .dl { border-top: 1px dotted var(--rule); }
[data-theme="elven"] .dl dt {
    font-family: var(--mono);
    font-size: 0.92rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: lowercase;
    color: var(--gold);
}
[data-theme="elven"] .dl dd { font-weight: 400; }

[data-theme="elven"] .scan-frame { border: 1px solid var(--gold); border-radius: var(--r); background: var(--paper-deep); }

/* ---- Notices ---- */
[data-theme="elven"] .notice {
    background: var(--paper-soft);
    color: var(--ink);
    border: 1px solid rgba(217, 184, 96, 0.35);
    border-left: 4px solid var(--gold);
    border-radius: 3px 14px 3px 14px;
    box-shadow: var(--shadow-1);
    font-weight: 500;
}
[data-theme="elven"] .notice--success { border-left-color: var(--olive); }
[data-theme="elven"] .notice--info    { border-left-color: var(--cyan); }
[data-theme="elven"] .notice--warning { border-left-color: var(--red); }

[data-theme="elven"] .backlink {
    background: rgba(9, 20, 14, 0.45);
    color: #E8CD7E;
    border: 1px solid var(--rule);
    box-shadow: none;
    font-family: var(--mono);
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: lowercase;
    text-decoration: none;
}
[data-theme="elven"] .backlink:hover { background: var(--gold); color: var(--paper-deep); }

/* ---- Footer ---- */
[data-theme="elven"] .colophon {
    background: var(--paper-deep);
    border-top: 1px solid var(--gold-deep);
    color: var(--ink-mid);
}
[data-theme="elven"] .colophon__inner {
    font-family: var(--mono);
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: lowercase;
}
[data-theme="elven"] .colophon__inner .ribbon {
    background: none;
    color: var(--gold);
    border: 0;
    border-block: 1px solid var(--rule);
    border-radius: 0;
    font-family: var(--display);
    font-style: italic;
    font-weight: 600;
    font-size: 1.1rem;
    text-transform: none;
    letter-spacing: 0.02em;
}

/* ---- Mascots: moonlit, gently swaying like branches ---- */
[data-theme="elven"] .mascot {
    filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.45)) drop-shadow(0 0 10px rgba(217, 184, 96, 0.16));
    animation: elven-sway 7s ease-in-out infinite;
    transform-origin: 50% 100%;
}
@keyframes elven-sway {
    0%, 100% { transform: rotate(0deg) translateY(0); }
    50% { transform: rotate(-1.5deg) translateY(-2px); }
}
@media (prefers-reduced-motion: reduce) {
    [data-theme="elven"] .mascot { animation: none; }
}

/* ================================================================
   Explorar — shared-with-me search (all themes)
   ================================================================ */
.tag--available { background: var(--paper); color: var(--ink); border-style: dashed; }
[data-theme="steampunk"] .tag--available { background: var(--paper-deep); color: var(--olive); border-color: var(--olive); border-style: dashed; }
[data-theme="elven"] .tag--available { background: transparent; color: var(--olive); border-color: var(--olive); border-style: dashed; }

/* Mis estantes | Compartidos conmigo — sits after the Filter button in the
   DOM (so Enter submits the current page) but is shown as the first row. */
.scope-switch {
    grid-column: 1 / -1;
    order: -1;
    justify-self: start;
    display: inline-flex;
    border: 2px solid var(--ink);
    border-radius: var(--r-pill);
    overflow: hidden;
    font-family: var(--mono);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}
.scope-switch__opt {
    padding: 0.45rem 0.95rem 0.4rem;
    background: var(--paper);
    color: var(--ink);
    border: 0;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
}
.scope-switch__opt + .scope-switch__opt { border-left: 2px solid var(--ink); }
button.scope-switch__opt:hover { background: var(--cyan); }
.scope-switch__opt.is-active { background: var(--ink); color: var(--paper); cursor: default; }
[data-theme="steampunk"] .scope-switch { border-color: var(--brass); }
[data-theme="steampunk"] .scope-switch__opt { background: var(--paper-deep); color: var(--amber); }
[data-theme="steampunk"] .scope-switch__opt + .scope-switch__opt { border-left-color: var(--brass); }
[data-theme="steampunk"] button.scope-switch__opt:hover { background: #4A3520; }
[data-theme="steampunk"] .scope-switch__opt.is-active { background: var(--brass); color: var(--paper-deep); }
[data-theme="elven"] .scope-switch {
    border: 1px solid rgba(217, 184, 96, 0.5);
    border-radius: 3px 12px 3px 12px;
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: lowercase;
}
[data-theme="elven"] .scope-switch__opt { background: var(--paper-deep); color: var(--ink); }
[data-theme="elven"] .scope-switch__opt + .scope-switch__opt { border-left: 1px solid rgba(217, 184, 96, 0.5); }
[data-theme="elven"] button.scope-switch__opt:hover { background: #1F3A2A; color: var(--gold); }
[data-theme="elven"] .scope-switch__opt.is-active { background: var(--gold); color: #0B1A11; }

@media (min-width: 761px) {
    .library-toolbar--explore { grid-template-columns: 1.6fr repeat(2, 1fr) auto auto; }
}
.explore-checks {
    border: 0;
    margin: 0;
    padding: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.explore-checks legend {
    padding: 0;
    margin-bottom: 0.3rem;
    font-family: var(--mono);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}
.explore-checks label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}
[data-theme="elven"] .explore-checks legend { font-size: 0.9rem; font-weight: 500; letter-spacing: 0.04em; text-transform: lowercase; color: var(--gold); }
[data-theme="elven"] .explore-checks label { font-weight: 400; }

/* Book cards here are containers of links, not links themselves. */
[data-theme] .bookcard.explore-card,
[data-theme] .bookcard.explore-card:hover { transform: none !important; }
.explore-card__head { display: flex; gap: 0.9rem; align-items: flex-start; }
.explore-card__head .bookcard__title { margin-top: 0; padding-right: 0; }
.explore-card__cover {
    flex-shrink: 0;
    width: 3.2rem;
    height: 4.6rem;
    object-fit: cover;
    border: 2px solid var(--ink);
    border-radius: 4px;
    background: var(--paper-deep);
}
.explore-card__cover--initial {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--display);
    font-weight: 700;
    font-size: 1.7rem;
    color: var(--paper);
    background: var(--red);
}
[data-theme="steampunk"] .explore-card__cover { border: 1px solid var(--brass); }
[data-theme="steampunk"] .explore-card__cover--initial { background: var(--paper-deep); color: var(--amber); }
[data-theme="elven"] .explore-card__cover { border: 1px solid rgba(217, 184, 96, 0.5); border-radius: 3px 10px 3px 10px; }
[data-theme="elven"] .explore-card__cover--initial { background: var(--paper-deep); color: var(--gold); }

.explore-card__owners {
    margin-top: auto;
    padding-top: 0.85rem;
    border-top: 2px dashed var(--rule);
}
[data-theme="steampunk"] .explore-card__owners { border-top: 1px dashed var(--rule); }
[data-theme="elven"] .explore-card__owners { border-top: 1px dotted var(--rule); }
.explore-card__label {
    display: block;
    margin-bottom: 0.45rem;
    font-family: var(--mono);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink-mid);
}
[data-theme="elven"] .explore-card__label { font-size: 0.88rem; font-weight: 500; letter-spacing: 0.04em; text-transform: lowercase; }
.owner-chips { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.owner-chip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.5rem;
    padding: 0.3rem 0.4rem;
    border-radius: var(--r);
    color: var(--ink);
    text-decoration: none;
}
.owner-chip:hover, .owner-chip:focus-visible { background: var(--paper-soft); color: var(--ink); }
/* Steampunk's generic `a:hover` (higher specificity: [data-theme] + a + :hover)
   otherwise wins over the rule above and repaints this hover state in
   --copper, which fails against --paper-soft (2.7:1). Match the amber this
   chip already renders at rest (7.3:1) instead of the unreachable --ink. */
[data-theme="steampunk"] .owner-chip:hover,
[data-theme="steampunk"] .owner-chip:focus-visible { color: var(--amber); }
.owner-chip__name { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.owner-chip:hover .owner-chip__name { text-decoration: underline; }
.owner-chip__tags { display: inline-flex; flex-wrap: wrap; gap: 0.3rem; margin-left: auto; }
.owner-chip__tags .tag { font-size: 0.58rem; padding: 0.14rem 0.45rem 0.1rem; box-shadow: none; }
[data-theme="elven"] .owner-chip__tags .tag { font-size: 0.74rem; }
[data-theme="elven"] .owner-chip:hover, [data-theme="elven"] .owner-chip:focus-visible { background: rgba(217, 184, 96, 0.08); }
[data-theme="elven"] .owner-chip__name { font-weight: 600; }
.explore-card__more { margin: 0.45rem 0 0 0.4rem; font-weight: 700; color: var(--ink-mid); font-size: 0.92rem; }

.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 2.5rem;
}
.pager__status { font-family: var(--mono); font-size: 0.8rem; letter-spacing: 0.12em; text-transform: uppercase; }
[data-theme="elven"] .pager__status { font-size: 0.95rem; letter-spacing: 0.04em; text-transform: lowercase; }
@media (max-width: 520px) {
    .scope-switch { justify-self: stretch; }
    .scope-switch__opt { flex: 1 1 auto; padding-inline: 0.55rem; letter-spacing: 0.04em; white-space: nowrap; text-align: center; }
}

/* ---- Photo scan (imports/photos.html) ---------------------------- */
.photo-drop {
    display: flex; flex-direction: column; align-items: center; gap: .5rem;
    padding: 2rem 1rem; border: 2px dashed currentColor; border-radius: 12px;
    cursor: pointer; text-align: center;
}
.photo-drop--over { background: color-mix(in srgb, currentColor 8%, transparent); }
.visually-hidden {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.photo-failed, .photo-list { list-style: none; padding: 0; margin: 0; }
.photo-failed__item { display: flex; gap: 1rem; align-items: flex-start; padding: .75rem 0; border-top: 1px solid color-mix(in srgb, currentColor 20%, transparent); }
.photo-failed__thumb { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; flex: none; }
.photo-failed__form { display: flex; gap: .5rem; flex-wrap: wrap; }
.photo-failed__form input { min-width: 0; flex: 1 1 10rem; }
.photo-list__item { display: flex; gap: .75rem; align-items: baseline; flex-wrap: wrap; padding: .4rem 0; border-top: 1px solid color-mix(in srgb, currentColor 12%, transparent); }
.photo-list__item .linkish { margin-left: auto; }
.photo-process { margin-top: 1.5rem; }
