:root {
    --red: #D9312F;
    --red-dark: #B72624;
    --red-line: #F08A88;
    --navy: #1E3566;
    --navy-soft: #E9EDF5;
    --paper: #FFFFFF;
    --paper-edge: #F3D6D5;
    --muted-on-paper: #56657F;
    --rule-on-paper: #E3E7EF;
    --green-on-paper: #1F7A4D;
    --card-w: clamp(46px, 7.2vw, 78px);
    --card-sm-w: clamp(22px, 3.2vw, 34px);
    --seat-reach: calc(var(--card-w) * 1.9);
    color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--red);
    color: var(--paper);
    font-family: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

button { font: inherit; }
h1, h2 { margin: 0; }

.game {
    max-width: 980px;
    margin: 0 auto;
    padding: 12px 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 100vh;
}

/* ---------- Buttons ---------- */
button.primary, button.secondary {
    border-radius: 10px; padding: 11px 20px; font-weight: 700; cursor: pointer;
}
button.primary { background: var(--red); color: var(--paper); border: 2px solid var(--red); }
button.primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
button.secondary { background: var(--paper); color: var(--navy); border: 2px solid var(--navy); }
button.secondary:hover { background: var(--navy-soft); }
button:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; }

/* ---------- Score bar ---------- */
.scorebar {
    display: grid;
    grid-template-columns: 1fr auto 1fr auto;
    align-items: center;
    gap: 12px;
    background: var(--red-dark);
    border-radius: 14px;
    padding: 10px 12px 10px 16px;
}
.team { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.team-right { justify-content: flex-end; }
.team-name { font-weight: 600; }
.team-score { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.team-bags { font-size: 0.85rem; opacity: 0.85; }
.hand-info { display: flex; gap: 6px; font-size: 0.85rem; opacity: 0.9; white-space: nowrap; }
.dot { opacity: 0.6; }
.menu-button {
    background: transparent; color: var(--paper);
    border: 2px solid rgba(255, 255, 255, .7); border-radius: 999px;
    padding: 4px 14px; font-weight: 600; cursor: pointer;
}
.menu-button:hover { background: rgba(255, 255, 255, .12); }
.menu-button.active { background: var(--paper); color: var(--red-dark); border-color: var(--paper); }
.bar-buttons { display: flex; gap: 8px; }
.menu-button:focus-visible { outline-color: var(--paper); }

/* ---------- Table ---------- */
.table {
    position: relative;
    display: grid;
    grid-template-columns: minmax(70px, 1fr) minmax(0, 2.4fr) minmax(70px, 1fr);
    grid-template-areas:
        ".    north ."
        "west trick east"
        ".    south .";
    align-items: center;
    justify-items: center;
    gap: 8px;
}
.seat { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.seat-north { grid-area: north; }
.seat-west { grid-area: west; }
.seat-east { grid-area: east; }
.seat-south { grid-area: south; }

.seat-label {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 6px 4px 12px;
    border-radius: 999px;
    border: 2px solid transparent;
    font-size: 0.95rem;
    transition: background-color .2s, border-color .2s;
}
.seat-label.turn { background: var(--red-dark); border-color: var(--paper); }
.seat-name { font-weight: 600; white-space: nowrap; }
.pill {
    background: var(--paper); color: var(--navy);
    border-radius: 999px; padding: 2px 10px;
    font-size: 0.8rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.chip {
    background: var(--navy); color: var(--paper);
    border-radius: 999px; padding: 2px 8px; font-size: 0.72rem; font-weight: 600;
}

.backs { display: flex; }
.backs-row .card + .card { margin-left: calc(var(--card-sm-w) * -0.55); }
.backs-col { flex-direction: column; align-items: center; }
.backs-col .card { transform: rotate(90deg); }
.backs-col .card + .card { margin-top: calc(var(--card-sm-w) * -1.05); }

/* ---------- Trick area ---------- */
.trick {
    grid-area: trick;
    position: relative;
    width: 100%;
    max-width: 440px;
    height: calc(var(--card-w) * 1.42 * 2.55);
    display: flex; align-items: center; justify-content: center;
}
.trick-ring {
    position: absolute; inset: 6% 4%;
    border: 2px dashed var(--red-line);
    border-radius: 50%;
}
.trick-slot { position: absolute; }
.slot-north { left: 50%; top: 0; transform: translateX(-50%); --fx: 0px; --fy: calc(var(--seat-reach) * -1); }
.slot-south { left: 50%; bottom: 0; transform: translateX(-50%); --fx: 0px; --fy: var(--seat-reach); }
.slot-west { left: 14%; top: 50%; transform: translateY(-50%) rotate(-8deg); --fx: calc(var(--seat-reach) * -1); --fy: 0px; }
.slot-east { right: 14%; top: 50%; transform: translateY(-50%) rotate(8deg); --fx: var(--seat-reach); --fy: 0px; }

/* A played card slides in from its player's side ... */
.trick-slot .card { animation: card-in .3s cubic-bezier(.2, .8, .3, 1) both; }
@keyframes card-in {
    from { translate: var(--fx) var(--fy); opacity: 0; }
    to { translate: 0 0; opacity: 1; }
}
/* ... and when the trick is won, the cards sweep to the winner after a beat. */
.trick.collect-north { --tx: 0px; --ty: calc(var(--seat-reach) * -1.3); }
.trick.collect-south { --tx: 0px; --ty: calc(var(--seat-reach) * 1.3); }
.trick.collect-west { --tx: calc(var(--seat-reach) * -1.6); --ty: 0px; }
.trick.collect-east { --tx: calc(var(--seat-reach) * 1.6); --ty: 0px; }
.trick.collect .trick-slot .card {
    animation: card-in .3s cubic-bezier(.2, .8, .3, 1) both, card-out .38s ease-in .75s forwards;
}
@keyframes card-out {
    to { translate: var(--tx) var(--ty); scale: .5; opacity: 0; }
}

.status-row { display: flex; justify-content: center; align-items: center; gap: 12px; flex-wrap: wrap; }
.link-button {
    background: transparent; color: var(--paper);
    border: none; padding: 2px 4px; cursor: pointer;
    font-size: 0.9rem; font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
}
.link-button:hover { text-decoration-thickness: 2px; }
.link-button:focus-visible { outline: 3px solid var(--paper); outline-offset: 2px; border-radius: 4px; }
.status {
    margin: 0;
    min-height: 1.5em;
    text-align: center; font-size: 1rem; font-weight: 600;
}

/* ---------- Cards ---------- */
.card {
    position: relative;
    flex: none;
    width: var(--card-w);
    height: calc(var(--card-w) * 1.42);
    border-radius: calc(var(--card-w) * 0.14);
    padding: 0;
    border: 2px solid var(--paper-edge);
    background: var(--paper);
    color: var(--navy);
    user-select: none;
}
.card.red { color: var(--red); }
.card.navy { color: var(--navy); }
.card .rank {
    position: absolute; top: 6%; left: 9%;
    font-size: calc(var(--card-w) * 0.3); font-weight: 700; line-height: 1;
    letter-spacing: -0.02em;
}
.card .pip-corner {
    position: absolute; top: 7%; right: 9%;
    font-size: calc(var(--card-w) * 0.2); line-height: 1;
}
.card .pip {
    position: absolute; left: 0; right: 0; bottom: 10%;
    text-align: center;
    font-size: calc(var(--card-w) * 0.56); line-height: 1;
}
.card.back {
    background: var(--navy);
    border: 2px solid var(--paper);
    display: flex; align-items: center; justify-content: center;
}
.card.back .back-mark { color: var(--red); font-size: calc(var(--card-w) * 0.38); }
.card.sm { width: var(--card-sm-w); height: calc(var(--card-sm-w) * 1.42); border-radius: calc(var(--card-sm-w) * 0.16); }
.card.sm.back .back-mark { font-size: calc(var(--card-sm-w) * 0.42); }
.card.winner { border-color: var(--navy); outline: 3px solid var(--paper); }

/* ---------- Your hand ---------- */
.hand {
    display: flex;
    justify-content: center;
    padding: 18px 0 8px;
    min-height: calc(var(--card-w) * 1.42 + 26px);
}
.hand-slot { animation: deal-in .35s cubic-bezier(.2, .8, .3, 1) backwards; animation-delay: calc(var(--i) * 45ms); }
.hand-slot + .hand-slot { margin-left: calc(var(--card-w) * -0.42); }
@keyframes deal-in {
    from { translate: 0 -40px; opacity: 0; }
}
.hand .card { transition: transform .15s ease-out, filter .15s; }
.hand .card.playable { cursor: pointer; transform: translateY(-14px); border-color: var(--navy); }
.hand .card.playable:hover, .hand .card.playable:focus-visible { transform: translateY(-24px); }
.hand-slot:has(.playable:hover), .hand-slot:has(.playable:focus-visible) { position: relative; z-index: 1; }
.hand .card.playable:focus-visible { outline: 3px solid var(--paper); outline-offset: 2px; }
.hand .card.dimmed { filter: brightness(.8) saturate(.7); }

/* ---------- Bid panel (centre of the table) ---------- */
.bid-panel {
    position: relative;
    background: var(--paper); color: var(--navy);
    border-radius: 16px;
    padding: 12px 14px 10px;
    width: min(100%, 340px);
    animation: pop-in .25s ease-out both;
}
.bid-title { margin: 0; font-weight: 700; font-size: 1.05rem; }
.bid-context { margin: 2px 0 10px; font-size: 0.85rem; color: var(--muted-on-paper); display: flex; gap: 6px; flex-wrap: wrap; }
.bid-buttons { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.bid {
    border: 2px solid var(--navy); background: var(--paper); color: var(--navy);
    border-radius: 8px; padding: 6px 0; font-weight: 700; cursor: pointer;
    font-variant-numeric: tabular-nums;
}
.bid:hover { background: var(--navy-soft); }
.bid.nil { font-size: 0.85rem; }
.bid.suggested { background: var(--navy); color: var(--paper); }
.bid.suggested:hover { background: #2A4580; }
.bid-hint { margin: 8px 0 0; font-size: 0.75rem; color: var(--muted-on-paper); }
@keyframes pop-in { from { opacity: 0; scale: .94; } }

/* ---------- Full screens (start, results) ---------- */
.screen {
    background: var(--paper); color: var(--navy);
    border-radius: 20px;
    padding: 24px;
    width: min(100%, 680px);
    align-self: center;
    animation: pop-in .25s ease-out both;
}
.screen h1 { font-size: 2.2rem; letter-spacing: -0.02em; }
.screen h2 { font-size: 1.3rem; margin-bottom: 14px; }
.lede { margin: 6px 0 20px; color: var(--muted-on-paper); line-height: 1.5; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }

.start-screen { margin-top: 6vh; }
.brand { display: flex; margin-bottom: 12px; }
.brand-card {
    width: 44px; height: 62px; border-radius: 8px;
    border: 2px solid var(--paper-edge); background: var(--paper);
    display: flex; align-items: center; justify-content: center; font-size: 26px;
}
.brand-card.navy { color: var(--navy); rotate: -8deg; }
.brand-card.red { color: var(--red); rotate: 8deg; margin-left: -10px; }

.notice {
    margin: 0 0 16px; padding: 10px 12px; border-radius: 10px;
    background: #FCEBEB; color: #8F1C1A; font-size: 0.9rem;
}
.resume-box {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    border: 2px solid var(--navy); border-radius: 14px; padding: 14px 16px; margin-bottom: 18px;
}
.resume-box button.primary { margin: 0; }
.resume-title { margin: 0; font-weight: 700; }
.resume-summary { margin: 2px 0 0; font-size: 0.9rem; color: var(--muted-on-paper); }
.new-game-heading { margin: 0 0 12px; font-weight: 700; color: var(--muted-on-paper); }
.choice-group { border: none; padding: 0; margin: 0 0 18px; }
.choice-group legend { font-weight: 700; margin-bottom: 8px; padding: 0; }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.choices-2 { grid-template-columns: repeat(2, 1fr); }
.choice {
    text-align: left;
    background: var(--paper); color: var(--navy);
    border: 2px solid var(--rule-on-paper); border-radius: 12px;
    padding: 12px; cursor: pointer;
    display: flex; flex-direction: column; gap: 4px;
}
.choice:hover { border-color: var(--navy); }
.choice.selected { border-color: var(--navy); background: var(--navy); color: var(--paper); }
.choice-name { font-weight: 700; }
.choice-desc { font-size: 0.85rem; line-height: 1.35; opacity: .85; }

.banner {
    margin: 0 0 6px; font-size: 1.8rem; font-weight: 800; letter-spacing: -0.02em;
}
.banner.won { color: var(--green-on-paper); }
.banner.lost { color: var(--red); }

.team-results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.team-card { border: 2px solid var(--rule-on-paper); border-radius: 14px; padding: 14px; }
.team-card.ours { border-color: var(--navy); }
.team-card header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.team-card-name { font-weight: 700; }
.hand-points { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.hand-points.pos { color: var(--green-on-paper); }
.hand-points.neg { color: var(--red); }
.player-lines { list-style: none; margin: 0 0 8px; padding: 0; font-size: 0.9rem; }
.player-lines li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; }
.player-lines li.missed span:last-child { color: var(--red); }
.contract { margin: 0 0 12px; font-size: 0.85rem; color: var(--muted-on-paper); }
.contract .notes { color: var(--navy); }
.total-row { display: flex; align-items: baseline; gap: 6px; margin-bottom: 6px; }
.total { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.of-target { color: var(--muted-on-paper); font-size: 0.9rem; }
.bags { margin-left: auto; font-size: 0.85rem; color: var(--muted-on-paper); }
.progress { height: 8px; border-radius: 999px; background: var(--navy-soft); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--navy); border-radius: 999px; transition: width .6s ease-out; }
.team-card:not(.ours) .progress span { background: var(--red); }

/* ---------- Last trick (over the table) ---------- */
.overlay {
    position: absolute; inset: -6px;
    background: rgba(143, 28, 26, .55);
    border-radius: 16px;
    display: flex; align-items: center; justify-content: center;
    padding: 12px;
    z-index: 5;
    animation: fade-in .15s ease-out both;
}
@keyframes fade-in { from { opacity: 0; } }
.last-trick-panel {
    --card-w: clamp(44px, 8vw, 64px);
    background: var(--paper); color: var(--navy);
    border-radius: 16px; padding: 14px 16px;
    width: min(100%, 420px);
    animation: pop-in .2s ease-out both;
}
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.panel-heading { margin: 0; font-weight: 700; }
.muted { color: var(--muted-on-paper); font-weight: 500; }
button.secondary.small { padding: 5px 12px; border-radius: 8px; font-size: 0.85rem; }
.last-trick-cards {
    list-style: none; margin: 0; padding: 0;
    display: flex; justify-content: center; gap: 10px;
}
.last-trick-cards li { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.last-trick-who { font-size: 0.8rem; color: var(--muted-on-paper); white-space: nowrap; }
.last-trick-cards li.won .last-trick-who { color: var(--navy); font-weight: 700; }
.last-trick-cards .card.winner { outline-color: var(--navy); }
.last-trick-summary { margin: 12px 0 0; text-align: center; font-weight: 600; }

/* ---------- Score history ---------- */
.history-heading { margin: 22px 0 10px; font-size: 1.05rem; }
.history-empty { color: var(--muted-on-paper); margin: 0; }
.history { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.history th, .history td { text-align: left; vertical-align: top; padding: 10px 8px; border-bottom: 1px solid var(--rule-on-paper); }
.history thead th { font-size: 0.8rem; color: var(--muted-on-paper); font-weight: 600; padding-top: 0; }
.history .hand-no { font-weight: 700; width: 4.5em; }
.history .hand-no span { display: block; }
.history .dealer { font-weight: 400; font-size: 0.75rem; color: var(--muted-on-paper); }
.history-score { display: flex; align-items: baseline; gap: 8px; }
.history-total { font-size: 1.15rem; font-weight: 800; }
.history-delta { font-weight: 700; font-size: 0.9rem; }
.history-delta.pos { color: var(--green-on-paper); }
.history-delta.neg { color: var(--red); }
.history-detail { font-size: 0.8rem; color: var(--muted-on-paper); }
.history-notes { font-size: 0.8rem; color: var(--navy); }
.scores-screen { margin-top: 4px; }
.visually-hidden {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- Small screens ---------- */
@media (max-width: 600px) {
    .game { padding: 8px 12px 16px; }
    .scorebar { grid-template-columns: 1fr 1fr; row-gap: 6px; }
    .hand-info { grid-column: 1 / -1; grid-row: 2; justify-content: center; }
    .bar-buttons { grid-column: 1 / -1; grid-row: 3; justify-self: center; }
    .team-score { font-size: 1.2rem; }
    .table { grid-template-columns: 52px minmax(0, 1fr) 52px; }
    .seat-label { flex-direction: column; gap: 2px; padding: 4px 8px; border-radius: 12px; }
    .bid-panel { padding: 10px; }
    .bid-buttons { grid-template-columns: repeat(5, 1fr); gap: 5px; }
    .bid-hint { display: none; }
    .trick { height: calc(var(--card-w) * 1.42 * 3.1); }
    .hand-slot + .hand-slot { margin-left: calc(var(--card-w) * -0.5); }
    .status { font-size: 0.9rem; }
    .screen { padding: 18px; border-radius: 16px; }
    .choices, .team-results { grid-template-columns: 1fr; }
    .choices-2 { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    .trick-slot .card, .trick.collect .trick-slot .card, .hand-slot, .bid-panel, .screen,
    .overlay, .last-trick-panel { animation: none; }
    .trick.collect .trick-slot .card { opacity: .5; }
    .hand .card, .progress span { transition: none; }
}

/* ---------- Loading indicator and error bar (from the Blazor template, recoloured) ---------- */
#blazor-error-ui {
    background: var(--paper);
    color: var(--navy);
    bottom: 0;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
#blazor-error-ui .reload { color: var(--red); }

.blazor-error-boundary { background: var(--paper); color: var(--red); padding: 1rem; border-radius: 12px; }
.blazor-error-boundary::after { content: "Something went wrong. Reload the page to start again."; }

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}
.loading-progress circle {
    fill: none;
    stroke: var(--red-dark);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}
.loading-progress circle:last-child {
    stroke: var(--paper);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}
.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: 700;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Loading"); }
