/* 
 * Veedle - Style 
 * Premium Aesthetic, Dark Mode, Responsive
 */

:root {
    /* DEFAULT TO LIGHT MODE */
    --color-bg: #f8f0ef;
    --color-tone-1: #1a1a1b;
    --color-tone-2: #d3d6da;
    --color-tone-3: #dfdfe0;
    --color-tone-4: #d3d6da;
    /* Inactive borders */
    --color-tone-5: #f0f0f0;
    --color-tone-6: #f0f0f0;
    /* Ad bg */
    --color-tone-7: #ffffff;

    --color-nav-height: 50px;
    --header-height: 50px;
    --keyboard-height: 200px;

    /* Game Colors */
    --color-absent: #787c7e;
    --color-present: #c9b458;
    --color-correct: #6aaa64;

    /* Title Theme (Light Mode Default) */
    --title-color: #d99950;
    --title-shadow:
        2px 2px 0px #43291a,
        4px 4px 0px #43291a;

    /* Modal Theme (Light Mode Default) */
    --modal-bg: #F3F3F3;
    --modal-text: #1a1a1b;

    /* Animations */
    --animation-speed: 250ms;

    font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
}

html.dark-mode {
    --color-bg: #2c2c2c;
    --color-tone-1: #ffffff;
    --color-tone-2: #818384;
    --color-tone-3: #565758;
    --color-tone-4: #3a3a3c;
    --color-tone-5: #272729;
    --color-tone-6: #1a1a1b;
    --color-tone-7: #121213;

    --color-present: #b59f3b;
    /* Yellow-ish Gold */
    --color-correct: #538d4e;
    /* Green */
    --color-absent: #3a3a3c;
    /* Dark Gray */

    /* Title Theme (Dark Mode) */
    --title-color: #f8f0ef;
    --title-shadow: none;

    /* Modal Theme (Dark Mode) */
    --modal-bg: #2c2c2c;
    --modal-text: #ffffff;
}

* {
    box-sizing: border-box;
}

body {
    background-color: var(--color-bg);
    color: var(--color-tone-1);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    /* Allow growth */
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    /* Allow specific vertical scrolling */
    transition: background-color 0.3s, color 0.3s;
}

/* Header */
header {
    flex: 0 0 75px;
    /* Fixed user typo 'xpx' back to 75px */
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 100%;
    border-bottom: 2px solid var(--color-tone-4);
    /* Thicker border */
    padding: 10px 20px;
    /* Increased padding */
    margin: 0 auto;
    background-color: var(--color-bg);
}

.header-left,
.header-right {
    width: 80px;
    /* Exact width to balance center */
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.branding {
    width: 80px;
    flex: 0 0 80px;
    justify-content: flex-start;
    padding-left: 0;
}

#Veedle_Logo {
    height: 100%;
    max-height: 60px;
    /* Limit height */
    width: auto;
}

#dark-mode-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-tone-1);
    padding: 0;
}

.title {
    font-weight: 400;
    /* Titan One is bold */
    font-size: 36px;
    /* Larger */
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-family: 'Titan One', cursive;
    /* Super Joyful */
    color: var(--title-color);
    /* Themed color */
    text-shadow: var(--title-shadow);
    /* Themed shadow */
    flex-grow: 1;
    text-align: center;
    display: flex;
    justify-content: center;
}

/* Game Container */
#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 500px;
    height: auto;
    /* Let it grow */
    min-height: 100%;
    margin: 0 auto;
    padding: 0;
    /* overflow: hidden; <-- Removed to allow scroll */
}

/* Spacer helpers if needed, or just use margins */

#board-container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-grow: 1;
    /* Take available space */
    width: 100%;
    overflow: hidden;
    /* Prevent spillover */
    padding: 10px;
}

#board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    grid-gap: 5px;
    padding: 10px;
    box-sizing: border-box;
    width: 100%;
    max-width: 350px;
    aspect-ratio: 5 / 6;
    /* Ensure it doesn't get too tall */
    max-height: 420px;
}

.board-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-gap: 5px;
}

.tile {
    width: 100%;
    height: 100%;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    line-height: 2rem;
    font-weight: bold;
    vertical-align: middle;
    box-sizing: border-box;
    border: 2px solid var(--color-tone-4);
    text-transform: uppercase;
    user-select: none;
    /* transition: transform 0.6s;  <-- REMOVED to prevent conflict with @keyframes flip-in */
}

/* Tile States - NO ANIMATION HERE explicitly */
.tile[data-state='active'] {
    border-color: var(--color-tone-2);
}

.tile[data-state='tbd'] {
    border-color: var(--color-tone-2);
}

.tile.selected {
    border-color: var(--color-tone-1) !important;
}

.tile[data-state='correct'] {
    background-color: var(--color-correct);
    border-color: var(--color-correct);
    color: #ffffff;
    /* Force white text for readability */
}

