:root {
    /* Updated Palette aligned with Background Image */
    --color-parchment-card: #f2e1c1; /* Warmer, more aged parchment */
    --color-ink: #2d1e1e;           /* Deep dark brown-black for text */
    --color-accent: #c08e2c;        /* Brass/Gold from the tools */
    --color-border: #5d4037;        /* Rich wood brown from the desk */
    --color-header: #fdf5e6;        /* Light parchment for high contrast against dark sky */

    /* Terrain Colors - PRESERVED */
    --color-forest: #4b6f44;
    --color-village: #a52a2a;
    --color-farm: #f4c430;
    --color-water: #4682b4;
    --color-monster: #4b0082;
    --color-mountain: #8b4513;

    --font-main: 'Crimson Text', serif;
    --font-heading: 'Old Standard TT', serif;
}

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

body {
    background-color: #1a1a1a; /* Dark fallback */
    color: var(--color-ink);
    font-family: var(--font-main);
    font-size: 18px;
    line-height: 1.6;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

/* UI Fade-in System */
.deck-container, .fullscreen-hint, .footer-seed {
    opacity: 1;
    transition: opacity 0.4s ease-in-out;
}

body.loading .deck-container, 
body.loading .fullscreen-hint,
body.loading .footer-seed {
    opacity: 0;
}

/* Background System */
.bg-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -10;
    background-size: cover;
    background-position: center;
    opacity: 0;
    transform: scale(1.1);
    transition: opacity 1s ease-in-out;
    background-image: url("Gemini_Generated_Image_4u0jq84u0jq84u0j.png"); /* Default background */
}

.bg-layer.active {
    opacity: 1;
}

.deck-container {
    width: 100%;
    max-width: 800px;
    text-align: center;
    padding: 2rem;
    z-index: 10;
}

header h1 {
    font-family: var(--font-heading);
    font-size: 3.5rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3rem;
    margin-bottom: 0.5rem;
    color: var(--color-header);
    text-shadow:
        2px 2px 4px rgba(0,0,0,0.8),
        0 0 20px rgba(192, 142, 44, 0.3);
}

.season-info {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.season-badge, .progress-badge, .seed-badge {
    padding: 0.4rem 1.2rem;
    border-radius: 4px;
    font-family: var(--font-heading);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 1rem;
    border: 1px solid var(--color-accent);
    background-color: rgba(45, 30, 30, 0.85);
    color: var(--color-accent);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    backdrop-filter: blur(4px);
}

.card-display {
    perspective: 1200px;
    margin: 1rem auto;
    display: flex;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.card {
    width: 340px;
    height: 500px;
    background-color: var(--color-parchment-card);
    background-image: url("https://www.transparenttextures.com/patterns/parchment.png");
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    border: 2px solid var(--color-border);
    position: relative;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.6s ease;
    transform-style: preserve-3d;
    cursor: pointer;
    padding: 0.8rem;
}

#ruins-card {
    cursor: default;
    opacity: 0.7;
    transform: scale(0.9);
    pointer-events: none;
}

.card-inner {
    height: 100%;
    border: 2px solid var(--color-border);
    border-radius: 4px;
    position: relative;
    padding: 1rem;
}

.card-front {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.card-header {
    border-bottom: 2px solid rgba(93, 64, 55, 0.3);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
    text-align: center;
}

.card-time-cost {
    position: absolute;
    top: -1.2rem;
    left: -1.2rem;
    width: 3.8rem;
    height: 3.8rem;
    background-color: var(--color-border);
    color: var(--color-parchment-card);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 1;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 2rem;
    box-shadow: 0 6px 12px rgba(0,0,0,0.4);
    border: 3px solid var(--color-accent);
    z-index: 30;
}

.season-warning {
    position: absolute;
    bottom: -1.8rem;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--color-farm);
    color: #2d1e1e;
    border: 2px solid var(--color-border);
    padding: 0.5rem 1.8rem;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.1rem;
    white-space: nowrap;
    text-transform: uppercase;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    z-index: 20;
    display: none;
}

.card-title {
    font-family: var(--font-heading);
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--color-border);
}

