:root {
    --gold: #E0B93A;
    --gold-light: #FAF0D0;
    --gold-dark: #B09060;
    --bg: #0f0c09;
    --bg-section: #1e1812;
    --card-bg: #2a1f14;
    --card-border: rgba(212,175,55,0.22);
    --text: #f5ebd5;
    --text-muted: #c8b49a;
    --red: #c0392b;
    --green: #2ecc71;
    --blue: #3498db;
    --fm-color: #d4a83c;
    --fm-bg: rgba(212,168,60,0.14);
    --shadow: 0 4px 20px rgba(0,0,0,0.6);
}

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

body {
    font-family: 'Crimson Text', Georgia, serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 15% 15%, rgba(212,175,55,0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 85% 85%, rgba(139,0,0,0.03) 0%, transparent 50%),
        url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 0L30 60M0 30L60 30' stroke='%23D4AF37' stroke-width='0.3' opacity='0.04'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: -1;
}

/* ── Header ── */
.hdr {
    background: linear-gradient(180deg, #1a1410 0%, #0f0c09 100%);
    border-bottom: 2px solid var(--gold);
    padding: 14px 20px;
    box-shadow: 0 2px 20px rgba(0,0,0,0.8);
}
.hdr-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.hdr-title {
    display: flex;
    align-items: center;
    gap: 12px;
}
.hdr-logo {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--gold-dark);
    object-fit: cover;
}
.hdr-text h1 {
    font-family: 'Cinzel', serif;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--gold-light);
    letter-spacing: 0.03em;
    line-height: 1.2;
}
.hdr-text p {
    font-size: 0.78rem;
    color: #a89880;
}
.hdr-nav {
    display: flex;
    align-items: center;
    gap: 14px;
}
.hdr-nav a {
    font-family: 'Cinzel', serif;
    font-size: 0.75rem;
    color: var(--gold-dark);
    text-decoration: none;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.hdr-nav a:hover { color: var(--gold-light); }
.hdr-nav img { width: 22px; height: 22px; border-radius: 50%; }

/* ── Stats bar ── */
.stats-bar {
    background: rgba(26,20,16,0.95);
    border-bottom: 1px solid var(--card-border);
    padding: 10px 20px;
}
.stats-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
}
.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
}
.stat-label { color: #c0b09a; }
.stat-label.stat-sub { font-size: 0.75rem; opacity: 0.75; }
.stat-value { font-family: 'Cinzel', serif; color: var(--gold); font-weight: 700; }
.stat-value.fm { color: var(--fm-color); }
.progress-wrap {
    flex: 1;
    min-width: 160px;
}
.progress-bar-bg {
    background: rgba(255,255,255,0.07);
    border-radius: 4px;
    height: 6px;
    overflow: hidden;
}
.progress-bar-fill {
    background: linear-gradient(90deg, var(--gold-dark), var(--gold));
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.stat-reset {
    background: transparent;
    border: 1px solid rgba(139,0,0,0.5);
    color: #e87;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Cinzel', serif;
}
.stat-reset:hover { background: rgba(139,0,0,0.2); border-color: #e87; }

.cloud-status {
    font-family: 'Cinzel', serif;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 3px 10px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.04);
    white-space: nowrap;
    letter-spacing: 0.02em;
    transition: color 0.3s, border-color 0.3s;
}
.cloud-status.cs-ok  { color: var(--green); border-color: rgba(46,204,113,0.3); background: rgba(46,204,113,0.06); }
.cloud-status.cs-err { color: #e08080;      border-color: rgba(200,80,80,0.3);  background: rgba(200,80,80,0.06); }

/* ── Controls ── */
.controls {
    max-width: 1400px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}
.search-input {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text);
    padding: 7px 14px;
    border-radius: 6px;
    font-family: 'Crimson Text', serif;
    font-size: 0.95rem;
    width: 220px;
    transition: border-color 0.2s;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { outline: none; border-color: var(--gold-dark); }

.filter-btns { display: flex; gap: 6px; }
.filter-btn {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: #c0b09a;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Cinzel', serif;
}
.filter-btn.active {
    background: rgba(212,175,55,0.12);
    border-color: var(--gold-dark);
    color: var(--gold-light);
}
.filter-btn:hover { border-color: var(--gold-dark); color: var(--text); }

/* ── VIP Access Banner ── */
.vip-access-banner {
    background: linear-gradient(90deg, rgba(160,100,0,0.22), rgba(180,140,0,0.12));
    border-bottom: 1px solid rgba(212,175,55,0.35);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: 'Crimson Text', serif;
    font-size: 0.92rem;
    color: #e8d090;
}
.vab-icon { font-size: 1.1rem; flex-shrink: 0; }
.vab-text { flex: 1; }
.vab-btn {
    display: inline-block;
    background: linear-gradient(135deg, #b8860b, #d4af37);
    color: #1a1005;
    padding: 7px 18px;
    border-radius: 6px;
    font-family: 'Cinzel', serif;
    font-size: 0.72rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
    transition: opacity 0.2s;
}
.vab-btn:hover { opacity: 0.85; }

/* ── Group Tabs ── */
.group-tabs-wrap {
    background: var(--bg-section);
    border-bottom: 1px solid var(--card-border);
    overflow-x: auto;
    scrollbar-width: none;
    position: sticky;
    top: 38px;
    z-index: 80;
    height: 120px;
}
.group-tabs-wrap::-webkit-scrollbar { display: none; }
.group-tabs {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    gap: 0;
    padding: 0;
    height: 100%;
}

/* Each tab fills the full bar height; overlay elements sit on the image */
.group-tab {
    position: relative;
    overflow: hidden;
    height: 100%;
    min-width: 100px;
    padding: 0;
    cursor: pointer;
    border: none;
    border-bottom: 3px solid transparent;
    background: #0f0c09;
    transition: border-color 0.2s;
    flex-shrink: 0;
}
.group-tab + .group-tab { border-left: 1px solid rgba(212,175,55,0.1); }
.group-tab:hover { background: #1a1410; }
.group-tab.active { border-bottom-color: var(--gold); background: #1e1812; }

/* Image fills entire tab */
.gtab-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    opacity: 0.55;
    transition: opacity 0.2s, filter 0.2s;
    filter: grayscale(35%) brightness(0.8);
    display: block;
}
.group-tab:hover .gtab-img {
    opacity: 0.82;
    filter: grayscale(10%) brightness(0.95);
}
.group-tab.active .gtab-img {
    opacity: 1;
    filter: drop-shadow(0 0 10px rgba(212,175,55,0.45));
}

/* Top gradient so FM badge text is readable */
.group-tab::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 36px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.55) 0%, transparent 100%);
    pointer-events: none;
    z-index: 2;
}

/* FM badge — top-left of group tab */
.gtab-fm-topleft {
    position: absolute;
    top: 6px;
    left: 7px;
    z-index: 3;
    font-family: 'Cinzel', serif;
    font-size: 0.58rem;
    font-weight: 700;
    color: #ffe28a;
    background: rgba(12,8,2,0.72);
    border: 1px solid rgba(212,168,60,0.5);
    border-radius: 4px;
    padding: 2px 6px;
    white-space: nowrap;
    text-shadow: 0 1px 4px rgba(0,0,0,1);
    pointer-events: none;
    backdrop-filter: blur(3px);
    letter-spacing: 0.02em;
}
.gtab-fm-topleft.gtab-fm-done {
    color: #70e898;
    background: rgba(2,12,6,0.72);
    border-color: rgba(46,204,113,0.5);
}

/* Progress bar — thicker, pinned to bottom, with % text */
.gtab-bar-bg {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 16px;
    background: rgba(0,0,0,0.50);
    z-index: 2;
    overflow: hidden;
    display: block;
}
.gtab-bar-fill {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    background: linear-gradient(90deg, var(--gold-dark), var(--gold), #f5d568);
    transition: width 0.4s ease;
}
.gtab-bar-pct {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Cinzel', serif;
    font-size: 0.55rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 0 5px rgba(0,0,0,1), 0 1px 3px rgba(0,0,0,1);
    letter-spacing: 0.04em;
    z-index: 1;
    pointer-events: none;
    white-space: nowrap;
}

/* ── Group tab lock/done states ── */

/* Tint overlay (sits over image, under text/badges) */
.gtab-tint {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    transition: background 0.25s;
}

/* LOCKED: dark red tint + image desaturated */
.gtab-locked .gtab-img {
    filter: grayscale(75%) brightness(0.4) sepia(40%);
}
.gtab-locked .gtab-tint {
    background: rgba(140,18,18,0.32);
}
.group-tab.gtab-locked {
    border-bottom-color: rgba(192,57,43,0.6) !important;
    box-shadow: inset 0 -3px 0 rgba(192,57,43,0.55);
}
.group-tab.gtab-locked:not(.active) .gtab-fm {
    color: #e08888;
}
.group-tab.gtab-locked.active {
    border-bottom-color: rgba(220,80,60,0.85) !important;
    box-shadow: inset 0 -3px 0 rgba(220,80,60,0.8);
}

/* COMPLETE: green tint */
.gtab-complete .gtab-img {
    filter: brightness(0.75) saturate(0.9);
}
.gtab-complete .gtab-tint {
    background: rgba(20,80,30,0.28);
}
.group-tab.gtab-complete {
    border-bottom-color: rgba(46,204,113,0.55) !important;
}
.group-tab.gtab-complete:not(.active) .gtab-fm {
    color: #70e896;
}

/* AVAILABLE: no special tint (default gold active behaviour kept) */
.gtab-available .gtab-tint { background: transparent; }

/* Lock/Done badges on group tabs */
.gtab-lock-badge,
.gtab-done-badge {
    position: absolute;
    top: 5px;
    right: 6px;
    font-size: 0.78rem;
    z-index: 3;
    filter: drop-shadow(0 1px 5px rgba(0,0,0,0.95));
    pointer-events: none;
}

/* ── Attribute Summary ── */
.attr-summary-wrap {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}
.attr-summary-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    margin: 12px 0 0;
    background: var(--bg-section);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Cinzel', serif;
    font-size: 0.80rem;
    font-weight: 600;
    color: var(--gold);
    letter-spacing: 0.04em;
    transition: background 0.2s;
}
.attr-summary-hdr:hover { background: #261d14; }
.attr-toggle-icon { color: var(--gold-dark); font-size: 0.75rem; }
.attr-summary-body {
    border: 1px solid var(--card-border);
    border-top: none;
    border-radius: 0 0 6px 6px;
    background: var(--bg-section);
    overflow: hidden;
    margin-bottom: 12px;
}
.attr-cat { border-bottom: 1px solid rgba(212,175,55,0.1); }
.attr-cat:last-child { border-bottom: none; }
.attr-cat-hdr {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    cursor: pointer;
    font-family: 'Cinzel', serif;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--gold-dark);
    background: rgba(0,0,0,0.2);
    transition: background 0.15s;
}
.attr-cat-hdr:hover { background: rgba(212,175,55,0.06); }
.attr-cat-label { flex: 1; }
.attr-cat-meta {
    font-family: 'Crimson Text', serif;
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 400;
}
.attr-cat-toggle { font-size: 0.65rem; color: var(--gold-dark); width: 12px; text-align: center; }
.attr-cat-rows { padding: 4px 0; }
.attr-row {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 1px 12px;
    padding: 5px 16px 5px 28px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}
.attr-row:last-child { border-bottom: none; }
.attr-row:hover { background: rgba(255,255,255,0.02); }
.attr-row-zero { opacity: 0.45; }
.attr-row-desc {
    font-family: 'Crimson Text', serif;
    font-size: 0.82rem;
    color: var(--text);
    grid-column: 1;
    grid-row: 1;
}
.attr-row-val {
    font-family: 'Cinzel', serif;
    font-size: 0.72rem;
    color: var(--gold);
    white-space: nowrap;
    grid-column: 2;
    grid-row: 1;
    text-align: right;
}
.attr-row-max {
    color: var(--text-muted);
    font-size: 0.65rem;
}
.attr-row-bar {
    grid-column: 1 / -1;
    grid-row: 2;
    height: 3px;
    background: rgba(255,255,255,0.07);
    border-radius: 2px;
    overflow: hidden;
}
.attr-row-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold-dark), var(--gold));
    border-radius: 2px;
    transition: width 0.4s ease;
}

