/* Team stats web app. Tokens first, then layout, components, pages. */

:root {
    color-scheme: light;
    --bg: #f2f4f8;
    --surface: #ffffff;
    --surface-2: #f6f7fa;
    --surface-3: #e9edf3;
    --text: #131a26;
    --text-2: #5b6676;
    --border: #dfe4ec;
    --accent: #2f55d4;
    --accent-ink: #ffffff;
    --accent-soft: #e6ecfd;
    --them: #8a94a6;
    --win: #12805c;
    --win-soft: #dcf5ea;
    --loss: #c93838;
    --loss-soft: #fbe3e3;
    --otl: #a8660a;
    --otl-soft: #fdefd3;
    --gold: #9a6b00;
    --gold-soft: #fbedc2;
    --shadow: 0 1px 2px rgba(19, 26, 38, 0.06), 0 2px 8px rgba(19, 26, 38, 0.04);
    --radius: 12px;
    --radius-sm: 8px;
    --header-h: 56px;
    --tabbar-h: 60px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    /* Legacy names still used by a few admin fragments. */
    --primary-color: var(--accent);
    --secondary-color: var(--them);
    --success-color: var(--win);
    --danger-color: var(--loss);
    --warning-color: var(--otl);
    --text-secondary: var(--text-2);
    --text-primary: var(--text);
    --border-color: var(--border);
    --bg-color: var(--surface-2);
    --card-bg: var(--surface);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #0c111a;
        --surface: #151c28;
        --surface-2: #1b2433;
        --surface-3: #263143;
        --text: #e8ecf3;
        --text-2: #98a3b5;
        --border: #2a3547;
        --accent: #7c9bff;
        --accent-ink: #0c111a;
        --accent-soft: #1d2a4d;
        --them: #7a8496;
        --win: #4ad09b;
        --win-soft: #123627;
        --loss: #ff7b7b;
        --loss-soft: #431c1f;
        --otl: #f0b34a;
        --otl-soft: #3d2d0f;
        --gold: #f2c94c;
        --gold-soft: #3b3112;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0c111a;
    --surface: #151c28;
    --surface-2: #1b2433;
    --surface-3: #263143;
    --text: #e8ecf3;
    --text-2: #98a3b5;
    --border: #2a3547;
    --accent: #7c9bff;
    --accent-ink: #0c111a;
    --accent-soft: #1d2a4d;
    --them: #7a8496;
    --win: #4ad09b;
    --win-soft: #123627;
    --loss: #ff7b7b;
    --loss-soft: #431c1f;
    --otl: #f0b34a;
    --otl-soft: #3d2d0f;
    --gold: #f2c94c;
    --gold-soft: #3b3112;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
}

h1, h2, h3, h4, p {
    margin: 0;
}

h1 { font-size: 1.5rem; line-height: 1.2; }
h2 { font-size: 1.125rem; line-height: 1.3; }
h3 { font-size: 1rem; line-height: 1.3; }
h4 { font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-2); font-weight: 600; }

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

a:hover {
    text-decoration: underline;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

code, pre {
    font-family: var(--mono);
    font-size: 0.8125rem;
}

pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

[hidden] {
    display: none !important;
}

.num, td.num, th.num {
    font-variant-numeric: tabular-nums;
}

.muted, .text-muted { color: var(--text-2); }
.small, .text-sm { font-size: 0.8125rem; }
.pos { color: var(--win); }
.neg { color: var(--loss); }
.flex { display: flex; }
.gap-2 { gap: 0.5rem; }
.gap-4 { gap: 1rem; }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; align-items: center; }
.stack > * + * { margin-top: 1rem; }
.stack-sm > * + * { margin-top: 0.5rem; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------------------------------------------------------------- shell */
.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.app-header-inner {
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 16px;
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.0625rem;
    color: var(--text);
    white-space: nowrap;
}

.brand:hover { text-decoration: none; }

.brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    flex: none;
}

.main-nav {
    display: flex;
    gap: 0.25rem;
    flex: 1;
    min-width: 0;
}

.main-nav a,
.menu > summary {
    padding: 0.4rem 0.7rem;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-weight: 600;
    font-size: 0.9375rem;
    white-space: nowrap;
}

.main-nav a:hover,
.menu > summary:hover {
    background: var(--surface-2);
    color: var(--text);
    text-decoration: none;
}

.main-nav a[aria-current="page"] {
    color: var(--accent);
    background: var(--accent-soft);
}

.header-tools {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: auto;
}

.menu {
    position: relative;
}

.menu > summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    user-select: none;
}

