:root {
    color-scheme: light;
    --bg: #f5f1e6;
    --ink: #1f2a21;
    --muted: #667064;
    --panel: #fffdf6;
    --line: #d9d0bd;
    --green: #2f7a4b;
    --green-dark: #245d3a;
    --danger: #a94232;
    --shadow: 0 14px 32px rgba(49, 42, 28, .14);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
    font: inherit;
}

button {
    border: 0;
    border-radius: 8px;
    background: var(--green);
    color: white;
    min-height: 44px;
    padding: 0 16px;
    font-weight: 700;
}

button:disabled,
.card.disabled {
    opacity: .45;
}

.shell {
    width: min(1120px, 100%);
    margin: 0 auto;
    padding: 18px;
}

.screen {
    display: none;
}

.screen-active {
    display: block;
}

.brand {
    padding: 22px 0 12px;
}

.brand h1,
.topbar h1,
.game-header h1 {
    margin: 0;
    font-size: clamp(2rem, 8vw, 4.5rem);
    line-height: .95;
}

.brand p {
    max-width: 36rem;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--green-dark);
    text-transform: uppercase;
    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .08em;
}

.panel,
.rules,
.message {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.panel {
    margin: 14px 0;
}

.panel h2,
.rules h2,
.hand-head h2 {
    margin: 0 0 12px;
}

.panel-title,
.topbar,
.game-header,
.route-top,
.hand-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

label {
    display: grid;
    gap: 6px;
    margin: 12px 0;
    font-weight: 700;
}

input,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    min-height: 44px;
    padding: 0 12px;
}

fieldset {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin: 14px 0;
}

legend {
    font-weight: 800;
}

.checkbox-label {
    display: flex;
    grid-template-columns: none;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.checkbox-label input {
    width: auto;
    min-height: auto;
}

.housemate-selection {
    border-top: 1px solid var(--line);
    margin-top: 10px;
    padding-top: 10px;
}

.disabled-options {
    opacity: .58;
}

.muted {
    color: var(--muted);
}

.hidden {
    display: none !important;
}

.icon-button,
.ghost-button {
    width: 44px;
    padding: 0;
    background: #e6dcc8;
    color: var(--ink);
}

.ghost,
.wide {
    width: 100%;
    background: #e6dcc8;
    color: var(--ink);
}

.danger {
    background: var(--danger);
}

.active-games,
.target-list {
    display: grid;
    gap: 10px;
}

.game-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    width: 100%;
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    padding: 10px;
}

.game-row span:first-child {
    display: grid;
    gap: 3px;
    text-align: left;
}

.game-row small {
    color: var(--muted);
}

.game-row-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.game-row-actions button {
    min-height: 38px;
    padding: 0 12px;
}

.player-list {
    padding-left: 20px;
}

.players {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
    gap: 7px;
    margin: 10px 0;
}

.player-chip {
    border: 2px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 7px 8px;
    display: grid;
    gap: 1px;
    font-size: .9rem;
}

.player-chip small {
    color: var(--muted);
    font-size: .72rem;
    line-height: 1.15;
}

.player-chip.current {
    box-shadow: inset 0 0 0 1px rgba(47, 122, 75, .18);
}

.player-chip.you {
    background: #f0faef;
}

.player-chip.winner,
.route-card.winner {
    animation: winnerPulse 1.4s ease-in-out infinite;
    box-shadow: 0 0 0 3px rgba(216, 137, 32, .18), 0 12px 24px rgba(47, 122, 75, .14);
}

.table {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 8px;
    margin: 10px 0;
}

.route-card {
    border: 2px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 9px;
}

.route-card h2,
.route-card p {
    margin: 0;
}

.route-card h2 {
    font-size: 1rem;
}

.route-top span,
.route-meta,
.status {
    color: var(--muted);
    font-size: .78rem;
}

.distance-counts {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    margin-top: 7px;
    font-size: .72rem;
}

.distance-counts span {
    border-radius: 5px;
    background: #eee7d8;
    padding: 4px 3px;
    text-align: center;
}

.progress {
    overflow: hidden;
    height: 12px;
    border-radius: 999px;
    background: #ded6c3;
    margin-top: 10px;
}

.progress span {
    display: block;
    height: 100%;
    background: var(--green);
}

.route-card.ride-red .progress span {
    background: #b83d35;
}

