:root {
    --bg: #f4f1ea;
    --ink: #1d1d1f;
    --muted: #5d5d63;
    --panel: #ffffff;
    --rule: #ddd8cc;
    --felt: #1f6b45;
    --felt-dark: #154d31;
    --felt-ink: #f3f7f2;
    --card: #fffdf8;
    --card-edge: #c9c3b6;
    --red: #c3242b;
    --black: #1d1d1f;
    --hold: #ffd23f;
    --hold-ink: #3a2a00;
    --accent: #1f6b45;
    --bad: #b3261e;
    --best: #e9f5ec;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #16181a;
        --ink: #ececec;
        --muted: #a5a8ad;
        --panel: #202326;
        --rule: #34383c;
        --felt: #1a5539;
        --felt-dark: #103725;
        --accent: #6fcf97;
        --bad: #ff8a80;
        --best: #1d3326;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.container { max-width: 880px; margin: 0 auto; padding: 16px; }

header h1 { margin: 8px 0 4px; font-size: 1.9rem; }
header p { margin: 0 0 8px; color: var(--muted); }
header nav ul { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 0; margin: 0 0 16px; }
header nav a { color: var(--accent); }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---- the felt: input and cards ---- */
.table-felt {
    background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
    color: var(--felt-ink);
    border-radius: 16px;
    padding: 20px;
    box-shadow: inset 0 0 0 6px rgba(0, 0, 0, .18);
}

.field { margin-bottom: 12px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field--inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.field--inline label { margin: 0; }

#cards {
    width: 100%;
    font: 600 1.4rem/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    letter-spacing: .04em;
    padding: 10px 12px;
    border-radius: 8px;
    border: 2px solid transparent;
    background: #fffdf8;
    color: #1d1d1f;
}
#cards:focus { outline: none; border-color: var(--hold); }
#cards[aria-invalid="true"] { border-color: #ff8a80; }

select {
    font: inherit;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--rule);
}

.help { margin: 6px 0 0; font-size: .85rem; opacity: .85; }
.help code { background: rgba(255, 255, 255, .15); padding: 0 4px; border-radius: 4px; }

.btn {
    font: 700 1rem/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    padding: 10px 22px;
    border-radius: 999px;
    border: 0;
    background: var(--hold);
    color: var(--hold-ink);
    cursor: pointer;
    box-shadow: 0 2px 0 rgba(0, 0, 0, .25);
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:not(:disabled):hover { filter: brightness(1.06); }
.btn--quiet { background: transparent; color: var(--accent); box-shadow: none; padding: 8px 0; }

/* ---- cards ---- */
.hand {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: clamp(6px, 2vw, 14px);
    margin: 18px 0 8px;
}

.card {
    position: relative;
    aspect-ratio: 5 / 7;
    border-radius: clamp(6px, 1.4vw, 10px);
    background: var(--card);
    border: 1px solid var(--card-edge);
    box-shadow: 0 3px 8px rgba(0, 0, 0, .35);
    color: var(--black);
    font-family: Georgia, "Times New Roman", serif;
    transition: opacity .25s, transform .25s;
    user-select: none;
}
.card--red { color: var(--red); }

.card__corner {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
    font-weight: 700;
    font-size: clamp(.8rem, 3.4vw, 1.35rem);
}
.card__corner span:last-child { font-size: .9em; }
.card__corner--top { top: 6%; left: 8%; }
.card__corner--bottom { bottom: 6%; right: 8%; transform: rotate(180deg); }

.card__pip {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: clamp(1.6rem, 9vw, 3.8rem);
}

.card--empty {
    background: transparent;
    border: 2px dashed rgba(255, 255, 255, .35);
    box-shadow: none;
}
.card--bad {
    background: #fde8e6;
    border: 2px solid var(--bad);
    color: var(--bad);
    font-family: inherit;
}
.card--bad .card__pip { font-size: clamp(.8rem, 3vw, 1.1rem); text-align: center; padding: 8px; white-space: pre-line; }

/* After Calculate: held cards get a HOLD stamp, the rest fade back. */
.hand.is-decided .card:not(.is-held) { opacity: .45; transform: translateY(6px); }

.card__hold {
    position: absolute;
    left: -6%;
    right: -6%;
    top: 50%;
    padding: 4px 0;
    background: var(--hold);
    color: var(--hold-ink);
    font: 900 clamp(.85rem, 3.6vw, 1.45rem)/1 system-ui, sans-serif;
    letter-spacing: .14em;
    text-align: center;
    border: 2px solid var(--hold-ink);
    border-radius: 4px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
    transform: translateY(-50%) rotate(-12deg) scale(0);
    transition: transform .22s cubic-bezier(.3, 1.6, .5, 1);
}
.card.is-held .card__hold { transform: translateY(-50%) rotate(-12deg) scale(1); }

.hand-error { min-height: 1.5em; margin: 4px 0 0; color: #ffd1cc; font-weight: 600; }
.summary { margin: 4px 0 0; font-size: 1.1rem; }
.summary strong { color: var(--hold); }

/* ---- results ---- */
.panel {
    background: var(--panel);
    border: 1px solid var(--rule);
    border-radius: 12px;
    padding: 16px 20px;
    margin-top: 20px;
}
.panel h2 { margin: 0 0 4px; font-size: 1.3rem; }
.caption { margin: 0 0 12px; color: var(--muted); }

.scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--rule); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { font-size: .85rem; color: var(--muted); font-weight: 600; }
tfoot td { font-weight: 700; border-bottom: 0; }
.odds-table tr.is-zero td { color: var(--muted); }

.holds-table th:nth-child(2), .holds-table td:nth-child(2) { text-align: left; }
.holds-table tbody tr { cursor: pointer; }
.holds-table tbody tr:hover { background: var(--best); }
.holds-table tbody tr.is-selected { background: var(--best); box-shadow: inset 4px 0 0 var(--accent); }
.holds-table .mini { font-weight: 700; margin-right: 6px; }
.holds-table .mini--red { color: var(--red); }
@media (prefers-color-scheme: dark) {
    .holds-table .mini--red { color: #ff7b72; }
}

.notes p { margin: 8px 0; }

/* ---- Ko-fi ---- */
header nav a.ko-fi-nav-link { font-weight: 600; }
.footer {
    margin-top: 20px;
    padding: 20px;
    text-align: center;
    border-top: 1px solid var(--rule);
}
.footer h2 { margin: 0 0 4px; font-size: 1.1rem; }
.footer p { margin: 0 0 14px; color: var(--muted); }
.ko-fi-button { display: inline-block; text-decoration: none; }
