:root {
    --bg:           #111318;
    --surface:      #181c26;
    --surface2:     #1e2330;
    --border:       #28304a;
    --rule:         #303c58;
    --gold:         #c8901a;
    --gold-hover:   #daa02a;
    --gold-dim:     #6a4a0a;
    --ink:          #d8ceb0;
    --ink-muted:    #706a54;
    --ink-dim:      #3a3830;
    --serif:        'Special Elite', 'Courier New', monospace;
    --mono:         'JetBrains Mono', 'Courier New', monospace;
}

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

body {
    font-family: var(--serif);
    font-size: 16px;
    background: var(--bg);
    color: var(--ink);
    max-width: 1320px;
    margin: 0 auto;
    padding: 32px 24px;
    min-height: 100vh;
    /* very faint paper grain */
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(30,40,70,0.4) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 20%, rgba(20,28,55,0.3) 0%, transparent 50%);
}

/* ── Masthead ── */
.masthead {
    text-align: center;
    margin-bottom: 36px;
}
.masthead-rule {
    border: none;
    border-top: 3px double var(--rule);
    margin: 10px 0;
}
.masthead-rule.thin {
    border-top: 1px solid var(--rule);
}
.masthead-eyebrow {
    font-family: var(--serif);
    font-size: 13px;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    color: var(--ink-muted);
    margin: 8px 0;
}
.masthead h1 {
    font-family: var(--serif);
    font-size: 42px;
    font-weight: 400;
    color: var(--ink);
    letter-spacing: 3px;
    text-transform: uppercase;
    line-height: 1.1;
    margin: 6px 0;
    text-shadow: 0 0 40px rgba(200, 144, 26, 0.15);
}
.masthead-sub {
    font-family: var(--serif);
    font-size: 13px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--gold);
    margin: 8px 0;
}

/* ── Nav ── */
.masthead-nav {
    margin-top: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    font-family: var(--serif);
    font-size: 13px;
    letter-spacing: 2px;
    text-transform: uppercase;
}
.nav-link {
    color: var(--ink-muted);
    text-decoration: none;
    padding-bottom: 1px;
    border-bottom: 1px dashed transparent;
    transition: color 0.15s, border-color 0.15s;
}
.nav-link:hover { color: var(--gold); border-color: var(--gold); }
.nav-link.active { color: var(--gold); border-bottom: 1px solid var(--gold); }
.nav-sep { color: var(--ink-dim); }

/* ── Nav dropdown ── */
.nav-dropdown {
    position: relative;
}
.nav-dropdown-trigger {
    color: var(--ink-muted);
    font-family: var(--serif);
    font-size: 13px;
    letter-spacing: 2px;
    text-transform: uppercase;
    padding-bottom: 1px;
    border-bottom: 1px dashed transparent;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    user-select: none;
}
.nav-dropdown-trigger:hover,
.nav-dropdown:focus-within .nav-dropdown-trigger { color: var(--gold); border-color: var(--gold); }
.nav-dropdown-trigger.active { color: var(--gold); border-bottom: 1px solid var(--gold); }
.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding-top: 10px;
    background: transparent;
    min-width: 130px;
    z-index: 100;
    flex-direction: column;
}
.nav-dropdown-menu::before {
    content: '';
    display: block;
    position: absolute;
    top: 10px;
    left: 0; right: 0; bottom: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    z-index: -1;
}
.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu,
.nav-dropdown-menu.dd-open { display: flex; }
.nav-dropdown-item {
    font-family: var(--serif);
    font-size: 12px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--ink-muted);
    text-decoration: none;
    padding: 9px 16px;
    border-bottom: 1px solid var(--surface2);
    transition: color 0.15s, background 0.15s;
    white-space: nowrap;
}
.nav-dropdown-item:last-child { border-bottom: none; }
.nav-dropdown-item:hover { color: var(--gold); background: var(--surface2); }
.nav-dropdown-item.active { color: var(--gold); }
/* Right-aligned dropdown (More menu) */
.nav-dd-right {
    left: auto;
    right: 0;
    transform: none;
}

