/* ═══════════════════════════════════════════════
   Chess Club Archive — Refined Dark Editorial
   ═══════════════════════════════════════════════ */

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

:root {
    --bg:          #161512;
    --bg-elevated: #302e2c;
    --bg-card:     #262321;
    --bg-hover:    #302e2b;
    --surface:     #1d1b18;

    --text:        #c9c9c9;
    --text-mid:    #969088;
    --text-muted:  #6b6660;

    --amber:       #c9a84c;
    --amber-dim:   #9e7f30;
    --amber-glow:  rgba(201, 168, 76, 0.08);

    --border:      #3d3a36;
    --border-light:#4d4a45;

    --radius:      6px;
    --radius-lg:   10px;

    --font-display: 'Playfair Display', 'Georgia', serif;
    --font-body:    'DM Sans', system-ui, sans-serif;
}

/* --- Grain overlay --- */
.grain-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 200px;
}

/* --- Base --- */
html { scroll-behavior: smooth; }

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }

/* --- Header --- */
header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #211e1a;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
}

header nav {
    max-width: 1100px;
    margin: 0 auto;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#auth-btn {
    border-color: transparent;
    color: var(--text-muted);
    opacity: 0.55;
    transition: all 0.2s;
}
#auth-btn:hover {
    border-color: var(--border);
    opacity: 1;
}
#auth-btn.topbar-btn-active {
    border-color: var(--amber-dim);
    color: var(--amber);
    opacity: 1;
}

/* --- Login modal --- */
.modal-overlay {
    display: none;
}
.modal-overlay:not([hidden]) {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-box {
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: min(380px, 90vw);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}
.modal-box-pgn {
    width: min(760px, 92vw);
}

.pgn-textarea {
    font-family: monospace;
    font-size: 0.85rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.75rem;
    resize: vertical;
    width: 100%;
    height: min(55vh, 500px);
    line-height: 1.5;
    transition: border-color 0.15s;
}
.pgn-textarea:focus {
    border-color: var(--amber-dim);
    outline: none;
}

.modal-title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
}
.modal-field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.modal-field label {
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-mid);
}
.modal-field input {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.95rem;
    padding: 0.6rem 0.85rem;
    transition: border-color 0.15s;
    width: 100%;
}
.modal-field input:focus {
    border-color: var(--amber-dim);
    outline: none;
}
.modal-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* Login gate on add page */
.login-gate {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    font-size: 0.95rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    transition: opacity 0.2s;
}
.logo:hover { opacity: 0.8; }

.logo-icon {
    font-size: 1.6rem;
    color: var(--amber);
    line-height: 1;
}

.logo-text {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text);
}

.nav-tagline {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-left: 0.6rem;
    padding-left: 0.6rem;
    border-left: 1px solid var(--border-light);
    white-space: nowrap;
    font-family: var(--font-body);
}

/* --- Footer --- */
footer {
    text-align: center;
    padding: 3rem 1rem 2rem;
    color: var(--text-muted);
}
.footer-mark {
    font-size: 1.4rem;
    opacity: 0.3;
}

/* --- Main container --- */
main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 2rem 2rem;
}

/* --- Hero (index) --- */
.hero {
    padding: 3.5rem 0 2.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2rem;
}

.hero-title {
    font-family: var(--font-display);
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
    line-height: 1.15;
}

.hero-sub {
    margin-top: 0.5rem;
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 300;
}

/* --- Archive section --- */
.archive-section {
    padding: 0.5rem 0;
}

.category-tree-below {
    margin-top: 2.5rem;
}

.sort-controls {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.5rem;
}

.sort-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.82rem;
    padding: 0.3rem 0.7rem;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    transition: color 0.2s, border-color 0.2s;
}

.sort-btn:hover {
    color: var(--fg);
    border-color: var(--fg);
}

.sort-arrow {
    font-size: 0.7rem;
}

/* --- Category tree --- */
.tree {
    list-style: none;
    padding-left: 0;
}

.tree .tree {
    padding-left: 1.5rem;
    margin-top: 0.25rem;
    border-left: 1px solid var(--border);
    margin-left: 0.5rem;
}

.tree-item {
    margin: 0.15rem 0;
}

/* Extra breathing room between sibling folder items */
.tree-item + .tree-item:has(details) {
    margin-top: 1.25rem;
}

details > summary {
    list-style: none;
}
details > summary::-webkit-details-marker { display: none; }

.tree-folder {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.45rem 0.75rem;
    border-radius: var(--radius);
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    user-select: none;
    transition: background 0.15s, color 0.15s;
    width: 100%;
}
.tree-folder:hover {
    background: var(--bg-hover);
    color: var(--amber);
}
.tree-sep {
    flex: 1;
    height: 1px;
    background: var(--border);
    opacity: 0.6;
    border-radius: 1px;
}