/* ── Main Content ── */
.main-wrap {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 0 40px;
}

/* ── Book Gallery ── */
.book-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 18px;
    padding: 20px 20px 0;
}

.bgcard {
    position: relative;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid rgba(212,175,55,0.2);
    background: #1a140e;
    aspect-ratio: 4/3;
    min-height: 155px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.bgcard:hover {
    transform: translateY(-4px) scale(1.015);
    box-shadow: 0 12px 36px rgba(0,0,0,0.7), 0 0 0 1px rgba(212,175,55,0.5);
    border-color: rgba(212,175,55,0.55);
}
.bgcard-locked {
    opacity: 0.72;
    border-color: rgba(192,57,43,0.55) !important;
    box-shadow: 0 0 0 1px rgba(192,57,43,0.35), 0 0 22px rgba(192,57,43,0.22), 0 4px 16px rgba(0,0,0,0.5) !important;
}
.bgcard-locked:hover { opacity: 0.88; }

.bgcard-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    filter: brightness(0.68) saturate(0.9);
    transition: filter 0.3s ease;
    display: block;
}
.bgcard:hover .bgcard-img { filter: brightness(0.9) saturate(1.1); }
.bgcard-locked .bgcard-img { filter: brightness(0.3) grayscale(60%); }

.bgcard-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.92) 0%, rgba(0,0,0,0.45) 55%, transparent 100%);
    pointer-events: none;
}