/* ── Cards ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1px;
    padding: 20px 24px;
    margin-bottom: 14px;
    position: relative;
    background-image: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 3px,
        rgba(255,255,255,0.007) 3px,
        rgba(255,255,255,0.007) 4px
    );
}

.wire-label {
    font-family: var(--serif);
    font-size: 13px;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--gold);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.wire-label::before,
.wire-label::after {
    content: '';
    flex: 1;
    border-top: 1px solid var(--border);
}

/* ── Ask section ── */
.ask-section { border-left: 3px solid var(--gold); }

.ask-input {
    width: 100%;
    padding: 12px 14px;
    font-family: var(--serif);
    font-size: 16px;
    background: var(--surface2);
    color: var(--ink);
    border: 1px solid var(--border);
    border-radius: 1px;
    outline: none;
    transition: border-color 0.15s;
}
.ask-input::placeholder { color: var(--ink-dim); }
.ask-input:focus { border-color: var(--gold); }

.ask-examples {
    margin-top: 12px;
    font-family: var(--serif);
    font-size: 14px;
    color: var(--ink-dim);
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 0;
    line-height: 2.2;
}
.ask-examples .label {
    color: var(--ink-muted);
    margin-right: 10px;
    font-size: 13px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}
.ask-examples span {
    cursor: pointer;
    color: var(--ink-muted);
    margin-right: 16px;
    border-bottom: 1px dashed var(--ink-dim);
    padding-bottom: 1px;
    transition: color 0.15s, border-color 0.15s;
}
.ask-examples span:hover { color: var(--gold); border-color: var(--gold); }

.btn-ask {
    background: var(--gold);
    color: #111318;
    border: none;
    padding: 10px 24px;
    border-radius: 1px;
    font-family: var(--serif);
    font-size: 15px;
    letter-spacing: 2px;
    text-transform: uppercase;
    cursor: pointer;
    margin-top: 14px;
    transition: background 0.15s;
}
.btn-ask:hover { background: var(--gold-hover); }
.btn-ask:disabled { background: var(--ink-dim); cursor: not-allowed; }

.generated-sql {
    background: var(--bg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--gold-dim);
    border-radius: 1px;
    padding: 14px 18px;
    margin-top: 18px;
}
.generated-sql h4 {
    font-family: var(--serif);
    font-size: 10px;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--gold);
    margin-bottom: 10px;
}
.generated-sql pre {
    font-family: var(--mono);
    font-size: 14px;
    color: var(--ink-muted);
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.7;
}

/* ── SQL textarea ── */
textarea {
    width: 100%;
    height: 110px;
    font-family: var(--mono);
    font-size: 14px;
    padding: 12px 14px;
    background: var(--bg);
    color: var(--ink-muted);
    border: 1px solid var(--border);
    border-radius: 1px;
    resize: vertical;
    outline: none;
    transition: border-color 0.15s;
    line-height: 1.7;
}
textarea::placeholder { color: var(--ink-dim); }
textarea:focus { border-color: var(--gold); }

button {
    background: transparent;
    color: var(--ink-muted);
    border: 1px solid var(--border);
    padding: 9px 22px;
    border-radius: 1px;
    font-family: var(--serif);
    font-size: 14px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    cursor: pointer;
    margin-top: 12px;
    transition: border-color 0.15s, color 0.15s;
}
button:hover { border-color: var(--gold); color: var(--gold); }

/* ── Details/summary ── */
details { margin-top: 4px; }
summary {
    cursor: pointer;
    color: var(--ink-muted);
    font-family: var(--serif);
    font-size: 14px;
    letter-spacing: 2px;
    text-transform: uppercase;
    padding: 6px 0;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
}
summary::-webkit-details-marker { display: none; }
summary::before {
    content: '▶';
    font-size: 8px;
    color: var(--ink-dim);
    transition: transform 0.15s;
}
details[open] summary::before { transform: rotate(90deg); }
summary:hover { color: var(--ink); }

/* ── SQL examples ── */
.examples {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 1px;
    padding: 16px;
    margin-top: 12px;
}
.examples h3 {
    font-family: var(--serif);
    font-size: 10px;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    color: var(--ink-muted);
    margin-bottom: 12px;
}
.example {
    font-family: var(--mono);
    font-size: 13px;
    color: var(--ink-muted);
    background: var(--surface);
    padding: 8px 12px;
    margin: 6px 0;
    border-radius: 1px;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: border-color 0.15s, color 0.15s;
    line-height: 1.6;
}
.example:hover { border-color: var(--gold); color: var(--ink); }

