/* Modern Clean Light Theme Stylesheet */
:root {
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-surface: #f1f5f9;
    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --accent-primary: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-success: #10b981;
    --accent-danger: #ef4444;
    --accent-warning: #f59e0b;
    --accent-purple: #8b5cf6;

    --arena-p1-bg: #eff6ff;
    --arena-p2-bg: #fff1f2;
    --arena-neutral-bg: #f8fafc;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
    min-height: 100vh;
}

/* App Header */
.app-header {
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--accent-primary);
    user-select: none;
}

.brand-badge {
    font-size: 0.75rem;
    background: #dbeafe;
    color: #1e40af;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-weight: 600;
}

.nav-tabs {
    display: flex;
    gap: 8px;
    background: var(--bg-surface);
    padding: 4px;
    border-radius: var(--radius-md);
}

.nav-tab-btn {
    border: none;
    background: transparent;
    padding: 6px 16px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}

.nav-tab-btn.active {
    background: var(--bg-card);
    color: var(--accent-primary);
    box-shadow: var(--shadow-sm);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* General Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

.btn-primary {
    background-color: var(--accent-primary);
    color: white;
}
.btn-primary:hover { background-color: var(--accent-hover); }

.btn-secondary {
    background-color: var(--bg-card);
    border-color: var(--border-color);
    color: var(--text-primary);
}
.btn-secondary:hover { background-color: var(--bg-surface); border-color: var(--border-hover); }

.btn-danger {
    background-color: var(--accent-danger);
    color: white;
}
.btn-danger:hover { background-color: #dc2626; }

.btn-success {
    background-color: var(--accent-success);
    color: white;
}
.btn-success:hover { background-color: #059669; }

.btn-warning {
    background-color: var(--accent-warning);
    color: white;
}

.btn-sm {
    padding: 4px 8px;
    font-size: 0.75rem;
}

.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: var(--radius-md);
}

/* Panic Button Special Style */
.btn-panic {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fca5a5;
    font-weight: 700;
}
.btn-panic:hover {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
}

/* Tab Containers */
.tab-content {
    display: none;
    padding: 16px;
    max-width: 1600px;
    margin: 0 auto;
}
.tab-content.active {
    display: block;
}

/* DECK BUILDER STYLES */
.builder-layout {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 20px;
}

@media (max-width: 1024px) {
    .builder-layout {
        grid-template-columns: 1fr;
    }
}

.builder-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: sticky;
    top: 70px;
    height: fit-content;
}

.card-uploader-dropzone {
    border: 2px dashed var(--accent-primary);
    background: #f0f7ff;
    padding: 24px;
    border-radius: var(--radius-md);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.card-uploader-dropzone:hover, .card-uploader-dropzone.dragover {
    background: #e0f0fe;
    border-color: var(--accent-hover);
}

.deck-count-badge {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    font-weight: 600;
}

.deck-count-num {
    font-size: 1.25rem;
    color: var(--accent-primary);
}

.deck-count-valid {
    color: var(--accent-success);
}
.deck-count-invalid {
    color: var(--accent-danger);
}

.deck-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 14px;
}

.builder-card-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    display: flex;
    flex-direction: column;
}

.builder-card-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.builder-card-thumb {
    width: 100%;
    aspect-ratio: 63 / 88;
    background: #e2e8f0;
    object-fit: cover;
    display: block;
}

.builder-card-info {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.builder-card-title {
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.builder-card-type-select {
    width: 100%;
    font-size: 0.72rem;
    padding: 3px 4px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
}

.builder-card-count-ctrl {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
}

/* SIMULATOR ARENA STYLES */
.arena-wrapper {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 16px;
    min-height: calc(100vh - 90px);
}

@media (max-width: 1200px) {
    .arena-wrapper {
        grid-template-columns: 1fr;
    }
}

.arena-board {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Top bar arena */
.arena-top-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
}

.turn-indicator-pill {
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.turn-pill-active {
    background: #dcfce7;
    color: #15803d;
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.4);
    animation: pulse-turn 1.5s infinite;
}
.turn-pill-waiting {
    background: #f1f5f9;
    color: #64748b;
}

@keyframes pulse-turn {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.85; transform: scale(1.03); }
}

/* Opponent Area (Top) */
.player-arena-zone {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
}

.opponent-zone {
    background: var(--arena-p2-bg);
    border-bottom: 2px dashed #fecdd3;
    opacity: 0.95;
}

.my-zone {
    background: var(--arena-p1-bg);
    border-top: 2px dashed #bfdbfe;
    flex: 1;
}

/* Neutral Zone (Center) */
.neutral-zone {
    background: var(--arena-neutral-bg);
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 16px;
    display: grid;
    grid-template-columns: 180px 1fr 180px;
    align-items: center;
    gap: 12px;
    min-height: 120px;
    position: relative;
}

.stadium-area, .transit-area {
    background: var(--bg-card);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 6px;
    padding: 6px;
    position: relative;
}

.stadium-area.active-stadium {
    border-style: solid;
    border-color: #38bdf8;
    background: #f0f9ff;
}

.center-stage-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
}

