:root {
    --black: #1c1c1c;
    --red: #b3261e;
    --green: #2e6b3e;
    --bg: #f7f5f0;
}

/* Prevent CSS display rules from overriding the HTML hidden attribute */
[hidden] { display: none !important; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--black);
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem 1.5rem 3rem;
}

header h1 a {
    color: var(--black);
    text-decoration: none;
}

.back-link {
    display: inline-block;
    color: #555;
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.back-link:hover {
    text-decoration: underline;
}

.menu {
    list-style: none;
    padding: 0;
}

.menu li {
    margin: 0.5rem 0;
}

.menu li a {
    display: block;
    padding: 0.75rem 1rem;
    background: white;
    border-radius: 8px;
    text-decoration: none;
    color: var(--black);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.menu li.disabled {
    padding: 0.75rem 1rem;
    color: #999;
}

.hand {
    background: #0d3b2a;
    border-radius: 10px;
    padding: clamp(0.5rem, 3vw, 1.5rem) clamp(0.3rem, 2vw, 0.75rem);
    margin: 1rem 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-wrap: nowrap;
    width: 100%;
    /* size as a CSS container so cards/text can scale off *this* box's
       width, not the viewport, and so the whole hand always fits without
       scrolling, on phones and desktops alike */
    container-type: inline-size;
    gap: clamp(0.05rem, 0.6vw, 0.4rem);
    justify-content: center;
}

.suit-gap {
    /* fixed-width breathing room between suits; doesn't grow/shrink so
       every card gets an equal share of the remaining space */
    flex: 0 0 clamp(0.3rem, 2vw, 0.9rem);
}

.playing-card {
    position: relative;
    background: white;
    border-radius: 8px;
    aspect-ratio: 5 / 7;
    /* each of the 13 cards shrinks/grows equally to fill the row */
    flex: 1 1 0;
    min-width: 0;
    max-width: 3rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    font-weight: 800;
    line-height: 1.1;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.playing-card.highlight {
    transform: scale(1.18);
    box-shadow: 0 0 0 3px gold, 0 3px 6px rgba(0, 0, 0, 0.4);
    z-index: 1;
}

.points {
    position: absolute;
    top: -0.7rem;
    right: -0.7rem;
    background: gold;
    color: var(--black);
    font-size: clamp(0.75rem, 5.5cqw, 1.5rem);
    font-weight: 800;
    border-radius: 50%;
    width: clamp(1.5rem, 11cqw, 2.6rem);
    height: clamp(1.5rem, 11cqw, 2.6rem);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    border: 2px solid white;
    opacity: 0;
    transform: scale(0.4);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.playing-card.highlight .points {
    opacity: 1;
    transform: scale(1);
}

.count-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    min-height: 2.2rem;
}

.hcp-counter {
    background: white;
    padding: 0.3rem 0.7rem;
    border-radius: 6px;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.button.replay {
    background: #555;
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
}

.playing-card .rank {
    font-size: clamp(0.55rem, 4.2cqw, 1.4rem);
}

.playing-card .symbol {
    font-size: clamp(0.45rem, 3.4cqw, 1.2rem);
}

.playing-card.suit-H,
.playing-card.suit-D {
    color: var(--red);
}

.playing-card.suit-S,
.playing-card.suit-C {
    color: var(--black);
}

form {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin: 1rem 0;
}

input[type="number"] {
    font-size: 1.1rem;
    padding: 0.4rem 0.6rem;
    width: 5rem;
}

button, .button {
    font-size: 1rem;
    padding: 0.5rem 1.1rem;
    background: var(--green);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

.secondary-btn {
    background: #8b5e3c;
}

.bid-buttons {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.5rem;
    margin: 1rem 0;
}

.bid-btn {
    flex: 1 1 auto;
    min-width: 3rem;
    font-size: clamp(0.85rem, 3.5vw, 1.3rem);
    font-weight: 800;
    padding: 0.65rem 0.5rem;
    text-align: center;
    border-radius: 8px;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.bid-nt      { background: #777; }
.bid-2nt              { background: #777; }
.bid-3nt              { background: #2a5298; }
.bid-3nt:disabled     { background: #bbb; cursor: not-allowed; opacity: 0.5; }
.bid-stop             { background: #cc0000; }
.bid-stop.stop-active { background: #880000; outline: 3px solid #ff6666; }

.stop-banner {
    background: #cc0000;
    color: white;
    font-size: 1.6rem;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-align: center;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    margin: 0.75rem 0 0.5rem;
}
.bid-spade   { background: #1c1c1c; }
.bid-heart   { background: var(--red); }
.bid-diamond { background: #e07b00; }
.bid-club    { background: #2a5298; }
.bid-pass    { background: var(--green); }

.balance-buttons {
    display: flex;
    gap: 1rem;
    margin: 1rem 0;
}

.balance-buttons .button {
    flex: 1;
    text-align: center;
    font-size: 1.1rem;
    padding: 0.75rem;
}

details.help {
    margin-bottom: 0.75rem;
}

details.help summary {
    display: inline-block;
    cursor: pointer;
    background: #555;
    color: white;
    padding: 0.35rem 0.85rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    list-style: none;
}

details.help summary::-webkit-details-marker { display: none; }

details.help[open] summary {
    margin-bottom: 0.5rem;
}

details.help p,
details.help > :not(summary) {
    background: white;
    border-radius: 8px;
    padding: 0.6rem 0.9rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    font-size: 0.95rem;
    display: block;
}

.shape-breakdown {
    background: white;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin: 0.75rem 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    font-size: 0.95rem;
}

.shape-breakdown p {
    margin: 0.25rem 0;
}

.result {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin: 1rem 0;
    font-weight: 600;
}

.result.correct {
    background: #e3f3e6;
    color: var(--green);
}

.result.incorrect {
    background: #fbe9e7;
    color: var(--red);
}

.stats {
    margin-top: 2rem;
    color: #666;
    font-size: 0.9rem;
}

/* Compact layout for short viewports (phones in landscape) so everything
   fits without vertical scrolling. */
@media (max-height: 500px) {
    body {
        padding: 0.5rem 1rem 1rem;
    }

    header h1 {
        font-size: 1.1rem;
        margin: 0 0 0.25rem;
    }

    h2 {
        font-size: 1rem;
        margin: 0.25rem 0;
    }

    .instructions {
        display: none;
    }

    .hand {
        margin: 0.5rem 0;
        padding: clamp(0.3rem, 2vw, 0.6rem);
    }

    .playing-card {
        max-width: 2.4rem;
    }

    form {
        margin: 0.5rem 0;
    }

    .result {
        margin: 0.5rem 0;
        padding: 0.5rem 0.75rem;
    }

    .stats {
        margin-top: 0.75rem;
        font-size: 0.8rem;
    }
}