.tree-date {
    font-family: var(--font-body);
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.folder-arrow {
    font-size: 1rem;
    color: var(--amber-dim);
    transition: transform 0.2s ease;
    display: inline-block;
}
details:not([open]) .folder-arrow {
    transform: rotate(-90deg);
}

.tree-leaf {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.92rem;
    font-weight: 400;
    color: var(--text-mid);
    transition: all 0.15s;
}
.tree-leaf:hover {
    background: var(--amber-glow);
    color: var(--amber);
}

.leaf-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--amber-dim);
    flex-shrink: 0;
}

/* --- Breadcrumb --- */
.breadcrumb {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.15rem;
    padding: 1.5rem 0 0.75rem;
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 400;
}
.breadcrumb a {
    color: var(--text-muted);
    transition: color 0.15s;
}
.breadcrumb a:hover { color: var(--amber); }
.breadcrumb .sep {
    margin: 0 0.35rem;
    opacity: 0.4;
}
.breadcrumb .current {
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
}

/* --- Category header --- */
.category-header {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 1.25rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2rem;
}

.game-count {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 400;
    padding: 0.2rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    white-space: nowrap;
}

.category-date {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 400;
    white-space: nowrap;
    margin-left: auto;
}

/* --- Category description --- */
.category-description {
    margin-top: 1rem;
    margin-bottom: 1.5rem;
    margin-left: 1rem;
    font-size: 0.92rem;
    color: var(--text-muted);
    line-height: 1.65;
}

.category-description p {
    margin: 0.4rem 0;
}

.category-description a {
    color: var(--amber);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.category-description a:hover {
    color: var(--fg);
}

.tree-description {
    margin: 0.4rem 0 0.5rem 1.5rem;
    font-size: 0.85rem;
}

.category-description-edit {
    margin-top: 0.5rem;
}

.desc-textarea {
    width: 100%;
    min-height: 5rem;
    background: var(--bg-card);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.6rem 0.75rem;
    font-family: var(--font-body);
    font-size: 0.88rem;
    resize: vertical;
}

.desc-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.btn-sm {
    font-size: 0.8rem;
    padding: 0.3rem 0.75rem;
}

/* --- Subcategories --- */
.subcategories {
    margin-bottom: 2rem;
}

/* --- Games grid --- */
.tree-games-grid {
    margin: 0.75rem 0 0.5rem 0.75rem;
}

.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 2rem;
}

.game-card {
    display: block;
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}
.card-lichess-link {
    position: absolute;
    bottom: 0.65rem;
    right: 0.65rem;
    color: var(--text-mid);
    opacity: 0.7;
    line-height: 0;
    padding: 7px;
    z-index: 1;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--bg-card);
    transition: opacity 0.15s, color 0.15s, border-color 0.15s;
}
.card-lichess-link:hover {
    opacity: 1;
    color: var(--amber);
    border-color: var(--amber-dim);
}
.game-card:hover {
    border-color: var(--amber-dim);
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 0 0 0 1px var(--amber-dim);
}

.game-board {
    width: 100%;
    background: var(--surface);
}

/* Contain the lichess viewer inside the card */
.game-card .game-board .lpv {
    border-radius: 0 !important;
}

.game-info {
    display: block;
    padding: 0.85rem 1rem;
    border-top: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}
.game-info:hover {
    background: var(--bg-hover);
}

.players {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.88rem;
    font-weight: 500;
}

.player {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.piece-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.white-dot {
    background: var(--text);
    box-shadow: 0 0 0 1px rgba(255,255,255,0.1);
}
.black-dot {
    background: var(--text-muted);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
}

.white-player { color: var(--text); }
.black-player { color: var(--text-mid); }

.vs {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 400;
}

.game-meta {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.4rem;
}

.result {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--amber);
}

.game-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.board-badge {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.1rem 0.4rem;
    font-family: var(--font-body);
}
.board-badge-topbar {
    font-size: 0.8rem;
    padding: 0.2rem 0.55rem;
}

/* --- Game topbar (breadcrumb + matchup on one line) --- */
.game-topbar-bar {
    border-bottom: 1px solid var(--border);
    background: #211e1a;
}

.game-topbar {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

.topbar-spacer {
    flex: 1;
}

.game-topbar .breadcrumb {
    padding: 0.75rem 0;
    flex: 0 1 auto;
}

.game-topbar-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0;
    flex-shrink: 0;
}