/* Board Row Layout */
.board-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.prizes-column {
    display: grid;
    grid-template-columns: repeat(2, 48px);
    grid-template-rows: repeat(3, 68px);
    gap: 6px;
    background: rgba(255, 255, 255, 0.6);
    padding: 6px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.bench-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 1;
    min-height: 96px;
    background: rgba(255, 255, 255, 0.4);
    padding: 6px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    overflow-x: auto;
}

.active-slot-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.deck-trash-column {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Card Slot generic */
.card-slot {
    width: 66px;
    height: 92px;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: var(--bg-card);
    transition: all 0.15s ease;
    user-select: none;
}

.card-slot.active-card-slot {
    width: 80px;
    height: 112px;
}

.card-slot.slot-dragover {
    border-color: var(--accent-primary);
    background: #e0f2fe;
    transform: scale(1.04);
}

.card-slot-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 700;
    pointer-events: none;
}

/* Universal Card Element */
.card-entity {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: grab;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: var(--shadow-sm);
    background: #fff;
    display: flex;
    flex-direction: column;
}

.card-entity:active {
    cursor: grabbing;
}

.card-entity.is-tapped {
    transform: rotate(90deg) scale(0.9);
}

.card-entity img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

.card-back {
    background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
    border: 2px solid #3b82f6;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 0.75rem;
}

/* Smart Stacking: Attached Energies & Tools */
.attached-cards-wrap {
    position: absolute;
    bottom: -10px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: -15px;
    pointer-events: none;
    z-index: 2;
}

.attached-card-tag {
    font-size: 0.6rem;
    background: rgba(15, 23, 42, 0.85);
    color: #fff;
    padding: 1px 5px;
    border-radius: var(--radius-full);
    pointer-events: auto;
    cursor: pointer;
}

/* Damage Counter Floating */
.damage-counter-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #dc2626;
    color: white;
    font-weight: 800;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    border: 2px solid white;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    z-index: 10;
}

/* Ability Token */
.ability-token-badge {
    position: absolute;
    top: -8px;
    left: -8px;
    background: #f59e0b;
    color: white;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
    animation: ability-glow 1.5s infinite alternate;
}

@keyframes ability-glow {
    from { box-shadow: 0 0 4px #f59e0b; }
    to { box-shadow: 0 0 12px #f59e0b, 0 0 16px #fbbf24; }
}

/* Status Badges */
.status-badges-bar {
    position: absolute;
    bottom: 2px;
    left: 2px;
    right: 2px;
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    z-index: 5;
    pointer-events: none;
}

.badge-status {
    font-size: 0.55rem;
    padding: 1px 3px;
    border-radius: 3px;
    font-weight: 700;
    color: white;
}
.badge-poison { background: #9333ea; }
.badge-burn { background: #ea580c; }
.badge-asleep { background: #3b82f6; }
.badge-paralyzed { background: #eab308; color: #000; }
.badge-confused { background: #06b6d4; }

/* Hand Drawer at the bottom */
.hand-drawer {
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.04);
    padding: 8px 16px;
    position: relative;
    transition: all 0.2s ease;
}

.hand-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.hand-cards-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 6px 0;
    scroll-behavior: smooth;
    min-height: 100px;
}

.hand-card-item {
    width: 68px;
    height: 95px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    cursor: grab;
    transition: transform 0.15s ease, margin 0.15s ease;
    position: relative;
    background: #fff;
    border: 1px solid var(--border-color);
}

.hand-card-item:hover {
    transform: translateY(-10px) scale(1.08);
    box-shadow: var(--shadow-lg);
    z-index: 10;
}

.hand-card-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}

/* Chat & Battle Log Sidebar */
.battle-sidebar {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 600px;
}

.sidebar-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
}

.logs-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.82rem;
}

.log-entry {
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    line-height: 1.4;
    word-break: break-word;
}
.log-chat {
    background: var(--bg-surface);
}
.log-chat-me {
    background: #e0f2fe;
    align-self: flex-end;
}
.log-system {
    background: #f1f5f9;
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.78rem;
}
.log-turn {
    background: #fef3c7;
    color: #92400e;
    font-weight: bold;
    text-align: center;
    border-top: 1px solid #fde68a;
    border-bottom: 1px solid #fde68a;
}
.log-rng {
    background: #e0e7ff;
    color: #3730a3;
    font-weight: 600;
}
.log-reveal {
    background: #fdf4ff;
    color: #86198f;
    border: 1px dashed #f0abfc;
}

.chat-input-bar {
    padding: 10px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 6px;
}

.chat-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    outline: none;
}
.chat-input:focus {
    border-color: var(--accent-primary);
}

/* Modals & Dialogs */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}
.modal-overlay.active {
    display: flex;
}

