/*#region GAME VARIABLES */
/* Game-specific CSS properties and dimensions
   Main variables moved to common.css for sharing with admin */
   :root {
    /* Game-specific dimensions */
    --card-width: 120px;
    --card-height: 168px;
    --offset-increment: 10px; /* Fertilizer stacking offset */
    --deck-gap: 150px;
    --cards-per-row: 3; /* Calculated dynamically by JS */
}
/*#endregion*/

/*#region LAYOUT STRUCTURE */
/* Game board, header positioning, and main layout areas */
body {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-board {
    position: relative;
    min-height: 100vh;
    width: 100%;
    padding: 20px;
    display: none; /* Hidden until authenticated */
}

#game-board.authenticated {
    display: block;
}

/* Background image overlay - reduced opacity for readability */
#game-board::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image: url('../images/Beautiful agricultural fields.jpg');
    background-size: cover;
    background-attachment: fixed;
    opacity: 0.6;
    z-index: -1;
}

/* Header positioning - absolute to stay fixed at top */
#game-header {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    z-index: 10; /* Above background */
    max-width: var(--max-width);
    width: 100%;
    box-sizing: border-box; /* Include padding in width calculation */
}
/* Align rules button with bank area left edge */
#info-button {
    margin-left: 30px; /* Offset the header's padding to align with bank area */
}

#sound-toggle, #music-toggle {
    position: absolute;
    font-size: 1.2em;
    padding: 0.5rem;
    width: auto;
    height: auto;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background-color: var(--crop-color);
    border: none;
    cursor: pointer;
    transition: opacity 0.2s;
}

#sound-toggle {
    right: 45px;
}

#music-toggle {
    right: 90px;
}

#sound-toggle img, #music-toggle img {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.button:active, .tab-button:active {
    transform: scale(0.95);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

#game-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%) scale(1);
  font-size: clamp(1.2rem, 2.5vw, 1.5rem);
  font-weight: bold;
  color: #333;
  text-shadow: 0.5px 0.5px 1px rgba(255, 0, 0, 0.8);
  transform-origin: center;
  will-change: transform;
  transition: font-size 0.3s ease, text-shadow 0.3s ease, color 0.3s ease;
}

#game-title.ripple {
    animation: redRippleShake 1s ease-out;
}

.ripple {
    animation: redRippleShake 1s ease-out;
}

.ripple-text {
    font-size: var(--title-size);
    font-weight: bold;
    color: #333;
}

.ripple-text.ripple {
    animation: redRippleShake 1s ease-out;
    color: red;
    text-shadow: 0 0 10px rgba(255, 0, 0, 0.5);
}

/* Area with bank, crop buttons, decks */
#deck-area {
    display: flex;
    justify-content: space-between;
    padding: 10px 20px 20px;
    gap: var(--card-spacing);
    width: 100%;
    max-width: var(--max-width);
    margin: 80px auto 0; /* Top margin accounts for header */
}

.left-controls {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

/* Main play area - contains the crop grid */
#play-area {
    min-height: 500px;
    position: relative;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    max-width: var(--max-width);
}

/*#endregion*/

/*#region CROP GRID SYSTEM */
/* Main play area - auto-fit with row spacing handled by JS */
#crop-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(var(--card-width), 1fr));
    gap: var(--card-spacing);
    padding: 20px;
    margin: 0 auto;
    justify-content: center;
    row-gap: 0; /* JS handles vertical spacing for fertilizer stacking */
    grid-auto-rows: min-content;
}

/* containers for cards and fertilizers */
.grid-cell {
    width: var(--card-width);
    height: var(--card-height);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border-radius: 20px;
}

/* Hide border when cell contains cards */
.grid-cell:has(.crop-card) {
    border: none;
}

/* Prevent z-index issues during animations */
.grid-cell.animating {
    isolation: isolate;
    border: none;
}

/*#endregion*/