.matchup {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.matchup-player {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.matchup-name {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 600;
}

.result-badge {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--amber);
    background: var(--amber-glow);
    border: 1px solid var(--amber-dim);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    line-height: 1;
    align-self: center;
}

/* --- Game page --- */
.game-page {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.game-page:fullscreen {
    background: var(--bg);
    border: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    --board-max: calc(100dvh - var(--controls-height, 4em));
}
.game-page:fullscreen .game-viewer-full {
    flex: 1;
    min-height: 0;
}
.game-page:fullscreen .lpv {
    max-height: 100dvh;
    max-width: calc(var(--board-max) + 360px);
    margin: 0 auto;
    grid-template-columns:
        minmax(200px, var(--board-max))
        minmax(280px, 360px) !important;
}

.topbar-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: var(--radius);
    padding: 0.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.topbar-btn[hidden] {
    display: none;
}
.topbar-btn:hover {
    border-color: var(--amber-dim);
    color: var(--amber);
    background: var(--amber-glow);
}
.topbar-btn-active {
    border-color: var(--amber-dim);
    color: var(--amber);
    background: var(--amber-glow);
}

/* --- Admin panel --- */
.edit-modal-fields {
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}
.edit-modal-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}
.edit-modal-category {
    flex: 1;
    min-width: 180px;
}
.edit-modal-board {
    width: 90px;
    flex-shrink: 0;
}
.modal-select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.95rem;
    padding: 0.6rem 2rem 0.6rem 0.85rem;
    width: 100%;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b6760' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    cursor: pointer;
    transition: border-color 0.15s;
}
.modal-select:focus {
    border-color: var(--amber-dim);
    outline: none;
}

/* kept for any remaining references */
.admin-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 200px;
}
.admin-field label {
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.admin-field input[type="text"],
.admin-field input[type="number"],
.admin-field select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.9rem;
    padding: 0.45rem 0.75rem;
    transition: border-color 0.15s;
    width: 100%;
}
.admin-field select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b6760' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
    cursor: pointer;
}
.admin-field input:focus,
.admin-field select:focus {
    border-color: var(--amber-dim);
    outline: none;
}
.admin-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    padding-bottom: 0.05rem;
}
.btn-sm {
    font-size: 0.82rem;
    padding: 0.4rem 0.9rem;
}
.btn-secondary {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-mid);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.6rem 1.4rem;
    transition: all 0.15s;
}
.btn-secondary:hover {
    border-color: var(--border-light);
    color: var(--text);
}
.btn-danger {
    background: none;
    border: 1px solid #5a2020;
    border-radius: var(--radius);
    color: #e07070;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.6rem 1.4rem;
    transition: all 0.15s;
}
.btn-danger:hover {
    background: rgba(224, 112, 112, 0.08);
    border-color: #e07070;
}

/* --- Empty state --- */
.empty-section {
    padding: 2rem 0;
}

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

.empty-icon {
    display: block;
    font-size: 3rem;
    opacity: 0.2;
    margin-bottom: 1rem;
}

.empty-state p {
    font-size: 1rem;
    margin: 0.25rem 0;
}

.empty-hint {
    font-size: 0.85rem !important;
    color: var(--text-muted);
    opacity: 0.6;
}

/* --- Animations --- */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-up {
    opacity: 0;
    animation: fadeUp 0.4s ease forwards;
}

/* --- Lichess viewer --- */

/* Prevent dark-mode / color-scheme interference with piece SVGs */
.lpv, .lpv * {
    color-scheme: light;
}

/* Board background: set the variable the library's SVG reads */
.lpv cg-board {
    --board-color: #b58863;
}

