@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&family=Caveat:wght@400..700&display=swap');

:root {
    --bg-color: #020617;
    --card-bg: rgba(30, 41, 59, 0.7);
    --accent-color: #ef4444;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --glass-border: rgba(255, 255, 255, 0.1);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Hero Section */
.hero {
    height: 80vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    position: relative;
    overflow: hidden;
}

/* Pile Mode */
.pile-card {
    position: absolute;
    top: 50%;
    left: 50%;
    /* Enforce standard card size */
    width: 60vh;
    aspect-ratio: 0.714;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    background: transparent;
    opacity: 0;
    animation: drop-in 0.5s cubic-bezier(0.25, 1, 0.5, 1) forwards;
    z-index: 1000;
    /* Base Z-index */
}

.hero-backgrounds {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

.hero-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 4s ease-in-out;
    filter: blur(5px) brightness(0.6);
}

body.ss-active .hero-image {
    filter: none;
}

body.ss-active {
    overflow: hidden;
}

body.ss-active header .container,
body.ss-active main,
body.ss-active footer,
body.ss-active .nav-bar {
    display: none;
}

body.ss-active .hero {
    height: 100vh;
}

.hero-image.active {
    opacity: 1;
}

.hero h1 {
    font-size: 5rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: -2px;
    background: linear-gradient(to bottom, #fff, #ef4444);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 1rem;
    animation: fadeInDown 1s ease-out;
}

.hero p {
    font-size: 1.5rem;
    color: var(--text-secondary);
    max-width: 600px;
    animation: fadeInUp 1s ease-out 0.5s both;
}

/* Faults Grid */
.faults-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-top: -100px;
    position: relative;
    z-index: 10;
}

.fault-card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2rem;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
    cursor: pointer;
}

.fault-card:hover {
    transform: translateY(-10px) scale(1.02);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4), 0 0 20px rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.5);
}

.fault-card h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--accent-color);
}

.fault-card p {
    color: var(--text-secondary);
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: rgba(239, 68, 68, 0.1);
    color: var(--accent-color);
    border-radius: 99px;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 1rem;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* Screen Saver Dock */
.ss-dock {
    display: flex;
    gap: 0.5rem;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(12px);
    padding: 0.5rem;
    border-radius: 99px;
    border: 1px solid var(--glass-border);
}

.ss-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 99px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

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

/* SS Card Face - Decoupled from 3D TCG logic */
.ss-card-face {
    background: var(--theme-pattern), var(--theme-bg);
    background-size: var(--theme-pattern-size), cover;
    display: flex;
    flex-direction: column;
    padding: 12px;
    border: 8px solid rgba(255, 255, 255, 0.05);
    border-radius: 18px;
    width: 100%;
    height: 100%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    /* Explicitly NO 3D transforms */
    transform: none !important;
    backface-visibility: visible !important;

    /* CRITICAL: Enable Container Queries for text scaling (cqw units) */
    container-type: inline-size;
}

/* Flyby Mode Animation */
.flyby-card {
    position: fixed;
    top: 50%;
    left: 120%;
    /* Start off-screen right */
    transform: translate(-50%, -50%);
    /* Base centering, animation overrides */
    animation: flyby-sequence 6s linear forwards;
    z-index: 2000;
}

@keyframes flyby-sequence {
    0% {
        left: 120%;
        transform: translate(-50%, -50%) rotate(15deg) scale(0.8);
    }

    10% {
        left: 50%;
        transform: translate(-50%, -50%) rotate(0deg) scale(1);
    }

    /* Arrive fast */
    60% {
        left: 50%;
        transform: translate(-50%, -50%) rotate(0deg) scale(1);
    }

    /* Stay */
    80% {
        left: -20%;
        transform: translate(-50%, -50%) rotate(-15deg) scale(0.8);
    }

    /* Exit */
    100% {
        left: -20%;
    }
}

@keyframes drop-in {
    0% {
        transform: translate(-50%, -50%) scale(3);
        opacity: 0;
    }

    100% {
        transform: var(--final-transform);
        opacity: 1;
    }
}

/* Navigation */
.nav-bar {
    position: absolute;
    top: 2rem;
    left: 2rem;
    right: 2rem;
    z-index: 10001;
    /* Boost Z-index to be above Screen Saver (1000-2000) */
    display: flex;
    /* Enable flexbox layout */
    align-items: center;
    /* Vertically center items */
    gap: 1rem;
}

/* Ensure SS Card Containers have dimensions */
.flyby-card {
    width: 60vh;
    aspect-ratio: 0.714;
    pointer-events: auto;
    /* Enable interaction for Flyby cards */
    cursor: pointer;
}

/* Pile Mode Specifics */
.pile-card {
    position: absolute;
    /* Needed for random placement */
    width: 30vh;
    /* 1/2 of 60vh standard (User Request) */
    aspect-ratio: 0.714;
    pointer-events: auto;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
    opacity: 0;
    animation: drop-in 0.5s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

/* Green Felt Table Background */
.ss-table-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at center, #355e3b 0%, #1a2f1d 100%);
    /* Classic felt green */
    z-index: 999;
    /* Below cards (1000+), above hero (0) */
    opacity: 0;
    transition: opacity 1s ease-in;
    pointer-events: none;
    /* Let clicks pass to exit button if needed, though card layer is above */
}

/* Button Reset */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 99px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
    border: 1px solid var(--glass-border);
    cursor: pointer;
}

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

