:root {
    --bg: #1c1c1e;
    --surface: #2c2c2e;
    --surface-2: #3a3a3c;
    --text: #f5f5f7;
    --muted: #98989d;
    --accent: #4cc56a;
    --accent-dim: #2f7d44;
    --border: #38383a;
    --danger: #ff6b6b;
    --radius: 14px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.6;
    color: var(--text);
    background-color: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: clip;   /* guard against any horizontal drift (keeps sticky header working) */
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { width: 100%; max-width: 1000px; margin: 0 auto; padding: 0 20px; }

/* Header / nav */
.site-header {
    border-bottom: 1px solid var(--border);
    background: rgba(28, 28, 30, 0.85);
    backdrop-filter: saturate(180%) blur(12px);
    position: sticky;
    top: 0;
    z-index: 10;
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-top: 14px;
    padding-bottom: 14px;
    flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { font-size: 1.6em; }
.brand-text strong { display: block; font-size: 1.1em; font-weight: 600; letter-spacing: -0.01em; }
.brand-text em { display: block; font-style: normal; font-size: 0.8em; color: var(--muted); }
.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.nav a {
    color: var(--muted);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.95em;
}
.nav a:hover { color: var(--text); text-decoration: none; background: var(--surface); }
.nav a.active { color: var(--text); background: var(--surface); }
.nav a.nav-edit { color: var(--accent); }
.nav a.nav-edit.active { background: var(--accent-dim); color: #fff; }

/* Main */
main.wrap { flex: 1; padding-top: 32px; padding-bottom: 48px; }

h1 { font-size: 2.4em; font-weight: 600; letter-spacing: -0.02em; margin-bottom: 0.3em; }
h2 { font-size: 1.5em; font-weight: 600; margin: 1.4em 0 0.6em; }
h3 { font-size: 1.15em; font-weight: 600; margin-bottom: 0.2em; }
p { color: #d6d6db; }
.muted { color: var(--muted); }
.lead { font-size: 1.15em; color: var(--muted); margin-bottom: 1.5em; }

/* Hero */
.hero {
    padding: 28px 0 8px;
}
.hero h1 { font-size: 3em; }

/* Cards / grid */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
}
.card .eyebrow { color: var(--accent); font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.06em; }

/* Player cards */
.players { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.player {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    text-align: center;
}
.player .avatar {
    width: 84px; height: 84px; border-radius: 50%;
    margin: 0 auto 12px; object-fit: cover;
    background: var(--surface-2);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.8em; color: var(--muted);
    border: 2px solid var(--accent-dim);
}
.player .avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
img.flip { transform: scaleX(-1); }
.player .pname { font-weight: 600; }
.player .pmeta { color: var(--muted); font-size: 0.9em; }
.rounds { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.round-chip {
    border: 1px solid var(--border); border-radius: 999px;
    padding: 2px 10px; font-size: 0.76em; color: var(--muted); cursor: default;
}
.round-chip strong { color: var(--text); }
.round-chip.up { background: rgba(76, 197, 106, 0.12); border-color: rgba(76, 197, 106, 0.35); color: #bdebc9; }
.round-chip.up strong { color: #fff; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.96em; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 0.82em; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8em; font-weight: 600; }
.badge.win { background: var(--accent-dim); color: #eafff0; }
.badge.loss { background: #5a2a2a; color: #ffe3e3; }
.badge.upcoming { background: var(--surface-2); color: var(--muted); }
.badge.home { background: #2a3a5a; color: #dbe7ff; }
.badge.away { background: var(--surface-2); color: var(--muted); }

/* News */
.post { border-bottom: 1px solid var(--border); padding: 20px 0; }
.post:last-child { border-bottom: none; }
.post .date { color: var(--muted); font-size: 0.85em; }

/* Buttons / forms */
.btn {
    display: inline-block; cursor: pointer;
    background: var(--accent); color: #04210d; border: none;
    padding: 9px 18px; border-radius: 10px; font-size: 0.95em; font-weight: 600;
    font-family: inherit;
}
.btn:hover { text-decoration: none; filter: brightness(1.07); }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid #5a2a2a; padding: 6px 12px; font-size: 0.85em; }
.btn.small { padding: 6px 12px; font-size: 0.85em; }

form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
label { display: block; font-size: 0.85em; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
    width: 100%; font-family: inherit; font-size: 0.95em;
    background: var(--bg); color: var(--text);
    border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
.field { margin-bottom: 12px; }

.panel {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 22px; margin-bottom: 24px;
}
.panel h2 { margin-top: 0; }

.notice {
    background: var(--accent-dim); color: #eafff0;
    padding: 12px 16px; border-radius: 10px; margin-bottom: 20px;
}
.empty { color: var(--muted); padding: 24px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

.inline-form { display: inline; }
.row-actions { white-space: nowrap; text-align: right; }

/* Weekly schedule / lineup editor */
.week-row {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 12px;
    background: var(--bg);
}
.week-head { overflow: hidden; }
.week-row details { margin-top: 8px; }
.week-row summary {
    cursor: pointer; color: var(--accent); font-size: 0.9em;
    list-style: none;
}
.week-row summary::-webkit-details-marker { display: none; }
.lineup-form { margin-top: 12px; }
.checkgrid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 6px 14px; margin: 8px 0 12px;
}
.check {
    display: flex; align-items: center; gap: 8px;
    color: var(--text); font-size: 0.95em; margin: 0; cursor: pointer;
}
.check input { width: auto; }

/* Lineup picker grouped by role */
.lineup-group { margin-bottom: 10px; }
.lineup-group-title {
    font-size: 0.74em; font-weight: 700; color: var(--muted);
    text-transform: uppercase; letter-spacing: 0.06em;
    margin: 8px 0 4px;
}
.lineup-group .checkgrid { margin: 0 0 4px; }

/* Per-player In/Out toggle */
.picklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 7px 16px; margin: 6px 0 10px; }
.pick { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pick-name { font-size: 0.92em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex: none; }
.seg-opt { cursor: pointer; }
.seg-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg-opt span { display: block; padding: 5px 13px; font-size: 0.8em; color: var(--muted); user-select: none; }
.seg-opt + .seg-opt span { border-left: 1px solid var(--border); }
.seg-in:has(input:checked) span { background: var(--accent-dim); color: #eafff0; }
.seg-out:has(input:checked) span { background: #5a2a2a; color: #ffe3e3; }

/* Page header with an in-context add/edit control */
.page-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 14px; flex-wrap: wrap; margin-bottom: 6px;
}
.page-head h1 { margin-bottom: 0; }

/* <summary> styled as a button */
.add-box { position: relative; }
.add-box > summary {
    list-style: none; cursor: pointer; display: inline-block;
    -webkit-appearance: none;
}
.add-box > summary::-webkit-details-marker { display: none; }
.add-box[open] > summary { filter: brightness(0.92); }
.add-box[open] { flex-basis: 100%; }   /* revealed form spans the full row */
.add-form { margin-top: 14px; width: 100%; }

/* Action controls on a player card */
.player { position: relative; }
.card-actions {
    display: flex; gap: 8px; justify-content: center;
    margin-top: 14px;
}

/* Modal dialog (edit player) */
dialog.modal {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius);
    padding: 0;
    width: min(460px, calc(100vw - 32px));
    max-height: 90vh;
    overflow: auto;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.6); }
.modal-form { padding: 22px; }
/* Invisible guard that takes initial focus so inputs (esp. date pickers) don't auto-open */
.dialog-autofocus { position: absolute; width: 0; height: 0; padding: 0; margin: 0; border: 0; opacity: 0; pointer-events: none; }
.modal-form h3 { margin: 0 0 14px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.photo-current { display: flex; align-items: center; gap: 12px; }
.photo-current img {
    width: 56px; height: 56px; border-radius: 50%; object-fit: cover;
    border: 2px solid var(--accent-dim);
}
.photo-current .check { margin: 0; }

/* Weather forecast snippet */
.wx { font-size: 0.85em; white-space: nowrap; color: #d6d6db; }
.wx-ico { margin-right: 3px; }
.wx-precip { color: #6db3ff; margin-left: 5px; }

/* Share control */
.share-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 2px 0 20px; }
.week-actions { display: flex; gap: 6px; flex: none; }
.toast {
    position: fixed; left: 50%; bottom: 84px;
    transform: translateX(-50%) translateY(10px);
    background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 10px;
    padding: 10px 16px; font-size: 0.9em;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
    opacity: 0; transition: opacity 0.25s, transform 0.25s; z-index: 100;
    max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Schedule as a card list */
.section-head { font-size: 1.2em; margin: 26px 0 12px; }
.section-head-past { color: var(--muted); }
.weeks { display: flex; flex-direction: column; gap: 10px; }
.weeks-past .week { opacity: 0.72; }
.weeks-past .week:hover { opacity: 1; }
.week {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 13px 16px;
}
.week-short { border-left: 3px solid #ff9f43; }
.week-over { border-left: 3px solid #8a7dff; }
.week-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.week-when { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; min-width: 0; }
.week-date { font-weight: 600; }
.week-format { color: var(--muted); font-size: 0.9em; }
.icon-btn {
    flex: none; cursor: pointer;
    width: 36px; height: 36px; line-height: 1;
    background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 9px;
    font-size: 1.05em;
}
.icon-btn:hover { filter: brightness(1.12); }

.lineup-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px; }
.chip {
    background: var(--surface-2); color: var(--text);
    border: 1px solid transparent; border-radius: 999px;
    padding: 3px 11px; font-size: 0.85em; white-space: nowrap;
}
.chip-sub { background: transparent; border-color: var(--border); color: var(--muted); font-style: italic; }
button.chip { cursor: pointer; font-family: inherit; -webkit-appearance: none; appearance: none; }
button.chip:hover { filter: brightness(1.14); }

/* Read-only player info popup */
.pi-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.pi-head .avatar {
    width: 64px; height: 64px; border-radius: 50%; flex: none; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface-2); color: var(--muted); font-size: 1.5em;
    border: 2px solid var(--accent-dim);
}
.pi-head .avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.pi-head h3 { margin: 0; }
.pi-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.pi-row {
    display: flex; align-items: center; gap: 10px;
    color: var(--text); text-decoration: none;
    padding: 9px 12px; background: var(--bg);
    border: 1px solid var(--border); border-radius: 10px;
}
a.pi-row:hover { border-color: var(--accent); text-decoration: none; }
.pi-row span { font-size: 1.1em; }
.pi-row .pi-num { font-size: 1em; }
.pi-row .contact-actions { margin-left: auto; }

/* Call / Text action pair */
.contact-actions { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.contact-actions a {
    background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 999px;
    padding: 4px 12px; font-size: 0.82em; text-decoration: none; white-space: nowrap;
}
.contact-actions a:hover { border-color: var(--accent); text-decoration: none; filter: brightness(1.1); }
.player .contact-actions { justify-content: center; margin-top: 6px; }
.chip-warn {
    background: rgba(255, 159, 67, 0.14); border-color: rgba(255, 159, 67, 0.4);
    color: #ffcc66; font-weight: 700;
}
.chip-over {
    background: rgba(138, 125, 255, 0.16); border-color: rgba(138, 125, 255, 0.45);
    color: #c4bcff; font-weight: 700;
}
.chip-out { background: transparent; border-color: var(--border); color: var(--muted); text-decoration: line-through; }

/* "Out" row under a week's lineup */
.lineup-out { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.out-label { font-size: 0.74em; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.modal-remove { padding: 0 22px 20px; }

/* Footer */
.site-footer {
    border-top: 1px solid var(--border);
    color: var(--muted);
    padding: 20px 0;
    font-size: 0.9em;
}
.site-footer .dot { margin: 0 8px; }

/* Mobile bottom tab bar (shown only on small screens) */
.tabbar { display: none; }

@media (max-width: 600px) {
    h1, .hero h1 { font-size: 2em; }
    .header-inner { gap: 10px; }

    /* Stack form fields cleanly inside modals on phones */
    .modal-form .row { grid-template-columns: 1fr; }

    /* Swap the top link row for a thumb-friendly bottom tab bar */
    .site-header .nav { display: none; }

    .tabbar {
        display: flex;
        position: fixed; left: 0; right: 0; bottom: 0;
        z-index: 50;
        background: rgba(28, 28, 30, 0.97);
        backdrop-filter: saturate(180%) blur(12px);
        border-top: 1px solid var(--border);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .tab {
        flex: 1; min-width: 0;
        display: flex; flex-direction: column; align-items: center; justify-content: center;
        gap: 3px; padding: 8px 2px 7px;
        color: var(--muted); font-size: 0.66rem; font-weight: 500;
        text-decoration: none;
    }
    .tab:hover { text-decoration: none; }
    .tab-ico { font-size: 1.3rem; line-height: 1; }
    .tab.active { color: var(--accent); }

    /* Keep content clear of the fixed bar */
    main.wrap { padding-bottom: 78px; }
    .site-footer { margin-bottom: 58px; }
}
