:root {
    --bg: #f4f1ea;
    --panel: #fffdf8;
    --ink: #1f2933;
    --muted: #5f6c7b;
    --line: #d7cec0;
    --accent: #1e5d4f;
    --accent-2: #b5672b;
    --danger: #8c2f39;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    color: var(--ink);
    background: linear-gradient(180deg, #efe7d8 0%, var(--bg) 45%, #f8f5ef 100%);
}
.topbar, .page-shell, .grid, .stack { display: flex; }
.topbar {
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 253, 248, 0.92);
    position: sticky;
    top: 0;
}
.page-shell {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1.25rem 4rem;
    flex-direction: column;
    gap: 1rem;
}
.brand {
    text-decoration: none;
    color: var(--ink);
    font-size: 1.3rem;
    font-weight: 700;
}
.nav-left, .nav-actions, .subnav, .inline-form { display: flex; }
.nav-left { gap: 1rem; align-items: center; }
.subnav { gap: 0.75rem; flex-wrap: wrap; align-items: center; }
.subnav a {
    text-decoration: none;
    color: var(--muted);
    font-size: 0.95rem;
}
.nav-dropdown {
    position: relative;
}
.nav-dropdown-toggle {
    color: var(--ink);
    font-size: 0.9rem;
    font-weight: 700;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 253, 248, 0.95);
    cursor: pointer;
    font-family: inherit;
}
.nav-dropdown-toggle::after {
    content: "▾";
    font-size: 0.8rem;
    color: var(--muted);
}
.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 0.35rem);
    left: 0;
    min-width: 220px;
    padding: 0.45rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: 0 14px 30px rgba(39, 45, 52, 0.12);
    z-index: 20;
}
.nav-dropdown-menu a {
    display: block;
    padding: 0.6rem 0.7rem;
    border-radius: 8px;
}
.nav-dropdown-menu a:hover,
.nav-dropdown-menu a:focus-visible {
    background: #f4efe6;
    color: var(--ink);
}
.nav-dropdown.is-open .nav-dropdown-menu {
    display: block;
}
.nav-dropdown.is-open .nav-dropdown-toggle {
    background: #f4efe6;
    border-color: #c8baa5;
}
.nav-dropdown.is-open .nav-dropdown-toggle::after {
    content: "▴";
}
.nav-actions { gap: 0.75rem; align-items: center; }
.hero { padding: 1rem 0 0.5rem; }
.hero h1,
.card h2,
.card h3 { margin-top: 0; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent-2); }
.muted { color: var(--muted); }
.grid { gap: 1rem; flex-wrap: wrap; }
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 1.25rem;
    box-shadow: 0 14px 30px rgba(39, 45, 52, 0.08);
    min-width: 280px;
    flex: 1 1 320px;
}
.auth-card {
    max-width: 420px;
    margin: 4rem auto;
}
.stack { flex-direction: column; gap: 0.9rem; }
label span { display: block; margin-bottom: 0.35rem; font-size: 0.95rem; }
input {
    width: 100%;
    padding: 0.75rem;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: white;
}
select, textarea {
    width: 100%;
    padding: 0.75rem;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: white;
    font: inherit;
}
.button {
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: white;
    padding: 0.75rem 1.1rem;
    cursor: pointer;
}
.button-secondary {
    background: white;
    color: var(--ink);
    border: 1px solid var(--line);
}
.user-pill {
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    background: #ebe5d8;
}
.alert {
    padding: 0.9rem 1rem;
    border-radius: 10px;
}
.alert-error {
    background: #f8e6e8;
    color: var(--danger);
    border: 1px solid #e5b5bb;
}
.alert-success {
    background: #e6f4ed;
    color: var(--accent);
    border: 1px solid #b8dbc7;
}
.table {
    width: 100%;
    border-collapse: collapse;
}
.table-wrap {
    overflow-x: auto;
}
.table th, .table td {
    text-align: left;
    padding: 0.65rem 0.4rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}
