/* Nine-Card Don, browser edition. One pub-table look: green baize, timber, brass. */

:root {
    --bg: #101814;
    --panel: #1a2520;
    --panel-2: #21302a;
    --border: #35473f;
    --text: #e9efe9;
    --muted: #a9b8ae;
    --accent: #e3b85a;
    --accent-ink: #20170a;
    --us: #7cc4ff;
    --them: #ff9a76;
    --turn: #ffd66b;
    --red: #c4122e;
    --black: #151515;
    --blue: #1f5fc4;
    --green: #1a7f3a;
    --felt-edge: #4a2c12;
    --card-face: #fdfcf7;
    /* Card width follows both the window's width and its height, so a wide monitor and a laptop both get the biggest cards that fit. */
    --cw: clamp(56px, min(6.4vw, 11.5vh), 128px);
    --ch: calc(var(--cw) * 1.42);
    --overlap: 0.1;
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
button { font: inherit; color: inherit; }
code { font-family: ui-monospace, Consolas, "Cascadia Mono", monospace; color: var(--accent); }

/* ------------------------------------------------------------------ boot screen */

.boot { display: grid; place-items: center; align-content: center; gap: 12px; height: 100vh; }
.boot-title { font-size: 28px; font-weight: 600; color: var(--accent); letter-spacing: .02em; }
.loading-progress { width: 6rem; height: 6rem; }
.loading-progress circle { fill: none; stroke: var(--border); stroke-width: .5rem; transform-origin: 50% 50%; transform: rotate(-90deg); }
.loading-progress circle:last-child {
    stroke: var(--accent);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray .05s ease-in-out;
}
.loading-progress-text { color: var(--muted); }
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Loading"); }

#blazor-error-ui {
    display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
    padding: 10px 16px; background: #5a1a1a; color: #fff;
}
#blazor-error-ui .reload { color: var(--accent); margin-left: 8px; }
#blazor-error-ui .dismiss { cursor: pointer; float: right; }

/* ------------------------------------------------------------------ page frame */

.app { display: grid; grid-template-rows: auto 1fr auto; min-height: 100vh; min-height: 100dvh; }