.modal-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 520px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modal-pop 0.2s ease-out;
}

@keyframes modal-pop {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
    font-size: 1.1rem;
}

.modal-body {
    padding: 20px;
    max-height: 70vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

/* Giant Reveal Screen */
.giant-reveal-card {
    max-width: 800px;
    text-align: center;
}

.reveal-cards-container {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
    margin: 20px 0;
}

.reveal-card-item {
    width: 160px;
    height: 224px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
}
.reveal-card-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}

/* 3D Dice & Coin Animation Stage */
.stage-3d-wrap {
    perspective: 1000px;
    width: 140px;
    height: 140px;
    margin: 20px auto;
    position: relative;
}

/* 3D Coin */
.coin-3d {
    width: 100px;
    height: 100px;
    margin: 20px auto;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 2.5s cubic-bezier(0.15, 0.85, 0.35, 1.2);
}

.coin-face {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.2rem;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3), 0 4px 10px rgba(0, 0, 0, 0.2);
    border: 4px solid #f59e0b;
}

.coin-heads {
    background: radial-gradient(circle, #fde047 0%, #eab308 100%);
    color: #78350f;
}

.coin-tails {
    background: radial-gradient(circle, #cbd5e1 0%, #94a3b8 100%);
    color: #1e293b;
    border-color: #64748b;
    transform: rotateY(180deg);
}

.flipping-heads {
    transform: rotateY(1800deg);
}
.flipping-tails {
    transform: rotateY(1980deg);
}

/* 3D Dice (D6) */
.dice-3d {
    width: 80px;
    height: 80px;
    position: relative;
    margin: 30px auto;
    transform-style: preserve-3d;
    transition: transform 2.5s cubic-bezier(0.17, 0.89, 0.32, 1.28);
}

.dice-face {
    position: absolute;
    width: 80px;
    height: 80px;
    background: white;
    border: 2px solid #cbd5e1;
    border-radius: 12px;
    display: grid;
    padding: 10px;
    box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.08);
}

.pip {
    display: block;
    width: 14px;
    height: 14px;
    background-color: #ef4444;
    border-radius: 50%;
    justify-self: center;
    align-self: center;
}

.face-1 { transform: translateZ(40px); }
.face-2 { transform: rotateY(180deg) translateZ(40px); }
.face-3 { transform: rotateY(-90deg) translateZ(40px); }
.face-4 { transform: rotateY(90deg) translateZ(40px); }
.face-5 { transform: rotateX(90deg) translateZ(40px); }
.face-6 { transform: rotateX(-90deg) translateZ(40px); }

/* Fast Shake Animation for Shuffle */
@keyframes deck-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px) rotate(-3deg); }
    40% { transform: translateX(6px) rotate(3deg); }
    60% { transform: translateX(-4px) rotate(-2deg); }
    80% { transform: translateX(4px) rotate(2deg); }
}

.deck-shaking {
    animation: deck-shake 0.4s ease-in-out infinite;
}

/* Card Context Menu */
.context-menu {
    position: fixed;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    padding: 6px;
    display: none;
    flex-direction: column;
    z-index: 1000;
    min-width: 170px;
}
.context-menu.active { display: flex; }

.context-menu-item {
    padding: 8px 12px;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.1s ease;
}
.context-menu-item:hover {
    background: var(--bg-surface);
    color: var(--accent-primary);
}
.context-menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

/* Toast notifications */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 9999;
}
.toast {
    padding: 10px 16px;
    border-radius: var(--radius-md);
    background: #0f172a;
    color: white;
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.25s ease-out;
}
@keyframes toast-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