/* game-body: make the entire page a vertical flex column so main fills remaining space */
.game-body {
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.game-body main {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-rows: auto auto 1fr;
    padding-bottom: 0;
    overflow: hidden;
}
.game-viewer-full {
    flex: 1;
    min-height: 0;
}

/* The lpv sizes its board with 100vh — replace with the actual available height */
.game-page {
    --board-max: calc(100dvh - 110px - var(--controls-height, 4em));
}
.game-page .lpv {
    max-height: calc(100dvh - 110px);
    grid-template-columns:
        minmax(200px, var(--board-max))
        minmax(232px, 1fr) !important;
}

/* --- Responsive --- */
@media (max-width: 700px) {
    header { padding: 0 1rem; }
    main { padding: 0 1rem 2rem; }

    .hero { padding: 2.5rem 0 1.5rem; }
    .hero-title { font-size: 1.75rem; }
    .nav-tagline { display: none; }

    .games-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .category-header {
        flex-direction: column;
        gap: 0.5rem;
    }

    .matchup {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .game-page-header {
        padding: 1rem;
    }

    /* Game page: let the viewer scroll naturally on mobile instead of
       forcing a fixed-height two-column layout that doesn't fit */
    .game-body {
        height: auto;
        overflow: auto;
    }
    .game-body main {
        display: flex;
        flex-direction: column;
        overflow: visible;
    }
    .game-page {
        --board-max: none;
    }
    /* Remove the !important two-column override so the viewer can
       collapse to its own single-column responsive layout */
    .game-page .lpv {
        max-height: unset;
        grid-template-columns: unset !important;
    }
}

/* ── Add game form ─────────────────────────────── */

.add-form-wrap {
    max-width: 640px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.add-form-row {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}
.add-form-row .add-form-field {
    flex: 1;
}
.add-form-field-narrow {
    flex: 0 0 120px !important;
}

.label-optional {
    color: var(--text-muted);
    font-size: 0.7rem;
    text-transform: none;
    letter-spacing: 0;
}

.admin-field-narrow {
    flex: 0 0 100px !important;
    min-width: 0 !important;
}

.add-form-field input[type="number"],
.admin-field input[type="number"] {
    -moz-appearance: textfield;
}
.add-form-field input[type="number"]::-webkit-inner-spin-button,
.add-form-field input[type="number"]::-webkit-outer-spin-button,
.admin-field input[type="number"]::-webkit-inner-spin-button,
.admin-field input[type="number"]::-webkit-outer-spin-button {
    opacity: 0.3;
}

.add-form-field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.add-form-field label {
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-mid);
}

.add-form-field input[type="text"],
.add-form-field input[type="password"],
.add-form-field input[type="number"],
.add-form-field textarea,
.add-form-field select {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.95rem;
    padding: 0.6rem 0.85rem;
    resize: vertical;
    transition: border-color 0.15s;
    width: 100%;
}

.add-form-field select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b6760' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.85rem center;
    padding-right: 2.2rem;
    cursor: pointer;
}

.add-form-field input:focus,
.add-form-field textarea:focus,
.add-form-field select:focus {
    border-color: var(--amber-dim);
    outline: none;
}

.add-form-field textarea {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
}

.remember-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0;
    cursor: pointer;
}

.add-form-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-primary {
    background: var(--amber);
    border: none;
    border-radius: var(--radius);
    color: #0e0e0e;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.6rem 1.4rem;
    transition: background 0.15s;
}

.btn-primary:hover { background: var(--amber-dim); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.status-ok    { color: #7ec99a; font-size: 0.88rem; }
.status-error { color: #e07070; font-size: 0.88rem; }

/* --- Tree add button --- */
.tree-add-btn {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0 0.3rem;
    line-height: 1;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
    text-decoration: none;
}
.tree-add-btn:hover {
    color: var(--amber);
    background: var(--amber-glow);
}

.category-add-btn {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0 0.4rem;
    border-radius: var(--radius);
    transition: color 0.15s, background 0.15s;
    line-height: 1;
    text-decoration: none;
    align-self: center;
}
.category-add-btn:hover {
    color: var(--amber);
    background: var(--amber-glow);
}

/* --- Tree count badge --- */
.tree-count {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.1rem 0.45rem;
    font-family: var(--font-body);
    flex-shrink: 0;
    margin-right: 0.25rem;
}

/* --- Player profile links (game page) --- */
.player-profile-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 0.35rem;
    vertical-align: middle;
    opacity: 0.6;
    transition: opacity 0.15s;
}
.player-profile-link:hover {
    opacity: 1;
}
.player-profile-link img {
    display: block;
}

.player-add-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0 0.25rem;
    margin-left: 0.25rem;
    border-radius: 3px;
    cursor: pointer;
    vertical-align: middle;
    line-height: 1.2;
    transition: color 0.15s, border-color 0.15s;
}
.player-add-btn:hover {
    color: var(--amber);
    border-color: var(--amber-dim);
}

/* --- Players admin page --- */
.player-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.player-form .modal-input {
    flex: 1;
    min-width: 150px;
}

.players-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.players-table th {
    text-align: left;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-muted);
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.players-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.player-name-cell {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.player-display-name {
    font-weight: 500;
}

.player-norm {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.player-link-edit {
    width: 100%;
    background: var(--bg-card);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0.25rem 0.4rem;
    font-size: 0.82rem;
    font-family: var(--font-body);
}

.player-actions {
    white-space: nowrap;
}

.player-delete-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.player-delete-btn:hover {
    color: #e07070;
    border-color: #e07070;
}

/* --- Search page --- */
.search-form {
    margin-bottom: 2rem;
}

.search-input-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    max-width: 540px;
    transition: border-color 0.15s;
}
.search-input-wrap:focus-within {
    border-color: var(--amber-dim);
}

.search-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-input-wrap input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.95rem;
}
.search-input-wrap input::placeholder {
    color: var(--text-muted);
}

.search-results-header {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.search-cat {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
