/* Mobile Styles */
@media screen and (min-width: 769px) and (max-width: 1100px) {
    /* Mobile-only styles */
    body {
        padding: 5px;
        width: 100vw;
        height: 100dvh;
        margin: 0;
        font-size: 0.7em;
    }

    .game-container {
        display: flex;
        flex-direction: column;
        height: 100dvh;
        padding: 10px;
        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.1em;
        letter-spacing: -1px;
        letter-spacing: 0.5em;
    }

    /* 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.7em;
        margin-bottom: 2px;
    }

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

    /* 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: 100vh;
        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: 1em;
        height: inherit;
        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 strong {
        color: var(--accent-color);
    }
    .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);
        font-family: var(--font-family);
    }

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

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

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


    /* Label visibility */
    .desktop-label {
        display: none;
    }

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

    .mobile-label {
        display: inline;
        margin: 0;
        word-wrap: break-word;
        font-size: 0.75em;
    }

    /* 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.5em;
        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: 6vw;
        outline: 2px solid var(--card-bg-color);
        height: 8vw;
        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.5em;
        position: absolute;
        left: 50%;
        bottom: -30px;
        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 */
    /* Fallback classes for browsers that don't support :has() */
    .three-cards .card:hover:nth-of-type(1) {
      transform: translate(5rem, 1rem) scale(1.6);
      z-index: 4;
    }

    .three-cards .card:hover:nth-of-type(2) {
      transform: translate(0, 0rem) scale(1.6);
      z-index: 4;
    }

    .three-cards .card:hover:nth-of-type(3) {
      transform: translate(-5rem, 1rem) scale(1.6);
      z-index: 4;
    }

    .two-cards .card:hover:nth-of-type(1) {
      transform: translate(5rem, 1rem) scale(1.6);
      z-index: 4;
    }

    .two-cards .card:hover:nth-of-type(2) {
      transform: translate(-5rem, 1rem) scale(1.6);
      z-index: 4;
    }

    /* Original :has() selectors for browsers that support it */
    #card-hand:has(.card:nth-of-type(3)) {  
        .card:hover:nth-of-type(1) {
          transform: translate(5rem, 1rem) scale(1.6);
          z-index: 4;
        }
    
        .card:hover:nth-of-type(2) {
          transform: translate(0, 0rem) scale(1.6);
          z-index: 4;
        }
    
        .card:hover:nth-of-type(3) {
          transform: translate(-5rem, 1rem) scale(1.6);
          z-index: 4;
        }
      }
    
    #card-hand:has(.card:nth-of-type(2)):not(:has(.card:nth-of-type(3))) {
    
        .card:hover:nth-of-type(1) {
          transform: translate(5rem, 1rem) scale(1.6);
          z-index: 4;
        }
    
        .card:hover:nth-of-type(2) {
          transform: translate(-5rem, 1rem) scale(1.6);
          z-index: 4;
        } 
      }
      
    .card-area {
        display: flex;
        justify-content: center;
        grid-template-areas:
            "deck discard"
            "hand hand";
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
        gap: 2vh;
        justify-items: center;
        align-items: center;
        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;
    }

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

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

    .card.expanded {
        z-index: 100 !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-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;
    }



    /* Game board layout */
    .game-board {
        display: grid;
        grid-template-areas:
            "center center"
            "left right";
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
        gap: 2vh;
        padding: 5px;
        margin-top: 2vh;
        position: relative;
        flex: 1;
    }

    .center-section {
        grid-area: center;
        width: 100%;
        display: flex;
        flex-direction: column;
        justify-content: space-evenly;
        gap: 3vh;
        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%;
        position: relative;
        z-index: 1;
    }

    /* 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: 60px;
        height: 60px;
        position: relative;
        cursor: pointer;
        transform-style: preserve-3d;
        transform: rotateX(-10deg) rotateY(5deg);
    }
    
    .dice-face {
        position: absolute;
        width: 60px;
        height: 60px;
        background: #F0EAD6;
        border: 2px solid #ccc;
        border-radius: 10px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        padding: 10px;
        backface-visibility: visible;
    }
    
    /* Position faces */
    .face-1 { transform: translateZ(30px); }
    .face-2 { transform: rotateX(180deg) translateZ(30px); }
    .face-4 { transform: rotateY(90deg) translateZ(30px); }
    .face-3 { transform: rotateY(-90deg) translateZ(30px); }
    .face-6 { transform: rotateX(90deg) translateZ(30px); }
    .face-5 { transform: rotateX(-90deg) translateZ(30px); }
    
    .dot {
        position: absolute;
        width: 10px;
        height: 10px;
        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;
    }
}

@media screen and (min-width: 769px) and (max-width: 1024px) {
    #message {
        position: fixed;
        top: 10px;
        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;
        max-width: 300px;
        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;
        }
    }
}