.menu > summary::-webkit-details-marker { display: none; }

.menu > summary::after {
    content: "";
    width: 0.4rem;
    height: 0.4rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
}

.menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 220px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
    padding: 0.4rem;
    display: grid;
    z-index: 40;
}

.menu-panel a,
.menu-panel button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.55rem 0.7rem;
    border: 0;
    background: none;
    font: inherit;
    color: var(--text);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.menu-panel a:hover,
.menu-panel button:hover {
    background: var(--surface-2);
    text-decoration: none;
}

.menu-panel a[aria-current="page"] { color: var(--accent); font-weight: 600; }

.menu-label {
    padding: 0.5rem 0.7rem 0.2rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-2);
}

.menu-sep {
    height: 1px;
    background: var(--border);
    margin: 0.3rem 0;
}

.only-phone { display: none; }

main {
    display: block;
}

.container {
    max-width: 1120px;
    margin: 0 auto;
    padding: 20px 16px 48px;
}

.container > * + * {
    margin-top: 16px;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    flex-wrap: wrap;
}

.page-head .sub {
    color: var(--text-2);
    font-size: 0.9375rem;
}

.crumbs {
    font-size: 0.875rem;
    color: var(--text-2);
}

.tabbar {
    display: none;
}

@media (max-width: 760px) {
    .main-nav { display: none; }
    .only-phone { display: block; }
    .hide-phone { display: none !important; }

    body.has-tabbar {
        padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    }

    .tabbar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 30;
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: 1fr;
        height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--surface);
        border-top: 1px solid var(--border);
    }

    .tabbar a {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        font-size: 0.6875rem;
        font-weight: 600;
        color: var(--text-2);
    }

    .tabbar a:hover { text-decoration: none; }
    .tabbar a[aria-current="page"] { color: var(--accent); }

    .tabbar svg {
        width: 22px;
        height: 22px;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.8;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .container {
        padding-top: 16px;
    }
}

/* ----------------------------------------------------------- components */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    min-width: 0;
}

.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-header { padding: 14px 16px; margin: 0; }
.card.flush > .card-body { padding: 0 16px 16px; }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.card-body > * + * { margin-top: 12px; }

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

@media (max-width: 860px) {
    .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 40px;
    padding: 0 0.95rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    font-size: 0.9375rem;
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-success { background: var(--win); border-color: var(--win); color: var(--surface); }
.btn-success:hover { background: var(--win); filter: brightness(1.08); }
.btn-danger { color: var(--loss); border-color: var(--loss); }
.btn-warning { color: var(--otl); border-color: var(--otl); }
.btn-sm { min-height: 32px; padding: 0 0.7rem; font-size: 0.8125rem; }
.btn-ghost { border-color: transparent; background: none; color: var(--text-2); }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.5;
    background: var(--surface-3);
    color: var(--text-2);
    white-space: nowrap;
    vertical-align: middle;
}

.badge-success, .badge-w { background: var(--win-soft); color: var(--win); }
.badge-danger, .badge-l { background: var(--loss-soft); color: var(--loss); }
.badge-warning, .badge-otl { background: var(--otl-soft); color: var(--otl); }
.badge-gold { background: var(--gold-soft); color: var(--gold); }
.badge-info, .badge-admin { background: var(--accent-soft); color: var(--accent); }
.badge-owner { background: var(--gold-soft); color: var(--gold); }

.result {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.1rem;
    height: 1.6rem;
    padding: 0 0.4rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.02em;
}

.result-w { background: var(--win-soft); color: var(--win); }
.result-l { background: var(--loss-soft); color: var(--loss); }
.result-otl { background: var(--otl-soft); color: var(--otl); }

.form-dots {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.alert {
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 0.9375rem;
}

.alert strong { margin-right: 0.4rem; }
.alert-error { background: var(--loss-soft); border-color: transparent; color: var(--loss); }
.alert-success { background: var(--win-soft); border-color: transparent; color: var(--win); }
.alert-info { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

.empty-state {
    text-align: center;
    padding: 28px 12px;
    color: var(--text-2);
}

.empty-state h3 { color: var(--text); margin-bottom: 4px; }
.empty-state-icon { font-size: 1.75rem; margin-bottom: 6px; }

/* forms */
.form-group { display: grid; gap: 0.3rem; min-width: 0; }
.form-group + .form-group { margin-top: 0.9rem; }
.form-row .form-group + .form-group { margin-top: 0; }

.form-label, label.form-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-2);
}

.form-control, .form-input, .form-select, .form-textarea,
input[type="text"], input[type="email"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
    width: 100%;
    min-height: 40px;
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 1rem;
}