.player-chip.ride-red,
.route-card.ride-red {
    border-color: #b83d35;
}

.route-card.ride-orange .progress span {
    background: #d88920;
}

.player-chip.ride-orange,
.route-card.ride-orange {
    border-color: #d88920;
}

.route-card.ride-green .progress span {
    background: var(--green);
}

.player-chip.ride-green,
.route-card.ride-green {
    border-color: var(--green);
}

.winner-celebration {
    position: relative;
    overflow: hidden;
    min-height: 86px;
    margin: 10px 0;
    border: 2px solid #d88920;
    border-radius: 8px;
    background: linear-gradient(135deg, #fff8dc 0%, #eef9e8 100%);
    box-shadow: var(--shadow);
}

.winner-copy {
    position: relative;
    z-index: 1;
    display: grid;
    place-items: center;
    min-height: 86px;
    text-align: center;
    padding: 12px;
}

.winner-copy strong {
    color: var(--green-dark);
    font-size: clamp(1.6rem, 7vw, 3rem);
    line-height: 1;
    animation: winnerPop .9s ease-out both;
}

.winner-copy span {
    color: var(--muted);
    font-weight: 700;
}

.confetti {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.confetti i {
    position: absolute;
    top: -18px;
    left: calc((var(--i) * 47px) % 100%);
    width: 8px;
    height: 14px;
    border-radius: 2px;
    background: hsl(calc(var(--i) * 37deg), 72%, 48%);
    animation: confettiFall 1.8s ease-in-out infinite;
    animation-delay: calc(var(--i) * -0.11s);
    transform: rotate(calc(var(--i) * 19deg));
}

@keyframes confettiFall {
    0% {
        transform: translateY(-18px) rotate(0deg);
        opacity: 0;
    }
    15% {
        opacity: 1;
    }
    100% {
        transform: translateY(120px) rotate(250deg);
        opacity: 0;
    }
}

@keyframes winnerPop {
    0% {
        transform: scale(.86);
        opacity: 0;
    }
    70% {
        transform: scale(1.06);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes winnerPulse {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-2px);
    }
}

.hand-wrap {
    position: sticky;
    bottom: 0;
    background: rgba(245, 241, 230, .94);
    padding: 8px 0 3px;
    backdrop-filter: blur(8px);
}

.hand {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
    gap: 7px;
}

.card {
    min-height: 0;
    height: 112px;
    padding: 5px;
    border: 1px solid var(--line);
    background: white;
    color: var(--ink);
    display: grid;
    grid-template-rows: 82px 18px;
    gap: 3px;
    overflow: hidden;
}

.card img {
    width: 100%;
    height: 82px;
    aspect-ratio: auto;
    object-fit: contain;
    border-radius: 6px;
    background: #eee7d8;
}

.card span {
    font-size: .68rem;
    line-height: 18px;
    min-height: 18px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dialog {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    background: rgba(24, 28, 22, .48);
    padding: 18px;
}

.dialog-box {
    width: min(460px, 100%);
    background: var(--panel);
    border-radius: 8px;
    padding: 18px;
    box-shadow: var(--shadow);
}

.dialog-box h2 {
    margin-top: 0;
}

.dialog-card-image {
    display: block;
    width: min(260px, 74vw);
    max-height: 42vh;
    object-fit: contain;
    margin: 0 auto 12px;
    border-radius: 8px;
    background: #eee7d8;
    box-shadow: 0 10px 24px rgba(49, 42, 28, .18);
}

.dialog-box > button {
    width: 100%;
    margin-top: 10px;
}

.dialog-box .target-list button {
    width: 100%;
}

.rule-list {
    padding-left: 20px;
}

.rule-list li {
    margin: 8px 0;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%) translateY(18px);
    opacity: 0;
    pointer-events: none;
    background: #172016;
    color: white;
    border-radius: 8px;
    padding: 12px 14px;
    transition: .18s ease;
    max-width: min(92vw, 420px);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%);
}

@media (min-width: 760px) {
    #startScreen {
        display: grid;
        grid-template-columns: 1.1fr .9fr;
        gap: 18px;
        align-items: start;
    }

    #startScreen.screen:not(.screen-active) {
        display: none;
    }

    .brand,
    .rules {
        grid-column: 1;
    }

    #activePanel,
    #createForm,
    #startScreen > .panel:last-of-type {
        grid-column: 2;
    }
}