.btn-outline {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    backdrop-filter: blur(8px);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(239, 68, 68, 0.3);
}

/* Forms */
.form-container {
    max-width: 500px;
    margin: 100px auto;
    background: var(--card-bg);
    padding: 3rem;
    border-radius: 32px;
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(20px);
}

.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

input,
textarea {
    width: 100%;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: white;
    font-family: inherit;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent-color);
}

.admin-actions {
    display: flex;
    gap: 10px;
    margin-top: 1.5rem;
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

.flash-messages {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid var(--accent-color);
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 2rem;
    color: var(--accent-color);
}

.fault-indicator {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 2rem;
}

.dot {
    width: 12px;
    height: 12px;
    background: var(--accent-color);
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

.dot:nth-child(2) {
    animation-delay: 0.2s;
}

.dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.5);
        opacity: 0.5;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Error Banner - Peter's Fault style */
.error-banner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 9999;
    padding: 1rem;
    background: rgba(239, 68, 68, 0.2);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid #ef4444;
    animation: slideInDown 0.5s ease-out;
}

.error-banner.hidden {
    display: none;
}

.error-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    color: white;
}

.error-icon {
    font-size: 1.5rem;
}

.error-banner p {
    flex-grow: 1;
    margin: 0;
    font-weight: 500;
}

.error-banner button {
    background: transparent;
    border: 1px solid white;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 99px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.error-banner button:hover {
    background: white;
    color: #020617;
}

/* Security Status Indicators */
#security-status {
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

.status-checking {
    color: #94a3b8;
}

.status-secure {
    color: #00ff88;
}

.status-insecure {
    color: #ef4444;
}

@keyframes slideInDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(15px);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease-out;
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    padding: 3rem;
    border-radius: 32px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(20px);
}

.modal-content h2 {
    color: var(--accent-color);
    margin-bottom: 1rem;
    font-size: 2rem;
    font-weight: 800;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.modal-content.modal-large {
    max-width: 800px;
    text-align: left;
}

.edit-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    text-align: left;
}

.form-group.full-width {
    grid-column: span 2;
}

.edit-form-grid .form-group {
    margin-bottom: 0.5rem;
}

