:root {
    /* Color Palette */
    --color-primary: #0f0f23;
    --color-secondary: #1a1a3a;
    --color-accent: #4CAF50;
    --color-text: #fff;
    --color-text-muted: #aaa;
    --color-gold: #FFD700;
    --color-positive: #90EE90;
    --color-negative: #FFA500;
    --color-invalid: #FF4444;
    
    /* Spacing */
    --spacing-xs: 2px;
    --spacing-sm: 4px;
    --spacing-md: 8px;
    --spacing-lg: 12px;
    --spacing-xl: 16px;
    --spacing-xxl: 20px;
    
    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--color-primary);
    color: var(--color-text);
    min-height: 100vh;
    margin: 0;
    padding: 0;
    overflow-x: auto;
    padding-top: env(safe-area-inset-top);
}

.game-container {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    grid-template-areas:
        "header"
        "content"
        "help";
    gap: var(--spacing-md);
    padding: var(--spacing-xl);
    max-width: 1200px;
    margin: 0 auto;
}

.top-bar,
header.top-bar {
    grid-area: header;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--color-secondary), #2d2d5f);
    padding: var(--spacing-md) var(--spacing-xl);
    border-radius: var(--radius-lg);
    border: 1px solid #333;
    gap: var(--spacing-xxl);
    position: sticky;
    top: 0;
    z-index: 100;
}