/* ── Alerts ── */
.error {
    background: rgba(160, 40, 40, 0.1);
    color: #c07070;
    padding: 12px 16px;
    border-left: 3px solid #803030;
    border-right: 1px solid rgba(160,40,40,0.2);
    border-top: 1px solid rgba(160,40,40,0.2);
    border-bottom: 1px solid rgba(160,40,40,0.2);
    border-radius: 1px;
    margin-bottom: 14px;
    font-family: var(--serif);
    font-size: 13px;
}
.error::before { content: '⚠  '; }

.warning {
    background: rgba(160, 110, 0, 0.08);
    color: #a07830;
    padding: 12px 16px;
    border-left: 3px solid var(--gold-dim);
    border-right: 1px solid rgba(160,110,0,0.15);
    border-top: 1px solid rgba(160,110,0,0.15);
    border-bottom: 1px solid rgba(160,110,0,0.15);
    border-radius: 1px;
    margin-bottom: 14px;
    font-family: var(--serif);
    font-size: 13px;
}

/* ── Player suggestions ── */
.suggestions-card { border-left: 3px solid var(--gold); }
.suggestions-card p {
    font-family: var(--serif);
    color: var(--ink-muted);
    font-size: 13px;
    margin-bottom: 14px;
}
.player-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.player-btn {
    background: transparent;
    color: var(--ink-muted);
    border: 1px solid var(--border);
    padding: 6px 16px;
    border-radius: 1px;
    font-family: var(--serif);
    font-size: 14px;
    letter-spacing: 0.5px;
    cursor: pointer;
    margin: 0;
    transition: border-color 0.15s, color 0.15s;
}
.player-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ── Chart ── */
.chart-card h3 {
    font-family: var(--serif);
    font-size: 13px;
    font-weight: 400;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--ink-muted);
    margin-bottom: 18px;
}
.chart-wrapper { position: relative; max-height: 420px; }

/* ── Table filter ── */
.table-filter {
    padding: 10px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}
.filter-input {
    width: 100%;
    padding: 7px 12px;
    font-family: var(--mono);
    font-size: 14px;
    background: var(--surface2);
    color: var(--ink);
    border: 1px solid var(--border);
    border-radius: 1px;
    outline: none;
    transition: border-color 0.15s;
}
.filter-input::placeholder { color: var(--ink-dim); }
.filter-input:focus { border-color: var(--gold); }

/* ── Sortable headers ── */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th.sort-asc::after  { content: ' ▲'; color: var(--gold); font-size: 9px; }
th.sort-desc::after { content: ' ▼'; color: var(--gold); font-size: 9px; }

/* ── Results table ── */
.results { overflow: hidden; margin-top: 4px; }
.results-header {
    padding: 10px 18px;
    background: var(--bg);
    border-bottom: 2px solid var(--border);
    font-family: var(--serif);
    font-size: 13px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--ink-muted);
    display: flex;
    align-items: center;
    gap: 12px;
}
.results-header::before,
.results-header::after {
    content: '───';
    color: var(--ink-dim);
    letter-spacing: -1px;
}
.results-header strong { color: var(--gold); }
.btn-csv {
    margin-top: 0;
    margin-left: auto;
    padding: 4px 14px;
    font-size: 10px;
}

.table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
th {
    background: var(--bg);
    padding: 10px 16px;
    text-align: left;
    font-family: var(--serif);
    font-weight: 400;
    font-size: 13px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--ink-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
td {
    padding: 9px 16px;
    border-bottom: 1px solid rgba(40, 48, 74, 0.7);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ink);
    font-family: var(--mono);
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}
tr:hover td { background: var(--surface2); }
tr:nth-child(even) td { background: rgba(255,255,255,0.01); }
tr:nth-child(even):hover td { background: var(--surface2); }
tr.league-avg-row td {
    border-top: 2px solid rgba(200,144,26,0.4);
    color: var(--gold);
    font-style: italic;
    background: rgba(200,144,26,0.05);
}
tr.league-avg-row:hover td { background: rgba(200,144,26,0.1); }

