* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --card-w: 99px;
    --card-h: 140px;
}

/* ── Full-viewport canvas ──────────────────────────────────────────────────── */

body {
    background-color: #c8b020;
    background-image: url('assets/cover.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(65, 60, 0, 0.28);
    pointer-events: none;
    z-index: 0;
}

/* ── Touch / tablet support ────────────────────────────────────────────────── */
/* manipulation keeps tap + pinch-zoom but kills double-tap zoom, so rapid card
   taps (selecting a set/run) register as taps instead of zooming. */
html, body {
    touch-action: manipulation;
    overscroll-behavior: none;            /* no pull-to-refresh / rubber-band bounce */
    -webkit-tap-highlight-color: transparent;
}
.card, .card-stack, button, .restart-btn, .deckades-logo {
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;          /* no long-press image/text callout on cards */
}

#game {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    z-index: 1;
    font-family: 'Fredoka', 'Noto Sans JP', sans-serif;
    color: white;
    touch-action: none;
}

/* ── Header bar ────────────────────────────────────────────────────────────── */

#game-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 14px;
    background: rgba(0, 0, 0, 0.30);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    z-index: 300;
}

/* ── Deckades logo ─────────────────────────────────────────────────────────── */

.deckades-logo {
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: clamp(14px, 1.6vw, 20px);
    letter-spacing: 0.12em;
    color: rgba(240,234,216,0.60);
    text-decoration: none;
    user-select: none;
    transition: color 0.2s;
}
.deckades-logo:hover { color: rgba(240,234,216,0.90); }
.deckades-spade {
    color: rgba(220,195,55,0.75);
    font-size: 1.2em;
    vertical-align: 1px;
    transition: color 0.2s;
}
.deckades-logo:hover .deckades-spade { color: rgba(240,215,70,0.9); }

/* ── Rules button ────────────────────────────────────────────────────────────── */

#rules-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid rgba(220, 195, 55, 0.65);
    color: rgba(240, 215, 70, 0.85);
    font-size: 18px;
    line-height: 42px;
    text-align: center;
    cursor: pointer;
    padding: 0;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
#rules-btn:hover {
    background: rgba(200, 170, 30, 0.18);
    color: rgba(255, 230, 80, 1.0);
    border-color: rgba(240, 215, 70, 0.95);
}

/* ── Header right cluster (AI indicator + rules button) ─────────────────────── */

#header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ── Live ranking table (top-right) ─────────────────────────────────────────── */

#ranking-table {
    position: fixed;
    top: 52px;
    right: 14px;
    width: 168px;
    z-index: 200;
    pointer-events: none;
    user-select: none;
    font-family: 'Fredoka', sans-serif;
}
#ranking-table .rank-row {
    position: absolute;
    left: 0;
    right: 0;
    height: 34px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 12px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(220, 195, 55, 0.18);
    color: rgba(240, 234, 216, 0.85);
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    transition: top 380ms cubic-bezier(.45, .1, .3, 1), border-color 0.2s, background 0.2s;
}
#ranking-table .rank-row.active-player {
    border-color: rgba(240, 215, 70, 0.85);
    background: rgba(40, 30, 0, 0.70);
}
#ranking-table .rank-place {
    font-size: 11px;
    font-weight: 600;
    color: rgba(220, 195, 55, 0.75);
    min-width: 18px;
    text-align: left;
}
#ranking-table .rank-row.active-player .rank-place { color: rgba(255, 230, 80, 1); }
#ranking-table .rank-name {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: rgba(240, 234, 216, 0.85);
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#ranking-table .rank-row.active-player .rank-name { color: rgba(255, 255, 240, 1); }
#ranking-table .rank-score {
    font-size: 16px;
    font-weight: 700;
    color: rgba(255, 215, 90, 0.95);
    min-width: 26px;
    text-align: right;
}

/* ── AI indicator ──────────────────────────────────────────────────────────── */

#ai-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px 3px 8px;
    border-radius: 12px;
    font-family: 'Fredoka', sans-serif;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    background: rgba(0, 0, 0, 0.30);
    border: 1px solid rgba(220, 195, 55, 0.18);
    color: rgba(240, 234, 216, 0.70);
    user-select: none;
    cursor: default;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}
