: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;
    --cm-color: #5bc4f0;
    --wb-color: #f0885b;
    --fm-color: #d4a83c;
    --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%);
    pointer-events: none;
    z-index: -1;
}

/* ── VIP Gate ── */
.vip-gate {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(10,7,4,0.95);
    z-index: 9999;
}
.vip-gate-box {
    background: var(--card-bg);
    border: 1px solid var(--gold-dark);
    border-radius: 12px;
    padding: 40px 48px;
    text-align: center;
    max-width: 420px;
}
.vip-gate-icon { font-size: 2.5rem; margin-bottom: 12px; }
.vip-gate-title {
    font-family: 'Cinzel', serif;
    color: var(--gold-light);
    font-size: 1.4rem;
    margin-bottom: 12px;
}
.vip-gate-sub { color: var(--text-muted); font-size: 0.95rem; line-height: 1.6; margin-bottom: 24px; }
.vip-gate-btn {
    display: inline-block;
    background: linear-gradient(135deg, #8b6914, #d4a83c);
    color: #0f0c09;
    padding: 10px 28px;
    border-radius: 6px;
    font-family: 'Cinzel', serif;
    font-size: 0.88rem;
    font-weight: 700;
    text-decoration: none;
    letter-spacing: 0.05em;
}

/* ── 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: 16px;
}
.hdr-nav a {
    display: flex; align-items: center; gap: 6px;
    text-decoration: none; color: var(--text-muted);
    font-size: 0.8rem; transition: color 0.2s;
}
.hdr-nav a:hover { color: var(--gold); }
.hdr-nav img { width: 20px; height: 20px; border-radius: 50%; }

/* ── Stats Bar ── */
.stats-bar {
    background: #1a1410;
    border-bottom: 1px solid rgba(212,175,55,0.15);
    padding: 10px 20px;
}
.stats-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
}
.stat-item { display: flex; align-items: center; gap: 6px; }
.stat-label { font-size: 0.78rem; color: var(--text-muted); }
.stat-sub { font-size: 0.75rem; color: var(--text-muted); }
.stat-value { font-size: 0.9rem; font-weight: 600; color: var(--gold-light); }
.cm-label { color: var(--cm-color); }
.cm-val   { color: var(--cm-color); }
.wb-label { color: var(--wb-color); }
.wb-val   { color: var(--wb-color); }
.fm-label { color: var(--fm-color); }
.fm-val   { color: var(--fm-color); }
.stat-reset {
    margin-left: auto;
    background: transparent;
    border: 1px solid rgba(192,57,43,0.5);
    color: #e57373;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.78rem;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}
.stat-reset:hover { background: rgba(192,57,43,0.15); border-color: #e57373; }
.cloud-status {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 3px 8px;
    border-radius: 4px;
    background: rgba(255,255,255,0.04);
}
.cloud-status.cs-ok  { color: #4caf50; }
.cloud-status.cs-err { color: #e57373; }

/* ── Filters ── */
.filters-wrap {
    max-width: 1400px;
    margin: 16px auto;
    padding: 0 20px;
}
.filters-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.search-input {
    flex: 1;
    min-width: 200px;
    max-width: 320px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 7px 12px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.88rem;
}
.search-input:focus { outline: none; border-color: var(--gold-dark); }
.filter-btns { display: flex; gap: 6px; }
.filter-btn {
    background: transparent;
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    padding: 5px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}
.filter-btn:hover { border-color: var(--gold-dark); color: var(--text); }
.filter-btn.active {
    background: rgba(212,175,55,0.12);
    border-color: var(--gold);
    color: var(--gold-light);
}
.season-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.season-tab {
    background: transparent;
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.78rem;
    cursor: pointer;
    font-family: 'Cinzel', serif;
    transition: all 0.2s;
}
.season-tab:hover { border-color: var(--gold-dark); color: var(--text); }
.season-tab.active {
    background: rgba(212,175,55,0.15);
    border-color: var(--gold);
    color: var(--gold-light);
}

/* ── Trees Grid ── */
.trees-wrap {
    max-width: 1400px;
    margin: 0 auto 40px;
    padding: 0 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 12px;
    align-items: start;
}
.loading-msg {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
}
.no-match-msg {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
    font-style: italic;
}

/* ── Tree Card ── */
.tree-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    overflow: hidden;
    transition: border-color 0.2s;
}
.tree-card.is-done { border-color: rgba(78,160,78,0.4); }
.tree-card-hdr {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}
.tree-card-hdr:hover { background: rgba(255,255,255,0.03); }
.tree-season-badge {
    font-family: 'Cinzel', serif;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(212,175,55,0.12);
    border: 1px solid rgba(212,175,55,0.25);
    color: var(--gold);
    flex-shrink: 0;
    letter-spacing: 0.05em;
}
.tree-name {
    flex: 1;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tree-medal-badge {
    font-size: 0.72rem;
    padding: 2px 6px;
    border-radius: 3px;
    flex-shrink: 0;
}
.tree-medal-badge.cm { background: rgba(91,196,240,0.12); color: var(--cm-color); border: 1px solid rgba(91,196,240,0.25); }
.tree-medal-badge.wb { background: rgba(240,136,91,0.12); color: var(--wb-color); border: 1px solid rgba(240,136,91,0.25); }
.tree-medal-badge.fm { background: rgba(212,168,60,0.12); color: var(--fm-color); border: 1px solid rgba(212,168,60,0.25); }

.tree-pct {
    font-size: 0.78rem;
    color: var(--text-muted);
    flex-shrink: 0;
    min-width: 34px;
    text-align: right;
}
.tree-pct.done { color: #4caf50; }
.tree-chevron {
    font-size: 0.7rem;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: transform 0.2s;
}
.tree-card.expanded .tree-chevron { transform: rotate(180deg); }

/* progress bar under header */
.tree-prog-bar {
    height: 3px;
    background: rgba(255,255,255,0.06);
}
.tree-prog-fill {
    height: 100%;
    background: linear-gradient(90deg, #4a8a4a, #4caf50);
    transition: width 0.3s;
}

/* ── Tree Body (nodes) ── */
.tree-body {
    display: none;
    border-top: 1px solid rgba(212,175,55,0.1);
}
.tree-card.expanded .tree-body { display: block; }

.node-row {
    display: flex;
    flex-direction: column;
    padding: 7px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    transition: background 0.1s;
    gap: 3px;
}
.node-row:last-child { border-bottom: none; }
.node-row:hover { background: rgba(255,255,255,0.02); }
.node-row.node-done { opacity: 0.55; }

.node-row-main {
    display: flex;
    align-items: center;
    gap: 8px;
}

.node-name {
    flex: 1;
    font-size: 0.82rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.node-attr {
    font-size: 0.72rem;
    color: rgba(212,175,55,0.6);
    padding-left: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.node-type {
    font-size: 0.7rem;
    color: var(--text-muted);
    flex-shrink: 0;
    padding: 1px 5px;
    background: rgba(255,255,255,0.05);
    border-radius: 3px;
}

.node-ctrl {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.node-btn {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--text-muted);
    width: 22px; height: 22px;
    border-radius: 3px;
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
    display: flex; align-items: center; justify-content: center;
}
.node-btn:hover { background: rgba(212,175,55,0.15); border-color: var(--gold-dark); color: var(--gold); }
.node-lv-display {
    font-size: 0.8rem;
    color: var(--gold-light);
    min-width: 38px;
    text-align: center;
    cursor: pointer;
    padding: 2px 0;
    border-radius: 3px;
    transition: background 0.15s;
}
.node-lv-display:hover { background: rgba(212,175,55,0.1); }

.node-cost {
    font-size: 0.78rem;
    flex-shrink: 0;
    min-width: 56px;
    text-align: right;
}
.node-cost.cm { color: var(--cm-color); }
.node-cost.wb { color: var(--wb-color); }
.node-cost.fm { color: var(--fm-color); }
.node-cost.none { color: var(--text-muted); }

/* tree footer totals */
.tree-footer {
    padding: 8px 14px;
    background: rgba(0,0,0,0.2);
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 0.78rem;
}
.tree-footer-item { display: flex; gap: 5px; align-items: center; }
.tree-footer-label { color: var(--text-muted); }
.tree-footer-val { font-weight: 600; }
.tree-footer-val.cm { color: var(--cm-color); }
.tree-footer-val.wb { color: var(--wb-color); }
.tree-footer-val.fm { color: var(--fm-color); }
.tree-footer-val.cp { color: var(--gold); }

/* ── Level Modal ── */
.level-modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
}
.level-modal {
    background: var(--card-bg);
    border: 1px solid var(--gold-dark);
    border-radius: 10px;
    padding: 28px 32px;
    min-width: 240px;
    text-align: center;
}
.level-modal-title {
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    color: var(--gold-light);
    margin-bottom: 4px;
}
.level-modal-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}
.level-modal-input {
    width: 100%;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--gold-dark);
    border-radius: 6px;
    color: var(--text);
    font-size: 1.4rem;
    text-align: center;
    padding: 8px;
    font-family: inherit;
    margin-bottom: 16px;
}
.level-modal-input:focus { outline: none; border-color: var(--gold); }
.level-modal-btns { display: flex; gap: 8px; }
.level-modal-btns button {
    flex: 1;
    padding: 8px;
    border-radius: 5px;
    font-family: 'Cinzel', serif;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: opacity 0.2s;
}
.level-modal-btns button:hover { opacity: 0.85; }
.btn-max    { background: rgba(212,175,55,0.18); color: var(--gold); border: 1px solid rgba(212,175,55,0.3) !important; }
.btn-cancel { background: rgba(255,255,255,0.06); color: var(--text-muted); }
.btn-confirm { background: linear-gradient(135deg, #8b6914, #d4a83c); color: #0f0c09; }

/* ── Attribute Summary ── */
.attr-summary-wrap {
    max-width: 1400px;
    margin: 0 auto 16px;
    padding: 0 20px;
}
.attr-summary-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: #1e1812;
    border: 1px solid var(--card-border);
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Cinzel', serif;
    font-size: 0.88rem;
    color: var(--gold-light);
    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;
    overflow: hidden;
}

/* Legion view tabs */
.legion-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 16px;
    background: rgba(0,0,0,0.25);
    border-bottom: 1px solid rgba(212,175,55,0.14);
}
.legion-tab {
    background: transparent;
    border: 1px solid rgba(212,175,55,0.18);
    color: var(--text-muted);
    padding: 4px 11px;
    border-radius: 4px;
    font-size: 0.73rem;
    cursor: pointer;
    font-family: 'Cinzel', serif;
    transition: all 0.2s;
    white-space: nowrap;
}
.legion-tab:hover { border-color: var(--gold-dark); color: var(--text); }
.legion-tab.active {
    background: rgba(212,175,55,0.14);
    border-color: var(--gold);
    color: var(--gold-light);
}

/* top-level troop category */
.attr-cat-hdr {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    background: rgba(212,175,55,0.07);
    border-bottom: 1px solid rgba(212,175,55,0.12);
    cursor: pointer;
    transition: background 0.15s;
}
.attr-cat-hdr:hover { background: rgba(212,175,55,0.12); }
.attr-cat-label { font-family: 'Cinzel', serif; font-size: 0.82rem; color: var(--gold-light); flex: 1; }
.attr-cat-meta  { font-size: 0.72rem; color: var(--text-muted); }
.attr-cat-toggle { font-size: 0.7rem; color: var(--gold-dark); }

.attr-cat-inner {}

/* subcategory */
.attr-sub { border-bottom: 1px solid rgba(255,255,255,0.04); }
.attr-sub:last-child { border-bottom: none; }
.attr-sub-hdr {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px 6px 28px;
    background: rgba(255,255,255,0.025);
    border-bottom: 1px solid rgba(255,255,255,0.03);
    cursor: pointer;
    transition: background 0.15s;
}
.attr-sub-hdr:hover { background: rgba(255,255,255,0.04); }
.attr-sub-icon  { font-size: 0.75rem; }
.attr-sub-label { font-size: 0.78rem; color: var(--text); flex: 1; }
.attr-sub-meta  { font-size: 0.68rem; color: var(--text-muted); }
.attr-sub-toggle { font-size: 0.65rem; color: var(--text-muted); }

.attr-sub-rows {}

/* bonus rows */
.attr-row {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 3px 12px;
    padding: 6px 16px 6px 40px;
    border-bottom: 1px solid rgba(255,255,255,0.025);
    align-items: center;
}
.attr-row:last-child { border-bottom: none; }
.attr-row-zero { opacity: 0.38; }
.attr-row-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
    grid-column: 1;
    grid-row: 1;
}
.attr-row-val {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--gold-light);
    grid-column: 2;
    grid-row: 1;
    text-align: right;
    white-space: nowrap;
}
.attr-row-max { font-size: 0.7rem; color: var(--text-muted); font-weight: 400; }
.attr-row-bar {
    grid-column: 1 / -1;
    grid-row: 2;
    height: 3px;
    background: rgba(255,255,255,0.05);
    border-radius: 2px;
}
.attr-row-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold-dark), var(--gold));
    border-radius: 2px;
    transition: width 0.3s;
}

.node-name mark {
    background: rgba(212,175,55,0.3);
    color: var(--gold-light);
    border-radius: 2px;
}

@media (max-width: 600px) {
    .trees-wrap { grid-template-columns: 1fr; padding: 0 10px; }
    .hdr-nav a span { display: none; }
    .stats-inner { gap: 12px; }
}
