/* Royal Spades web — studio design language.
   Deep navy-black #060A13, cyan-to-violet gradient, gold ONLY for
   currency / rewards / tier progression. Green felt table, as in the
   phone app. Cinzel for display, Inter for body (Google Fonts, with
   system fallbacks if offline). No other external assets. */
:root {
    --bg: #060a13;
    --panel: #0c1424;
    --panel-2: #101c33;
    --line: #1e2c47;
    --text: #e8eefc;
    --muted: #8b99b5;
    --cyan: #22d3ee;
    --violet: #8b5cf6;
    --gold: #d4af37;
    --red: #e5484d;
    --green: #34d399;
    /* Card size is capped by BOTH width and viewport height so the whole
       game fits one phone screen with no page scroll (360x800 target). */
    --card-w: clamp(38px, min(12vw, 7dvh), 62px);
    --card-h: calc(var(--card-w) * 1.42);
    --display: "Cinzel", "Times New Roman", serif;
    --body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0; padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--body);
    height: 100%;
    overflow: hidden; /* the game never scrolls the page — see #app */
}

body {
    background:
        radial-gradient(120% 60% at 50% -10%, rgba(139, 92, 246, 0.16), transparent 60%),
        radial-gradient(100% 50% at 50% 110%, rgba(34, 211, 238, 0.10), transparent 60%),
        var(--bg);
}

/* The whole game surface lives in exactly one viewport: header,
   scoreboard, table, hand — no vertical page scroll mid-match. */
#app {
    max-width: 640px; margin: 0 auto; position: relative;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    padding-top: calc(8px + env(safe-area-inset-top));
    height: 100vh; height: 100dvh;
    overflow: hidden;
    display: flex; flex-direction: column;
}

/* ------------------------------------------------------------------ header */
header { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.logo {
    flex: 1; text-align: center;
    font-family: var(--display); font-size: 26px; font-weight: 900; letter-spacing: 0.14em;
    background: linear-gradient(90deg, var(--cyan), var(--violet));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo small { font-family: var(--body); font-size: 11px; font-weight: 600; letter-spacing: 0.28em; display: block; color: var(--muted); -webkit-text-fill-color: var(--muted); }
#motion-toggle {
    flex: 0 0 auto; min-height: 44px; padding: 0 10px; border-radius: 999px;
    border: 1px solid var(--line); background: var(--panel); color: var(--muted);
    font-family: var(--body); font-size: 11px; font-weight: 700; cursor: pointer;
}
.tier-badge {
    display: block; width: max-content; margin: 4px auto 0; padding: 4px 12px; border-radius: 999px;
    border: 1px solid rgba(212, 175, 55, 0.55); color: var(--gold);
    font-size: 12px; font-weight: 700; letter-spacing: 0.08em;
}
.tier-badge .sub { color: var(--muted); font-weight: 500; letter-spacing: 0; }

/* Phase label, as in the app: gold Cinzel, e.g. BIDDING PHASE. */
#phase-label {
    font-family: var(--display); font-weight: 900; text-align: center;
    font-size: 18px; letter-spacing: 0.14em; color: var(--gold);
    min-height: 24px; margin-top: 4px;
}
#phase-label:empty { display: none; }

