:root {
    color-scheme: light;
    --bg: #f4f6f8;
    --panel: #ffffff;
    --ink: #1f2933;
    --muted: #637083;
    --line: #d8dee8;
    --accent: #b42338;
    --accent-2: #14756f;
    --gold: #a56c00;
    --shadow: 0 16px 40px rgba(31, 41, 51, 0.1);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.4;
}

.topbar {
    align-items: center;
    background: #223343;
    color: #f7fbff;
    display: flex;
    justify-content: space-between;
    min-height: 92px;
    padding: 22px max(20px, calc((100vw - 1180px) / 2));
}

.top-actions {
    display: flex;
    flex: 0 0 auto;
    gap: 10px;
    position: relative;
}

.icon-button {
    font-size: 22px;
    line-height: 1;
    min-width: 48px;
}

.admin-menu {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 4px;
    min-width: 190px;
    padding: 8px;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 20;
}

.admin-menu button {
    background: transparent;
    border-radius: 6px;
    color: var(--ink);
    font-weight: 800;
    padding: 10px 12px;
    text-align: left;
}

.admin-menu button:hover {
    background: #edf1f5;
}

.icon-button.active,
.admin-menu button.active {
    background: #ffd166;
    color: #223343;
}

h1 {
    font-size: clamp(26px, 3vw, 38px);
    line-height: 1.1;
    margin: 0;
}

main {
    margin: 0 auto;
    max-width: 1180px;
    padding: 22px 20px 48px;
}

button,
input,
select {
    font: inherit;
}

button {
    border: 0;
    cursor: pointer;
}

.ghost,
.settings-panel button {
    background: #f7fbff;
    border-radius: 6px;
    color: #223343;
    font-weight: 700;
    padding: 10px 14px;
}

.settings-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(2, minmax(180px, 1fr));
    margin: -42px 0 22px;
    padding: 18px;
    position: relative;
}

.player-select {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.player-select button {
    background: #eaf1f7;
    border-radius: 999px;
    color: #223343;
    font-size: 13px;
    font-weight: 800;
    padding: 8px 12px;
}

.player-select button.active {
    background: #223343;
    color: #fff;
}

.history-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
    padding: 16px;
}

.history-panel h2,
.final-list h2 {
    font-size: 18px;
    margin: 0 0 12px;
}

.history-entry {
    border-top: 1px solid var(--line);
    display: grid;
    gap: 3px;
    padding: 9px 0;
}

.history-entry:first-child {
    border-top: 0;
    padding-top: 0;
}

.history-entry strong,
.empty {
    color: var(--muted);
    font-size: 13px;
}

.history-nav {
    align-items: center;
    border-top: 1px solid var(--line);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding-top: 12px;
}

.history-nav button {
    background: #eaf1f7;
    border-radius: 6px;
    color: #223343;
    font-size: 18px;
    font-weight: 800;
    min-width: 42px;
    padding: 7px 10px;
}

.history-nav button:disabled {
    cursor: default;
    opacity: 0.45;
}

.history-nav span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

label {
    color: var(--muted);
    display: grid;
    gap: 7px;
    font-size: 13px;
    font-weight: 700;
}

input,
select {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--ink);
    min-height: 40px;
    padding: 8px 10px;
    width: 100%;
}

.players {
    display: grid;
    gap: 10px;
    grid-column: 1 / -1;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.settings-panel button {
    background: var(--accent);
    color: white;
    justify-self: start;
}

.summary {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(3, 1fr);
    margin-bottom: 18px;
}

.final-list {
    margin-bottom: 18px;
}

.final-items {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.final-item {
    background: #e8f7e8;
    border: 1px solid #9ed19d;
    border-left: 5px solid #2f8f46;
    border-radius: 8px;
    display: grid;
    gap: 3px;
    padding: 11px 12px;
}

.final-item span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.summary div {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 15px;
}

.summary strong {
    display: block;
    font-size: 28px;
}

.summary span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.date-list {
    display: grid;
    gap: 14px;
}

.date-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-left: 6px solid transparent;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(31, 41, 51, 0.06);
    padding: 16px;
}

.date-card.chosen {
    background: #e8f7e8;
    border-color: #9ed19d;
    border-left-color: #2f8f46;
}

.date-card.same-weekend {
    background: #fff7d6;
    border-color: #ead184;
    border-left-color: #d9a411;
}

.date-card.past {
    background: #f9fafb;
    opacity: 0.82;
}

.date-card.past.chosen {
    background: #edf8ed;
}

.date-card.past.same-weekend {
    background: #fff9df;
}

.date-head,
.meta-row {
    align-items: center;
    display: flex;
    gap: 16px;
    justify-content: space-between;
}

.note-row {
    margin: 8px 0 14px;
}

textarea {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--ink);
    font: inherit;
    min-height: 68px;
    padding: 8px 10px;
    resize: vertical;
    width: 100%;
}