.compact-table th, .compact-table td {
    font-size: 0.9rem;
    white-space: nowrap;
}
.worksheet-table input,
.worksheet-table select {
    min-width: 110px;
    padding: 0.45rem 0.55rem;
    border-radius: 8px;
}
.worksheet-wrap {
    max-height: 560px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
}
.worksheet-grid-shell {
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    background: #fbf7ef;
}
.worksheet-grid-meta {
    padding: 0.8rem 0.95rem;
    border-bottom: 1px solid var(--line);
    background: #fffaf1;
}
.js-sheet {
    overflow: auto;
    max-height: 560px;
    background: #fbf7ef;
}
.js-sheet-header,
.js-sheet-row {
    display: grid;
    min-width: max-content;
}
.js-sheet-header {
    position: sticky;
    top: 0;
    z-index: 6;
}
.js-sheet-header-cell,
.js-sheet-cell {
    min-height: 42px;
    padding: 0.65rem 0.45rem;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
    font-size: 0.9rem;
    background: #fffdf8;
}
.js-sheet-header-cell {
    background: #f3ecdf;
    font: inherit;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}
.js-sheet-header-cell[data-sort-dir="asc"]::after {
    content: " ↑";
    color: var(--accent);
}
.js-sheet-header-cell[data-sort-dir="desc"]::after {
    content: " ↓";
    color: var(--accent);
}
.js-sheet-row:nth-child(even) .js-sheet-cell {
    background: #fffaf1;
}
.js-sheet-row:hover .js-sheet-cell {
    background: #f4efe6;
}
.js-sheet-row.is-selected .js-sheet-cell {
    background: #ebe5d8;
}
.js-sheet-cell.is-sticky,
.js-sheet-header-cell.is-sticky {
    position: sticky;
    z-index: 4;
    box-shadow: 1px 0 0 var(--line);
}
.js-sheet-header-cell.is-sticky {
    z-index: 7;
}
.js-sheet-row:nth-child(even) .js-sheet-cell.is-sticky {
    background: #fffaf1;
}
.js-sheet-row:hover .js-sheet-cell.is-sticky {
    background: #f4efe6;
}
.js-sheet-row.is-selected .js-sheet-cell.is-sticky {
    background: #ebe5d8;
}
.score-link {
    background: none;
    border: 0;
    color: var(--accent);
    font: inherit;
    padding: 0;
    text-decoration: underline;
    cursor: pointer;
}
.score-link:hover,
.score-link:focus-visible {
    color: var(--accent-2);
}
.js-sheet .score-link {
    text-align: left;
    padding: 0.65rem 0.45rem;
    white-space: nowrap;
}
.worksheet-table .button {
    padding: 0.5rem 0.8rem;
}
.new-row td {
    background: #f7f1e5;
}
.detail-row td {
    background: #faf6ef;
}
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 0.75rem;
}
.inset-card {
    box-shadow: none;
    background: #fffaf1;
    padding: 0.9rem;
    min-width: 0;
}
.metric {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0.2rem 0 0.45rem;
}
.settings-actions {
    display: flex;
    align-items: end;
    padding-top: 1.35rem;
}
.code-block {
    white-space: pre-wrap;
    background: #f4efe6;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.9rem;
    overflow-x: auto;
}
.checkbox {
    display: flex;
    gap: 0.6rem;
    align-items: center;
}
.checkbox input {
    width: auto;
}
.inline-form {
    gap: 0.6rem;
    margin-bottom: 1rem;
}
.split-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 1rem;
}
.status-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
}
.worksheet-totals {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem 1.2rem;
    margin-top: 0.9rem;
    padding-top: 0.9rem;
    border-top: 1px solid var(--line);
    font-size: 0.92rem;
}
.score-dialog {
    width: min(880px, calc(100vw - 2rem));
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 1.2rem;
    background: var(--panel);
    color: var(--ink);
    box-shadow: 0 24px 48px rgba(39, 45, 52, 0.18);
}
.score-dialog::backdrop {
    background: rgba(25, 30, 35, 0.4);
}
.score-dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}
.wrap { flex-wrap: wrap; }
@media (max-width: 720px) {
    .topbar, .nav-left, .nav-actions, .inline-form {
        flex-direction: column;
        align-items: flex-start;
    }
    .subnav {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }
    .nav-dropdown {
        width: 100%;
    }
    .nav-dropdown-toggle {
        width: 100%;
        justify-content: space-between;
    }
    .nav-dropdown-menu {
        position: static;
        display: none;
        margin-top: 0.35rem;
        min-width: 0;
        width: 100%;
        box-shadow: none;
    }
    .split-header {
        flex-direction: column;
    }
    .score-dialog {
        width: calc(100vw - 1rem);
        padding: 1rem;
    }
    .score-dialog-header {
        flex-direction: column;
    }
}
