:root {
    color-scheme: light;
    --ink: #172026;
    --muted: #63727d;
    --line: #d9e1e7;
    --surface: #ffffff;
    --band: #f5f8fa;
    --green: #267d5c;
    --blue: #315f8f;
    --amber: #a36a10;
    --red: #b74444;
    --shadow: 0 10px 30px rgba(30, 45, 58, 0.08);
    font-family: Inter, "Open Sans", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--band);
    color: var(--ink);
}

button, select {
    font: inherit;
}

button {
    min-height: 42px;
    border: 1px solid var(--blue);
    background: var(--blue);
    color: #fff;
    border-radius: 6px;
    padding: 0 14px;
    cursor: pointer;
}

button:hover { filter: brightness(0.96); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

select {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    padding: 0 10px;
}

.app-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    padding: 20px clamp(16px, 4vw, 42px);
    background: #fff;
    border-bottom: 1px solid var(--line);
}

h1, h2, p { margin: 0; }

h1 { font-size: clamp(28px, 4vw, 40px); font-weight: 750; }
h2 { font-size: 18px; font-weight: 720; }

.eyebrow {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-actions select { width: 78px; }

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0 10px;
    border-radius: 999px;
    background: #edf4f1;
    color: var(--green);
    font-size: 13px;
    font-weight: 700;
}

.status-pill.model-status {
    background: #e8f0f7;
    color: var(--blue);
}

main { padding: 18px clamp(16px, 4vw, 42px) 40px; }

.alert-band {
    display: grid;
    gap: 6px;
    padding: 12px 14px;
    margin-bottom: 16px;
    border-left: 4px solid var(--red);
    background: #fff7f7;
    color: #6a2626;
}

.control-band {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

label {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.player-link-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--blue);
    text-decoration: none;
    border-radius: 8px;
    padding: 0;
    margin-left: 8px;
}

.player-link-button img {
    width: 16px;
    height: 16px;
    display: block;
}

.player-link-button:hover {
    background: #eef4fb;
}

label span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.round-tabs-wrap {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.panel > .round-tabs-wrap {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
}

.round-tabs-wrap > span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.round-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.round-tab {
    min-height: 34px;
    border-color: var(--line);
    background: #fff;
    color: var(--ink);
    padding: 0 11px;
}

.round-tab[aria-selected="true"] {
    border-color: var(--blue);
    background: var(--blue);
    color: #fff;
}

.summary-band {
    display: grid;
    gap: 16px;
    margin-top: 18px;
    padding: 18px;
    background: #102027;
    color: #fff;
    border-radius: 8px;
}

.summary-band .eyebrow { color: #b9cad3; }

.score-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.score-strip div {
    min-height: 70px;
    display: grid;
    align-content: center;
    gap: 4px;
    padding: 10px;
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 6px;
}

.score-strip span { font-size: 24px; font-weight: 780; }
.score-strip small { color: #c8d7de; }

.workbench {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-top: 18px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    min-width: 0;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px;
    border-bottom: 1px solid var(--line);
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.button-row button:last-child {
    border-color: var(--green);
    background: var(--green);
}

.home-toggle {
    border-color: var(--line);
    background: #fff;
    color: var(--ink);
}

.home-toggle[aria-pressed="true"] {
    border-color: var(--amber);
    background: #fff7e8;
    color: #6f4708;
}

.secondary-button {
    border-color: var(--line);
    background: #fff;
    color: var(--ink);
}

.icon-button {
    width: 38px;
    min-height: 38px;
    padding: 0;
}

.team-modal[hidden] {
    display: none;
}

.team-modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 18px;
}

.team-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(16, 32, 39, 0.46);
}

.team-dialog {
    position: relative;
    width: min(760px, 100%);
    max-height: min(760px, calc(100vh - 36px));
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(16, 32, 39, 0.28);
    overflow: hidden;
}

.team-dialog-head,
.team-dialog-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px;
    border-bottom: 1px solid var(--line);
}

.team-dialog-actions {
    justify-content: flex-end;
    border-top: 1px solid var(--line);
    border-bottom: 0;
}

.team-dialog-status {
    padding: 10px 14px;
    color: var(--muted);
    font-weight: 700;
    border-bottom: 1px solid var(--line);
}

.team-player-list {
    overflow: auto;
    display: grid;
    gap: 8px;
    padding: 12px 14px;
    background: #f8fafb;
}

.team-player-option {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
}

.team-player-option input {
    width: 18px;
    height: 18px;
}

.team-player-main {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.team-player-main strong,
.team-player-main small,
.team-player-note {
    overflow-wrap: anywhere;
}

.team-player-main small,
.team-player-note {
    color: var(--muted);
    font-size: 12px;
}

.team-player-note {
    max-width: 220px;
    text-align: right;
}

.team-player-option.is-disabled {
    background: #f0f2f4;
    color: #7b8790;
}

.team-player-option.is-disabled .team-player-note {
    color: var(--red);
    font-weight: 700;
}

.table-scroll {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 620px;
}

.data-table th,
.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    background: #f8fafb;
}

.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table select { min-width: 190px; }

.rank-list,
.history-list {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 14px;
}

.rank-list { list-style-position: inside; }

.rank-list li,
.history-item {
    display: grid;
    gap: 4px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fbfcfd;
}

.player-line {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
}

.player-line small,
.history-item small {
    color: var(--muted);
}

.expectation-good { color: var(--green); font-weight: 800; }
.expectation-even { color: var(--amber); font-weight: 800; }
.expectation-hard { color: var(--red); font-weight: 800; }

.player-cell {
    display: flex;
    align-items: center;
    gap: 6px;
}

.duplicate-warning {
    flex-shrink: 0;
    color: var(--amber);
    font-size: 16px;
    cursor: default;
}

.prediction-panel {
    display: grid;
    gap: 12px;
    padding: 14px;
    border-top: 1px solid var(--line);
    background: #f8fafb;
}

.prediction-panel[hidden] {
    display: none;
}

.prediction-summary {
    display: grid;
    gap: 10px;
}

.prediction-summary h3 {
    margin: 2px 0 0;
    font-size: 18px;
}

.profile-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.profile-metrics span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 30px;
    padding: 0 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.profile-metrics strong {
    color: var(--ink);
}

.scenario-list {
    display: grid;
    gap: 10px;
}

.scenario-card {
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.scenario-card header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
}

.scenario-card header span {
    color: var(--green);
    font-weight: 800;
}

.scenario-boards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 8px;
}