.date-title {
    font-size: 21px;
    font-weight: 800;
}

.date-sub {
    color: var(--muted);
    font-size: 14px;
    margin-top: 2px;
}

.count-pill {
    background: #eaf1f7;
    border-radius: 999px;
    color: #35495c;
    flex: 0 0 auto;
    font-size: 13px;
    font-weight: 800;
    padding: 8px 12px;
}

.votes {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
    margin: 16px 0;
}

.vote-row {
    align-items: center;
    display: grid;
    gap: 8px;
    grid-template-columns: minmax(0, 84px) minmax(0, 1fr);
    min-width: 0;
}

.player {
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.vote-buttons {
    display: grid;
    gap: 4px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    min-width: 0;
}

.vote {
    background: #edf1f5;
    border-radius: 6px;
    color: #4c5967;
    font-size: 12px;
    font-weight: 800;
    min-height: 34px;
    padding: 6px;
    white-space: nowrap;
}

.vote.yes.active {
    background: var(--accent-2);
    color: #fff;
}

.vote.maybe.active {
    background: var(--gold);
    color: #fff;
}

.vote.no.active {
    background: var(--accent);
    color: #fff;
}

.place-label {
    flex: 1;
}

.date-actions {
    align-items: flex-start;
    display: grid;
    flex: 0 0 156px;
    gap: 8px;
}

.chosen-toggle {
    background: #eaf1f7;
    border-radius: 6px;
    color: var(--ink);
    font-size: 13px;
    font-weight: 800;
    min-height: 40px;
    padding: 8px 10px;
    white-space: nowrap;
}

.chosen-toggle.active {
    background: #2f8f46;
    color: #fff;
}

.collapse-toggle {
    background: #f1f4f7;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: #223343;
    font-size: 13px;
    font-weight: 800;
    min-height: 38px;
    padding: 8px 10px;
}

.date-card.collapsed {
    padding: 10px 12px;
}

.date-card.collapsed .date-details {
    display: none;
}

.collapsed-row {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    min-height: 38px;
}

.collapsed-row .date-title {
    font-size: 18px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.collapsed-row .collapse-toggle {
    flex: 0 0 auto;
}

.archive {
    margin-top: 22px;
}

.archive-toggle {
    background: #dfe7ef;
    border-radius: 6px;
    color: #223343;
    font-weight: 800;
    margin-bottom: 14px;
    padding: 10px 14px;
}

.archive-toggle:disabled {
    cursor: default;
    opacity: 0.62;
}

.archive-list {
    margin-top: 0;
}

@media (max-width: 760px) {
    .topbar {
        align-items: stretch;
        display: grid;
        gap: 16px;
        grid-template-columns: 1fr auto;
        justify-content: stretch;
        min-height: auto;
        padding: 20px;
    }

    .topbar > div:first-child {
        min-width: 0;
    }

    .date-head,
    .meta-row {
        align-items: stretch;
        flex-direction: column;
    }

    .top-actions {
        align-self: start;
        justify-self: end;
    }

    .icon-button {
        height: 48px;
        min-width: 58px;
        padding: 8px 12px;
    }

    .admin-menu {
        left: auto;
        max-width: calc(100vw - 40px);
        min-width: 220px;
        right: 0;
        width: min(280px, calc(100vw - 40px));
    }

    h1 {
        font-size: clamp(28px, 8vw, 38px);
        overflow-wrap: anywhere;
    }

    .settings-panel,
    .summary {
        grid-template-columns: 1fr;
    }

    .players {
        grid-template-columns: 1fr;
    }

    .count-pill {
        align-self: flex-start;
    }

    .date-actions {
        flex: none;
        width: 100%;
    }

    .collapsed-row {
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
    }

    .vote-row {
        grid-template-columns: 1fr;
    }

    .vote-buttons {
        grid-template-columns: repeat(3, 1fr);
    }
}