.tile[data-state='present'] {
    background-color: var(--color-present);
    border-color: var(--color-present);
    color: #ffffff;
    /* Force white text */
}

.tile[data-state='absent'] {
    background-color: var(--color-absent);
    border-color: var(--color-absent);
    color: #ffffff;
    /* Force white text */
}

/* Keyboard */
#keyboard-container {
    height: auto;
    width: 100%;
    margin-top: auto;
    /* Push to bottom if space allows, or just separate */
    padding-bottom: 20px;
    /* Space before footer/bottom */
}

#keyboard {
    margin: 0 8px;
    user-select: none;
}

.keyboard-row {
    display: flex;
    width: 100%;
    margin: 0 auto 8px;
    touch-action: manipulation;
}

.key {
    font-family: inherit;
    font-weight: bold;
    border: 0;
    padding: 0;
    margin: 0 6px 0 0;
    height: 58px;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    background-color: var(--color-tone-2);
    color: var(--color-tone-1);
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    text-transform: uppercase;
    transition: background-color 0.1s ease;
}

.key:last-of-type {
    margin: 0;
}

.key.wide {
    flex: 1.5;
}

.key[data-state='correct'] {
    background-color: var(--color-correct);
    color: #ffffff;
}

.key[data-state='present'] {
    background-color: var(--color-present);
    color: #ffffff;
}

.key[data-state='absent'] {
    background-color: var(--color-absent);
    color: #ffffff;
}

/* Footer (Ads) */
footer {
    height: 90px;
    /* Specific ad height */
    width: 100%;
    background-color: var(--color-tone-6);
    display: flex;
    justify-content: center;
    align-items: center;
    border-top: 1px solid var(--color-tone-4);
    font-size: 0.8rem;
    color: var(--color-tone-2);
    flex-shrink: 0;
}

/* Animations */
@keyframes pop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

.pop {
    animation: pop 0.1s;
}

@keyframes shake {

    10%,
    90% {
        transform: translate3d(-1px, 0, 0);
    }

    20%,
    80% {
        transform: translate3d(2px, 0, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-4px, 0, 0);
    }

    40%,
    60% {
        transform: translate3d(4px, 0, 0);
    }
}

.shake {
    animation: shake 0.5s;
}

@keyframes flip-in {
    0% {
        transform: rotateX(0);
    }

    50% {
        transform: rotateX(-90deg);
    }

    100% {
        transform: rotateX(0);
    }
}

.flip {
    animation: flip-in 0.6s ease-in-out;
}

/* Messages */
#message-container {
    position: absolute;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.message {
    background-color: var(--color-tone-1);
    color: var(--color-tone-7);
    padding: 10px 20px;
    border-radius: 4px;
    margin-bottom: 10px;
    opacity: 1;
    transition: opacity 0.3s;
    font-weight: bold;
}

.message.fade-out {
    opacity: 0;
}

/* Mobile Adjustments */
@media (max-height: 600px) {
    #board {
        height: 350px;
        width: 300px;
    }

    .key {
        height: 48px;
    }

    .title {
        font-size: 24px;
    }
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    /* Semi-transparent dim */
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

.modal-card {
    position: relative;
    width: 432px;
    /* Fixed Layout Width */
    height: 590px;
    /* Fixed Layout Height */
    flex-shrink: 0;
    /* CRITICAL: Prevent flexbox from squashing the layout */
    background-color: var(--modal-bg);
    /* Themed */
    border-radius: 24px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    /* Mobile Scaling: If screen is smaller than card, scale down */
    transform-origin: center center;
    transition: background-color 0.3s;
}

/* Media Query for responsive scaling on small screens */
@media (max-width: 450px),
(max-height: 620px) {
    .modal-card {
        transform: scale(0.85);
    }
}

@media (max-width: 380px),
(max-height: 550px) {
    .modal-card {
        transform: scale(0.75);
    }
}

@media (max-width: 330px),
(max-height: 550px) {
    .modal-card {
        transform: scale(0.65);
    }
}

/* Elements */
.modal-instruction_illustration {
    /* Renamed back to match HTML */
    position: absolute;
    top: 34px;
    right: 39px;
    width: 100px;
    height: auto;

}

.modal-title {
    position: absolute;
    top: 93px;
    left: 40px;
    font-family: 'Roboto', sans-serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--modal-text);
    /* Themed */
    margin: 0;
    transition: color 0.3s;
}

.modal-text {
    position: absolute;
    top: 155px;
    left: 40px;
    right: 40px;
    font-family: 'Roboto', sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: var(--modal-text);
    /* Themed */
    transition: color 0.3s;
}

.modal-text p {
    margin: 0;
}

/* Visual Examples Area */
.modal-examples {
    position: absolute;
    top: 345px;
    left: 50px;
    width: 360px;
    height: 200px;
}