.edit-form-grid label {
    font-size: 0.8rem;
    color: var(--accent-color);
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 2rem;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* TCG Specific Variables */
:root {
    --tcg-max-width: 800px;
    /* Allow card to grow much larger on desktop */
    --tcg-aspect-ratio: 0.718;
    /* Standard card aspect ratio (2.5/3.5) */
    --tcg-gold: #ffd700;
    --tcg-mythic: #ff4500;

    /* Overlay Config (User Request: 50% translucent black, nice glass blur) */
    --tcg-overlay-bg: rgba(0, 0, 0, 0.5);
    --tcg-overlay-blur: 10px;
    --tcg-anim-duration: 0.8s;

    /* Narrative Flourishes */
    --tcg-stamp-red: #ff4d4d;
    --tcg-signature-font: 'Caveat', cursive;

    /* Type Themes */
    --theme-primary: var(--accent-color);
    --theme-secondary: rgba(239, 68, 68, 0.1);
    --theme-bg: linear-gradient(135deg, #1e293b 0%, #020617 100%);
    --theme-pattern: radial-gradient(circle at 2px 2px, rgba(255, 255, 255, 0.05) 1px, transparent 0);
    --theme-pattern-size: 20px 20px;
}

/* Theme Definitions */
[data-theme="epic"] {
    --theme-primary: #ffd700;
    --theme-secondary: rgba(255, 215, 0, 0.1);
    --theme-bg: linear-gradient(135deg, #422006 0%, #020617 100%);
    --theme-pattern: repeating-conic-gradient(from 0deg, rgba(255, 215, 0, 0.03) 0deg 10deg, transparent 10deg 20deg);
    --theme-pattern-size: 100% 100%;
}

[data-theme="system"] {
    --theme-primary: #ff4d4d;
    --theme-secondary: rgba(255, 77, 77, 0.1);
    --theme-bg: linear-gradient(135deg, #450a0a 0%, #020617 100%);
    --theme-pattern: linear-gradient(rgba(255, 0, 0, 0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 0, 0, 0.05) 1px, transparent 1px);
    --theme-pattern-size: 20px 20px;
}

[data-theme="bio"] {
    --theme-primary: #00ff88;
    --theme-secondary: rgba(0, 255, 136, 0.1);
    --theme-bg: linear-gradient(135deg, #064e3b 0%, #020617 100%);
    --theme-pattern: radial-gradient(circle, rgba(0, 255, 136, 0.05) 1px, transparent 1px);
    --theme-pattern-size: 15px 15px;
}

[data-theme="creative"] {
    --theme-primary: #a855f7;
    --theme-secondary: rgba(168, 85, 247, 0.1);
    --theme-bg: linear-gradient(135deg, #3b0764 0%, #020617 100%);
    --theme-pattern: repeating-linear-gradient(45deg, rgba(168, 85, 247, 0.05) 0, rgba(168, 85, 247, 0.05) 2px, transparent 2px, transparent 10px);
    --theme-pattern-size: 100% 100%;
}

[data-theme="aqua"] {
    --theme-primary: #00d2ff;
    --theme-secondary: rgba(0, 210, 255, 0.1);
    --theme-bg: linear-gradient(135deg, #083344 0%, #020617 100%);
    --theme-pattern: radial-gradient(ellipse at 50% 50%, rgba(0, 210, 255, 0.05) 0%, transparent 70%);
    --theme-pattern-size: 100px 100px;
}

[data-theme="cosmic"] {
    --theme-primary: #fbbf24;
    --theme-secondary: rgba(251, 191, 36, 0.1);
    --theme-bg: linear-gradient(135deg, #422006 0%, #020617 100%);
    --theme-pattern: radial-gradient(circle at 50% 50%, rgba(251, 191, 36, 0.08) 1px, transparent 1px);
    --theme-pattern-size: 30px 30px;
}

/* TCG Overlay & Modal */
.tcg-view-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--tcg-overlay-bg);
    backdrop-filter: blur(var(--tcg-overlay-blur));
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.tcg-view-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* TCG Navigation Buttons */
.tcg-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    color: white;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 10002;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.tcg-nav-btn:hover {
    background: var(--accent-color);
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.5);
    transform: translateY(-50%) scale(1.1);
}

.tcg-nav-btn.prev-btn {
    left: 2rem;
}

.tcg-nav-btn.next-btn {
    right: 2rem;
}

.tcg-nav-btn svg {
    transition: transform 0.3s ease;
}

.tcg-nav-btn:active {
    transform: translateY(-50%) scale(0.95);
}

/* 3D Scene Wrapper */
.tcg-scene {
    /* Dynamic sizing to fit both height and width constraints */
    width: min(var(--tcg-max-width), 85vw, calc(85vh * var(--tcg-aspect-ratio)));
    aspect-ratio: var(--tcg-aspect-ratio);
    height: auto;
    perspective: 1500px;
    container-type: inline-size;
    /* Enable container queries for font scaling */
}

/* Card Container */
.tcg-card-container {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform var(--tcg-anim-duration) cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
    cursor: pointer;
}

.tcg-card-container.is-flipped {
    transform: rotateY(180deg);
}

/* Face Styling */
.tcg-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 18px;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* FRONT: Simple Fault Card Look */
.tcg-front {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    padding: 2rem;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.tcg-front h2 {
    color: var(--theme-primary);
    margin-bottom: 1rem;
}

/* BACK: Full TCG Card Look */
.tcg-back {
    background: var(--theme-pattern), var(--theme-bg);
    background-size: var(--theme-pattern-size), cover;
    transform: rotateY(180deg);
    display: flex;
    flex-direction: column;
    padding: 12px;
    border: 8px solid rgba(255, 255, 255, 0.05);
}

/* TCG Layout Components */
.tcg-inner {
    flex: 1;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.3);
    position: relative;
}

.tcg-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1cqw 3cqw;
    background: var(--theme-secondary);
    border-bottom: 2px solid var(--theme-primary);
    font-weight: 800;
    font-size: clamp(1rem, 5cqw, 1.8rem);
    color: var(--theme-primary);
}

.tcg-cost {
    font-size: 0.7rem;
    font-family: 'Courier New', Courier, monospace;
    color: var(--theme-primary);
    border: 2px solid var(--theme-primary);
    padding: 2px 6px;
    border-radius: 4px;
    transform: rotate(-10deg);
    text-transform: uppercase;
    font-weight: 900;
    letter-spacing: 1px;
    background: var(--theme-secondary);
    box-shadow: 0 0 5px var(--theme-secondary);
}

.tcg-art {
    width: calc(100% - 12px);
    aspect-ratio: 4/3;
    height: auto;
    margin: 6px auto;
    background: #000;
    border: 2px solid var(--theme-primary);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    /* Prevent crushing */
}

.tcg-art img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: brightness(0.8) contrast(1.1);
}

.tcg-type-line {
    padding: 0.5cqw 3cqw;
    background: var(--theme-secondary);
    border-bottom: 2px solid var(--theme-primary);
    font-size: clamp(0.7rem, 3.5cqw, 1.1rem);
    font-style: italic;
    color: var(--theme-primary);
}

.tcg-text-box {
    flex: 1;
    padding: 3cqw;
    /* Reduced scaling slightly from 4.2cqw to 3.8cqw to prevent overflow */
    font-size: clamp(0.7rem, 3.8cqw, 1.3rem);
    line-height: 1.35;
    display: flex;
    flex-direction: column;
    gap: 1.5cqw;
    overflow-y: auto;
    /* Prevent clipping */
    min-height: 0;
    /* Necessary for flex child scrolling */

    /* Hide Scrollbar Visuals */
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */
}

/* Chrome/Safari Scrollbar Hide */
.tcg-text-box::-webkit-scrollbar {
    display: none;
}

.tcg-description {
    color: var(--text-primary);
}

.tcg-flavor {
    font-style: italic;
    color: var(--text-secondary);
    font-size: clamp(0.7rem, 3.8cqw, 1.2rem);
    margin-top: auto;
    padding-top: 2cqw;
    border-top: 1px solid var(--theme-primary);
}

.tcg-footer {
    padding: 1cqw 3cqw;
    display: flex;
    justify-content: space-between;
    font-size: clamp(0.5rem, 2.8cqw, 0.8rem);
    color: rgba(255, 255, 255, 0.3);
    position: relative;
}

.tcg-signature {
    position: absolute;
    bottom: 25px;
    right: 15px;
    font-family: var(--tcg-signature-font);
    font-size: 1.8rem;
    color: rgba(255, 255, 255, 0.4);
    transform: rotate(-5deg);
    pointer-events: none;
    user-select: none;
}

/* Holofoil Effect */
.tcg-holo {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: linear-gradient(105deg,
            transparent 40%,
            rgba(255, 215, 0, 0.1) 45%,
            rgba(255, 0, 0, 0.1) 50%,
            transparent 54%);
    background-size: 200% 200%;
    animation: holoFlow 5s infinite linear;
    z-index: 5;
}

@keyframes holoFlow {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}