#ai-indicator::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(180, 180, 180, 0.5);
    box-shadow: 0 0 6px rgba(180, 180, 180, 0.4);
}
#ai-indicator.ai-pending::before { background: rgba(220, 195, 55, 0.85); box-shadow: 0 0 6px rgba(220, 195, 55, 0.55); }
#ai-indicator.ai-onnx {
    color: rgba(140, 240, 160, 0.95);
    border-color: rgba(140, 240, 160, 0.45);
}
#ai-indicator.ai-onnx::before { background: rgba(140, 240, 160, 0.95); box-shadow: 0 0 8px rgba(140, 240, 160, 0.7); }
#ai-indicator.ai-heuristic {
    color: rgba(220, 180, 110, 0.95);
    border-color: rgba(220, 180, 110, 0.35);
}
#ai-indicator.ai-heuristic::before { background: rgba(220, 180, 110, 0.9); box-shadow: 0 0 6px rgba(220, 180, 110, 0.5); }

#rules-popup {
    position: fixed;
    right: 14px;
    top: 46px;
    background: rgba(40, 30, 0, 0.95);
    border: 1px solid rgba(220, 195, 55, 0.45);
    border-radius: 8px;
    padding: 12px 34px 12px 14px;
    color: rgba(240, 234, 216, 0.75);
    font-size: 12px;
    letter-spacing: 0.4px;
    z-index: 500;
    min-width: 160px;
    line-height: 1.5;
    pointer-events: auto;
}
#rules-popup-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: transparent;
    border: none;
    color: rgba(180, 148, 60, 0.55);
    font-size: 13px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.15s;
}
#rules-popup-close:hover { color: rgba(180, 148, 60, 0.95); }
#rules-popup a {
    display: inline-block;
    margin-top: 6px;
    color: rgba(180, 148, 60, 0.9);
    text-decoration: underline;
    cursor: pointer;
    font-size: 11px;
}

/* ── Board ──────────────────────────────────────────────────────────────────── */

#board {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(860px, 94vw);
    height: min(560px, 68vh);
    display: grid;
    grid-template-columns: 130px 1fr 130px;
    grid-template-rows: 1fr 2fr 1fr;
    gap: 6px;
    padding: 8px;
    background: rgba(0,0,0,0.38);
    border-radius: 18px;
    border: 1px solid rgba(255,255,255,0.07);
    box-shadow: 0 0 60px rgba(0,0,0,0.5), inset 0 0 30px rgba(0,0,0,0.2);
    z-index: 5;
}

/* ── Play zones — invisible positioning targets for card animations ─────────── */

.play-zone {
    position: relative;
    overflow: visible;
}

#play-zone-1 { grid-column: 1; grid-row: 2; }
#play-zone-2 { grid-column: 2; grid-row: 1; }
#middle-area { grid-column: 2; grid-row: 2; }
#play-zone-3 { grid-column: 3; grid-row: 2; }
#play-zone-0 { grid-column: 2; grid-row: 3; }

/* ── Middle / claim area ────────────────────────────────────────────────────── */

#middle-area {
    background: rgba(0,0,0,0.22);
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.08);
    position: relative;
    align-self: center;
    justify-self: center;
    overflow: visible;
    /* Fixed size: holds 4 full-size card stacks + gaps + padding */
    width: calc(var(--card-w) * 4 + 48px);
    height: calc(var(--card-h) + 40px);
}

#middle-row {
    position: absolute;
    inset: 0;
}

#middle-area.claiming {
    border-color: rgba(255, 210, 60, 0.6);
    animation: claim-glow 1.6s ease-in-out infinite;
}

@keyframes claim-glow {
    0%, 100% { box-shadow: 0 0 14px 3px rgba(255, 200, 40, 0.35), inset 0 0 20px rgba(0,0,0,0.2); }
    50%       { box-shadow: 0 0 28px 8px rgba(255, 200, 40, 0.65), inset 0 0 20px rgba(0,0,0,0.2); }
}

/* ── Cards ──────────────────────────────────────────────────────────────────── */

.card {
    border-radius: 7px;
    border: 2px solid rgba(255,255,255,0.2);
    user-select: none;
    flex-shrink: 0;
    box-shadow: 1px 2px 6px rgba(0,0,0,0.45);
    transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
    background-size: cover;
    background-position: center;
    width: var(--card-w);
    height: var(--card-h);
}