.bgcard-lock-overlay {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 1.5rem;
    z-index: 2;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.9));
}

/* TSSS unlock badge */
.bgcard-tsss {
    font-family: 'Cinzel', serif;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 3px 8px;
    border-radius: 4px;
    text-shadow: 0 1px 4px rgba(0,0,0,0.9);
    box-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
.bgcard-tsss-front {
    background: linear-gradient(135deg, rgba(200,50,30,0.88), rgba(240,80,30,0.78));
    border: 1px solid rgba(255,120,80,0.6);
    color: #ffe0d0;
}
.bgcard-tsss-mid {
    background: linear-gradient(135deg, rgba(160,110,0,0.88), rgba(210,160,20,0.78));
    border: 1px solid rgba(255,210,80,0.6);
    color: #fff4c0;
}
.bgcard-tsss-back {
    background: linear-gradient(135deg, rgba(20,70,160,0.88), rgba(30,110,210,0.78));
    border: 1px solid rgba(80,160,255,0.6);
    color: #d0e8ff;
}

.bgcard-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 12px 10px;
    z-index: 2;
}
.bgcard-name {
    font-family: 'Cinzel', serif;
    font-size: 0.8rem;
    font-weight: 700;
    color: #ffffff;
    line-height: 1.35;
    margin-bottom: 7px;
    text-shadow: 0 1px 8px rgba(0,0,0,1), 0 2px 16px rgba(0,0,0,1);
}
/* Top-left wrapper (stacks TSSS + status badge) */
.bgcard-topleft-wrap {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
    pointer-events: none;
}
.bgcard-topleft-wrap .bgcard-tsss {
    position: static;
}

/* FM / Done badge — top-left */
.bgcard-topleft-status {
    font-family: 'Cinzel', serif;
    font-size: 0.62rem;
    font-weight: 700;
    border-radius: 4px;
    padding: 3px 7px;
    white-space: nowrap;
    text-shadow: 0 1px 5px rgba(0,0,0,1);
    backdrop-filter: blur(3px);
    letter-spacing: 0.02em;
}
.bgcard-status-fm {
    color: #ffe28a;
    background: rgba(20,14,4,0.65);
    border: 1px solid rgba(212,168,60,0.55);
}
.bgcard-status-done {
    color: #70e898;
    background: rgba(4,20,8,0.65);
    border: 1px solid rgba(46,204,113,0.55);
}

/* Thick progress bar with % text */
.bgcard-bar-bg {
    position: relative;
    height: 18px;
    background: rgba(0,0,0,0.40);
    border-radius: 9px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.08);
}
.bgcard-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold-dark), var(--gold), #f5d568);
    border-radius: 9px;
    transition: width 0.4s ease;
}
.bgcard-bar-pct {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Cinzel', serif;
    font-size: 0.66rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 0 6px rgba(0,0,0,1), 0 1px 3px rgba(0,0,0,1);
    letter-spacing: 0.04em;
    z-index: 1;
    pointer-events: none;
    white-space: nowrap;
}

/* ── Quick-complete button on each book card ── */
/* Sits at the very bottom of the card (position:absolute).
   Hidden by default; appears on hover (or always when book is done). */