.title-section {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.title-section h1 {
    font-size: 1.6em;
    margin: 0;
    background: linear-gradient(45deg, #00d4ff, #00ff88);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
    white-space: nowrap;
    line-height: 1;
}

.subtitle {
    font-size: 0.75em;
    color: #ccc;
    margin-top: 2px;
}

.balance-section {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    justify-content: center;
}

.balance-title {
    font-size: 0.9em;
    font-weight: bold;
    color: #ccc;
    white-space: nowrap;
}

.controls-section {
    display: flex;
    align-items: center;
}



.balance-display {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.balance-item {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 0.85em;
    white-space: nowrap;
    flex: 1;
    justify-content: center;
    min-width: 0;
    max-width: 80px;
}

.balance-item .label {
    font-size: 0.8em;
    color: #ccc;
}

.balance-item .value {
    font-size: 1.1em;
    font-weight: bold;
}

.balance-item .value.negative {
    color: #ff4444;
}

.balance-item .value.positive {
    color: #44ff44;
}

.projection {
    font-size: 0.9em;
    margin-left: 8px;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.3s;
}

.projection.show {
    opacity: 1;
}

.projection.positive {
    color: #90EE90;
}

.projection.negative {
    color: #FFA500;
}

.projection.neutral {
    color: #DDD;
}

.arrow {
    font-size: 0.9em;
    margin: 0 5px;
    opacity: 0;
    transition: opacity 0.3s;
}

.arrow.show {
    opacity: 1;
    color: #DDD;
}

.new-value {
    font-size: 1.2em;
    font-weight: bold;
    visibility: hidden;
    transition: visibility 0.3s;
    display: inline;
    width: 2em;
    text-align: right;
}

.new-value.show {
    visibility: visible;
}

.new-value.positive {
    color: #90EE90;
}

.new-value.negative {
    color: #FFA500;
}

.new-value.neutral {
    color: #DDD;
}

.new-value.invalid {
    color: #FF4444;
    text-shadow: 0 0 5px #FF4444;
}

.game-controls {
    display: flex;
    gap: 10px;
}

.btn {
    background: var(--color-accent);
    color: white;
    border: none;
    padding: var(--spacing-lg) var(--spacing-xxl);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 1em;
    transition: background 0.3s;
}

.btn:hover:not(:disabled) {
    background: #45a049;
}

.btn:disabled {
    background: #666;
    cursor: not-allowed;
}

.game-content,
main.game-content {
    grid-area: content;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.play-areas-row,
.shops-row {
    display: flex;
    gap: 20px;
    align-items: stretch;
}

.shops-row .shop-section {
    flex: 1;
    min-height: 200px;
}

.generators-section,
.consumers-section {
    background: linear-gradient(135deg, #1e3a1e, #2d4f2d);
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #4a4a6a;
    flex: 1;
    width: 100%;
    min-height: 200px;
}

.generators-section {
    background: linear-gradient(135deg, #1e1e3a, #2d2d4f);
}

.consumers-section {
    background: linear-gradient(135deg, #3a1e1e, #4f2d2d);
}

.generators-section h3,
.consumers-section h3,
.shop-section h3 {
    text-align: center;
    margin: 0 0 8px 0;
    font-size: 1em;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.game-grid--generators,
.game-grid--consumers {
    display: grid;
    grid-template-columns: repeat(4, minmax(100px, 1fr));
    gap: 8px;
    justify-content: center;
    justify-items: center;
    width: 100%;
    margin: 0 auto;
}

.slot {
    width: 100px;
    height: 140px;
    border: 2px dashed #666;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    position: relative;
}

.slot--valid-target {
    border-color: #4CAF50;
    background: rgba(76, 175, 80, 0.2);
}

.slot--invalid-target {
    border-color: #f44336;
    background: rgba(244, 67, 54, 0.2);
}

.slot--incentive-target {
    border-color: #FFD700;
    background: rgba(255, 215, 0, 0.3);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
}

.card {
    width: 90px;
    height: 130px;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 0;
    transition: all 0.3s;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    position: relative;
    display: flex;
    flex-direction: column;
    border: 2px solid #ddd;
    overflow: hidden;
}

.shop-section .card:not(.card--under-construction) {
    cursor: pointer;
}

.shop-section .card--under-construction {
    cursor: default;
    pointer-events: none;
}

.shop-section .card:hover:not(.card--under-construction):not(.card--dragging) {
    transform: translateY(-5px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

/* Card type background colors */
.card--generator {
    background: #e3f2fd;
    border: 2px solid #5a67d8;
}

.card--big-generator {
    background: #e0f7fa;
    border: 2px solid #38b2ac;
}

.card--consumer {
    background: #ffebee;
    border: 2px solid #e53e3e;
}

.card--incentive {
    background: #fff7ed;
    border: 2px solid #d69e2e;
}

.card--generator .card__header {
    background: #5a67d8;
    min-height: 32px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 1px 4px;
    border-bottom: 1px solid #ddd;
}

.card--big-generator .card__header {
    background: #38b2ac;
    min-height: 32px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 1px 4px;
    border-bottom: 1px solid #ddd;
}

.card--consumer .card__header {
    background: #e53e3e;
    min-height: 32px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 1px 4px;
    border-bottom: 1px solid #ddd;
}

.card--incentive .card__header {
    background: #d69e2e;
    min-height: 32px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 1px 4px;
    border-bottom: 1px solid #ddd;
}

.card--fossil {
    background: #fdf6f0;
    border: 2px solid #c05621;
}

.card--fossil .card__header {
    background: #c05621;
    min-height: 32px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 1px 4px;
    border-bottom: 1px solid #ddd;
}

/* Under construction card styles */
.card--under-construction {
    background: linear-gradient(135deg, #333 0%, #666 100%);
}

.card--under-construction .card__content {
    display: none;
}

.card--under-construction::before {
    content: "Under Construction";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.7em;
    color: #fff;
    text-align: center;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    line-height: 1.2;
    width: 80%;
}

/* Unrevealed card styles */
.card--unrevealed {
    background: linear-gradient(135deg, #666 0%, #999 100%);
    opacity: 0.7;
}

.card--unrevealed .card__content {
    display: none;
}

.card--unrevealed .card__type,
.card--unrevealed .card__name {
    display: none;
}

.card--unrevealed .card__header {
    background: transparent;
    border: none;
}

.card--unrevealed::before {
    content: "Revealed After Turn " attr(data-reveal-turn);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.6em;
    color: #fff;
    text-align: center;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    line-height: 1.2;
    width: 80%;
}

.card__next-turn-indicator {
    color: #666;
    text-align: center;
    padding: 2px 4px;
    font-size: 0.75em;
    font-weight: bold;
    margin-top: 1px;
}

.card__header {
    background: #5a67d8;
    padding: 1px 4px;
    border-bottom: 1px solid #ddd;
    min-height: 32px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.card__type {
    font-size: 0.55em;
    font-weight: normal;
    text-align: center;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
    line-height: 1;
    flex-shrink: 0;
}

.card__name {
    font-size: 0.6em;
    font-weight: bold;
    margin: 0;
    text-align: center;
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    line-height: 1.1;
    word-wrap: break-word;
    hyphens: auto;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 2px;
    overflow: hidden;
}

.card__content {
    padding: 4px;
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
}

.card__stats {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 1px;
    margin-top: 2px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #fff;
    padding: 1px 2px;
    border-radius: 3px;
    border: 1px solid #e0e0e0;
    font-size: 0.8em;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
    min-height: 28px;
}

.stat__label {
    font-weight: bold;
    color: #333;
    text-transform: capitalize;
    font-size: 0.85em;
    line-height: 1;
    margin-bottom: 1px;
}

.stat__value {
    font-weight: bold;
    color: #333;
    font-size: 1.1em;
    line-height: 1;
}

.stat__value--positive {
    color: #28a745;
    font-weight: bold;
}

.stat__value--negative {
    color: #dc3545;
    font-weight: bold;
}



.goal-section {
    grid-area: help;
    text-align: center;
    padding: var(--spacing-md);
    color: var(--color-gold);
    font-size: 0.9em;
    margin-bottom: var(--spacing-xs);
}

.attribution-section {
    text-align: center;
    padding: var(--spacing-sm);
    font-size: 0.8em;
    color: var(--color-text-muted);
    margin-bottom: var(--spacing-sm);
}

.attribution-section a {
    color: #4CAF50;
    text-decoration: none;
    margin: 0;
    padding: 0;
}

.attribution-section a:hover {
    color: #66BB6A;
    text-decoration: underline;
}



.shop-section {
    background: linear-gradient(135deg, #2a2a2a, #3a3a3a);
    padding: 6px;
    border-radius: 8px;
    border: 1px solid #4a4a6a;
    flex: 1;
    width: 100%;
}

.shop-section h3 {
    text-align: center;
    margin-bottom: 8px;
    font-size: 1.1em;
}

.shop__grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(100px, 1fr));
    gap: 8px;
    justify-content: center;
    justify-items: center;
    width: 100%;
    margin: 0 auto;
}

.shop__slot {
    width: 100px;
    height: 140px;
    border: 2px solid transparent;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    position: relative;
}



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

.modal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
    margin-bottom: 20px;
    font-size: 2em;
}

.modal-content p {
    margin-bottom: 15px;
    font-size: 1.1em;
    line-height: 1.4;
}

.score-display {
    background: rgba(255, 255, 255, 0.2);
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
    text-align: center;
}

.score-display h3 {
    font-size: 1.5em;
    margin-bottom: 5px;
    color: #FFD700;
}

.score-subtitle {
    font-size: 0.9em;
    opacity: 0.8;
    margin-bottom: 0 !important;
}

.card--selected {
    border: 3px solid #FFD700 !important;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.8);
}

.card--disabled {
    opacity: 0.5;
    cursor: not-allowed !important;
    filter: grayscale(50%);
}

.card--disabled:hover {
    transform: none !important;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2) !important;
}

.card--dragging {
    opacity: 1 !important;
    transform: scale(1.05) !important;
    z-index: 1000;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.slot--drag-over {
    border-color: #4CAF50;
    background: rgba(76, 175, 80, 0.3);
    border-width: 3px;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

@media (max-width: 1100px) {
    .top-bar,
    header.top-bar {
        border-radius: 0 !important;
        margin: -16px -16px 16px -16px;
        position: sticky;
        top: 0;
    }
}

@media (max-width: 768px) {
    .top-bar {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        text-align: left;
        align-items: flex-start;
    }
    
    .title-section {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        flex: 1;
        min-width: 0;
    }
    
    .controls-section {
        margin: 0;
        align-self: flex-start;
    }
    
    .balance-section {
        order: 3;
        justify-content: center;
        width: 100%;
        flex-basis: 100%;
    }
}

@media (max-width: 600px) {
    .balance-section {
        gap: 8px;
    }
    
    .balance-item {
        padding: 3px 4px;
        font-size: 0.8em;
        max-width: none;
        flex: 1;
    }
    
    .balance-display {
        gap: 2px;
        width: 100%;
    }
}

@media (max-width: 1100px) {
    .play-areas-row {
        flex-direction: column;
        gap: 12px;
    }
}

@media (max-width: 1000px) {
    .shops-row {
        flex-direction: column;
        gap: 12px;
    }
    
    .shops-row .shop-section {
        flex: none;
    }
}

@media (max-width: 1100px) {
    body {
        padding-top: 0;
    }
    
    .game-container {
        padding: 0 16px 16px 16px;
        margin-top: 0;
    }
}

@media (max-width: 768px) {
    .top-bar,
    header.top-bar {
        margin: -16px -8px 12px -8px;
    }
    
    .game-container {
        padding: 0 8px 8px 8px;
        gap: 12px;
    }
    
    .grid-container {
        gap: 12px;
    }
    
    .play-areas-row {
        flex-direction: column;
        gap: 12px;
    }
}

@media (max-width: 400px) {
    .balance-item {
        padding: 2px 3px;
        font-size: 0.75em;
        max-width: none;
        flex: 1;
    }
    
    .balance-item .label {
        font-size: 0.75em;
    }
    
    .balance-item .value {
        font-size: 1em;
    }
    
    .balance-display {
        gap: 1px;
        width: 100%;
    }
}

@media (min-width: 800px) and (max-width: 999px) {
    .game-grid--generators,
    .game-grid--consumers,
    .shop__grid {
        grid-template-columns: repeat(4, minmax(100px, 140px));
        gap: 8px;
        max-width: 600px;
    }
    
    .card__header,
    .card--generator .card__header,
    .card--big-generator .card__header,
    .card--consumer .card__header,
    .card--incentive .card__header,
    .card--fossil .card__header {
        min-height: 36px;
    }
    
    .card__name {
        font-size: 0.65em;
        height: 22px;
    }
}

@media (min-width: 1000px) and (max-width: 1199px) {
    .game-grid--generators,
    .game-grid--consumers,
    .shop__grid {
        grid-template-columns: repeat(4, minmax(110px, 150px));
        gap: 10px;
        max-width: 700px;
    }
    
    .card__header,
    .card--generator .card__header,
    .card--big-generator .card__header,
    .card--consumer .card__header,
    .card--incentive .card__header,
    .card--fossil .card__header {
        min-height: 40px;
    }
    
    .card__name {
        font-size: 0.7em;
        height: 24px;
    }
}

@media (min-width: 1100px) {
    .top-bar {
        position: relative;
        justify-content: center;
        min-height: 70px;
        align-items: center;
    }
    
    .title-section {
        position: absolute;
        left: var(--spacing-xl);
        top: 50%;
        transform: translateY(-50%);
        z-index: 10;
    }
    
    .controls-section {
        position: absolute;
        right: var(--spacing-xl);
        top: 50%;
        transform: translateY(-50%);
        z-index: 10;
    }
    
    .balance-section {
        position: relative;
        z-index: 5;
        margin: 0;
    }
}

@media (min-width: 1200px) {
    .game-grid--generators,
    .game-grid--consumers,
    .shop__grid {
        grid-template-columns: repeat(4, minmax(120px, 200px));
        gap: 12px;
        max-width: 900px;
    }
    
    .card__header,
    .card--generator .card__header,
    .card--big-generator .card__header,
    .card--consumer .card__header,
    .card--incentive .card__header,
    .card--fossil .card__header {
        min-height: 44px;
    }
    
    .card__name {
        font-size: 0.75em;
        height: 26px;
    }
}

@media (max-width: 500px) {
    .game-grid--generators,
    .game-grid--consumers,
    .shop__grid {
        grid-template-columns: repeat(4, minmax(100px, 1fr));
        gap: 3px;
        justify-content: center;
        justify-items: center;
    }
}

@media (max-width: 450px) {
    .game-grid--generators,
    .game-grid--consumers,
    .shop__grid {
        grid-template-columns: repeat(4, minmax(90px, 1fr));
        gap: 2px;
        justify-content: center;
        justify-items: center;
    }
    
    .card__type {
        display: none;
    }
    
    .stat {
        border: none;
        box-shadow: none;
        background: transparent;
        padding: 1px 2px;
    }
}

@media (max-width: 400px) {
    .game-grid--generators,
    .game-grid--consumers,
    .shop__grid {
        grid-template-columns: repeat(4, minmax(80px, 1fr));
        gap: 2px;
        justify-content: center;
        justify-items: center;
    }
    
    .slot {
        width: 85px;
        height: 110px;
    }
    
    .card {
        width: 80px;
        height: 105px;
    }
}

@media (max-width: 350px) {
    .game-grid--generators,
    .game-grid--consumers,
    .shop__grid {
        grid-template-columns: repeat(4, minmax(70px, 1fr));
        gap: 1px;
    }
    
    .slot {
        width: 75px;
        height: 105px;
    }
    
    .card {
        width: 70px;
        height: 100px;
    }
    
    .stat {
        border: none;
        box-shadow: none;
        background: transparent;
        padding: 1px 2px;
        min-height: 22px;
    }
    
    .game-container {
        padding: 4px;
    }
}



/* Held card styles - match dragging appearance */
.card--held {
    cursor: none;
    opacity: 1 !important;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
    transition: none;
    will-change: transform;
    z-index: 1000;
}

/* Drag following element - same as held cards */
.card--drag-following {
    cursor: none;
    opacity: 1 !important;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
    transition: none;
    will-change: transform;
    z-index: 10000;
}