/* Mobile Styles */
@media screen and (max-width: 768px) {
    /* Mobile-only styles */
    #rules-popup {
        position: fixed;
        background: #000000e6;
        z-index: 1000;
        text-align: center;
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh;
        right: 0 !important;
        top: 0 !important;
        left: 0 !important;
    }

    #rules-popup .popup-arrow {
    display: none; /* Hide arrow on mobile */
    }

    #rules-popup .popup-content {
        margin: 0;
        padding: 0;
        display: flex;
        justify-content: center;
        flex-direction: column;
        align-items: center;
        margin-top: 10vh;
    }

    body {
        padding: 5px;
        width: 100%;
        height: 100dvh;
        margin: 0;
        font-size: 0.7em;
        background-position: 100% -6%, center 99%, center 80%, 0 0;
    }

    .game-container {
        display: flex;
        flex-direction: column;
        height: calc(100dvh - 50px); /* Account for body padding */
        padding: 5px; /* Reduce padding */
        box-sizing: border-box;
    }

    /* Header Layout */
    header {
        display: grid;
        grid-template-rows: auto auto;
        padding: 0px;
        gap: 5px;
        margin: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 0;
    }

    /* First row: title and menu */
    .header-top {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 5px;
    }

    .game-title {
        justify-self: start;
        font-size: 1em;
        line-height: 1.2;
        padding: 0;
        margin: 0;
        min-width: 0;
    }

    .game-title .main-title {
        color: var(--neutral-color);
        font-family: var(--game-font);
        font-size: 1.7em;
        letter-spacing: -1px;
    }
    
    .game-title .sub-title {
        color: var(--card-bg-color);
        font-family: monospace;
        font-size: 1.5em;
        letter-spacing: 0.5px;
    }

    /* Second row: stats */
    .game-stats {
        display: flex;
        width: 100%;
        margin: 0;
        padding: 0;
        gap: 0;
        justify-content: space-between;
    }

    .stat-item {
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        text-align: center;
        padding: 0;
        margin: 0;
        min-width: 0;
        width: 20%;
    }
    
    .stat-item span {
        font-size: 1.2em;
        margin-bottom: 2px;
    }

    .stat-item label {
        color: var(--accent-color);
        font-size: 1.1em;
    }

    /* Menu button */
    .header-buttons {
        position: absolute;
        top: 5px;
        right: 5px;
        display: flex;
        gap: 10px;
        align-items: center;
    }

    .header-buttons button {
        font-family: var(--font-family);
        font-size: 1em;
        padding: 8px 16px;
        background: var(--secondary-color);
        border: none;
        border-radius: 4px;
        color: var(--text-color);
        cursor: pointer;
        transition: background-color 0.2s;
    }

    .header-buttons button:hover {
        background-color: var(--accent-color);
    }

    /* Dropdown Menu */
    .dropdown-menu {
        position: absolute;
        top: 100%;
        right: 0;
        background-color: var(--primary-color);
        border: 2px solid var(--accent-color);
        border-radius: 5px;
        padding: 5px;
        display: none;
        flex-direction: column;
        gap: 5px;
        z-index: 1000;
        margin-top: 5px;
    }

    .dropdown-menu.active {
        display: flex;
    }

    .dropdown-menu button {
        white-space: nowrap;
        width: 100%;
        text-align: left;
        padding: 8px 12px;
        background: none;
        border: none;
        color: var(--text-color);
        cursor: pointer;
        font-size: 1em;
    }

    .dropdown-menu button:hover {
        background-color: var(--accent-color);
    }

    /* Modal Adjustments */
    .modal {
        display: none;
        position: fixed;
        z-index: 1000;
        left: 0;
        top: 0;
        width: 100vw;
        height: 100dvh;
        background-color: rgba(0, 0, 0, 0.5);
        overflow: hidden;
    }

    .modal-content {
        background-color: var(--background-color);
        margin: 0;
        padding: 15px;
        width: 100vw;
        color: var(--text-color);
        overflow-y: auto;
        position: relative;
        box-sizing: border-box;
    }

    /* Rules Content Styles */
    #rules-content {
        padding: 15px;
        background: var(--secondary-color);
        font-family: var(--font-family);
        margin-bottom: 15px;
        font-size: 1.5em;
        height: calc(100dvh - 30px);
        overflow-y: auto;
        box-sizing: border-box;
    }

    #rules-content h1,
    #rules-content h2,
    #rules-content h3,
    #rules-content h4,{
        color: var(--accent-color);
        margin-top: 1.2em;
        margin-bottom: 0.5em;
    }

    #rules-content h1:first-child {
        margin-top: 0;
    }

    #rules-content p {
        margin-bottom: 1em;
        line-height: 1.4;
    }

    #rules-content ul,
    #rules-content ol {
        margin-bottom: 1em;
        padding-left: 1.5em;
    }

    #rules-content li {
        margin-bottom: 0.5em;
    }

    #rules-content code {
        background: var(--background-color);
        padding: 0.2em 0.4em;
        border-radius: 3px;
        font-family: var(--font-family);
        font-size: 0.9em;
    }

    #rules-content pre {
        background: var(--background-color);
        padding: 0.8em;
        border-radius: 8px;
        overflow-x: auto;
        margin-bottom: 1em;
        font-size: 0.9em;
    }

    #rules-content blockquote {
        border-left: 4px solid var(--accent-color);
        margin: 0;
        padding-left: 1em;
        color: #888;
    }

    /* Settings Section Styles */
    .settings-section {
        margin-bottom: 20px;
        padding: 15px;
        background: var(--secondary-color);
        border-radius: 8px;
    }

    .settings-section h3 {
        margin: 0 0 15px 0;
        color: var(--accent-color);
        font-size: 1.1em;
    }

    .setting-group {
        margin-bottom: 15px;
    }

    .setting-group:last-child {
        margin-bottom: 0;
    }

    .setting-group label {
        display: block;
        margin-bottom: 5px;
        color: var(--text-color);
        font-size: 0.9em;
    }

    .setting-group input {
        width: 100%;
        padding: 8px;
        border: 1px solid var(--accent-color);
        border-radius: 4px;
        background-color: var(--background-color);
        color: var(--text-color);
        font-size: 0.9em;
    }

    .button-group {
        display: flex;
        justify-content: flex-end;
        gap: 0.8rem;
        margin-top: 1.5rem;
    }

    .primary-button,
    .secondary-button {
        padding: 0.5rem 1rem;
        border: none;
        border-radius: 5px;
        cursor: pointer;
        font-size: 0.9rem;
        transition: all 0.3s ease;
    }

    .primary-button {
        background-color: var(--accent-color);
        color: var(--text-color);
    }

    .secondary-button {
        background-color: var(--secondary-color);
        color: var(--text-color);
    }

    #settings-reset {
        margin-right: auto;
    }

    /* Modal Adjustments */
    .modal-content {
        width: 90%;
        max-height: 80vh;
        margin: 10vh auto;
    }


    /* Label visibility */
    .desktop-label {
        display: none;
    }
    .mobile-label {
        display: inline;
        margin: 0;
        word-wrap: break-word;
        font-size: 1.5em;
    }

    /* Objectives styling */
    .status-objectives, .main-objectives {
        display: flex;
        flex-direction: row;
        justify-content: space-evenly;
        width: 100%;
    }

    .objective {
        display: flex;
        flex-direction: column;
        align-items: center;
        position: relative;
    }

    .objective h3 {
        font-size: 1.1em;
        text-align: center;
        line-height: 1.1;
        margin-bottom: 2px;
    }

    .objective:not(.selected):hover {
        transform: scale(1.05);
    }

    .objective.selected {
        outline: 2px solid var(--accent-color);
        border-radius: 4px;
    }

    .objective.selected::after {
        content: '';
        position: absolute;
        inset: 0;
        background: var(--accent-color);
        opacity: 0.1;
        pointer-events: none;
        z-index: 1;
    }

    .objective-track {
        width: 8vw;
        outline: 2px solid var(--card-bg-color);
        height: 10vw;
        position: relative;
        margin: 5px;
        transform-origin: right;
    }

    .bar-marker {
        position: absolute;
        bottom: 0;
        width: 100%;
        transition: height 0.3s ease, background-color 0.3s ease;
        transform-origin: bottom;
    }

    .bar-marker.neutral {
        background-color: var(--neutral-color);
        height: var(--value, 50%);
    }

    .bar-marker.positive {
        background-color: var(--success-color);
        height: var(--value, 50%);
    }

    .bar-marker.warning {
        background-color: var(--warning-color);
        height: var(--value, 50%);
    }

    .objective-value {
        position: absolute;
        font-size: 1.2em;
        position: absolute;
        left: 50%;
        bottom: -25px;
        transform: translateX(-50%);
        color: var(--text-color);
    }

    .objective-item {
        width: 100%;
        position: relative;
        background: var(--background-color);
        height: 2px;
        border-radius: 12px;
        overflow: hidden;
    }

    .objective-progress {
        position: absolute;
        height: 100%;
        background: var(--accent-color);
        transition: width 0.3s ease-in-out;
    }

    .objective-marker {
        position: absolute;
        width: 2px;
        height: 100%;
        background: var(--text-color);
        opacity: 0.8;
    }

    .objective-label {
        position: absolute;
        left: 10px;
        top: 50%;
        transform: translateY(-50%);
        color: var(--text-color);
        font-size: 0.8em;
        z-index: 1;
    }


    
    
    /* Card Hand Styles */
    .card-area {
        display: grid;
        grid-template-areas:
            "deck discard"
            "hand hand";
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
        justify-items: center;
        align-items: center;
        gap: 1vh;
        height: 100%;
        position: relative;
    }

    .card-deck, .discard-pile {
        width: var(--card-width);
        height: var(--card-height);
        border-radius: 10px;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        position: relative;
        z-index: 1;
    }

    .card-deck:hover {
        transform: rotate(-3deg) scale(1.0);
    }

    .discard-pile .card {
        position: absolute;
        z-index: 1;
    }

    #card-hand {
        z-index: 2;
    }

    .card.expanded {
        z-index: 100 !important;
        position: fixed !important;
        left: 50% !important;
        top: 50% !important;
        transform: translate(-50%, -50%) scale(2) !important;
        transition: all 0.3s ease !important;
    }

    .card.magnified {
        z-index: 100 !important;
        transform: translate(-50%, -50%) scale(2) !important;
        transition: all 0.3s ease !important;
    }

    .card-deck {
        grid-area: deck;
        transform: rotate(-3deg);
    }

    .discard-pile {
        grid-area: discard;
        position: relative;
        border: 2px dashed var(--accent-color);
        font-size: 14px;
        box-shadow: inset 0 0 10px rgba(0, 255, 0, 0.2);
    }
    
    .discard-pile .card {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        margin: 0;
        transform-origin: center;
        transition: transform 0.3s ease;
    }

    .discard-pile .card:nth-last-child(2) {
        transform: rotate(-3deg) translateY(-2px);
    }

    .discard-pile .card:last-child {
        transform: rotate(3deg) translateY(-4px);
    }

    .card-glow-effects,
    #card-hand {
        grid-area: hand;
        width: calc(var(--card-width) * 2.5);
        display: flex;
        justify-content: center;
        align-items: center;
        height: var(--card-height);
        perspective: 1000px;
        position: relative;
    }

   

    .card-icon {
        margin-bottom: 0px;
    }
    /* override */
    .card-icon .desktop-label {
      display: flex;
      margin-bottom: 4px;
    }

    .card-content {
        padding: 6px;
    }

    /* Game board layout */
    .game-board {
        display: grid;
        grid-template-areas:
            "center center"
            "left right";
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
        padding: 5px;
        position: relative;
        flex: 1;
        min-height: 0;
    }

    .center-section {
        grid-area: center;
        width: 100%;
        display: flex;
        flex-direction: column;
        justify-content: space-evenly;
        height: 100%;
    }

    .left-section {
        grid-area: left;
        width: 100%;
        display: flex;
        align-items: center;
        height: 100%;
    }

    .right-section {
        grid-area: right;
        width: 100%;
        display: flex;
        border-radius: 10px;
        align-items: center;
        height: 100%;
    }

    /* Message area positioning */
    

    

    /* Dice Section */
    .dice-section {
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;
        z-index: 10;
        margin: 10px 0;
        perspective: 1000px;
    }

    .die {
        width: 40px;
        height: 40px;
        position: relative;
        cursor: pointer;
        transform-style: preserve-3d;
        transform: rotateX(-10deg) rotateY(5deg);
        z-index: 10;
    }

    .dice-face {
        position: absolute;
        width: 40px;
        height: 40px;
        background: #F0EAD6;
        border: 2px solid #ccc;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        padding: 8px;
        backface-visibility: visible;
    }

    /* Position faces */
    .face-1 { transform: translateZ(20px); }
    .face-2 { transform: rotateX(180deg) translateZ(20px); }
    .face-4 { transform: rotateY(90deg) translateZ(20px); }
    .face-3 { transform: rotateY(-90deg) translateZ(20px); }
    .face-6 { transform: rotateX(90deg) translateZ(20px); }
    .face-5 { transform: rotateX(-90deg) translateZ(20px); }

    .dot {
        position: absolute;
        width: 8px;
        height: 8px;
        background: black;
        border-radius: 50%;
    }

    /* Dot positions */
    .top { top: 10%; }
    .bottom { bottom: 10%; }
    .left { left: 10%; }
    .right { right: 10%; }
    .middle { top: 50%; transform: translateY(-50%); }
    .center { left: 50%; transform: translateX(-50%); }
    .middle.center { transform: translate(-50%, -50%); }

    .die:hover {
        transform: scale(1.05) rotateX(-10deg) rotateY(5deg);
    }

    .die:active {
        transform: scale(0.95) rotateX(-10deg) rotateY(5deg);
    }

    @keyframes roll {
        0% { transform: rotateX(-10deg) rotateY(5deg); }
        20% { transform: rotateX(360deg) rotateY(180deg); }
        40% { transform: rotateX(720deg) rotateY(360deg); }
        60% { transform: rotateX(1080deg) rotateY(540deg); }
        80% { transform: rotateX(1440deg) rotateY(720deg); }
        100% { transform: rotateX(var(--final-x)) rotateY(var(--final-y)); }
    }

    .die[style*="animation"] {
        transform-style: preserve-3d;
    }

    #message {
        position: fixed;
        top: 5px;
        right: 60px; /* Adjust based on menu button position */
        z-index: 1000;
        background-color: rgba(0, 0, 0, 0.7);
        color: white;
        padding: 10px;
        border-radius: 5px;
        font-size: 0.9em;
        text-align: center;
        opacity: 0;
        transition: opacity 0.3s ease-in-out;
    }

    #message.show {
        opacity: 1;
        animation: fadeOut 3s forwards;
    }

    @keyframes fadeOut {
        0%, 90% {
            opacity: 1;
        }
        100% {
            opacity: 0;
            display: none;
        }
    }
}