.card.small {
    width: calc(var(--card-w) * 0.77);
    height: calc(var(--card-h) * 0.77);
    border-radius: 5px;
}

.card.in-hand { cursor: pointer; }
.card.in-hand:hover:not(.selected) {
    filter: brightness(1.18);
    border-color: rgba(255,255,255,0.5);
    z-index: 100 !important;
}
.card.selected {
    transform: translateY(-18px);
    border-color: gold;
    box-shadow: 0 0 0 2px gold, 1px 14px 20px rgba(0,0,0,0.65);
    z-index: 100 !important;
}
.card.inactive {
    opacity: 0.55;
    cursor: default;
}

/* ── Trick type label ───────────────────────────────────────────────────────── */

.trick-type-label {
    position: absolute;
    bottom: 4px;
    right: 6px;
    font-size: 9px;
    opacity: 0.42;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    pointer-events: none;
}


/* ── Play button ─────────────────────────────────────────────────────────────── */

#play-btn {
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    padding: 12px 28px;
    min-height: 44px;
    font-size: 0.9rem;
    font-weight: bold;
    background: #27ae60;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    letter-spacing: 0.04em;
    white-space: nowrap;
    touch-action: manipulation;
}
#play-btn:disabled {
    opacity: 0.22;
    cursor: default;
    background: #555;
}
#play-btn:not(:disabled):hover { background: #2ecc71; }

/* ── Modal ──────────────────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: linear-gradient(155deg, #201e00 0%, #353200 55%, #161400 100%);
    border-radius: 16px;
    padding: 44px 56px 40px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-width: 360px;
    border: 1px solid rgba(240,210,70,0.45);
    box-shadow: 0 0 80px rgba(0,0,0,0.75), 0 0 30px rgba(200,160,0,0.15), inset 0 1px 0 rgba(255,255,255,0.05);
}

.modal-eyebrow {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.78rem;
    letter-spacing: 0.30em;
    text-transform: uppercase;
    color: rgba(255,224,70,0.60);
}

.modal-content h2 {
    font-family: 'Fredoka', sans-serif;
    font-size: 2.6rem;
    font-weight: 700;
    color: rgba(255,224,70,0.95);
    line-height: 1.1;
    margin: 0;
}

/* ── Ranking rows ────────────────────────────────────────────────────────────── */

#game-over-ranking {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.rank-row {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    align-items: center;
    gap: 14px;
    padding: 10px 16px;
    border-radius: 9px;
    background: rgba(0,0,0,0.22);
    border: 1px solid rgba(240,210,70,0.10);
}
.rank-row.rank-1 { background: rgba(212,175,55,0.12); border-color: rgba(240,210,70,0.50); }
.rank-row.rank-2 { border-color: rgba(192,192,192,0.25); }
.rank-row.rank-3 { border-color: rgba(184,115,51,0.25); }

.rank-medal {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.35rem;
    font-weight: 700;
    text-align: center;
    line-height: 1;
}
.rank-1 .rank-medal { color: #d4af37; }
.rank-2 .rank-medal { color: #9eaab4; }
.rank-3 .rank-medal { color: #b87333; }
.rank-4 .rank-medal { color: rgba(255,255,255,0.22); }

.rank-name {
    text-align: left;
    font-size: 0.97rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: rgba(255,224,70,0.88);
}
.rank-4 .rank-name { color: rgba(255,224,70,0.35); }

.rank-score {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: rgba(255,224,70,0.80);
}
.rank-1 .rank-score { color: #f0d040; }
.rank-4 .rank-score { color: rgba(255,224,70,0.28); }

/* ── Restart button ──────────────────────────────────────────────────────────── */

.restart-btn {
    padding: 12px 28px;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    background: rgba(39,174,96,0.85);
    color: rgba(240,234,216,0.95);
    border: 1px solid rgba(46,204,113,0.4);
    border-radius: 9px;
    cursor: pointer;
    margin-top: 6px;
    transition: background 0.15s, border-color 0.15s;
}
.restart-btn:hover {
    background: rgba(46,204,113,0.9);
    border-color: rgba(46,204,113,0.6);
}