/* ── Spinner ── */
.spinner {
    display: none;
    margin-left: 12px;
    font-family: var(--serif);
    font-size: 12px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--ink-dim);
}

/* ── Mobile responsive ── */
@media (max-width: 640px) {
    body {
        padding: 16px 14px;
    }

    .masthead {
        margin-bottom: 20px;
    }
    .masthead h1 {
        font-size: 26px;
        letter-spacing: 1px;
    }
    .masthead-eyebrow {
        font-size: 9px;
        letter-spacing: 1px;
    }
    .masthead-sub {
        font-size: 9px;
        letter-spacing: 1px;
    }

    /* Nav wraps on small screens — no horizontal scroll needed with condensed items */
    .masthead-nav {
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px;
        row-gap: 6px;
    }

    .card {
        padding: 14px 14px;
    }

    .ask-input,
    .filter-input {
        font-size: 16px; /* prevents iOS auto-zoom on focus */
    }

    .ask-examples {
        font-size: 11px;
        line-height: 2;
    }
    .ask-examples span {
        margin-right: 10px;
    }

    .btn-ask {
        display: block;
        width: 100%;
        text-align: center;
        padding: 12px;
        margin-top: 12px;
    }

    .results-header {
        flex-wrap: wrap;
        gap: 4px;
        padding: 10px 12px;
    }
    .results-header::before,
    .results-header::after {
        display: none;
    }
    .btn-csv {
        margin-left: 0;
    }

    th {
        padding: 8px 10px;
    }
    td {
        padding: 8px 10px;
        max-width: 180px;
    }

    .example {
        font-size: 10px;
        word-break: break-all;
    }

    .chart-wrapper {
        max-height: 280px;
    }

    /* team-totals bar wraps on narrow screens */
    .team-totals {
        flex-wrap: wrap;
    }
    .totals-group {
        min-width: 140px;
    }
}

/* ═══════════════════════════════════════════════════════════
   LIGHT MODE — Newspaper theme
   ═══════════════════════════════════════════════════════════ */

[data-theme="light"] {
    --bg:          #ede8dc;
    --surface:     #e5dfd2;
    --surface2:    #dbd4c6;
    --border:      #bfb49a;
    --rule:        #afa390;
    --gold:        #2e5c28;   /* forest green */
    --gold-hover:  #3a7032;
    --gold-dim:    #6a9e62;
    --ink:         #16130c;
    --ink-muted:   #38342a;
    --ink-dim:     #8a7e6a;
}

[data-theme="light"] body {
    background-color: var(--bg);
    /* Two noise layers: fine grain + large blotchy crinkle variation */
    background-image:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.68' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='250' height='250' filter='url(%23g)' opacity='0.06'/%3E%3C/svg%3E"),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='600' height='600'%3E%3Cfilter id='b'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.11' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='600' height='600' filter='url(%23b)' opacity='0.045'/%3E%3C/svg%3E"),
        radial-gradient(ellipse at 18% 82%, rgba(140,110,60,0.09) 0%, transparent 55%),
        radial-gradient(ellipse at 82% 12%, rgba(160,130,70,0.07) 0%, transparent 48%),
        radial-gradient(ellipse at 48% 55%, rgba(120,100,50,0.04) 0%, transparent 65%);
}

[data-theme="light"] .card {
    background: var(--surface);
    /* Subtle grain on cards too, no lines */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='150' height='150'%3E%3Cfilter id='c'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.72' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='150' height='150' filter='url(%23c)' opacity='0.035'/%3E%3C/svg%3E");
}