/*#region DECK SPACES & CONTROL AREAS */
/* Deck styling, bank area, fertilizer deck, and special areas */
.card-deck {
    width: var(--card-width);
    height: var(--card-height);
    background-color: rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

/* Interactive feedback for clickable decks */
.card-deck:hover:not(.disabled) {
    background-color: rgba(255, 255, 255, 0.2);
}

.card-deck.disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

/* Visual feedback when deck is clicked */
.card-deck.pulse {
    animation: pulse 0.3s ease;
}

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

/* Labels positioned above deck areas */
.deck-label {
    color: #333;
    font-size: var(--label-size);
    font-weight: bold;
    margin-bottom: 10px;
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap; /* Prevent wrapping on small screens */
}

/* Special deck areas */
/* Crop controls area - wider than standard deck */
.crop-controls-area {
    width: calc(var(--card-width) * 4);
    height: var(--card-height);
    background-color: #BBEBFE;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.3s ease;
    flex-shrink: 0;
    border: 2px solid #666;
}

#bank-area {
    background-color: #BBEBFE;
    background-image: url('../images/bank_3898067.png');
    background-size: 80%;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 0px;
    width: var(--card-height); /* Square aspect ratio */
    position: relative;
    cursor: default; /* Not clickable */
}

/* Fertilizer deck - displays reference card */
#fertilizer-deck {
    cursor: default; /* Not clickable */
    border-radius: 20px;
    border: 2px solid #666;
}

/*#endregion*/

/*#region CARD SYSTEM */
/* Card structure, faces, types, images, and interaction states */
/* Shared border radius for consistent appearance */
.card-deck, .card, .card-front, .card-back, .grid-cell {
    border-radius: 20px;
}

/* Base card structure - 3D transform container */
.card {
    border: 2px solid #666;
    position: absolute;
    width: 100%;
    height: 100%;
    transform-origin: center center;
    transform-style: preserve-3d; /* Enables 3D flipping */
}

/* Card faces - front and back sides */
.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden; /* Hide back when flipped */
    overflow: hidden;
}

/* Card back styling - game deck cards */
.card-deck .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--card-back-color);
}

/* Border for game deck card back */
#game-deck .card-back {
    border: 2px solid #666;
}

/* Card type styling */
/* Crop cards - interactive and green-themed */
.card.crop-card {
    cursor: pointer;
    overflow: hidden;
    background-color: var(--crop-color);
}

/* Fertilizer cards - non-interactive, stacked positioning */
.card.fertilizer-card {
    pointer-events: none; /* Can't be clicked */
    background-color: var(--fertilizer-color);
}

/* Locust cards - red-themed for danger */
.locust-card .card-front {
    background-color: var(--locust-color);
}

/* Color coding for different card types */
.card.fertilizer-card .card-front {
    background-color: var(--fertilizer-color);
}

/* Card images and content */
/* Image scaling and positioning */
.card-front img, .card-back img {
    width: 100%;
    height: 100%;
    border-radius: 15px;
}

/* Front images - padded for better appearance */
.card-front img {
    object-fit: contain;
    padding: 10px;
}

/* Back images - full coverage for deck */
.card-back img {
    object-fit: cover;
    padding: 0;
}


/* Special handling for reference cards in deck areas */
#fertilizer-deck .card-front,
#bank-area .card-front {
    transform: none;
    position: relative;
}

#fertilizer-deck .card-front {
    background-color: var(--fertilizer-color);
}