.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-size: 19px; color: var(--accent); white-space: nowrap; }
.brand-suit { color: #ff6b6b; }
.actions { display: flex; gap: 6px; align-items: center; }

.layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr) 280px;
    grid-template-areas: "left table right";
    gap: 12px; padding: 12px; min-height: 0;
}
.left { grid-area: left; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.table { grid-area: table; min-width: 0; display: flex; }
.right { grid-area: right; display: flex; flex-direction: column; gap: 8px; min-width: 0; overflow-y: auto; max-height: calc(100dvh - 120px); }

.statusbar {
    display: flex; justify-content: space-between; gap: 16px; align-items: center;
    padding: 6px 16px; background: var(--panel); border-top: 1px solid var(--border); font-size: 14px;
}
.statusbar .live { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.statusbar .code-line { white-space: nowrap; color: var(--muted); }

/* ------------------------------------------------------------------ buttons and menus */

.btn {
    background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
    padding: 7px 14px; cursor: pointer; line-height: 1.2;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:focus-visible, .card:focus-visible, .menu-list button:focus-visible, .icon-btn:focus-visible {
    outline: 3px solid var(--turn); outline-offset: 2px;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.tiny { padding: 1px 8px; font-size: 12px; border-radius: 6px; }
.icon-btn { background: none; border: none; font-size: 18px; cursor: pointer; padding: 4px 8px; color: var(--muted); }

.menu { position: relative; }
.menu-scrim { position: fixed; inset: 0; z-index: 40; }
.menu-list {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 230px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 6px;
    box-shadow: 0 10px 30px #0009; display: flex; flex-direction: column;
}
.menu-list button { background: none; border: none; text-align: left; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu-list button:hover:not(:disabled) { background: var(--panel-2); }
.menu-list button:disabled { opacity: .45; cursor: default; }
.menu-list hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; width: 100%; }

/* ------------------------------------------------------------------ side panels */

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.panel.center { text-align: center; }
.panel-head { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.panel.pre, .pre { white-space: pre-line; }
.strong { font-weight: 600; }
.small { font-size: 13px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.accent { color: var(--accent); }
.code-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

.trumps { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 700; }
.suit { display: block; fill: currentColor; }
.suit-big { width: 54px; height: 54px; font-size: 54px; line-height: 1; flex: none; }
.suit-big.none { color: var(--muted); }

.spades, .clubs { color: #f2f2f2; }
.hearts, .diamonds { color: #ff7a85; }
.four-colour .diamonds { color: #8cc0ff; }
.four-colour .clubs { color: #7ce090; }

.talk { list-style: none; margin: 0; padding: 0; font-size: 13px; display: flex; flex-direction: column; gap: 3px; }
.talk li:first-child { color: var(--text); font-weight: 600; }
.talk li { color: var(--muted); }

.played-grid { border-collapse: collapse; width: 100%; font-size: 11px; }
.played-grid th { width: 18px; font-size: 14px; text-align: left; }
.played-grid td { text-align: center; padding: 2px 0; color: var(--text); }
.played-grid td.played { color: var(--muted); text-decoration: line-through; opacity: .55; }
.played-grid td.mine { color: var(--accent); font-weight: 700; }

/* ------------------------------------------------------------------ scores and board */

.board { width: 100%; max-height: 62vh; display: block; }
.board .hole { fill: #1b1008; stroke: #00000080; stroke-width: .5; }
.board .hole.game { fill: #2a1508; stroke: var(--accent); stroke-width: .8; }
.board .board-num { font-size: 5px; fill: #f3e2c299; }
.board .peg { transition: transform .7s cubic-bezier(.3, .7, .4, 1); stroke: #000; stroke-width: .6; }
.board .peg.us { fill: var(--us); }
.board .peg.them { fill: var(--them); }
.board .peg.back { opacity: .65; }

.scores { display: grid; grid-template-columns: 1fr 1fr; text-align: center; }
.score span { display: block; font-weight: 600; }
.score strong { display: block; font-size: 34px; line-height: 1.1; }
.score.us { color: var(--us); }
.score.them { color: var(--them); }

/* ------------------------------------------------------------------ the table */

.felt {
    position: relative; flex: 1; min-height: 600px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2.2fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
        ". n ."
        "w c e"
        ". s ."
        "hand hand hand";
    padding: 14px 14px 18px;
    border-radius: 18px;
    border: 10px solid var(--felt-edge);
    background:
        radial-gradient(ellipse at 50% 40%, #ffffff14 0%, #00000000 55%, #00000055 100%),
        url("../img/cloth.jpg") center / 512px repeat,
        #2e8b57;
    /* The cloth texture is grey; multiplying it over the baize colour tints it, as the desktop does. */
    background-blend-mode: normal, multiply;
    box-shadow: inset 0 0 40px #000a, 0 6px 24px #0008;
}

.seat { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px; border-radius: 10px; }
.seat-n { grid-area: n; }
.seat-w { grid-area: w; align-self: center; }
.seat-e { grid-area: e; align-self: center; }
.seat-s { grid-area: s; padding-bottom: 2px; }
.seat-label {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center;
    background: #00000059; padding: 3px 10px; border-radius: 999px; font-size: 14px; font-weight: 600;
    border: 2px solid transparent;
}
.seat.turn .seat-label { border-color: var(--turn); box-shadow: 0 0 12px #ffd66b88; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 2px #ffd66b44; } }
.chip { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: #ffffff22; }
.chip.accent { background: var(--accent); color: var(--accent-ink); }

/* The other players' cards, face down: a fan of small backs, a third the size of a card. */
.backs { display: flex; padding-top: 2px; }
.mini-back {
    width: calc(var(--cw) * 0.32); height: calc(var(--cw) * 0.45); border-radius: calc(var(--cw) * 0.03); border: 2px solid #fdfcf7;
    background: repeating-linear-gradient(45deg, #7a1c24 0 4px, #5a0f16 4px 8px);
    box-shadow: 0 1px 3px #0009;
}
.mini-back + .mini-back { margin-left: calc(var(--cw) * -0.19); }

.trick-area {
    grid-area: c; position: relative;
    min-height: calc(var(--ch) * 2.5); min-width: calc(var(--cw) * 3.4);
}
.slot { position: absolute; transform: translate(-50%, -50%); animation: land .22s ease-out; }
.slot-n { left: 50%; top: 22%; }
.slot-s { left: 50%; top: 78%; }
.slot-w { left: 28%; top: 50%; }
.slot-e { left: 72%; top: 50%; }
@keyframes land { from { opacity: 0; transform: translate(-50%, -50%) scale(1.15); } }

.toasts { position: absolute; right: 0; top: 0; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; pointer-events: none; }
.toast {
    padding: 6px 12px; border-radius: 8px; font-weight: 700; font-size: 14px;
    background: #000c; border-left: 4px solid; animation: toast 2.8s ease forwards;
}
.toast.us { border-color: var(--us); color: var(--us); }
.toast.them { border-color: var(--them); color: var(--them); }
@keyframes toast { 0% { opacity: 0; transform: translateY(-6px); } 8%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

.hand {
    grid-area: hand; display: flex; justify-content: center; align-items: flex-end;
    min-height: calc(var(--ch) + 18px); padding-top: 14px;
}
/* A small gap between cards when there is room; otherwise they overlap just enough to fit (--n is the number of cards). */
.hand .card + .card {
    margin-left: min(calc(var(--cw) * var(--overlap)), calc((100% - var(--n, 9) * var(--cw)) / (var(--n, 9) - 1)));
}

.banner {
    position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--ch) + 64px);
    max-width: min(560px, 92%); text-align: center; padding: 8px 16px; border-radius: 8px;
    background: #2a180cdd; border: 2px solid var(--accent); color: var(--accent); font-weight: 600; z-index: 5;
}
.banner.subtle { border-width: 1px; color: var(--text); font-weight: 400; font-size: 14px; }

.table-buttons { position: absolute; left: 12px; top: 12px; display: flex; gap: 6px; flex-wrap: wrap; z-index: 4; }

.mobile-scores { display: none; }

/* ------------------------------------------------------------------ cards */

.card {
    position: relative; display: inline-block; flex: none;
    width: var(--cw); height: calc(var(--cw) * 1.42); padding: 0;
    border-radius: calc(var(--cw) * 0.08);
    background: var(--card-face); border: 1px solid #00000040;
    box-shadow: 0 2px 6px #0007;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-weight: 800;
    transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
    user-select: none;
}
.card.spades, .card.clubs { color: var(--black); }
.card.hearts, .card.diamonds { color: var(--red); }
.four-colour .card.diamonds { color: var(--blue); }
.four-colour .card.clubs { color: var(--green); }

/* Index in two corners: rank over suit. The centre carries a big suit, and on court cards the letter with the suit beneath it. */
.card .corner { position: absolute; display: flex; flex-direction: column; align-items: center; gap: calc(var(--cw) * 0.01); line-height: 1; }
.card .corner .r { font-size: calc(var(--cw) * 0.29); letter-spacing: -0.03em; }
.card .corner .s { width: calc(var(--cw) * 0.24); height: calc(var(--cw) * 0.24); }
.card .tl { left: 5%; top: 4%; }
.card .br { right: 5%; bottom: 4%; transform: rotate(180deg); }
.card .pip { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: calc(var(--cw) * 0.02); }
.card .pip .s { width: calc(var(--cw) * 0.5); height: calc(var(--cw) * 0.5); }
.card .pip.court .r { font-family: Georgia, "Times New Roman", serif; font-size: calc(var(--cw) * 0.5); line-height: 1; }
.card .pip.court .s { width: calc(var(--cw) * 0.28); height: calc(var(--cw) * 0.28); }

/* Cards inside dialogs (last trick, the cut) sit at a fixed, smaller size. */
.modal .card, .overlay .card { --cw: clamp(64px, 9vh, 96px); }

.card.back {
    background:
        repeating-linear-gradient(45deg, #7a1c24 0 5px, #5a0f16 5px 10px);
    border: 3px solid #fdfcf7;
}

button.card { cursor: default; }
button.card.playable { cursor: pointer; }
.your-turn button.card.playable:hover, .your-turn button.card.playable:focus-visible { transform: translateY(-12px); box-shadow: 0 10px 18px #000a; }
.your-turn button.card.unplayable { filter: brightness(.55) saturate(.6); }
button.card.selected { transform: translateY(-18px); outline: 3px solid var(--turn); outline-offset: 1px; }
button.card:disabled { color: inherit; }
button.card.hearts:disabled, button.card.diamonds:disabled { color: var(--red); }
.four-colour button.card.diamonds:disabled { color: var(--blue); }
.four-colour button.card.clubs:disabled { color: var(--green); }
button.card.spades:disabled, .card.dimmed { opacity: 1; }
.card.winner { box-shadow: 0 0 0 3px var(--turn), 0 0 18px #ffd66baa; }

/* ------------------------------------------------------------------ overlays on the table */

.overlay {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 10;
    width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow-y: auto;
    background: #0d1511f2; border: 2px solid var(--accent); border-radius: 14px;
    padding: 18px 22px; display: flex; flex-direction: column; gap: 10px;
    box-shadow: 0 16px 50px #000c;
}
.overlay h2 { color: var(--accent); font-size: 22px; }
.overlay p { margin: 0; }
.overlay .buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.overlay.start { text-align: left; }
.overlay .tips { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }

.cut-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.cut-card, .last-trick-card { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.last-trick { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin-bottom: 10px; }

.hand-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hand-side { background: var(--panel); border-radius: 10px; padding: 8px 12px; border-top: 3px solid; }
.hand-side.us { border-color: var(--us); }
.hand-side.them { border-color: var(--them); }

/* ------------------------------------------------------------------ dialogs */

.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: #000a; display: grid; place-items: center; padding: 16px; }
.modal {
    width: min(480px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column;
    background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 20px 60px #000;
    outline: none;
}
.modal.wide { width: min(680px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 18px; color: var(--accent); }
.modal-body { padding: 14px 18px; overflow-y: auto; }
.modal-body p { margin: 0 0 10px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }

.prose h3 { font-size: 16px; color: var(--accent); margin: 16px 0 6px; }
.prose h3:first-child { margin-top: 0; }
.prose p, .prose li { line-height: 1.5; }
.prose ul { margin: 0 0 10px; padding-left: 22px; }

.settings-group { border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 8px; }
.settings-group:last-child { border-bottom: none; margin-bottom: 0; }
.settings-group h3 { font-size: 15px; color: var(--accent); }
.settings-group fieldset { border: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.settings-group fieldset:disabled { opacity: .5; }
.field { display: grid; grid-template-columns: 170px minmax(0, 1fr) auto; align-items: center; gap: 10px; }
.field select, .field input[type=range] { width: 100%; }
.field output { font-size: 13px; color: var(--muted); min-width: 56px; text-align: right; }
select, .code-input {
    background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font: inherit;
}
input[type=range] { accent-color: var(--accent); }
.code-input { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 18px; letter-spacing: .05em; text-transform: uppercase; }
.error { color: #ff8a80; }
.not-found { padding: 40px; text-align: center; }
.not-found a { color: var(--accent); }

/* ------------------------------------------------------------------ narrower screens */

@media (max-width: 1180px) {
    .layout {
        grid-template-columns: minmax(0, 1fr) 260px;
        grid-template-areas: "table left" "table right";
        grid-template-rows: auto 1fr;
    }
    .left { flex-direction: row; flex-wrap: wrap; align-items: flex-start; }
    .left .panel { flex: 1 1 100%; }
    .left .board { width: 96px; max-height: none; }
    .left .scores { flex: 1; grid-template-columns: 1fr; gap: 8px; align-self: center; }
    .right { max-height: none; }
}

@media (max-width: 760px) {
    :root { --cw: min(15vw, 62px); --overlap: -0.42; }
    body { font-size: 14px; }
    .topbar { padding: 8px 12px; }
    .brand { font-size: 16px; }
    .actions { gap: 4px; }
    .actions .btn { padding: 6px 9px; font-size: 13px; white-space: nowrap; }
    .brand-suit { display: none; }
    .layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "table" "right" "left";
        grid-template-rows: auto;
        padding: 8px 0; gap: 10px;
    }
    .right, .left { padding: 0 16px; }
    .felt {
        min-height: min(640px, calc(100dvh - 110px));
        border-width: 6px; border-radius: 12px; padding: 40px 6px 12px;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) minmax(0, 1fr);
    }
    .seat-label { font-size: 12px; padding: 2px 8px; }
    .seat-w .backs, .seat-e .backs { display: none; }
    .slot-w { left: 12%; }
    .slot-e { left: 88%; }
    .trick-area { min-width: 0; min-height: calc(var(--ch) * 2.8); }
    .mobile-scores {
        display: flex; position: absolute; top: 8px; right: 10px; gap: 10px; align-items: center;
        background: #0009; border-radius: 999px; padding: 3px 12px; font-size: 13px; z-index: 3;
    }
    .mobile-scores .us { color: var(--us); }
    .mobile-scores .them { color: var(--them); }
    .table-buttons { left: 8px; top: 8px; }
    .banner { bottom: calc(var(--ch) + 46px); font-size: 13px; }
    .hand-summary { grid-template-columns: 1fr; }
    .field { grid-template-columns: 1fr; gap: 4px; }
    .field output { text-align: left; }
    .statusbar { padding: 6px 16px; font-size: 13px; }
    .statusbar .code-line { display: none; }
    .left .board { width: 80px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