textarea, .form-textarea {
    min-height: 8rem;
    resize: vertical;
    font-family: var(--mono);
    font-size: 0.875rem;
    line-height: 1.5;
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 0;
    border-color: transparent;
}

input[type="checkbox"] { width: auto; min-height: 0; }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    align-items: end;
}

.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }

details.filters {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

details.filters > summary {
    cursor: pointer;
    padding: 12px 16px;
    font-weight: 600;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

details.filters > summary::-webkit-details-marker { display: none; }
details.filters > summary::after { content: "+"; color: var(--text-2); font-size: 1.25rem; line-height: 1; }
details.filters[open] > summary::after { content: "–"; }
details.filters > form { padding: 0 16px 16px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 0.8rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.chip:hover { text-decoration: none; color: var(--text); }
.chip[aria-current="page"], .chip[aria-selected="true"], .chip.is-active {
    background: var(--accent-soft);
    border-color: transparent;
    color: var(--accent);
}

.scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.scroll-x::-webkit-scrollbar { display: none; }
.scroll-x > .chips { flex-wrap: nowrap; }

/* tables */
.table-wrap, .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

th, td {
    padding: 9px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-2);
    font-weight: 700;
    background: var(--surface-2);
}

tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
td.wrap, th.wrap { white-space: normal; }
td.strong { font-weight: 700; }

table.sticky-first th:first-child,
table.sticky-first td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--surface);
    box-shadow: 1px 0 0 var(--border);
    max-width: 46vw;
    overflow: hidden;
    text-overflow: ellipsis;
}

table.sticky-first th:first-child { background: var(--surface-2); z-index: 2; }

th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--text); }
th[aria-sort="ascending"]::after { content: " ▲"; }
th[aria-sort="descending"]::after { content: " ▼"; }
th[aria-sort] { color: var(--accent); }

.pb {
    display: inline-block;
    margin-left: 3px;
    padding: 0 4px;
    border-radius: 4px;
    font-size: 0.625rem;
    font-weight: 800;
    background: var(--gold-soft);
    color: var(--gold);
    vertical-align: 1px;
}

/* stat tiles */
.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 8px;
}

.tile {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    min-width: 0;
}

.tile-value {
    font-size: 1.375rem;
    font-weight: 700;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.tile-label {
    font-size: 0.75rem;
    line-height: 1.3;
    color: var(--text-2);
}

.tile-note { font-size: 0.75rem; color: var(--text-2); margin-top: 2px; }
.tiles.wide { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.tiles.big .tile-value { font-size: 1.75rem; }

.section-title {
    margin: 4px 0 8px;
}

/* tabs */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
    padding: 10px 14px;
    border: 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    background: none;
    color: var(--text-2);
    font: inherit;
    font-weight: 600;
    font-size: 0.9375rem;
    cursor: pointer;
    white-space: nowrap;
}

.tab[aria-selected="true"] {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* list rows */
.rows { display: grid; }

.row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    color: var(--text);
}

.rows > .row:first-child, .rows > details:first-child > .row { border-top: 0; }
a.row:hover { background: var(--surface-2); text-decoration: none; }

.row-title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.row-sub { font-size: 0.8125rem; color: var(--text-2); }
.row-end { text-align: right; }
.row-score { font-size: 1.125rem; font-weight: 700; font-variant-numeric: tabular-nums; }

details.row-details > summary {
    list-style: none;
    cursor: pointer;
}

details.row-details > summary::-webkit-details-marker { display: none; }
details.row-details > .row-more { padding: 0 16px 14px; }
details.row-details[open] > summary { background: var(--surface-2); }

/* pagination */
.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text-2);
}

/* comparison bars */
.cmp { display: grid; gap: 12px; }

.cmp-row {
    display: grid;
    grid-template-columns: 3.5rem minmax(0, 1fr) 3.5rem;
    align-items: center;
    gap: 10px;
    font-variant-numeric: tabular-nums;
}

.cmp-row .cmp-us { font-weight: 700; text-align: right; }
.cmp-row .cmp-them { font-weight: 700; color: var(--text-2); }
.cmp-mid { display: grid; gap: 4px; }
.cmp-label { text-align: center; font-size: 0.75rem; color: var(--text-2); }

.cmp-bar {
    display: flex;
    height: 8px;
    gap: 2px;
}

.cmp-bar span { border-radius: 4px; min-width: 4px; }
.cmp-bar .us { background: var(--accent); }
.cmp-bar .them { background: var(--them); }