/* Burnt orange on masthead sub, wire-labels, and transmit button text */
[data-theme="light"] .masthead-sub  { color: #bf5214; }
[data-theme="light"] .wire-label    { color: #bf5214; }
[data-theme="light"] .btn-ask       { color: var(--bg); }
[data-theme="light"] .wire-label::before,
[data-theme="light"] .wire-label::after { border-color: var(--border); }

/* Inputs */
[data-theme="light"] .ask-input,
[data-theme="light"] .filter-input,
[data-theme="light"] textarea {
    background: var(--bg);
    color: var(--ink);
    border-color: var(--border);
}

/* Generated SQL */
[data-theme="light"] .generated-sql {
    background: var(--surface2);
}
[data-theme="light"] .generated-sql pre { color: var(--ink-muted); }

/* Examples */
[data-theme="light"] .examples { background: var(--surface2); }
[data-theme="light"] .example  { background: var(--surface); }

/* Tables */
[data-theme="light"] th { background: var(--surface2); }
[data-theme="light"] tr:nth-child(even) td { background: rgba(0,0,0,0.018); }
[data-theme="light"] tr:nth-child(even):hover td { background: var(--surface2); }
[data-theme="light"] tr:hover td { background: var(--surface2); }
[data-theme="light"] .results { background: var(--surface); }
[data-theme="light"] .results-header { background: var(--surface2); }
[data-theme="light"] .table-filter { background: var(--surface2); }

/* Table filter input */
[data-theme="light"] .filter-input { background: var(--surface); }

/* League avg row */
[data-theme="light"] tr.league-avg-row td {
    background: rgba(122,78,8,0.05);
    color: var(--gold);
}
[data-theme="light"] tr.league-avg-row:hover td { background: rgba(122,78,8,0.1); }

/* Fantasy row-on-team */
[data-theme="light"] tr.row-on-team td { background: #e4dac8; }
[data-theme="light"] tr.row-on-team td:first-child { border-left-color: var(--gold); }
[data-theme="light"] tr.row-on-team:hover td { background: #d8cdb8; }
[data-theme="light"] tr.row-on-team .player-name { color: var(--gold); }

/* Stat colors */
[data-theme="light"] .stat-hi  { color: #2e5c28; }
[data-theme="light"] .stat-bad { color: #7a2010; }
[data-theme="light"] .move-pos { color: #2e5c28; }
[data-theme="light"] .move-neg { color: #7a2010; }

/* Error / warning */
[data-theme="light"] .error {
    background: rgba(160,40,40,0.06);
    color: #6a1a1a;
    border-left-color: #903030;
}
[data-theme="light"] .warning {
    background: rgba(130,80,0,0.07);
    color: #5a3800;
    border-left-color: var(--gold-dim);
}

/* Nav dropdown */
[data-theme="light"] .nav-dropdown-menu::before {
    background: var(--surface);
    border-color: var(--border);
}
[data-theme="light"] .nav-dropdown-item { border-bottom-color: var(--surface2); }
[data-theme="light"] .nav-dropdown-item:hover { background: var(--surface2); }

/* Live page badges */
[data-theme="light"] .badge-live {
    background: rgba(122,78,8,0.1);
    color: var(--gold);
    border-color: var(--gold-dim);
}
[data-theme="light"] .badge-final {
    background: rgba(0,0,0,0.05);
    color: var(--ink-muted);
    border-color: var(--border);
}
[data-theme="light"] .badge-preview {
    background: transparent;
    color: var(--ink-dim);
    border-color: var(--border);
}

/* Live page pitch code badge */
[data-theme="light"] .pitch-code-badge {
    background: rgba(122,78,8,0.08);
    border-color: var(--gold-dim);
    color: var(--gold);
}

/* Game page pitch mix */
[data-theme="light"] .pitch-mix-pitcher { background: var(--surface2); border-color: var(--border); }
[data-theme="light"] .pitch-pill { background: var(--surface); border-color: var(--border); }

/* Fantasy team totals */
[data-theme="light"] .team-totals { border-color: var(--border); }
[data-theme="light"] .totals-group { border-right-color: var(--border); }

/* Selects (year selector, team selector, filter dropdowns) */
[data-theme="light"] select {
    background-color: var(--surface);
    color: var(--ink);
    border-color: var(--border);
}

/* ── Theme toggle button ── */
.theme-toggle {
    background: none;
    border: none;
    padding: 0 0 1px;
    margin: 0;
    color: var(--ink-muted);
    font-family: var(--serif);
    font-size: 13px;
    letter-spacing: 2px;
    text-transform: uppercase;
    cursor: pointer;
    border-bottom: 1px dashed transparent;
    transition: color 0.15s, border-color 0.15s;
    line-height: 1;
}
.theme-toggle:hover { color: var(--gold); border-color: var(--gold); }