/* Card interaction states */
/* Hover effect for crop cards - lift and shadow */
.crop-card:hover {
    transform: translateY(-10px) !important;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

/* Selection state - blue border and glow */
.card.selected {
    border: 2px solid #606EBF;
    box-shadow: 0 0 0 2px rgba(96, 110, 191, 0.3), 0 0 8px 4px rgba(96, 110, 191, 0.4);
    transform: translateY(-5px);
    transition: all 0.3s ease;
}

/* Selling state - fade out during animation */
.crop-card.selling {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: scale(0) !important;
}

/* Front face visibility in grid */
.crop-card .card-front {
    transform: none !important;
    position: relative;
}

/* Stabilize crop card position during margin recalculations */
.crop-card {
    position: relative;
    isolation: isolate; /* Create new stacking context */
}

/* Animated cards system */
/* Base animated card - used for flying animations */
.animated-card {
    position: absolute;
    width: var(--card-width);
    height: var(--card-height);
    border-radius: 20px;
    border: 2px solid #666;
    z-index: 1000; /* Above all other content */
    transform-style: preserve-3d;
}

/* Remove double borders on animated cards */
.animated-card .card {
    border: none !important;
}

/* Animated card faces */
.animated-card .card-front,
.animated-card .card-back {
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    overflow: hidden;
}

/* Default orientations for flip animations */
.animated-card .card-front {
    transform: rotateY(180deg);
}

.animated-card .card-back {
    background-color: var(--card-back-color);
    transform: rotateY(0deg);
}

/* Type-specific animated card styling */
.animated-card.crop .card-front {
    background-color: var(--crop-color);
}

.animated-card.fertilizer .card-front {
    background-color: var(--fertilizer-color);
    transform: rotateY(0deg); /* Fertilizer shows front immediately */
}

.animated-card.locust .card-front {
    background-color: var(--locust-color);
}

/* Back image styling for animated cards */
.animated-card .card-back img {
    object-fit: cover;
    padding: 0;
}

/*#endregion*/

/*#region ANIMATIONS */
/* Keyframe animations and animated card systems */
/* Main card reveal animation - enlarge and flip */
@keyframes enlargeAndFlip {
    0% {
        transform: scale(1) rotateY(0deg);
    }
    100% {
        transform: scale(1.5) rotateY(180deg);
    }
}

/* move card from deck to card grid */
@keyframes flyToDestination {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1.5) rotateY(0deg);
    }
    100% {
        opacity: 1;
        transform: translate(var(--fly-x), var(--fly-y)) scale(1) rotateY(0deg);
    }
}

/* Locust sweep animation - destructive movement */
@keyframes locustSweep {
    0% {
        transform: translate(var(--fly-x), var(--fly-y)) scale(1) rotateY(0deg);
    }
    100% {
        transform: translate(calc(var(--fly-x) + 800px), var(--fly-y)) scale(1) rotateY(180deg) rotate(360deg);
        opacity: 0;
    }
}

/* Shake the title when locust card is drawn */
@keyframes redRippleShake {
    0%   { transform: translateX(-50%) scale(1) rotate(0deg); }
    10%  { transform: translateX(-50%) rotate(-2deg); }
    20%  { transform: translateX(-50%) scale(2.5) rotate(2deg); }
    30%  { transform: translateX(-50%) rotate(-1.5deg); }
    40%  { transform: translateX(-50%) rotate(1.5deg); }
    50%  {
      transform: translateX(-50%) scale(3) rotate(-1deg);
      text-shadow: 0 0 10px rgba(255, 0, 0, 0.5);
      color: red;
    }
    60%  { transform: translateX(-50%) rotate(1deg); }
    70%  { transform: translateX(-50%) rotate(-0.5deg); }
    80%  { transform: translateX(-50%) scale(2.5) rotate(0.5deg); }
    90%  { transform: translateX(-50%) rotate(0deg); }
    100% {
      transform: translateX(-50%) scale(1) rotate(0deg);
      color: #333;
      text-shadow: 1px 1px 2px rgba(255, 0, 0, 0.8);
    }
}

/* Special case - locust with no crops to destroy */
.locust-no-crops {
    animation: enlargeAndFlip 0.7s ease-in-out forwards, 
               locustPauseAndFade 2s 0.7s ease-in forwards;
}

/*#endregion*/