/* -------------------------------------------------------------- scoreboard */
#scoreboard {
    display: flex; gap: 8px; margin: 8px 0;
}
.score-box {
    flex: 1; background: var(--panel); border: 1px solid var(--line);
    border-radius: 12px; padding: 6px 10px; text-align: center;
}
.score-box .team { font-size: 11px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.score-box .pts { font-family: var(--display); font-size: 24px; font-weight: 900; line-height: 1.1; display: inline-block; }
.score-box .pts.score-pop { animation: score-pop 0.45s ease both; }
.score-box .bids { font-size: 12px; color: var(--muted); margin-top: 2px; }
.score-box .bags { font-size: 11px; color: var(--muted); }
.score-box.you { border-color: rgba(34, 211, 238, 0.45); }
.score-box .target { font-size: 11px; color: var(--muted); }
#round-info { text-align: center; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
#round-info b { color: var(--text); }

/* ------------------------------------------------------------------- table */
#table {
    /* Green felt, as in the phone app. */
    background:
        radial-gradient(120% 90% at 50% 0%, rgba(52, 211, 153, 0.14), transparent 55%),
        linear-gradient(160deg, #0d3a24, #072a17 70%);
    border: 1px solid #1d4d33; border-radius: 16px;
    padding: 8px; position: relative;
    flex: 1 1 auto; min-height: 0;
    display: flex; flex-direction: column; justify-content: space-between;
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.45);
}
.opp-row { display: flex; justify-content: space-between; align-items: flex-start; min-height: 56px; }
#table .opp-row:first-child { justify-content: center; }
.opp { display: flex; align-items: center; gap: 8px; min-width: 0; position: relative; }
.opp .avatar {
    width: 40px; height: 40px; border-radius: 50%; flex: 0 0 40px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 18px; color: #06121f;
    background: linear-gradient(135deg, var(--cyan), var(--violet));
}
/* Team rings, as in the app: partner cyan, opponents violet. */
.opp.partner .avatar { box-shadow: 0 0 0 2px var(--cyan), 0 0 14px rgba(34, 211, 238, 0.45); }
.opp.foe .avatar { box-shadow: 0 0 0 2px var(--violet), 0 0 14px rgba(139, 92, 246, 0.35); }
.opp .dealer-badge {
    position: absolute; top: -4px; right: -4px; width: 18px; height: 18px;
    border-radius: 50%; background: var(--gold); color: #06121f;
    font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center;
}
.opp .who { min-width: 0; }
.opp .name { font-weight: 700; font-size: 14px; white-space: nowrap; }
.opp .nick { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.opp .bid { font-size: 12px; color: var(--text); margin-top: 1px; }
.opp .bid .nil { color: var(--gold); font-weight: 700; }
.opp .backs { display: flex; align-items: center; gap: 4px; margin-left: 2px; }
.mini-back {
    width: 16px; height: 23px; border-radius: 3px;
    background: repeating-linear-gradient(45deg, #16233d 0 3px, #1d2f52 3px 6px);
    border: 1px solid #2b3f63;
}
.opp.turn .avatar { outline: 2px solid var(--cyan); outline-offset: 2px; }
.opp.west { flex-direction: row; }
.opp.east { flex-direction: row-reverse; text-align: right; }
.opp.east .who { text-align: right; }

#trick-area {
    display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: auto auto auto;
    gap: 2px; align-items: center; justify-items: center;
    min-height: calc(var(--card-h) * 2 + 40px); padding: 2px 0;
}
.trick-slot { width: var(--card-w); height: var(--card-h); display: flex; align-items: center; justify-content: center; }
.trick-slot.north { grid-column: 2; grid-row: 1; }
.trick-slot.west { grid-column: 1; grid-row: 2; }
.trick-slot.east { grid-column: 3; grid-row: 2; }
.trick-slot.south { grid-column: 2; grid-row: 3; }
.trick-center { grid-column: 2; grid-row: 2; text-align: center; }
#spades-flag { font-size: 12px; color: var(--muted); }
#spades-flag.broken { color: var(--cyan); font-weight: 700; }
#message { font-size: 13px; color: var(--text); min-height: 34px; display: flex; align-items: center; justify-content: center; text-align: center; padding: 0 6px; }
#message .hint { color: var(--muted); font-size: 12px; }

/* ------------------------------------------------------------------- cards */
.card {
    width: var(--card-w); height: var(--card-h); border-radius: 8px;
    background: linear-gradient(160deg, #ffffff, #e6e9f2);
    color: #101828; position: relative; flex: 0 0 auto;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
    user-select: none;
}
.card.red { color: var(--red); }
.card .corner { position: absolute; top: 3px; left: 5px; font-weight: 800; font-size: calc(var(--card-w) * 0.26); line-height: 1; text-align: center; }
.card .corner .s { display: block; font-size: calc(var(--card-w) * 0.30); }
.card .pip { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: calc(var(--card-w) * 0.58); }
.card.trick-winner { outline: 3px solid var(--gold); outline-offset: 1px; animation: winner-pulse 1s ease-in-out infinite; }
/* Hidden while its flying clone travels; revealed when the flight lands. */
.card.flying-hidden { visibility: hidden; }
/* Staggered deal: cards arrive one at a time from the deck. */
.card.deal-in { animation: deal-in 0.38s cubic-bezier(0.22, 0.9, 0.3, 1.05) both; }
.mini-back.deal-in { animation: deal-in 0.3s ease both; }
/* A played card's travelling clone. Transform-only motion (GPU-friendly). */
#fly-layer { position: absolute; inset: 0; pointer-events: none; z-index: 60; overflow: visible; }
.fly-card {
    position: absolute; left: 0; top: 0; margin: 0; z-index: 60;
    pointer-events: none; will-change: transform;
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.6);
}
@keyframes deal-in {
    from { opacity: 0; transform: translateY(-18px) scale(0.92); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes winner-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(212, 175, 55, 0.55); }
    50% { box-shadow: 0 0 14px 3px rgba(212, 175, 55, 0.45); }
}
@keyframes score-pop {
    0% { transform: scale(1.3); color: var(--gold); }
    100% { transform: scale(1); }
}
@keyframes bid-pop {
    0% { transform: scale(1.45); }
    100% { transform: scale(1); }
}
@keyframes sheet-in {
    from { opacity: 0; transform: translateY(14px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.bid-pop { animation: bid-pop 0.35s ease both; }
.card-back {
    width: var(--card-w); height: var(--card-h); border-radius: 8px;
    background: repeating-linear-gradient(45deg, #12233f 0 6px, #1a2f55 6px 12px);
    border: 1px solid #33507e; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
    display: flex; align-items: center; justify-content: center;
    color: var(--cyan); font-size: calc(var(--card-w) * 0.42);
}
#hand-area { margin-top: 8px; flex: 0 0 auto; }
#hand-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; justify-content: space-between; }
#hand-label b { color: var(--text); }
#hand { display: flex; justify-content: center; flex-wrap: nowrap; min-height: var(--card-h); padding: 4px 0 2px; }
#hand .card { margin-left: calc(var(--card-w) * -0.5); cursor: pointer; transition: transform 0.12s ease; }
#hand .card:first-child { margin-left: 0; }
#hand .card.playable:hover, #hand .card.playable:active { transform: translateY(-12px); }
/* Selection must be UNMISTAKABLE: raised high, thick cyan ring, glow. */
#hand .card.selected {
    transform: translateY(-16px) scale(1.04);
    outline: 3px solid var(--cyan); outline-offset: 1px;
    box-shadow: 0 8px 18px rgba(34, 211, 238, 0.45);
}
#hand .card.illegal { filter: brightness(0.55); cursor: not-allowed; }
#hand .card.legal-glow { outline: 2px solid rgba(34, 211, 238, 0.65); animation: glow-pulse 1.6s ease-in-out infinite; }
@keyframes glow-pulse {
    0%, 100% { outline-color: rgba(34, 211, 238, 0.35); }
    50% { outline-color: rgba(34, 211, 238, 0.9); }
}
/* Clear Play affordance: appears when a card is selected (tap-again still works). */
#play-btn {
    display: none; width: 100%; min-height: 48px; margin-top: 6px;
    border: none; border-radius: 12px; cursor: pointer;
    font-family: var(--body); font-size: 16px; font-weight: 800; color: #06121f;
    background: linear-gradient(90deg, var(--cyan), var(--violet));
}
#play-btn.show { display: block; animation: sheet-in 0.2s ease both; }
#play-btn:active { filter: brightness(1.15); }

/* --------------------------------------------------------------- bid panel */
#bid-panel { display: none; margin-top: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
#bid-panel.open { display: block; }
#bid-panel .title { font-family: var(--display); font-size: 15px; font-weight: 900; letter-spacing: 0.08em; margin-bottom: 8px; text-align: center; color: var(--gold); }
#bid-panel .title span { color: var(--gold); }
.bid-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
/* Round buttons, as in the app: violet circles, red NIL pill. */
.bid-btn {
    min-height: 44px; aspect-ratio: 1; border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--violet); color: #fff; font-size: 16px; font-weight: 700;
    cursor: pointer; font-family: inherit;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.1s ease;
}
.bid-btn:active { transform: scale(0.92); filter: brightness(1.2); }
.bid-btn.nil { background: var(--red); border-radius: 999px; aspect-ratio: auto; grid-column: span 1; color: #fff; border-color: rgba(212, 175, 55, 0.5); }
/* While bidding, the banner ad hides and cards shrink so the panel fits. */
#app.bidding .ad-slot { display: none; }
#app.bidding { --card-w: clamp(34px, min(10.5vw, 6dvh), 54px); }

/* ---------------------------------------------------------------- ad slots */
.ad-slot {
    margin: 8px 0; min-height: 48px; flex: 0 0 auto; border: 1px dashed #2b3f63; border-radius: 10px;
    background: rgba(12, 20, 36, 0.6); display: flex; flex-direction: column;
    align-items: center; justify-content: center; padding: 6px; text-align: center;
}
.ad-slot .ad-slot-label {
    font-size: 10px; letter-spacing: 0.22em; color: var(--muted); text-transform: uppercase;
}
.ad-slot .ad-slot-note { font-size: 11px; color: var(--muted); margin-top: 3px; max-width: 420px; }
.ad-slot.interstitial-ad { min-height: 110px; margin: 12px 0; }
.ad-slot-error .ad-slot-label { color: var(--red); }

/* ---------------------------------------------------------------- overlays */
#overlay {
    position: fixed; inset: 0; background: rgba(3, 6, 12, 0.88);
    display: none; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
#overlay.open { display: flex; }
/* Start screen: light backdrop so the dealt table stays visible behind
   the sheet — the first screen must read as the game itself. */
#overlay.light { background: rgba(3, 6, 12, 0.55); backdrop-filter: blur(2px); }
.sheet {
    background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
    max-width: 480px; width: 100%; max-height: 92vh; max-height: 92dvh; overflow-y: auto; padding: 20px;
    animation: sheet-in 0.28s ease both;
}
.sheet h2 { margin: 0 0 4px; font-family: var(--display); font-size: 22px; font-weight: 900; letter-spacing: 0.06em; text-align: center; }
.sheet h2 .grad { background: linear-gradient(90deg, var(--cyan), var(--violet)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sheet .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.sheet .gold { color: var(--gold); font-weight: 700; }
.stats { width: 100%; border-collapse: collapse; font-size: 14px; margin: 10px 0; }
.stats td, .stats th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: center; }
.stats td:first-child, .stats th:first-child { text-align: left; }
.stats th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.progress-wrap { margin: 12px 0 4px; }
.progress-wrap .lbl { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.progress-wrap .lbl b { color: var(--gold); }
.progress { height: 10px; border-radius: 999px; background: #16233d; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--cyan), var(--violet)); border-radius: 999px; }
.btn {
    display: block; width: 100%; min-height: 52px; margin-top: 12px; border: none; border-radius: 12px;
    font-size: 17px; font-weight: 800; font-family: inherit; cursor: pointer; color: #06121f;
    background: linear-gradient(90deg, var(--cyan), var(--violet));
}
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn:active { filter: brightness(1.15); }
.fine { font-size: 11px; color: var(--muted); text-align: center; margin-top: 10px; line-height: 1.5; }
.tier-list { font-size: 13px; line-height: 1.9; margin: 8px 0; }
.tier-list .cur { color: var(--gold); font-weight: 700; }
.tier-list .done { color: var(--green); }

@media (min-width: 560px) {
    :root { --card-w: 68px; }
    .logo { font-size: 30px; }
}

/* Calm motion sheds DECORATION only — hover lift, glows, pulses, sheet
   entrances. Core motion (deal, card flight, trick sweep, score count-up)
   always plays, at every tier. */
body.reduced-motion #hand .card.playable:hover,
body.reduced-motion #hand .card.playable:active { transform: none; }
body.reduced-motion #hand .card.legal-glow { animation: none; }
body.reduced-motion .card.trick-winner { animation: none; }
body.reduced-motion .sheet { animation: none; }
body.reduced-motion #play-btn.show { animation: none; }
