:root {
    --color-bg: #05070a;
    --color-celestial: #1a3a5f;
    --color-celestial-light: #4a9eff;
    --color-ashen: #3d1a1a;
    --color-ashen-light: #ff4a4a;
    --color-gold: #c5a059;
    --color-gold-light: #f5d76e;
    --color-glass: rgba(255, 255, 255, 0.05);
    --color-glass-border: rgba(255, 255, 255, 0.1);
    --font-main: 'Outfit', sans-serif;
    --font-display: 'Playfair Display', serif;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb {
    background: var(--color-glass-border);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--color-gold);
}

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

body {
    background-color: var(--color-bg);
    color: white;
    font-family: var(--font-main);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

#app {
    position: relative;
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    z-index: 1;
}

/* Background Effects */
.starfield {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(1px 1px at 20px 30px, #eee, rgba(0,0,0,0)),
                      radial-gradient(1px 1px at 40px 70px, #fff, rgba(0,0,0,0)),
                      radial-gradient(2px 2px at 50px 160px, #ddd, rgba(0,0,0,0));
    background-repeat: repeat;
    background-size: 200px 200px;
    opacity: 0.3;
    z-index: -2;
    animation: stars 100s linear infinite;
}

@keyframes stars {
    from { transform: translateY(0); }
    to { transform: translateY(-200px); }
}

.nebula {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 50% 50%, rgba(26, 58, 95, 0.2), transparent 70%);
    z-index: -1;
    filter: blur(100px);
}

/* Header */
header {
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 40px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
    border-bottom: 1px solid var(--color-glass-border);
}

.logo {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 2px;
}

.logo .sovereign { color: var(--color-gold); }
.logo .summon { color: white; }

.game-stats {
    display: flex;
    gap: 20px;
}

.board-summon {
    width: 100%;
    height: 100%;
    background: var(--color-celestial);
    border: 1px solid var(--color-gold);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 5px;
    font-size: 0.7rem;
    animation: fadeIn 0.3s ease-out;
    cursor: pointer;
    transition: var(--transition);
}

.board-summon.attacking {
    border-color: #e74c3c;
    box-shadow: 0 0 15px rgba(231, 76, 60, 0.5);
    transform: translateY(-10px) scale(1.05);
}

.board-summon.targetable {
    border-color: var(--color-celestial-light);
    box-shadow: 0 0 15px var(--color-celestial-light);
    animation: targetPulse 1s infinite alternate;
}

.board-summon.summoning-sickness {
    opacity: 0.7;
    filter: grayscale(0.5);
    border-style: dotted;
}

.board-summon.summoning-sickness::after {
    content: '💤';
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 0.8rem;
}

@keyframes targetPulse {
    from { box-shadow: 0 0 5px var(--color-celestial-light); }
    to { box-shadow: 0 0 20px var(--color-celestial-light); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.board-summon .name {
    font-weight: 800;
    text-align: center;
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.board-summon .stats {
    background: rgba(0,0,0,0.5);
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 800;
}

.board-summon .stats .atk { color: #f1c40f; }
.board-summon .stats .hp { color: #e74c3c; }

.opponent .board-summon {
    background: var(--color-ashen);
    border-color: var(--color-ashen-light);
}

.resource-pool {
    background: var(--color-glass);
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--color-glass-border);
}

.stat-item {
    background: var(--color-glass);
    padding: 4px 16px;
    border-radius: 20px;
    border: 1px solid var(--color-glass-border);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Board Layout */
.board {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 300px;
    grid-template-rows: 1fr 1fr;
    padding: 20px;
    gap: 20px;
    min-height: 0; /* Prevents expansion pushing the HUD down */
}

.player-area {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 10px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.02);
}

.opponent { flex-direction: column; }
.self { flex-direction: column-reverse; }

.zones {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

.zone {
    background: var(--color-glass);
    border: 1px dashed var(--color-glass-border);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.zone-label {
    position: absolute;
    bottom: -20px;
    font-size: 0.7rem;
    text-transform: uppercase;
    opacity: 0.5;
    letter-spacing: 1px;
}

.frontline {
    width: 600px;
    height: 180px;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    padding: 10px;
    border-style: solid;
}

.slot {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--color-glass-border);
    border-radius: 8px;
    transition: var(--transition);
}

.slot.highlight {
    background: rgba(197, 160, 89, 0.1);
    border-color: var(--color-gold);
}

.echo-zone {
    width: 120px;
    height: 120px;
    border-radius: 50%;
}

.apex-zone {
    width: 100px;
    height: 140px;
    border-style: solid;
    border-color: var(--color-gold);
}

/* Sovereign Card */
.sovereign-container {
    display: flex;
    justify-content: center;
}

.sovereign-card {
    width: 240px;
    height: 80px;
    background: var(--color-celestial);
    border: 2px solid var(--color-gold);
    border-radius: 12px;
    padding: 10px;
    position: relative;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

.opponent .sovereign-card { background: var(--color-ashen); border-color: var(--color-ashen-light); }

.resolve-bar {
    width: 100%;
    height: 20px;
    background: rgba(0,0,0,0.5);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    margin-bottom: 5px;
}

.resolve-bar .fill {
    height: 100%;
    background: linear-gradient(to right, #e74c3c, #f1c40f);
    transition: width 0.5s ease-out;
}

.resolve-bar .value {
    position: absolute;
    width: 100%;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 800;
    line-height: 20px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.sovereign-name {
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
}

/* Side Panel / Action Log */
.side-panel {
    grid-row: span 2;
    background: var(--color-glass);
    border-left: 1px solid var(--color-glass-border);
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent panel from growing */
}

.detail-panel {
    padding: 20px;
    border-bottom: 1px solid var(--color-glass-border);
    background: rgba(255, 255, 255, 0.02);
    min-height: 250px;
}

.detail-placeholder {
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    opacity: 0.4;
    font-size: 0.9rem;
    font-style: italic;
}

.card-detail-view h2 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    color: var(--color-gold);
    margin-bottom: 5px;
}

.card-detail-view .type {
    font-size: 0.7rem;
    text-transform: uppercase;
    opacity: 0.6;
    margin-bottom: 10px;
}

.card-detail-view .effect {
    font-size: 0.85rem;
    line-height: 1.4;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    margin-bottom: 10px;
}

.log-container {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Important for flex-grow to allow scrolling */
}

.log-container h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    opacity: 0.6;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.log-content {
    flex: 1;
    overflow-y: auto;
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 10px;
}

.log-entry {
    padding: 6px 10px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.03);
    border-left: 3px solid transparent;
}

.log-entry.system { border-color: var(--color-gold); }
.log-entry.player { border-color: var(--color-celestial-light); }
.log-entry.opponent { border-color: var(--color-ashen-light); }

/* HUD / Hand */
.hud {
    height: 220px;
    background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
    display: flex;
    padding: 20px 40px;
    gap: 40px;
    z-index: 10;
}

.resource-panel {
    width: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 15px;
}

.leyline-pool .label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    margin-bottom: 5px;
    opacity: 0.7;
}

.pool-items {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.resource {
    width: 20px;
    height: 20px;
    background: var(--color-celestial-light);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--color-celestial-light);
}

.resource.tapped {
    background: #333;
    box-shadow: none;
    opacity: 0.5;
}

.deck-stacks {
    display: flex;
    gap: 15px;
}

.deck {
    width: 60px;
    height: 80px;
    background: var(--color-glass);
    border: 1px solid var(--color-glass-border);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.deck .count { font-size: 1.2rem; font-weight: 800; }
.deck label { font-size: 0.6rem; text-transform: uppercase; }

.hand-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: -20px; /* Overlap cards */
}

/* Card Component */
.card {
    width: 130px;
    height: 180px;
    background: #111;
    border: 1px solid #333;
    border-radius: 8px;
    position: relative;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    transform-origin: bottom center;
}

.card:hover {
    transform: translateY(-40px) scale(1.1);
    z-index: 100 !important;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
}

.card .card-cost {
    position: absolute;
    top: -10px;
    left: -10px;
    width: 30px;
    height: 30px;
    background: var(--color-gold);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 800;
    color: black;
    z-index: 2;
}

.card .card-art {
    width: 100%;
    height: 55%;
    background: #222;
    border-radius: 6px 6px 0 0;
    overflow: hidden;
}

.card .card-info {
    padding: 8px;
}

.card .card-name {
    font-size: 0.75rem;
    font-weight: 800;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card .card-subtype {
    font-size: 0.55rem;
    opacity: 0.6;
    margin-bottom: 5px;
}

.card .card-stats {
    position: absolute;
    bottom: 5px;
    right: 5px;
    display: flex;
    gap: 5px;
}

.stat-box {
    background: rgba(0,0,0,0.8);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 800;
}

.stat-box.atk { color: #f1c40f; }
.stat-box.hp { color: #e74c3c; }

/* Action Panel */
.action-panel {
    width: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 15px;
}

.btn-primary {
    background: var(--color-gold);
    color: black;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-weight: 800;
    text-transform: uppercase;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    background: var(--color-gold-light);
    transform: scale(1.05);
}

.btn-secondary {
    background: var(--color-glass);
    color: white;
    border: 1px solid var(--color-glass-border);
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    background: rgba(255,255,255,0.1);
}

/* Overlays */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.hidden { display: none !important; }

.modal {
    background: #1a1a1a;
    border: 1px solid var(--color-gold);
    padding: 40px;
    border-radius: 20px;
    width: 400px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.targeting-modal {
    max-width: 500px;
    width: auto;
    min-width: 350px;
}

.target-list {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 300px;
    overflow-y: auto;
    text-align: left;
}

.target-list h4 {
    font-size: 0.7rem;
    text-transform: uppercase;
    opacity: 0.5;
    margin-top: 10px;
}

.target-option {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--color-glass-border);
    color: white;
    padding: 10px;
    border-radius: 4px;
    cursor: pointer;
    text-align: left;
    transition: var(--transition);
    font-size: 0.85rem;
}

.target-option:hover {
    background: var(--color-glass-border);
    border-color: var(--color-gold);
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.setting-group label {
    font-size: 0.8rem;
    text-transform: uppercase;
    opacity: 0.7;
}

.setting-group input, .setting-group select {
    background: #333;
    border: 1px solid #444;
    color: white;
    padding: 10px;
    border-radius: 6px;
}

/* Start Menu */
.start-menu {
    text-align: center;
    animation: fadeIn 1s ease-out;
}

.logo-large {
    display: flex;
    flex-direction: column;
    margin-bottom: 20px;
}

.logo-large .sovereign {
    font-family: var(--font-display);
    font-size: 5rem;
    line-height: 0.8;
    color: white;
    letter-spacing: 10px;
    text-shadow: 0 0 30px rgba(255,255,255,0.3);
}

.logo-large .summon {
    font-size: 1.5rem;
    font-weight: 300;
    letter-spacing: 20px;
    color: var(--color-gold);
    margin-top: 10px;
}

.subtitle {
    opacity: 0.5;
    text-transform: uppercase;
    letter-spacing: 4px;
    font-size: 0.8rem;
    margin-bottom: 50px;
}

.start-btn {
    padding: 20px 60px !important;
    font-size: 1.2rem !important;
    box-shadow: 0 0 30px rgba(241, 196, 15, 0.2);
}

.credits {
    margin-top: 60px;
    font-size: 0.7rem;
    opacity: 0.3;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.deck-selection {
    display: flex;
    gap: 30px;
    margin-bottom: 40px;
    justify-content: center;
}

.selection-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
}

.selection-group label {
    font-size: 0.7rem;
    text-transform: uppercase;
    opacity: 0.5;
    letter-spacing: 2px;
}

.selection-group select {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--color-glass-border);
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

.selection-group select:hover {
    border-color: var(--color-gold);
    background: rgba(255, 255, 255, 0.1);
}

/* Deck Library */
.library-container {
    width: 90vw;
    height: 85vh;
    display: flex;
    flex-direction: column;
    padding: 30px;
    position: relative;
    overflow: hidden;
}

.library-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    gap: 20px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 40px;
}

.library-filters {
    display: flex;
    gap: 15px;
}

.library-filters select, .library-filters input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 8px 15px;
    border-radius: 6px;
    font-size: 0.8rem;
    outline: none;
    transition: var(--transition);
}

.library-filters select:focus, .library-filters input:focus {
    border-color: var(--color-gold);
    background: rgba(255, 255, 255, 0.1);
}

.library-body {
    display: flex;
    gap: 30px;
    flex: 1;
    overflow: hidden;
}

.library-sidebar {
    width: 250px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.deck-tab {
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--color-glass-border);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
    letter-spacing: 1px;
}

.deck-tab:hover, .deck-tab.active {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--color-gold);
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.2);
}

.library-content {
    flex: 1;
    overflow-y: auto;
    padding-right: 15px;
}

.library-content::-webkit-scrollbar {
    width: 6px;
}

.library-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
}

.menu-actions {
    display: flex;
    gap: 20px;
    justify-content: center;
}

.btn-secondary {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
}

.btn-secondary:hover {
    border-color: white;
    background: rgba(255, 255, 255, 0.1);
}

#library-sovereign-preview {
    margin-bottom: 40px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    border-left: 4px solid var(--color-gold);
}

#library-sovereign-preview h2 {
    color: var(--color-gold);
    margin-bottom: 5px;
}

#library-sovereign-preview .subtitle {
    font-size: 0.8rem;
    opacity: 0.6;
    margin-bottom: 15px;
}

.card-library-effect {
    font-size: 0.7rem;
    line-height: 1.2;
    margin-top: 8px;
    opacity: 0.8;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card:hover .card-library-effect {
    -webkit-line-clamp: unset;
    overflow: visible;
    background: rgba(0, 0, 0, 0.8);
    padding: 10px;
    border-radius: 4px;
    position: absolute;
    bottom: 60px;
    left: 10px;
    right: 10px;
    z-index: 100;
}

.card-keywords {
    font-size: 0.6rem;
    text-transform: uppercase;
    color: var(--color-gold);
    margin-top: 5px;
    letter-spacing: 1px;
}

.card-rarity-tag {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 0.5rem;
    text-transform: uppercase;
    background: rgba(0, 0, 0, 0.5);
    padding: 2px 6px;
    border-radius: 10px;
    letter-spacing: 1px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Shuffle Button */
.shuffle-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #27ae60 !important;
    color: white !important;
    padding: 15px 40px !important;
    font-size: 1.5rem !important;
    z-index: 500;
    box-shadow: 0 0 40px rgba(46, 204, 113, 0.4);
    animation: pulseGlow 2s infinite;
}

.shuffle-btn:hover {
    background: #2ecc71 !important;
    transform: translate(-50%, -50%) scale(1.1) !important;
}

@keyframes pulseGlow {
    0% { box-shadow: 0 0 20px rgba(46, 204, 113, 0.4); }
    50% { box-shadow: 0 0 50px rgba(46, 204, 113, 0.7); }
    100% { box-shadow: 0 0 20px rgba(46, 204, 113, 0.4); }
}
