/* ===== Reset & base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --felt: #0d3b2a;
    --felt-dark: #072318;
    --line: rgba(255, 255, 255, 0.16);
    --text: #eef7f2;
    --muted: #8fb3a4;
    --gold: #ffd76a;
    --red: #d8332f;
    --black: #1c1c28;
    --card-radius: 6px;
}

html, body { height: 100%; overscroll-behavior: none; }

body {
    position: fixed;
    inset: 0;
    overflow: hidden;
    color: var(--text);
    font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Segoe UI', sans-serif;
    background:
        radial-gradient(circle at 50% 12%, #14543b, transparent 62%),
        linear-gradient(160deg, var(--felt) 0%, var(--felt-dark) 100%);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 100dvh;
    /* Seven cards at their largest come to about 960px; past that the extra
       width becomes margin rather than bigger cards, and the toolbar and the
       score line stay lined up with the table instead of running off to the
       edges of a desktop screen. */
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
    padding:
        max(6px, env(safe-area-inset-top))
        max(6px, env(safe-area-inset-right))
        max(6px, env(safe-area-inset-bottom))
        max(6px, env(safe-area-inset-left));
}

/* ===== Toolbar ===== */
.toolbar { display: flex; align-items: center; gap: 5px; flex: 0 0 auto; height: 38px; }
.toolbar-spacer { flex: 1; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 31px;
    padding: 0 9px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: rgba(0, 0, 0, 0.24);
    color: var(--text);
    font-family: inherit;
    font-size: 0.86rem;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.icon-btn-text { font-size: 0.76rem; font-weight: 600; }
.icon-btn:active { transform: scale(0.94); border-color: var(--gold); }
.icon-btn:disabled { opacity: 0.4; }

/* ===== HUD ===== */
.hud {
    display: flex;
    gap: 6px;
    flex: 0 0 auto;
    margin: 5px 0 4px;
}

.hud span {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 3px 2px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.2);
}

.hud b { font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.hud i { font-style: normal; font-size: 0.58rem; letter-spacing: 0.08em; color: var(--muted); }

/* ===== Board ===== */
.board { position: relative; flex: 1 1 auto; min-height: 0; }
.slots, .cards { position: absolute; inset: 0; }

.slot {
    position: absolute;
    border: 1px dashed var(--line);
    border-radius: var(--card-radius);
    background: rgba(0, 0, 0, 0.16);
}

.slot-mark {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.18);
}

.slot.is-target { border-color: var(--gold); border-style: solid; background: rgba(255, 215, 106, 0.12); }

/* ===== Cards ===== */
.card {
    position: absolute;
    top: 0;
    left: 0;
    border-radius: var(--card-radius);
    background: #fdfdfa;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
    will-change: transform;
    transition: transform 0.17s cubic-bezier(0.22, 0.7, 0.3, 1);
    overflow: hidden;
    cursor: pointer;
}

.card.is-dragging { transition: none; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55); }
.card.no-anim { transition: none; }

.card-face {
    position: absolute;
    inset: 0;
    font-weight: 800;
    line-height: 1;
}

.card.is-red .card-face { color: var(--red); }
.card.is-black .card-face { color: var(--black); }

/* The index lives in the corner and again upside down in the opposite one,
   the way it does on a real card. */
.index {
    position: absolute;
    left: var(--idx-pad, 3px);
    top: var(--idx-pad, 3px);
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.02;
}
.index.is-flipped {
    left: auto; top: auto;
    right: var(--idx-pad, 3px);
    bottom: var(--idx-pad, 3px);
    transform: rotate(180deg);
}
.index .rank { font-size: var(--rank-size, 13px); }
.index .rank.is-wide { font-size: calc(var(--rank-size, 13px) * 0.84); letter-spacing: -0.06em; }
.index .suit { font-size: var(--suit-size, 11px); }

.pip {
    position: absolute;
    transform: translate(-50%, -50%);
    font-size: var(--pip-size, 9px);
    line-height: 1;
}
.pip.is-flipped { transform: translate(-50%, -50%) rotate(180deg); }

.ace {
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    font-size: var(--ace-size, 22px);
    line-height: 1;
}

.court {
    position: absolute;
    left: 22%; right: 22%; top: 20%; bottom: 20%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.12em;
    border: 1px solid currentColor;
    border-radius: 3px;
    opacity: 0.92;
}
.court-letter { font-size: var(--court-size, 20px); line-height: 1; }
.court-suit { font-size: calc(var(--court-size, 20px) * 0.62); line-height: 1; }

.card-back {
    position: absolute;
    inset: 0;
    border-radius: var(--card-radius);
    background:
        repeating-linear-gradient(45deg, #2b4f8f 0 5px, #24427a 5px 10px);
    box-shadow: inset 0 0 0 2px #f2f4f8, inset 0 0 0 3px #24427a;
}

.card.is-hint { animation: nudge 0.5s ease; }

@keyframes nudge {
    0%, 100% { filter: none; }
    50% { filter: brightness(1.5); }
}

/* ===== Action bar ===== */
.action-bar {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding-top: 5px;
}

.btn {
    min-height: 44px;
    padding: 11px 26px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: rgba(0, 0, 0, 0.28);
    color: var(--text);
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.12s ease;
}

.btn:active { transform: scale(0.97); }
.btn[hidden] { display: none; }
.btn-primary { border-color: transparent; background: linear-gradient(135deg, #ffd76a, #f5a623); color: #2a1c00; }
.btn-secondary { border-color: var(--line); }

.hint { font-size: 0.68rem; color: var(--muted); text-align: center; }

/* ===== Win overlay ===== */
.overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(3, 16, 11, 0.88);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 500;
}

.overlay.is-open { display: flex; }

.panel {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 11px;
    padding: 22px 18px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: linear-gradient(180deg, #10422f, #08281c);
    text-align: center;
    animation: pop 0.24s ease;
}

@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(0.97); } to { opacity: 1; transform: none; } }

.panel-title {
    font-size: 1.7rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    color: var(--gold);
}

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.stat { padding: 9px 6px; border-radius: 11px; background: rgba(255, 255, 255, 0.07); }
.stat b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.64rem; color: var(--muted); }

@media (max-height: 620px) {
    .hud { margin: 3px 0 2px; }
    .hud b { font-size: 0.82rem; }
    .hint { display: none; }
    .btn { min-height: 40px; padding: 9px 22px; }
}

@media (prefers-reduced-motion: reduce) {
    .card { transition: none; }
    .panel { animation: none; }
}

/* Face-down cards show the back and nothing else. */
.card.is-down .card-face { display: none; }
.card:not(.is-down) .card-back { display: none; }