.bgcard-quick-btn {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 26px;
    margin: 0;
    padding: 0;
    background: rgba(22, 175, 65, 0.92);
    color: #fff;
    border: none;
    border-radius: 0 0 10px 10px;
    font-family: 'Cinzel', serif;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    cursor: pointer;
    z-index: 6;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s, background 0.15s;
    text-align: center;
}
/* Show on card hover (only if not disabled) */
.bgcard:hover .bgcard-quick-btn:not(:disabled) {
    opacity: 1;
    pointer-events: auto;
}
.bgcard-quick-btn:hover:not(:disabled) {
    background: rgba(30, 210, 80, 0.98);
}
/* Completed books: always show the undo button */
.bgcard-quick-btn.is-done:not(:disabled) {
    opacity: 0.72;
    pointer-events: auto;
    background: rgba(35, 35, 35, 0.88);
    color: #ccc;
}
.bgcard:hover .bgcard-quick-btn.is-done:not(:disabled) {
    opacity: 1;
    background: rgba(65, 65, 65, 0.92);
    color: #eee;
}
/* Locked books: always hidden */
.bgcard-quick-btn:disabled {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* ── Complete-all button inside group tab ── */
.gtab-complete-all {
    position: absolute;
    bottom: 18px;
    right: 5px;
    z-index: 5;
    padding: 2px 7px;
    background: rgba(28, 185, 70, 0.88);
    color: #fff;
    border: 1px solid rgba(50, 220, 100, 0.45);
    border-radius: 4px;
    font-family: 'Cinzel', serif;
    font-size: 0.5rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, opacity 0.15s;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}
.gtab-complete-all:hover:not(:disabled) {
    background: rgba(35, 210, 80, 0.97);
}
.gtab-complete-all:disabled {
    background: rgba(25, 25, 25, 0.7);
    color: #444;
    border-color: rgba(80, 80, 80, 0.25);
    cursor: not-allowed;
}

/* ── Book Modal ── */
.book-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.88);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}
.book-modal {
    background: var(--bg-section);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    width: min(96vw, 840px);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 28px 80px rgba(0,0,0,0.95);
}
.book-modal-hdr {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--card-border);
    flex-shrink: 0;
    background: linear-gradient(180deg, rgba(212,175,55,0.06) 0%, transparent 100%);
}
.bm-icon { font-size: 1.1rem; }
.bm-title {
    font-family: 'Cinzel', serif;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--gold);
    flex: 1;
    letter-spacing: 0.04em;
}
.bm-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.72rem;
}
.bm-prog {
    font-family: 'Cinzel', serif;
    font-size: 0.7rem;
    color: var(--gold-dark);
}
.book-modal-body {
    flex: 1;
    overflow-y: auto;
    background: #0f0c09;
}

/* ── Book card ── */
.book-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
}
.book-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: rgba(212,175,55,0.06);
    border-bottom: 1px solid var(--card-border);
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}
.book-header:hover { background: rgba(212,175,55,0.1); }
.book-name {
    font-family: 'Cinzel', serif;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--gold-light);
    letter-spacing: 0.03em;
}
.book-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.72rem;
    color: #c0ac90;
}
.book-mark-btn {
    font-family: 'Cinzel', serif;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid rgba(212,175,55,0.3);
    background: rgba(212,175,55,0.08);
    color: var(--gold-dark);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    line-height: 1;
}
.book-mark-btn:hover {
    background: rgba(212,175,55,0.18);
    border-color: var(--gold);
    color: var(--gold-light);
}
.book-progress {
    font-family: 'Cinzel', serif;
    font-size: 0.7rem;
    color: var(--gold-dark);
}
.book-toggle { font-size: 0.7rem; color: #b0a090; }

/* ── Book progress bar ── */
.book-pb-wrap {
    height: 3px;
    background: rgba(255,255,255,0.06);
    overflow: hidden;
}
.book-pb-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold-dark), var(--gold));
    transition: width 0.4s ease;
    min-width: 0;
}

/* ── Book FM display ── */
.book-fm-remain {
    font-family: 'Cinzel', serif;
    font-size: 0.7rem;
    color: var(--fm-color);
    background: var(--fm-bg);
    border: 1px solid rgba(212,168,60,0.25);
    border-radius: 3px;
    padding: 1px 6px;
    white-space: nowrap;
}
.book-fm-done {
    font-family: 'Cinzel', serif;
    font-size: 0.7rem;
    color: var(--green);
    background: rgba(46,204,113,0.08);
    border: 1px solid rgba(46,204,113,0.25);
    border-radius: 3px;
    padding: 1px 6px;
    white-space: nowrap;
}

/* ── Node FM total ── */
.node-fm-total {
    font-family: 'Cinzel', serif;
    font-size: 0.7rem;
    color: var(--fm-color);
    background: var(--fm-bg);
    border: 1px solid rgba(212,168,60,0.2);
    border-radius: 3px;
    padding: 1px 6px;
    white-space: nowrap;
    flex-shrink: 0;
}
.node-fm-total.zero {
    color: var(--green);
    background: rgba(46,204,113,0.08);
    border-color: rgba(46,204,113,0.2);
}

/* ── Lock strip ── */
.book-card.locked {
    border-color: rgba(139,0,0,0.25);
}
.book-card.locked .book-header {
    background: rgba(60,20,20,0.35);
}
.book-lock-strip {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(120,20,20,0.35);
    border-left: 4px solid #c0392b;
    border-bottom: 1px solid rgba(192,57,43,0.35);
    margin: 0;
}
.lock-label {
    color: #ff9090;
    font-family: 'Cinzel', serif;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.03em;
    margin-bottom: 2px;
}
.prereq-chain { display: flex; flex-direction: column; gap: 5px; }
.prereq-chain-row { display: flex; align-items: center; }
.prereq-chain-sub {
    border-left: 2px solid rgba(192,57,43,0.3);
    margin-left: 14px;
    padding-left: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 3px;
}
.prereq-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #f0d0c0;
    font-family: 'Crimson Text', serif;
    font-size: 0.82rem;
    background: rgba(0,0,0,0.25);
    border: 1px solid rgba(192,57,43,0.3);
    border-radius: 4px;
    padding: 3px 8px;
}
.prereq-item.prereq-link {
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    white-space: normal;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}
.prereq-item.prereq-link:hover {
    background: rgba(192,57,43,0.22);
    border-color: rgba(192,57,43,0.6);
    color: #ffb8a8;
}
.prereq-item.prereq-node {
    border-color: rgba(255,180,0,0.35);
    background: rgba(255,180,0,0.07);
    color: #ffd580;
    gap: 4px;
}
.prereq-or-header {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: #a0c4ff;
    text-transform: uppercase;
    margin: 6px 0 2px 0;
    opacity: 0.85;
}
.prereq-group {
    font-size: 0.7rem;
    color: #c0a060;
    opacity: 0.78;
    font-style: italic;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Pulsing blink when navigating to a book card */
@keyframes bookNavBlink {
    0%, 100% {
        box-shadow: 0 0 0 2px rgba(212,175,55,0.6), 0 0 12px rgba(212,175,55,0.25), 0 4px 16px rgba(0,0,0,0.5);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 0 5px rgba(212,175,55,1), 0 0 40px rgba(212,175,55,0.65), 0 0 70px rgba(212,175,55,0.25);
        transform: scale(1.03);
    }
}
.bgcard-nav-highlight {
    animation: bookNavBlink 0.85s ease-in-out infinite;
    border-color: rgba(212,175,55,1) !important;
    z-index: 3;
    position: relative;
}
.prereq-bar {
    display: inline-block;
    width: 52px;
    height: 5px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    overflow: hidden;
    flex-shrink: 0;
}
.prereq-fill {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #8b2020, #e05050);
    border-radius: 3px;
    transition: width 0.3s;
}
/* Disable checkboxes/buttons in locked book cards */
.book-card.locked .lv-check {
    pointer-events: none;
    opacity: 0.3;
}
.book-card.locked .node-mark-btn {
    pointer-events: none;
    opacity: 0.3;
}
.book-mark-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.book-status-icon {
    margin-right: 4px;
    font-size: 0.82rem;
}
.book-progress.complete {
    color: var(--green);
}

/* ── Node list ── */
.nodes-list { padding: 0; }

.node-item {
    border-bottom: 1px solid rgba(212,175,55,0.07);
}
.node-item:last-child { border-bottom: none; }

.node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    transition: background 0.15s;
}
.node-header:hover { background: rgba(255,255,255,0.03); }