/*#region UI CONTROLS */
/* Control elements, value displays, and interactive components */
#crop-area {
    font-size: var(--label-size);
    font-weight: bold;
    color: #333;
}

.crop-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
    width: 70%;
}

#crop-value, #selected-value {
    font-weight: bold;
    color: #333;
    text-align: center;
    margin: 10px 0;
    font-size: var(--label-size);
}

#crop-value {
    font-size: calc(var(--label-size) * 0.8);
}

#selected-value {
    width: 80%;
}

/*#endregion*/

/*#region TOOLTIP SYSTEM */
.tooltip {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 14px;
    max-width: 250px;
    z-index: 1000;
    pointer-events: none; /* Doesn't interfere with interactions */
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
    white-space: normal;
    text-align: left;
}

.tooltip.visible {
    opacity: 1;
}

#bank-area:hover > .tooltip {
    visibility: visible;
    opacity: 1;
}

/*#endregion*/

/*#region DIALOG SYSTEM */
/* Modal dialogs, tabs, and overlay content */
.info-dialog {
    padding: 0;
    border: none;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    max-width: min(65em, 80vw); /* Responsive to font size (900px ÷ 16px = 56.25em) */
    width: 90%;
    background: #fff;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
}

.info-dialog::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

dialog.compact-dialog {
    width: fit-content;
    max-width: 90vw;
    min-width: 260px;
    padding: 1.5rem 1rem;
}

dialog.compact-dialog .dialog-content {
    height: auto;
}

.dialog-content {
    padding: 1rem;
    background-color: white;
    border-radius: 10px;
    position: relative;
    height: min(40em, 80vh);
    display: flex;
    flex-direction: column;
}

.dialog-scroll-area {
    flex: 1; /* Take up remaining space */
    overflow-y: auto;
    padding-right: 10px;
    margin-bottom: 15px;
}

.tab-content {
    display: none;
    height: 100%; /* Take full height of scroll area */
}

.tab-content.active {
    display: block;
}

.dialog-content h2 {
    margin-top: 0;
    color: var(--crop-color); /* Theme consistency */
    font-size: var(--title-size);
    margin-bottom: 0.8rem;
}

.creator {
    color: #333;
    font-size: inherit;
    font-weight: normal;
}

.dialog-section {
    margin-bottom: 2rem;
}

.dialog-section h3 {
    color: var(--crop-color);
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    font-size: calc(var(--title-size) * 0.8);
}

.dialog-section p, .dialog-section ul {
    margin-bottom: 1rem;
    line-height: 1.5;
    font-size: var(--label-size);
}

.dialog-section ul {
    padding-left: 1.5rem;
}

.dialog-section li {
    margin-bottom: 0.5rem;
}

/* Dialog close button styles removed - no longer used */

.dialog-scroll-area::-webkit-scrollbar {
    width: 8px;
}

.dialog-scroll-area::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.dialog-scroll-area::-webkit-scrollbar-thumb {
    background: #555;
}

.credits-list li {
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.credits-list li a {
    color: var(--link-color);
    text-decoration: none;
}

.credits-list li a:hover {
    text-decoration: underline;
}

.credits-list li strong {
    color: #000;
    font-weight: 600;
}

.fade-out::before {
    content: '';
    position: fixed;
    inset: 0;
    background: white;
    opacity: 0;
    animation: fadeWhite 1s forwards;
    z-index: 9999;
}
  
@keyframes fadeWhite {
    0% { opacity: 0; }
    100% { opacity: 0.5; }
}

#final-balance-text {
    color: var(--crop-color);
    text-align: center;
}

#game-deck {
    cursor: pointer;
    position: relative;
    min-height: var(--card-height);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

#game-deck.empty {
    background-color: transparent;
    border: 2px dashed #666;
    cursor: not-allowed;
}

#game-deck .deck-label {
    text-align: center;
}

#fertilizer-deck .deck-label {
    text-align: center;
}
/*#endregion*/