* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --accent: #e11d48;
    --accent-light: #fb7185;
    --accent-dark: #9f1239;
    --gold: #fbbf24;
    --gold-dim: #d97706;
    --panel: rgba(8, 12, 20, 0.72);
    --panel-border: rgba(255, 255, 255, 0.1);
    --text: #f1f5f9;
    --text-dim: #94a3b8;

    /* Cards — larger, viewport-driven */
    --card-w: clamp(70px, 9vmin, 110px);
    --card-h: calc(var(--card-w) * 1.39);
    --card-leader-w: clamp(78px, 9.8vmin, 118px);
    --card-leader-h: calc(var(--card-leader-w) * 1.39);
    --card-don-w: clamp(38px, 4.8vmin, 56px);
    --card-don-h: calc(var(--card-don-w) * 1.39);
    --hand-card-w: clamp(88px, 12vmin, 148px);
    --hand-card-h: calc(var(--hand-card-w) * 1.39);
    /* hand card + slim label + hover headroom */
    --bottom-bar-h: calc(var(--hand-card-h) + 2.85rem);
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: 'Rajdhani', 'Segoe UI', system-ui, sans-serif;
    font-weight: 600;
    color: var(--text);
    background: #06080d;
}

#app-shell {
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Header ── */
.top-bar {
    flex: 0 0 auto;
    min-height: 46px;
    padding: 0.35rem 1rem;
    background: linear-gradient(180deg, #141a26 0%, #0c1018 100%);
    border-bottom: 2px solid var(--accent);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.75rem;
    z-index: 20;
}

.top-bar-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
}

.phase-strip {
    flex: 0 0 auto;
    padding: 0.3rem 0.75rem;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.35));
    border-bottom: 1px solid var(--panel-border);
    z-index: 19;
}

.phase-strip .phase-bar {
    justify-content: center;
    flex: none;
    width: 100%;
}

.logo {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    color: var(--text);
}

.logo span {
    color: var(--accent-light);
}

#connection-status {
    color: var(--text-dim);
    font-size: 0.8rem;
    white-space: nowrap;
    margin: 0;
}

.hidden { display: none !important; }

/* ── Buttons ── */
.btn {
    cursor: pointer;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.88rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.5rem 1.1rem;
    border-radius: 8px;
    border: none;
    color: #fff;
    transition: transform 0.1s, box-shadow 0.15s, filter 0.15s;
    white-space: nowrap;
}

.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(2px); }