.node-name-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    cursor: pointer;
}
.node-name {
    font-size: 0.9rem;
    color: #f8eedd;
    line-height: 1.3;
}
.node-name.done { color: #7a7060; text-decoration: line-through; }
.node-desc {
    font-size: 0.72rem;
    color: #b8a888;
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
    line-height: 1.2;
}

.type-badge {
    font-size: 0.62rem;
    font-family: 'Cinzel', serif;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
    white-space: nowrap;
}
.type-badge.t2 { background: rgba(41,128,185,0.15); color: #5dade2; border: 1px solid rgba(41,128,185,0.3); }
.type-badge.t3 { background: var(--fm-bg); color: var(--fm-color); border: 1px solid rgba(196,154,60,0.3); }

.troop-badge {
    font-size: 0.78rem;
    padding: 1px 4px;
    border-radius: 3px;
    white-space: nowrap;
    line-height: 1.6;
    cursor: default;
}
.troop-badge.troop-footmen { background: rgba(100,70,30,0.25); color: #d4a574; border: 1px solid rgba(180,120,50,0.35); }
.troop-badge.troop-archer  { background: rgba(39,150,80,0.18); color: #7de0a0; border: 1px solid rgba(50,180,90,0.35); }
.troop-badge.troop-cavalry { background: rgba(160,100,200,0.18); color: #c090e8; border: 1px solid rgba(150,80,200,0.35); }

.node-mark-btn {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 3px;
    border: 1px solid rgba(212,175,55,0.25);
    background: rgba(212,175,55,0.06);
    color: var(--gold-dark);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s;
    line-height: 1.4;
}
.node-mark-btn:hover {
    background: rgba(212,175,55,0.16);
    border-color: var(--gold);
    color: var(--gold-light);
}
.node-mark-btn.done {
    border-color: rgba(39,174,96,0.35);
    background: rgba(39,174,96,0.08);
    color: #5dbd80;
}
.node-mark-btn.done:hover {
    background: rgba(139,0,0,0.12);
    border-color: rgba(139,0,0,0.4);
    color: #e08080;
}
.node-toggle { font-size: 0.65rem; color: #b0a090; }

/* ── Level rows ── */
.levels-container { display: none; background: rgba(0,0,0,0.15); }
.levels-container.open { display: block; }

.levels-col-hdr {
    display: grid;
    grid-template-columns: 18px 36px 1fr 58px 72px 80px;
    gap: 6px;
    align-items: center;
    padding: 4px 14px 4px 32px;
    border-bottom: 1px solid rgba(212,175,55,0.15);
    background: rgba(212,175,55,0.07);
}
.col-lbl {
    font-family: 'Cinzel', serif;
    font-size: 0.6rem;
    font-weight: 700;
    color: #c8a860;
    text-align: right;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.level-row {
    display: grid;
    grid-template-columns: 18px 36px 1fr 58px 72px 80px;
    gap: 6px;
    align-items: center;
    padding: 6px 14px 6px 32px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    transition: background 0.15s;
}
.level-row:last-child { border-bottom: none; }
.level-row:hover { background: rgba(255,255,255,0.05); }

.lv-check {
    width: 14px;
    height: 14px;
    cursor: pointer;
    accent-color: var(--gold);
}
.lv-num {
    font-family: 'Cinzel', serif;
    font-size: 0.68rem;
    color: #dfc070;
    text-align: center;
}
.lv-attr {
    font-size: 0.84rem;
    color: #eeddc0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: right;
}
.lv-cp {
    font-size: 0.78rem;
    color: #80d8a8;
    text-align: right;
    font-family: monospace;
    white-space: nowrap;
}
.lv-time {
    font-size: 0.78rem;
    color: #d0c0b0;
    text-align: right;
    font-family: monospace;
}
.lv-fm-val {
    font-family: 'Cinzel', serif;
    font-size: 0.75rem;
    color: #f0c040;
    text-align: right;
    white-space: nowrap;
}

.lv-done-row {
    background: rgba(46,120,80,0.12);
    border-bottom-color: rgba(46,180,100,0.08);
}
.lv-done-row .lv-num    { color: #7a9070;  text-decoration: line-through; }
.lv-done-row .lv-attr   { color: #9a9080;  text-decoration: line-through; }
.lv-done-row .lv-cp     { color: #5a9878;  text-decoration: line-through; }
.lv-done-row .lv-time   { color: #908878;  text-decoration: line-through; }
.lv-done-row .lv-fm-val { color: #9a8840;  text-decoration: line-through; }

/* Node completamente concluído */
.node-done .node-header {
    background: rgba(46,120,70,0.12);
    border-left: 3px solid rgba(46,204,113,0.4);
}
.node-done .node-name { color: #7a9070 !important; }
.node-done .node-desc { color: #607858 !important; }

/* ── Blocked node (prerequisite not done yet) ── */
.node-blocked .node-header {
    background: rgba(160, 60, 10, 0.08);
    border-left: 3px solid rgba(220, 100, 30, 0.4);
    opacity: 0.78;
}
.node-blocked .node-name { color: #c8956a !important; }
.node-blocked-hint {
    font-size: 0.64rem;
    color: #e8a456;
    padding: 3px 14px 6px;
    line-height: 1.3;
    opacity: 0.9;
}

/* ── Empty/no-match state ── */
.no-match {
    text-align: center;
    padding: 60px 40px;
    color: #c0b09a;
    font-style: italic;
}

/* ── Research Tree Modal ── */
.tree-open-btn {
    border-color: rgba(212,175,55,0.4) !important;
    color: var(--gold-dark) !important;
}
.tree-open-btn:hover { background: rgba(212,175,55,0.1) !important; color: var(--gold) !important; }

.tree-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
.tree-modal {
    background: var(--bg-section);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    width: min(96vw, 980px);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 70px rgba(0,0,0,0.9);
}
.tree-modal-hdr {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--card-border);
    flex-shrink: 0;
}
.tree-modal-title {
    font-family: 'Cinzel', serif;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--gold);
    flex: 1;
    letter-spacing: 0.04em;
}
.tree-nav-btn {
    font-family: 'Cinzel', serif;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--gold-dark);
    background: none;
    border: 1px solid rgba(212,175,55,0.3);
    padding: 5px 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.tree-nav-btn:hover { border-color: var(--gold); color: var(--gold); }
.tree-modal-body {
    flex: 1;
    overflow: auto;
    padding: 18px 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background: #0d0a07;
}
/* ── HTML Flowchart Tree ─────────────────────────────────────────────────── */
.ftree-bv, .ftree-gv {
    display: flex; flex-direction: column; align-items: center;
    padding: 14px 10px 24px; gap: 0; width: 100%; box-sizing: border-box;
}
.ftree-row {
    display: flex; gap: 8px; justify-content: center;
    flex-wrap: wrap; width: 100%;
}
.fcard {
    position: relative; display: flex; flex-direction: column; align-items: flex-start;
    gap: 3px; padding: 8px 9px 7px; width: 130px; min-height: 74px;
    border-radius: 8px; border: 1px solid rgba(212,175,55,0.22);
    background: rgba(18,13,6,0.92); box-sizing: border-box; overflow: hidden;
    transition: transform 0.13s, box-shadow 0.13s;
}
.fcard::after {
    content: ''; position: absolute; top: 0; right: 0; width: 48px; height: 48px;
    background: var(--bgi, none) center/cover no-repeat; opacity: 0.2;
    border-radius: 0 8px 0 0;
    -webkit-mask-image: linear-gradient(to bottom-left, rgba(0,0,0,0.85) 20%, transparent 75%);
    mask-image: linear-gradient(to bottom-left, rgba(0,0,0,0.85) 20%, transparent 75%);
    pointer-events: none;
}
.fcard-book { cursor: pointer; }
.fcard-book:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(212,175,55,0.18); }
.fcard-ext  { border-style: dashed; border-color: rgba(212,175,55,0.15); opacity: 0.8; width: 142px; }
.fcard-gtag {
    font-size: 0.55rem; color: rgba(212,175,55,0.5); text-transform: uppercase;
    letter-spacing: 0.08em; font-family: 'Cinzel', serif; line-height: 1; margin-bottom: 1px;
}
.fcard-tsss-tag {
    font-size: 0.54rem; font-family: 'Cinzel', serif; font-weight: 700;
    padding: 1px 5px; border-radius: 3px; line-height: 1.4; margin-bottom: 2px;
}
.fcard-tsss-front { background: rgba(200,50,30,0.75); color: #ffe0d0; }
.fcard-tsss-mid   { background: rgba(155,105,0,0.75); color: #fff0b0; }
.fcard-tsss-back  { background: rgba(40,100,40,0.75); color: #c0f0c0; }
.fcard-name {
    font-family: 'Cinzel', serif; font-size: 0.69rem; font-weight: 600;
    color: #e8d48b; line-height: 1.35; padding-right: 26px; width: 100%;
}
.fcard-badge { font-size: 0.78rem; font-weight: 700; color: var(--gold); }
.fcard-bar   { width: 100%; height: 3px; background: rgba(255,255,255,0.08); border-radius: 2px; overflow: hidden; margin-top: 2px; }
.fcard-bar-fill { height: 100%; border-radius: 2px; background: var(--gold); transition: width 0.3s; }
.fcard-cross { font-size: 0.57rem; color: rgba(255,190,80,0.6); line-height: 1.3; margin-top: 2px; padding-right: 20px; }

.fcard-done   { border-color: rgba(46,204,113,0.45); background: rgba(8,20,10,0.92); }
.fcard-done   .fcard-name  { color: rgba(165,238,180,0.9); }
.fcard-done   .fcard-badge { color: #2ecc71; }
.fcard-done   .fcard-bar-fill { background: #2ecc71; }
.fcard-locked { border-color: rgba(100,100,100,0.18); opacity: 0.52; }
.fcard-locked .fcard-name  { color: rgba(175,155,120,0.65); }
.fcard-locked .fcard-badge { color: rgba(120,120,120,0.7); }
.fcard-active { border-color: rgba(212,175,55,0.38); box-shadow: 0 0 8px rgba(212,175,55,0.05); }

.fconn      { display: flex; flex-direction: column; align-items: center; min-height: 38px; padding: 3px 0 1px; justify-content: center; gap: 2px; }
.fconn-arr  { font-size: 1.05rem; color: rgba(212,175,55,0.38); line-height: 1; }
.fconn-lbl  { font-family: 'Cinzel', serif; font-size: 0.57rem; font-weight: 700; color: rgba(212,175,55,0.48); text-transform: uppercase; letter-spacing: 0.1em; text-align: center; }

.ftree-gv-top    { margin-bottom: 2px; }
.fcard-g         { width: 136px; cursor: pointer !important; }
.fcard-g:hover   { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(212,175,55,0.18); }
.ftree-gv-branch { display: flex; justify-content: center; gap: 80px; color: rgba(212,175,55,0.38); font-size: 1.25rem; padding: 2px 0; }
.ftree-gv-cols   { display: flex; gap: 12px; align-items: flex-start; justify-content: center; width: 100%; }
.ftree-gv-col    { display: flex; flex-direction: column; align-items: center; gap: 0; }
.fconn-darr      { color: rgba(212,175,55,0.38); font-size: 1rem; text-align: center; padding: 1px 0; line-height: 1; }
.ftree-gv-note   { margin-top: 12px; font-size: 0.63rem; color: rgba(212,175,55,0.42); text-align: center; padding: 7px 12px; border: 1px solid rgba(212,175,55,0.12); border-radius: 4px; max-width: 340px; line-height: 1.5; }
.ftree-gv-note b { color: rgba(212,175,55,0.65); font-weight: 700; }

@media (max-width: 500px) {
    .fcard { width: 96px; min-height: 62px; padding: 6px 7px 5px; }
    .fcard-ext { width: 110px; }
    .fcard-g { width: 100px; }
    .fcard-name { font-size: 0.6rem; }
    .ftree-gv-cols { gap: 6px; }
    .ftree-gv-branch { gap: 52px; font-size: 1.1rem; }
}

.tree-svg { width: 100%; height: auto; display: block; }

/* SVG edge lines */
.te     { stroke: rgba(212,175,55,0.3); stroke-width: 1.5; fill: none; }
.te-done{ stroke: rgba(46,204,113,0.5); stroke-width: 2;   fill: none; }
.te-ext { stroke: rgba(120,120,120,0.3); stroke-width: 1.5; stroke-dasharray: 5 3; fill: none; }

/* Node backgrounds — fill only, border handled by tnbg-stroke */
.tnbg { fill: #1e1812; stroke: none; }
.tng-done   .tnbg { fill: #0d1a10; }
.tng-locked .tnbg { fill: #131110; }
.tng-ext    .tnbg { fill: #100f0e; }

/* Border rect rendered on top of image */
.tnbg-stroke { fill: none; stroke: rgba(212,175,55,0.18); stroke-width: 1; }
.tng-active .tnbg-stroke { stroke: rgba(212,175,55,0.72); stroke-width: 1.5; }
.tng-done   .tnbg-stroke { stroke: rgba(46,204,113,0.55); stroke-width: 1.5; }
.tng-locked .tnbg-stroke { stroke: rgba(100,100,100,0.2); }
.tng-ext    .tnbg-stroke { stroke: rgba(100,100,100,0.25); stroke-dasharray: 4 3; }

/* Book images inside tree nodes */
.tn-bk-img  { opacity: 0.72; }
.tn-bk-ext  { opacity: 0.35; filter: grayscale(60%); }
.tn-bk-locked { opacity: 0.22; filter: grayscale(90%); }

/* Node images (group-level only) */
.tn-img { opacity: 0.82; }
.tng-locked .tn-img { opacity: 0.28; filter: grayscale(100%); }

/* Label strip below image */
.tn-strip { fill: rgba(0,0,0,0.68); }

/* Text */
.tn-name {
    font-family: 'Cinzel', serif;
    font-size: 9px;
    font-weight: 600;
    fill: var(--text);
}
.tng-locked .tn-name { fill: rgba(200,180,154,0.4); }
.tng-ext    .tn-name { fill: rgba(200,180,154,0.45); }

.tn-badge {
    font-family: 'Cinzel', serif;
    font-size: 9.5px;
    fill: var(--gold);
}
.tng-done   .tn-badge { fill: rgba(46,204,113,0.9); font-size: 11px; }
.tng-locked .tn-badge { fill: rgba(120,120,120,0.6); font-size: 11px; }

.tn-ext-lbl {
    font-family: 'Crimson Text', serif;
    font-size: 8px;
    font-style: italic;
    fill: rgba(150,140,120,0.55);
}

/* Progress bars */
.tn-bar     { fill: var(--gold); }
.tn-bar-ext { fill: rgba(120,120,120,0.35); }

/* TSSS badge inside tree nodes */
.tn-tsss text { font-family: 'Cinzel', serif; font-size: 6.5px; font-weight: 700; }
.tn-tsss rect { stroke-width: 0.8; }
.tn-tsss-front rect { fill: rgba(200,50,30,0.88); stroke: rgba(255,120,80,0.65); }
.tn-tsss-front text { fill: #ffe0d0; }
.tn-tsss-mid  rect { fill: rgba(155,105,0,0.88); stroke: rgba(255,210,80,0.65); }
.tn-tsss-mid  text { fill: #fff4c0; }
.tn-tsss-back rect { fill: rgba(20,70,160,0.88); stroke: rgba(80,160,255,0.65); }
.tn-tsss-back text { fill: #d0e8ff; }

/* Hover glow on clickable nodes */
.tree-node { transition: opacity 0.15s; }
.tree-node:hover { opacity: 0.88; }

/* ── FM Calculator ── */
.fm-calc-btn {
    border-color: rgba(212,168,60,0.45) !important;
    color: var(--fm-color) !important;
}
.fm-calc-btn:hover { background: rgba(212,168,60,0.1) !important; color: var(--gold) !important; }

.fm-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.88);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}
.fm-modal {
    background: var(--bg-section);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    width: min(96vw, 680px);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 28px 80px rgba(0,0,0,0.95);
}
.fm-modal-hdr {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--card-border);
    flex-shrink: 0;
    background: linear-gradient(180deg, rgba(212,168,60,0.07) 0%, transparent 100%);
}
.fm-modal-title {
    font-family: 'Cinzel', serif;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--fm-color);
    flex: 1;
    letter-spacing: 0.04em;
}
.fm-modal-body { flex: 1; overflow-y: auto; }

.fm-needed-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: rgba(212,168,60,0.06);
    border-bottom: 1px solid var(--card-border);
}
.fm-needed-label { color: #c0b09a; font-size: 0.85rem; }
.fm-needed-value {
    font-family: 'Cinzel', serif;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--fm-color);
}

.fm-section-hdr {
    padding: 7px 18px 5px;
    font-family: 'Cinzel', serif;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--gold-dark);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: rgba(0,0,0,0.28);
    border-bottom: 1px solid rgba(212,175,55,0.1);
    border-top: 1px solid rgba(212,175,55,0.1);
    margin-top: 2px;
}

.fm-event-row { border-bottom: 1px solid rgba(212,175,55,0.07); }
.fm-event-main {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px 9px 18px;
    transition: background 0.15s;
}
.fm-event-main:hover { background: rgba(255,255,255,0.03); }
.fm-event-check {
    width: 15px; height: 15px;
    accent-color: var(--fm-color);
    cursor: pointer;
    flex-shrink: 0;
}
.fm-event-label { flex: 1; font-size: 0.84rem; color: var(--text); }
.fm-event-note {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-style: italic;
    display: block;
    margin-top: 1px;
}
.fm-event-fm {
    font-family: 'Cinzel', serif;
    font-size: 0.72rem;
    color: var(--fm-color);
    background: var(--fm-bg);
    border: 1px solid rgba(212,168,60,0.2);
    border-radius: 3px;
    padding: 2px 7px;
    white-space: nowrap;
    min-width: 108px;
    text-align: right;
    transition: opacity 0.2s;
}
.fm-event-cost {
    font-family: 'Cinzel', serif;
    font-size: 0.72rem;
    color: #8de888;
    background: rgba(46,180,80,0.08);
    border: 1px solid rgba(46,180,80,0.2);
    border-radius: 3px;
    padding: 2px 7px;
    white-space: nowrap;
    min-width: 54px;
    text-align: right;
    transition: opacity 0.2s;
}
.fm-dimmed { opacity: 0.32; }
.fm-event-expand {
    font-size: 0.6rem;
    color: #b0a090;
    background: none;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 3px;
    cursor: pointer;
    padding: 2px 7px;
    transition: background 0.15s;
    flex-shrink: 0;
}
.fm-event-expand:hover { background: rgba(255,255,255,0.07); }

.fm-pack-list {
    display: none;
    background: rgba(0,0,0,0.18);
    border-top: 1px solid rgba(212,175,55,0.07);
    padding: 4px 18px 4px 52px;
}
.fm-pack-list.open { display: block; }
.fm-pack-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    font-size: 0.76rem;
    color: var(--text-muted);
}
.fm-pack-row:last-child { border-bottom: none; }
.fm-pack-check { width: 12px; height: 12px; accent-color: var(--fm-color); cursor: pointer; }
.fm-pack-price { color: #8de888; font-family: 'Cinzel', serif; font-size: 0.7rem; min-width: 34px; }
.fm-pack-qty   { color: #c0b09a; font-size: 0.7rem; }
.fm-pack-fm    { margin-left: auto; font-family: 'Cinzel', serif; font-size: 0.7rem; color: var(--fm-color); }
.fm-pack-cost  { color: #808878; font-size: 0.65rem; }

.fm-summary {
    background: rgba(212,168,60,0.06);
    border-top: 2px solid rgba(212,168,60,0.22);
    padding: 15px 18px 18px;
}
.fm-summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 20px;
    margin-bottom: 12px;
}
.fm-summary-item { display: flex; flex-direction: column; gap: 2px; }
.fm-summary-label { font-size: 0.68rem; color: #a8a090; }
.fm-summary-value {
    font-family: 'Cinzel', serif;
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--fm-color);
}
.fm-summary-value.cost { color: #8de888; }
.fm-summary-divider { border: none; border-top: 1px solid rgba(212,175,55,0.15); margin: 10px 0; }
.fm-result { display: flex; align-items: flex-start; gap: 20px; flex-wrap: wrap; }
.fm-result-item { display: flex; flex-direction: column; gap: 3px; }
.fm-result-label { font-size: 0.68rem; color: #a8a090; }
.fm-result-value {
    font-family: 'Cinzel', serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gold-light);
}
.fm-result-value.cost { color: #7dde9a; font-size: 0.95rem; }
.fm-no-selection {
    text-align: center;
    padding: 18px;
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.82rem;
}

/* ── Oculta shared-header quando modal está aberto ── */
body.modal-open #sh-bar { display: none !important; }

/* ── Lock strip toggle ── */
.lock-strip-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.prereq-toggle-btn {
    font-family: 'Cinzel', serif;
    font-size: 0.62rem;
    font-weight: 600;
    color: #ff9090;
    background: none;
    border: 1px solid rgba(192,57,43,0.4);
    border-radius: 3px;
    padding: 2px 8px;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}
.prereq-toggle-btn:hover { background: rgba(192,57,43,0.15); }

/* ── Responsive ── */
@media (max-width: 700px) {
    .hdr-nav a span { display: none; }
    .hdr-text h1 { font-size: 1rem; }
    .controls { padding: 10px 12px; }
    .main-wrap { grid-template-columns: 1fr; padding: 10px 10px 30px; }
    .level-row { grid-template-columns: 18px 28px 1fr 48px 58px 66px; padding-left: 24px; }
    .levels-col-hdr { grid-template-columns: 18px 28px 1fr 48px 58px 66px; padding-left: 24px; }
    .stats-inner { gap: 10px; }
}

/* ── Mobile modal header fix ── */
@media (max-width: 600px) {
    .book-modal {
        max-height: 95vh;
    }
    .book-modal-hdr {
        position: relative;
        flex-wrap: wrap;
        padding: 10px 48px 10px 12px;
        gap: 4px 6px;
        align-items: flex-start;
    }
    .bm-icon {
        margin-top: 3px;
        flex-shrink: 0;
    }
    .bm-title {
        flex: 1;
        min-width: 0;
        font-size: 0.88rem;
        word-break: break-word;
    }
    .bm-meta {
        order: 3;
        width: 100%;
        flex-wrap: wrap;
        gap: 6px;
        padding-top: 4px;
        border-top: 1px solid rgba(212,175,55,0.1);
    }
    /* Close button pinned absolute top-right */
    .book-modal-hdr > .tree-nav-btn {
        position: absolute;
        top: 10px;
        right: 10px;
        flex-shrink: 0;
    }
}