.scenario-boards div {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 2px 8px;
    min-height: 54px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fbfcfd;
}

.scenario-boards span {
    grid-row: span 2;
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: #edf4f1;
    color: var(--green);
    font-weight: 800;
}

.scenario-boards strong,
.scenario-boards small {
    min-width: 0;
    overflow-wrap: anywhere;
}

.scenario-boards small,
.scenario-card li,
.prediction-notes li {
    color: var(--muted);
    font-size: 12px;
}

.scenario-card ul,
.prediction-notes {
    margin: 0;
    padding-left: 18px;
}

@media (min-width: 760px) {
    .control-band {
        grid-template-columns: repeat(4, minmax(130px, 1fr));
        align-items: end;
    }

    .round-tabs-wrap {
        grid-column: span 3;
    }

    .summary-band {
        grid-template-columns: minmax(220px, 1fr) minmax(360px, 520px);
        align-items: center;
    }

    .workbench {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .wide {
        grid-column: 1 / -1;
    }
}

@media (min-width: 1180px) {
    .workbench {
        grid-template-columns: 1.4fr 0.8fr 0.8fr;
    }

    .wide {
        grid-column: span 2;
    }

    .workbench .wide:first-child {
        grid-column: span 3;
    }
}

/* ── Share button ─────────────────────────────────────────── */
#shareButton {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* ── Share labels (read-only filter context strip) ────────── */
.share-labels {
    display: grid;
    gap: 4px;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.share-labels[hidden] { display: none; }

.share-context {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.01em;
}

/* ── Share badge ──────────────────────────────────────────── */
.share-badge {
    background: #e8f0f7;
    color: var(--blue);
}

/* ── Share toast ──────────────────────────────────────────── */
.share-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 100;
    padding: 12px 18px;
    background: #102027;
    color: #fff;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(16, 32, 39, 0.28);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.25s, transform 0.25s;
    pointer-events: none;
}

.share-toast[hidden] { display: none; }

.share-toast-visible {
    opacity: 1;
    transform: translateY(0);
}

/* ── Share / read-only mode ───────────────────────────────── */
.is-share-mode .control-band { display: none; }

.is-share-mode #homeToggleButton,
.is-share-mode #configureTeamButton,
.is-share-mode #shareButton,
.is-share-mode #optimizeButton { display: none; }