.card-body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    text-align: center;
}

.description-text {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    font-size: 1.4rem;
    line-height: 1.4;
    width: 100%;
    color: var(--color-ink);
}

.terrain-options {
    flex: 0 0 50%;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem;
    border-bottom: 1px solid rgba(93, 64, 55, 0.15);
}

.terrain-badge {
    width: 38px;
    height: 38px;
    border-radius: 6px;
    display: inline-block;
    box-shadow: 2px 2px 4px rgba(0,0,0,0.2);
    border: 1px solid rgba(0,0,0,0.2);
}

.terrain-badge.forest,
.shape-grid.terrain-forest .shape-cell.filled {
    background-color: var(--color-forest);
    background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='10' cy='8' r='5' fill='none' stroke='rgba(255,255,255,0.6)' stroke-width='1.0'/%3E%3Crect x='9' y='13' width='2' height='4' fill='none' stroke='rgba(255,255,255,0.6)' stroke-width='1.0'/%3E%3C/svg%3E");
    background-position: center;
    background-repeat: no-repeat;
    background-size: 80% 80%;
}
.terrain-badge.forest { background-color: var(--color-forest); }
.terrain-badge.village,
.shape-grid.terrain-village .shape-cell.filled {
    background-color: var(--color-village);
    background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4 16h12V10l-6-5-6 5v6z' fill='none' stroke='rgba(255,255,255,0.6)' stroke-width='1.0'/%3E%3C/svg%3E");
    background-position: center;
    background-repeat: no-repeat;
    background-size: 80% 80%;
}
.terrain-badge.village { background-color: var(--color-village); }
.terrain-badge.farm,
.shape-grid.terrain-farm .shape-cell.filled { 
    background-color: var(--color-farm);
    background-image: repeating-linear-gradient(
        135deg,
        rgba(255, 255, 255, 0.4) 0,
        rgba(255, 255, 255, 0.4) 1px,
        transparent 1px,
        transparent 5px
    );
}
.terrain-badge.farm { background-color: var(--color-farm); }
.terrain-badge.water,
.shape-grid.terrain-water .shape-cell.filled {
    background-color: var(--color-water);
    background-image: url("data:image/svg+xml,%3Csvg width='20' height='12' viewBox='0 0 20 12' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 6 Q5 2 10 6 T20 6' fill='none' stroke='rgba(255,255,255,0.5)' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 20px 12px;
}
.terrain-badge.water { background-color: var(--color-water); }
.terrain-badge.monster,
.shape-grid.terrain-monster .shape-cell.filled {
    background-color: var(--color-monster);
    background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='10' cy='11' r='4' fill='none' stroke='rgba(255,255,255,0.6)' stroke-width='1.0'/%3E%3Cpath d='M6 8l-2-3M14 8l2-3' fill='none' stroke='rgba(255,255,255,0.6)' stroke-width='1.0' stroke-linecap='round'/%3E%3C/svg%3E");
    background-position: center;
    background-repeat: no-repeat;
    background-size: 80% 80%;
}
.terrain-badge.monster { background-color: var(--color-monster); }

.shape-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    position: relative;
}

.coin {
    position: absolute;
    width: 52px;
    height: 52px;
    background: linear-gradient(135deg, #ffd700, #daa520);
    border: 2px solid #b8860b;
    border-radius: 50%;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.coin-left { top: 65px; left: 20px; }
.coin-right { top: 0; right: -1.2rem; }

.shape-container {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    width: 100%;
}

.shape-grid {
    display: grid;
    gap: 5px;
    justify-items: center;
    align-items: center;
}

.shape-cell {
    width: 36px;
    height: 36px;
    background-color: rgba(93, 64, 55, 0.08);
    border: 1px dashed rgba(93, 64, 55, 0.2);
    border-radius: 4px;
}

.shape-cell.filled {
    background-color: var(--shape-fill-color, var(--color-ink));
    border: 1px solid rgba(0,0,0,0.2);
    box-shadow: inset 1px 1px 2px rgba(0,0,0,0.2);
    border-radius: 4px;
}

.shape-divider {
    width: 2px;
    height: 80px;
    background-color: var(--color-border);
    opacity: 0.2;
}

/* Precision SVG Directional Arrows */
.direction-arrow {
    position: absolute;
    width: 160px;
    height: 160px;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    z-index: 5;
}

.direction-arrow svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: var(--color-monster);
    stroke-width: 6;
    stroke-linecap: round;
    opacity: 0.9;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.direction-arrow .arrowhead {
    fill: var(--color-monster);
    stroke: none;
}

.direction-arrow.ccw svg {
    transform: scaleX(-1);
}

/* Collection Overlay */
.collection-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6); /* Reduced opacity */
    z-index: 1000;
    display: none; /* Hidden by default in CSS */
    justify-content: center;
    align-items: flex-start;
    padding: 2rem;
    overflow-y: auto;
    backdrop-filter: blur(5px); /* Reduced blur */
}