.example-tile {
    position: absolute;
    width: 56px;
    height: 57px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Roboto', sans-serif;
    font-size: 32px;
    font-weight: bold;
    color: #ffffff;
    border-radius: 4px;
    /* Slight rounded corners for tiles usually looked better, or 0 if strict */
}

/* Specific Positions based on layout "B A S I S" */
/* B */
.tile-green {
    background-color: #006E4C;
}

.pos-green {
    position: absolute;
    top: 50px;
    left: 0;
}

/* Note: The group wrapper is for relative positioning of arrows/text */

/* A */
.tile-grey {
    background-color: #A9A29F;
}

.pos-a {
    top: 50px;
    left: 70px;
}

/* S */
.tile-yellow {
    background-color: #EF9C00;
}

.pos-yellow {
    position: absolute;
    top: 50px;
    left: 140px;
}

/* I */
.pos-i {
    top: 50px;
    left: 210px;
}

/* S */
.pos-grey {
    position: absolute;
    top: 50px;
    left: 280px;
}

/* Arrows & Text */
.arrow {
    position: absolute;
}

.example-text {
    position: absolute;
    font-family: 'Roboto', sans-serif;
    font-size: 12px;
    line-height: 1.5;
    color: #565758;
    /* Muted text for explanations */
    white-space: nowrap;
    /* Prevent unwanted wrapping if possible */
}

/* Green Group Details */
.text-green {
    color: #047d57;
    bottom: 34px;
    left: -3px;
    transform: rotate(-10deg);
    font-weight: 600;
}

.arrow-green {
    width: 30px;
    bottom: -13px;
    left: 30px;
}

/* Yellow Group Details */
/* Arrow points down-right from bottom of tile */
.arrow-yellow {
    width: 30px;
    top: 55px;
    left: 10px;
}

.text-yellow {
    color: #EF9C00;
    top: 85px;
    left: -100px;
    transform: rotate(5deg);
    font-weight: 600;
    text-align: center;
}

/* Grey Group Details */
/* Arrow points up-right from top of tile */
.arrow-grey {
    width: 35px;
    bottom: -5px;
    left: 10px;
}

.text-grey {
    color: #9b9694;
    bottom: 29px;
    right: -62px;
    text-align: center;
    font-weight: 600;
    transform: rotate(5deg);
}

/* Button */
.modal-btn {
    position: absolute;
    bottom: 30px;
    right: 30px;
    width: 94px;
    height: 51px;
    background-color: #006E4C;
    color: white;
    font-family: 'Roboto', sans-serif;
    font-weight: bold;
    font-size: 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.modal-btn:hover {
    background-color: #005a3e;
}

/* Help and Stats Button in Header */
#help-button,
#stats-button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-tone-1);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Statistics Modal Specifics */
.stats-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0;
    /* We control padding via children */
}

/* Close button positioning */
.stats-card .close-icon {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--modal-text);
    padding: 10px;
    /* Touch target */
    z-index: 20;
}

.stats-animation-container {
    margin-top: 30px;
    width: 100px;
    height: 100px;
    background-color: #43291a;
    /* Theme Dark Brown */
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.win-animation {
    width: 95%;
    height: auto;
    mix-blend-mode: screen;
    /* Removes black background */
}

.stats-title {
    position: static;
    /* Override absolute from .modal-title */
    margin-top: 20px;
    margin-bottom: 20px;
    text-align: center;
    width: 100%;
}

.stats-content {
    width: 100%;
    padding: 0 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stats-overview {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 25px;
    gap: 10px;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    flex: 1;
}

.stat-number {
    font-size: 24px;
    font-weight: 700;
    font-family: 'Roboto', sans-serif;
    color: var(--modal-text);
}

.stat-label {
    font-size: 10px;
    font-family: 'Roboto', sans-serif;
    color: var(--modal-text);
    margin-top: 5px;
    line-height: 1.2;
}

.stats-subtitle {
    font-family: 'Roboto', sans-serif;
    font-size: 14px;
    font-weight: 700;
    color: var(--modal-text);
    margin-bottom: 30px;
    text-transform: uppercase;
    align-self: flex;
}

/* Distribution Chart */
.stats-distribution {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 30px;
}

.dist-row {
    display: flex;
    align-items: center;
    width: 100%;
    height: 20px;
}

.dist-label {
    width: 15px;
    font-family: 'Roboto', sans-serif;
    font-size: 12px;
    color: var(--modal-text);
    font-weight: bold;
    margin-right: 5px;
    text-align: right;
}

.dist-bar-container {
    flex-grow: 1;
    height: 100%;
    display: flex;
    /* Allow bar to size itself */
}

.dist-bar {
    height: 100%;
    background-color: var(--color-tone-2);
    color: white;
    font-family: 'Roboto', sans-serif;
    font-size: 11px;
    font-weight: bold;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding-right: 5px;
    min-width: 7%;
    /* Ensure text fits */
}

.dist-bar.highlight {
    background-color: var(--color-correct);
}