/* leaderboards */
.leader-list { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }

.leader {
    display: grid;
    grid-template-columns: 1.4rem minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    padding: 6px 0;
}

.leader .rank { color: var(--text-2); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.leader .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leader .val { font-weight: 700; font-variant-numeric: tabular-nums; }
.leader:first-child .val { color: var(--accent); }

/* charts */
.chart-container, .chart-box {
    position: relative;
    height: 260px;
}

/* spinner / htmx */
.spinner {
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    display: inline-block;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.htmx-indicator { display: none; align-items: center; gap: 0.5rem; color: var(--text-2); }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-flex; }

@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 2s; }
    * { scroll-behavior: auto !important; }
}

/* ------------------------------------------------------------------ pages */
/* login */
.login-container {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 16px;
}

.login-box {
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.login-box .brand-mark { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 12px; display: block; }
.login-box p { color: var(--text-2); margin: 4px 0 20px; }
.login-box .btn { width: 100%; min-height: 46px; }
.login-box .btn + .btn { margin-top: 10px; }

/* home */
.hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px 20px;
    align-items: center;
}

.hero-record { font-size: 2rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.hero-streak { font-size: 1rem; font-weight: 700; padding: 0.35rem 0.8rem; border-radius: 999px; }

.scoreline {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    text-align: center;
}

.scoreline .team { font-weight: 600; font-size: 0.9375rem; overflow-wrap: anywhere; }
.scoreline .score { font-size: 2.5rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.scoreline .score .dash { color: var(--text-2); font-weight: 400; margin: 0 0.3rem; }
.scoreline.sm .score { font-size: 1.75rem; }

.mover {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 8px 0;
    border-top: 1px solid var(--border);
}

.mover:first-child { border-top: 0; }
.mover .arrow { font-weight: 800; width: 1.2rem; text-align: center; }

/* analysis text */
.prose {
    white-space: pre-wrap;
    line-height: 1.65;
    overflow-wrap: anywhere;
}

details.fold > summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--accent);
    list-style: none;
}

details.fold > summary::-webkit-details-marker { display: none; }
details.fold[open] > summary { margin-bottom: 8px; }

/* chat */
.container.chat-page { padding-bottom: 16px; }

.chat {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - var(--header-h) - 38px);
    max-width: 760px;
    margin: 0 auto;
}

@media (max-width: 760px) {
    .chat { height: calc(100dvh - var(--header-h) - var(--tabbar-h) - env(safe-area-inset-bottom, 0px) - 34px); }
}

.chat-log {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 4px 2px 12px;
}

.msg {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 16px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.5;
}

.msg-user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg-bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-meta { display: block; margin-top: 6px; font-size: 0.75rem; color: var(--text-2); white-space: normal; }
.msg-error { border-color: var(--loss); color: var(--loss); }

.chat-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding-top: 8px;
}

.chat-form textarea {
    min-height: 46px;
    max-height: 140px;
    font-family: var(--font);
    font-size: 1rem;
    resize: none;
}

.chat-form .btn { min-height: 46px; }

/* admin */
.admin-nav { margin-bottom: 4px; }

.kv {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 4px 16px;
    font-size: 0.9375rem;
}

.kv dt { color: var(--text-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.trace {
    border-top: 1px solid var(--border);
    padding: 10px 0;
}

.trace:first-of-type { border-top: 0; }
.trace > summary { cursor: pointer; overflow-wrap: anywhere; }
.trace-body { margin-top: 10px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }

.codeblock, .preview-json, .preview-text {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    overflow-x: auto;
    max-height: 420px;
    overflow-y: auto;
}

.preview-text { font-family: var(--font); font-size: 0.9375rem; line-height: 1.6; }
.preview-meta { font-size: 0.8125rem; color: var(--text-2); margin-bottom: 6px; }
.preview-details > summary { cursor: pointer; font-weight: 600; color: var(--accent); margin-bottom: 6px; }
.preview-loader { margin-top: 8px; }

.logbox {
    max-height: 520px;
    overflow: auto;
    background: #10151e;
    color: #cfd6e4;
    padding: 12px;
    border-radius: var(--radius-sm);
}

.logbox pre { font-size: 0.75rem; line-height: 1.45; white-space: pre; }

.bar-mini {
    height: 6px;
    border-radius: 3px;
    background: var(--surface-3);
    overflow: hidden;
}

.bar-mini > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

.cmp-names {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-weight: 700;
}

.cmp-names a { min-width: 0; overflow-wrap: anywhere; }
.cmp-names a:last-child { text-align: right; }