body.loading .collection-overlay {
    display: none !important;
}

.collection-content {
    width: 100%;
    max-width: 1400px;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.collection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--color-accent);
    padding-bottom: 1rem;
    color: var(--color-header);
}

.collection-header h2 {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    text-transform: uppercase;
    letter-spacing: 0.2rem;
}

.collection-hint {
    font-family: var(--font-heading);
    font-size: 1rem;
    text-transform: uppercase;
    color: var(--color-accent);
}

.collection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.5rem;
    width: 100%;
}

/* Mini Card Overrides */
.collection-grid .card {
    width: 100%;
    height: 320px;
    padding: 0.4rem;
    font-size: 0.8rem;
    cursor: default;
}

.collection-grid .card-inner {
    padding: 0.6rem;
}

.collection-grid .card-title {
    font-size: 1.1rem;
}

.collection-grid .card-time-cost {
    width: 2.4rem;
    height: 2.4rem;
    font-size: 1.2rem;
    top: -0.8rem;
    left: -0.8rem;
    border-width: 2px;
}

.collection-grid .terrain-badge {
    width: 28px;
    height: 28px;
}

.collection-grid .shape-cell {
    width: 24px;
    height: 24px;
    gap: 3px;
}

.collection-grid .shape-grid {
    gap: 3px;
}

.collection-grid .description-text {
    font-size: 1rem;
}

.collection-grid .coin {
    width: 32px;
    height: 32px;
}

.collection-grid .coin-left { top: 35px; left: 10px; }
.collection-grid .coin-right { top: 0; right: -0.6rem; }

.collection-grid .direction-arrow {
    width: 100px;
    height: 100px;
}

.collection-grid .shape-divider {
    height: 50px;
}

.fullscreen-hint, .footer-seed {
    position: fixed;
    bottom: 1.5rem;
    padding: 0.4rem 1.2rem;
    border-radius: 4px;
    font-family: var(--font-heading);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.85rem;
    border: 1px solid var(--color-accent);
    background-color: rgba(45, 30, 30, 0.7);
    color: var(--color-accent);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    backdrop-filter: blur(4px);
    z-index: 100;
    opacity: 0.8;
    transition: opacity 0.3s ease;
}

.fullscreen-hint {
    left: 1.5rem;
    pointer-events: none;
}

.footer-seed {
    right: 1.5rem;
    pointer-events: auto;
    cursor: text;
    user-select: text;
}

.fullscreen-hint strong, .footer-seed strong {
    color: var(--color-parchment-card);
    font-size: 1.1rem;
}

.ranking-list {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 1.15rem;
    width: 100%;
    margin-top: 0.5rem;
}

.ranking-item {
    display: grid;
    grid-template-columns: 45px 1fr;
    text-align: left;
    border-bottom: 1px dashed rgba(93, 64, 55, 0.15);
    padding-bottom: 2px;
}

.ranking-score {
    font-weight: 700;
    color: var(--color-border);
}

.ranking-title {
    color: var(--color-ink);
}

/* Animations */
@keyframes drawCard {
    0% { transform: translateY(100vh) rotate(5deg); opacity: 0; }
    100% { transform: translateY(0) rotate(0); opacity: 1; }
}

.card-draw-animation {
    animation: drawCard 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