.btn-primary {
    background: linear-gradient(180deg, #f43f5e 0%, #be123c 55%, #9f1239 100%);
    border: 1px solid #fb7185;
    box-shadow: 0 4px 0 #7f1d1d, 0 6px 16px rgba(225, 29, 72, 0.35);
}

.btn-primary:active {
    box-shadow: 0 1px 0 #7f1d1d, 0 2px 8px rgba(225, 29, 72, 0.25);
}

.btn-secondary {
    background: linear-gradient(180deg, #334155 0%, #1e293b 100%);
    border: 1px solid #475569;
    box-shadow: 0 3px 0 #0f172a, 0 4px 10px rgba(0, 0, 0, 0.35);
}

.btn-secondary:active {
    box-shadow: 0 1px 0 #0f172a;
}

.btn-secondary.active-mode,
.btn.active-mode {
    background: linear-gradient(180deg, #f59e0b 0%, #d97706 55%, #b45309 100%);
    border-color: #fcd34d;
    color: #1c1917;
    box-shadow: 0 3px 0 #92400e, 0 0 14px rgba(251, 191, 36, 0.45);
}

.btn-ghost {
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid var(--panel-border);
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    box-shadow: none;
}

.btn-ghost:active { transform: none; }

.action-bar .btn {
    padding: 0.4rem 0.85rem;
    font-size: 0.82rem;
}

.connecting-overlay {
    position: absolute;
    inset: 50px 0 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(4, 6, 10, 0.92);
    z-index: 35;
    color: var(--text-dim);
    font-size: 1rem;
    letter-spacing: 0.06em;
}

/* ── Lobby ── */
.lobby-overlay {
    position: absolute;
    inset: 50px 0 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(4, 6, 10, 0.9);
    z-index: 30;
}

.lobby-card {
    width: min(440px, 92vw);
    padding: 1.5rem;
    background: linear-gradient(160deg, #1a2233 0%, #111827 100%);
    border-radius: 14px;
    border: 1px solid var(--panel-border);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.lobby-card h2 {
    font-size: 1.4rem;
    margin-bottom: 1rem;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.hint { color: var(--text-dim); font-size: 0.95rem; margin-top: 0.6rem; }
.room-list { padding-left: 1.25rem; color: var(--text-dim); font-size: 0.9rem; max-height: 80px; overflow: hidden; }

.row {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 0.75rem;
}

input, select {
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    border: 1px solid #475569;
    background: #0f172a;
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
}

.toast {
    position: fixed;
    top: 58px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(180deg, #9a3412, #7c2d12);
    border: 1px solid #ea580c;
    padding: 0.65rem 1.25rem;
    border-radius: 10px;
    z-index: 100;
    font-size: 0.95rem;
    max-width: 90vw;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* ── Game layout ── */
.game-root {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-rows: 1fr auto;
    position: relative;
    overflow: hidden;
}

.phase-bar {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    justify-content: center;
}

.phase-step {
    padding: 0.35rem 0.9rem;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-dim);
    background: linear-gradient(180deg, #2a3344 0%, #1a2230 100%);
    border: 1px solid #3d4f66;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.phase-step.active {
    color: #fff;
    background: linear-gradient(180deg, #fb7185 0%, #e11d48 50%, #be123c 100%);
    border-color: #fda4af;
    box-shadow: 0 0 16px rgba(225, 29, 72, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.game-info {
    font-size: clamp(0.72rem, 1.8vmin, 0.9rem);
    color: var(--text);
    line-height: 1.2;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.game-info strong { color: var(--gold); }

.banner {
    text-align: center;
    padding: 0.4rem 0.65rem;
    background: linear-gradient(90deg, rgba(120, 53, 15, 0.9), rgba(180, 83, 9, 0.85));
    border: 1px solid var(--gold);
    border-radius: 8px;
    color: #fef3c7;
    font-size: 0.85rem;
    letter-spacing: 0.03em;
}

.pane-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--gold);
    flex-shrink: 0;
    margin-bottom: 0.2rem;
}

.bottom-bar {
    display: grid;
    grid-template-columns: minmax(108px, 11rem) 1fr minmax(140px, 22%);
    height: var(--bottom-bar-h);
    min-height: 0;
    overflow: visible;
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.92) 0%, rgba(15, 23, 42, 0.88) 100%);
    border-top: 3px solid var(--accent);
    z-index: 18;
}

.detail-pane,
.hand-pane,
.action-pane {
    min-width: 0;
    min-height: 0;
    padding: 0.35rem 0.55rem 0.45rem;
    display: flex;
    flex-direction: column;
}

.detail-pane {
    border-right: 1px solid var(--panel-border);
    overflow: hidden;
}

.hand-pane {
    border-right: 1px solid var(--panel-border);
    overflow: visible;
    padding-bottom: 0.2rem;
}

.hand-title-strip {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.35rem;
    flex-shrink: 0;
}

.hand-title-strip .pane-label {
    margin-bottom: 0;
}

.action-pane {
    overflow-y: auto;
}

.detail-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.78rem;
    line-height: 1.35;
    padding: 0.25rem;
}

.detail-pane.detail-empty .detail-placeholder { display: flex; }
.detail-pane:not(.detail-empty) .detail-placeholder { display: none; }

.detail-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.hand-nav-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex: 0 0 auto;
    min-height: 0;
    overflow: visible;
    margin-top: 0.05rem;
}

.zone-nav-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex: 1;
    min-height: 0;
}

.hand-viewport {
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    overflow-y: visible;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 0.75rem;
}

.char-viewport-wrap {
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.nav-btn {
    flex: 0 0 auto;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    background: linear-gradient(180deg, #2a3344, #1a2230);
    color: var(--gold);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
}

.nav-btn:hover:not(:disabled) {
    filter: brightness(1.12);
    border-color: var(--gold);
}

.nav-btn:disabled {
    opacity: 0.25;
    cursor: default;
}

.nav-counter {
    font-size: 0.68rem;
    color: var(--text-dim);
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.zone-title .nav-counter {
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0.02em;
}

.action-bar {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    flex: 1;
    align-content: center;
}

.action-pane .banner {
    margin: 0 0 0.25rem;
    flex-shrink: 0;
    font-size: 0.78rem;
    padding: 0.3rem 0.5rem;
}

@media (max-width: 900px) {
    .bottom-bar {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr auto;
        height: calc(var(--hand-card-h) + 3rem);
    }

    .detail-pane {
        grid-column: 1;
        grid-row: 1;
        border-right: none;
        border-bottom: 1px solid var(--panel-border);
    }

    .hand-pane {
        grid-column: 2;
        grid-row: 1 / span 2;
        border-right: none;
    }

    .action-pane {
        grid-column: 1;
        grid-row: 2;
    }
}

.badge-hint {
    color: var(--gold);
    font-size: 0.88rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ── Playmat ── */
.playmat {
    min-height: 0;
    overflow: hidden;
    background: url('/assets/ui/playmat.svg') center / cover no-repeat;
    display: flex;
    flex-direction: column;
    padding: 0.4rem 0.6rem;
    gap: 0;
}

.center-line {
    flex: 0 0 2px;
    margin: 0.15rem 1rem;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
}

.playmat .player-board {
    flex: 1;
    min-height: 0;
}

.playmat .player-board.self {
    flex: 1.08;
}

.player-board {
    display: grid;
    grid-template-columns: auto auto auto minmax(0, 1fr) auto;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 0.35rem 0.45rem;
    align-items: end;
    padding: 0.25rem 0.3rem;
}

.player-board.opponent {
    align-items: start;
}

.player-board .zone-life {
    grid-column: 1;
    grid-row: 1;
    flex-shrink: 0;
    min-width: calc(3 * var(--card-w) + 2 * 0.35rem);
    width: max-content;
}

.player-board .zone-life .zone-cards {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow: hidden;
}

.player-board .zone-life .tcg-card {
    flex-shrink: 0;
}
.player-board .zone-leader { grid-column: 2; grid-row: 1; }
.player-board .zone-stage { grid-column: 3; grid-row: 1; }
.player-board .zone-chars { grid-column: 4; grid-row: 1; min-width: 0; }
.player-board .zone-piles { grid-column: 5; grid-row: 1; }
.player-board .zone-don {
    grid-column: 1 / -1;
    grid-row: 2;
}

.zone {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 0.35rem 0.45rem;
    backdrop-filter: blur(4px);
}

.zone-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--gold);
    margin-bottom: 0.25rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.zone-cards {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.35rem;
    align-items: flex-end;
    overflow: hidden;
}

.zone-cards.chars.char-page-grid {
    display: grid;
    grid-template-columns: repeat(10, var(--card-w));
    grid-template-rows: var(--card-h);
    gap: 0.35rem;
    flex: 1;
    min-width: 0;
    align-content: end;
}

.card-slot-empty {
    width: var(--card-w);
    height: var(--card-h);
    border-radius: 6px;
    border: 1px dashed rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.15);
}

.hand-slot-empty {
    width: var(--hand-card-w);
    height: var(--hand-card-h);
    border-radius: 6px;
    border: 1px dashed rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

.zone-piles {
    display: flex;
    gap: 0.35rem;
    align-items: flex-end;
}

.pile-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}

.pile-label {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
}

.pile {
    position: relative;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.55);
    flex-shrink: 0;
}

.pile .pile-count {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    text-shadow: 0 1px 3px #000;
}

.pile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ── Cards ── */
.tcg-card {
    position: relative;
    width: var(--card-w);
    height: var(--card-h);
    border-radius: 6px;
    flex-shrink: 0;
    cursor: default;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.55);
}

.tcg-card.leader {
    width: var(--card-leader-w);
    height: var(--card-leader-h);
}

.tcg-card.don {
    width: var(--card-don-w);
    height: var(--card-don-h);
}

.tcg-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
    display: block;
    border: 2px solid rgba(255, 255, 255, 0.12);
}

.tcg-card.clickable { cursor: pointer; }

.tcg-card.clickable:hover {
    transform: translateY(-6px) scale(1.03);
    z-index: 5;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.6), 0 0 0 2px rgba(251, 191, 36, 0.5);
}

.tcg-card.selected {
    outline: 3px solid #22c55e;
    outline-offset: 2px;
    z-index: 6;
}

.tcg-card.targetable {
    outline: 3px solid var(--gold);
    outline-offset: 2px;
    animation: pulse 1.2s ease-in-out infinite;
}

.tcg-card.illegal-block {
    opacity: 0.42;
    filter: grayscale(0.55) brightness(0.85);
    cursor: not-allowed;
    pointer-events: none;
}

.tcg-card.illegal-block::after {
    content: '✕';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 700;
    color: rgba(248, 113, 113, 0.85);
    background: rgba(0, 0, 0, 0.35);
    border-radius: inherit;
    pointer-events: none;
}

@keyframes pulse {
    50% { outline-color: #fef08a; box-shadow: 0 0 20px rgba(251, 191, 36, 0.5); }
}

.tcg-card.rested {
    transform: rotate(90deg);
    opacity: 0.9;
}

.tcg-card.rested.clickable:hover {
    transform: rotate(90deg) translateY(-6px) scale(1.03);
}

.card-overlay {
    position: absolute;
    pointer-events: none;
    font-weight: 700;
    text-shadow: 0 1px 3px #000;
    z-index: 2;
}

.card-overlay.power {
    bottom: 4px;
    left: 4px;
    background: linear-gradient(180deg, #3b82f6, #1d4ed8);
    color: #fff;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: clamp(0.7rem, 1.8vmin, 0.95rem);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.card-overlay.don-count {
    top: 4px;
    right: 4px;
    background: linear-gradient(180deg, #fef9c3, #fde047);
    color: #422006;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: clamp(0.62rem, 1.5vmin, 0.82rem);
    border: 1px solid #ca8a04;
}

/* ── Hand ── */
.hand-row {
    display: grid;
    grid-template-columns: repeat(10, var(--hand-card-w));
    grid-template-rows: var(--hand-card-h);
    gap: 0.35rem;
    justify-content: center;
    align-items: flex-end;
    min-height: 0;
}

.hand-row .tcg-card {
    width: var(--hand-card-w);
    height: var(--hand-card-h);
    flex-shrink: 0;
}

.hand-row .tcg-card:hover {
    transform: translateY(-12px) scale(1.06);
    z-index: 30;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55);
}

/* ── Log ── */
.log-panel {
    position: absolute;
    top: 0.5rem;
    right: 0.6rem;
    z-index: 25;
}

.log-list {
    list-style: none;
    margin-top: 0.35rem;
    width: 280px;
    max-height: 160px;
    overflow-y: auto;
    background: rgba(8, 12, 20, 0.95);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 0.5rem;
    font-size: 0.82rem;
    color: var(--text-dim);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.log-list li {
    margin-bottom: 0.35rem;
    border-bottom: 1px solid #1e293b;
    padding-bottom: 0.3rem;
    line-height: 1.3;
}

.detail-name {
    color: var(--gold);
    font-size: clamp(0.78rem, 2vmin, 0.9rem);
    line-height: 1.15;
    display: block;
}

.detail-meta {
    font-size: clamp(0.68rem, 1.6vmin, 0.76rem);
    color: var(--text-dim);
    margin: 0;
}

.detail-text {
    font-size: clamp(0.7rem, 1.7vmin, 0.8rem);
    line-height: 1.3;
    color: #e2e8f0;
}

.tcg-card .ability-dot {
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 8px;
    height: 8px;
    background: var(--gold);
    border-radius: 50%;
    box-shadow: 0 0 6px var(--gold);
}

.game-over-actions {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
}

.win-text {
    color: #4ade80;
    font-weight: 700;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    text-shadow: 0 0 12px rgba(74, 222, 128, 0.4);
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.15rem;
    vertical-align: middle;
}

.status-dot.online {
    background: #4ade80;
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.7);
}

.status-dot.offline {
    background: #f87171;
    box-shadow: 0 0 6px rgba(248, 113, 113, 0.5);
}

.game-info {
    font-size: 0.85rem;
    line-height: 1.35;
}
