html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
}

/* --- Global Styles & Variables --- */
:root {
    --pond-bg: #0A2E36;
    --ui-panel-bg: rgba(15, 53, 63, 0.85);
    --text-primary: #E0E0E0;
    --text-secondary: #A0B4B8;
    --accent-color: #FFC107;
    --accent-hover: #FFD54F;
    --type-tag-bg: #4FC3F7;
    --number-tag-bg: #81C784;
    --font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    --water-shadow: drop-shadow(0px 0px 1px #367a9c) drop-shadow(0px 0px 2px #367a9c) drop-shadow(0px 0px 3px #367a9c) drop-shadow(0px 0px 4px #367a9c) drop-shadow(0px 0px 5px #367a9c);
}

body {
    margin: 0;
    font-family: var(--font-family);
    background-color: var(--pond-bg);
    color: var(--text-primary);
    overflow: hidden;
}

/* --- Layout Containers --- */
#pond-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    pointer-events: none; /* Allow clicks to pass through to elements behind */
}

#game-container {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    padding: 0rem;
    padding-top: 10rem;
    gap: 0rem;
    height: 100vh;
    box-sizing: border-box;
    user-select: none;
}

#center-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    margin: 0px 5px;
    width: 100%;
    max-width: 600px;
}

#right-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 200px;
}

/* --- Left Panels --- */

#top-bar{
    text-align: center;
    width: 300px;
    min-width: 300px;
}
#session-timer-container{
    filter: var(--water-shadow);
}

#reward-display {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 1rem;
    padding: 1rem;
    min-height: 300px;
    box-sizing: border-box;
    
    /* This container no longer fades, it just appears to hold space */
    visibility: hidden;
}

#reward-display.visible {
    visibility: visible;
}

#reward-image {
    margin-top: 15px;
    width: 100%;
    max-width: 256px;
    object-fit: cover;
    border-radius: 17px;
    border: 3px solid #0b53a9;
    height: 150px;
    opacity: 0;
    border-width: 0;
    transform: translateY(-20px);
    transition: height 0.3s ease-in-out, border-width 0.3s ease-in-out, opacity 1s ease-in-out 0.1s, transform 0.4s ease-in-out 0.0s;
}

#reward-image.loaded {
    height: 256px;
    opacity: 1;
    border-width: 3px;
    transform: translateY(0);
}
#reward-image.loadedNot {
    height: 40px;
}

#reward-trivia {
    filter: var(--water-shadow);
    text-align: center;
    width: 100%;
    margin: 0;
    padding: 0;
    opacity: 0;
    transform: translateY(-20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

#reward-trivia.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- Reward Display States --- */
.reward-with-image #reward-trivia {
    /* Custom styles for trivia when an image is present */
    font-size: 0.9rem;
}

.reward-no-image {
    /* Custom styles for the container when there is NO image */
    justify-content: center; /* Center the trivia vertically */
}

.reward-no-image #reward-trivia {
    /* Custom styles for trivia when there is NO image */
    font-size: 1.1rem;
    font-weight: bold;
}

.reward-no-image #reward-canvas {
    display: none; /* Hide the canvas if there's no image */
}

/* --- Device-Specific Reward Styles --- */

/* Desktop with image */
.desktop.reward-with-image {
    /* Your styles here */
}
/* Desktop with no image */
.desktop.reward-no-image {
    margin-top: 110px;
    /* Your styles here */
}
/* Mobile with image */
.mobile.reward-with-image {
    /* Your styles here */
}
/* Mobile with no image */
.mobile.reward-no-image {
    /* Your styles here */
}



#word-card {
    transition: opacity 0.5s ease, transform 0.5s ease;
}



/* --- UI Panels & Cards --- */
.panel {
    background-color: var(--ui-panel-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 1.5rem;
    width: 100%;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

#word-card {
    text-align: center;
}

/* --- Word Card Specifics --- */
#definition-metadata {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.meta-tag-type, .meta-tag-number {
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: bold;
    color: #000;
}

.meta-tag-type { background-color: var(--type-tag-bg); }
.meta-tag-number { background-color: var(--number-tag-bg); }

#definition-display p {
    font-size: 1.5rem;
    line-height: 1.6;
    margin: 0px 10px;
    filter: var(--water-shadow);
}

#example-sentence p {
    font-size: 1rem;
    font-style: italic;
    color: var(--text-secondary);
    margin-top: 1rem;
    filter: var(--water-shadow);
}

/* --- Input & Actions --- */
#input-area {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

#guess-input-container {
    position: relative; /* Establishes a positioning context for the absolute child */
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: nowrap; /* Prevent main boxes from wrapping */
}

#guess-overflow-container {
    position: absolute;
    top: 0;
    left: 100%;
    display: flex;
    gap: 0.5rem;
    margin-left: 0.5rem; /* Creates space between main boxes and overflow boxes */
}

.guess-input-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 50px; /* Lock height to prevent layout shift */
    overflow: hidden; /* Clip the overflowing letter boxes */
}

.letter-box {
    width: 45px;
    height: 45px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8rem;
    font-weight: bold;
    text-transform: uppercase;
    color: var(--text-primary);
    background-color: rgba(0, 0, 0, 0.2);
    border: 2px solid var(--text-secondary);
    border-radius: 6px;
    transition: all 0.2s ease;
}

.letter-box.active {
    border-color: var(--accent-color);
    box-shadow: 0 0 8px var(--accent-hover);
}

.letter-box.overflow {
    opacity: 0.5;
    border-style: dashed;
}

/* Feedback colors */
.letter-box.correct {
    background-color: #4CAF50; /* Green */
    border-color: #4CAF50;
}
.letter-box.misplaced {
    background-color: #FFC107; /* Yellow */
    border-color: #FFC107;
}
.letter-box.incorrect {
    background-color: #424242; /* Dark Grey */
    border-color: #424242;
}

.letter-box.faded-incorrect {
    transition: opacity 0.3s ease-in-out;
    color: #ffffff4f;
}

.letter-box.dropped {
    background-color: transparent;
    border-color: transparent;
    color: transparent;
    transition: all 0.2s ease-out;
}

/* Visually hidden input for mobile keyboard handling */
#hidden-input {
    position: absolute;
    top: -9999px;
    left: -9999px;
    opacity: 0;
    width: 0;
    height: 0;
    border: none;
    padding: 0;
    margin: 0;
    /* Allow it to be focused */
    pointer-events: auto; 
}

#hint-metrics-container {
    display: flex;
    justify-content: space-around;
    width: 100%;
    max-width: 300px;
    margin-top: 1rem;
    padding: 0.5rem;
    background-color: rgba(0, 0, 0, 0.15);
    border-radius: 8px;
}

.hint-metric {
    text-align: center;
}

.hint-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: block;
}

.hint-value {
    font-size: 1.5rem;
    font-weight: bold;
    display: block;
}

#hint-correct-position { color: #4CAF50; } /* Green */
#hint-wrong-position { color: #FFC107; } /* Yellow */
#hint-semantic { color: #4FC3F7; } /* Blue */

#hint-display {
    font-size: 0.9rem;
    color: var(--text-secondary);
    height: 20px; /* Reserve space */
    filter: var(--water-shadow);
    margin-bottom: 6px;
    transition: color 0.3s ease;
}

#hint-display.success { color: #4CAF50; }
#hint-display.error { color: #F44336; }
#hint-display.info { color: #4FC3F7; }
#hint-display.hint { color: var(--text-secondary); }

#action-buttons {
    display: flex;
    gap: 1rem;
}

button {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    background-color: var(--accent-color);
    color: #000;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

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

button:active {
    transform: scale(0.98);
}

#skip-button.highlighted {
    box-shadow: 0 0 10px 3px red;
    background-color: red;
}

/* --- Deck Display --- */
#deck-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
}

.deck {
    background-color: var(--ui-panel-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.deck:hover {
    background-color: rgba(35, 73, 83, 0.9);
}

.deck-name {
    font-size: 1.1rem;
    font-weight: bold;
    display: block;
}

.deck-count {
    font-size: 1.5rem;
    color: var(--accent-color);
    font-weight: bold;
}

#deck-done {
    background-color: #1a4a4a;
    border-color: #2a6a6a;
}

/* --- Utility Classes --- */
.hidden {
    display: none !important;
}

/* --- Settings Panel --- */
#settings-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 100;
}

#settings-icon {
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    background-color: var(--ui-panel-bg);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

#settings-panel {
    position: absolute;
    right: 0;
    top: 3.5rem;
    width: 250px;
    background-color: var(--ui-panel-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 1rem;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.setting-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.75rem;
}

#mute-button {
    background: none;
    border: 1px solid var(--text-secondary);
    color: var(--text-primary);
    border-radius: 5px;
    width: 30px;
    height: 30px;
    padding: 0;
}

/* --- Deck Management Panel --- */
#deck-management-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7); /* Darker overlay */
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
    /* backdrop-filter: blur(5px); REMOVED */
}

#deck-panel-content {
    background-color: var(--pond-bg);
    border: 1px solid var(--accent-color);
    border-radius: 12px;
    padding: 2rem;
    width: 80%;
    max-width: 700px; /* Increased max-width slightly */
    height: 75%; /* Increased height slightly */
    display: flex;
    flex-direction: column;
    box-shadow: 0 5px 25px rgba(0,0,0,0.5);
}

#deck-word-list-container {
    position: relative;
    flex-grow: 1;
    /* This container will now handle the scrolling */
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    background-color: rgba(0, 0, 0, 0.2);
    padding: 0.5rem;
}

#deck-word-list {
    /* The list itself no longer needs overflow properties */
    width: 100%;
}

.deck-word-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.deck-word-item:last-child {
    border-bottom: none;
}

.word-item-interval {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-right: 1rem; /* ADDED: Spacing between interval and word */
    min-width: 40px; /* Ensures alignment */
    text-align: right;
}

.word-item-name {
    font-size: 1.2rem;
    font-weight: bold;
    flex-shrink: 0; /* Prevents the name from shrinking */
}

.word-item-definition {
    flex-grow: 1;
    margin: 0 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-secondary);
    font-style: italic;
    min-width: 50px; /* Allows the definition to be present but shrink */
}

.word-item-controls {
    position: relative; /* For positioning the context menu */
    margin-left: auto; /* Push controls to the far right */
}

.word-item-controls button {
    padding: 0.25rem 0.5rem;
    background-color: var(--ui-panel-bg);
    color: var(--text-primary);
    border: 1px solid var(--text-secondary);
    border-radius: 4px;
}

#close-deck-panel {
    margin-top: 1rem;
    align-self: center;
}

/* --- New Styles for Deck Panel Refactor --- */

/* Blur effect for the learning deck */
#deck-word-list.blurred {
    filter: blur(5px);
    pointer-events: none; /* Prevent interaction with blurred content */
}

/* Overlay for the blurred list */
#deck-list-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-primary);
    background-color: rgba(0, 0, 0, 0.4);
    cursor: pointer;
    z-index: 10;
    border-radius: 8px; /* Match container's border-radius */
}

/* "Move" button and its context menu */
.context-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%; /* Position below the "Move" button */
    background-color: var(--pond-bg);
    border: 1px solid var(--accent-color);
    border-radius: 6px;
    z-index: 20;
    min-width: 100px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.context-menu.visible {
    display: block;
}

.context-menu button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0.5rem 1rem;
}

.context-menu button:hover {
    background-color: var(--ui-panel-bg);
}

/* --- Responsive Design for Mobile --- */
@media (max-width: 768px) {
    body {
        overflow-y: auto; /* Allow scrolling on mobile */
    }

    #game-container {
        flex-direction: column;
        align-items: center;
        padding: 1rem;
        padding-top: 1rem; /* Reduce top padding */
        height: auto; /* Allow container to grow */
    }

    #center-column {
        order: 2; /* Gameplay below the top bar */
        gap: 1rem;
        max-width: 100%;
    }

    #right-column {
        order: 3; /* Decks at the bottom */
        width: 100%;
        max-width: 500px; /* Limit width on tablets */
    }

    #top-bar {
        order: 1; /* Top bar at the top */
        width: 100%;
        min-width: unset;
        margin-bottom: 1rem;
    }

    #top-bar {
        display: contents;
    }

    #session-timer-container {
        order: 1;
        width: 100%;
        margin-bottom: 1rem;
    }

    #reward-display {
        order: 4;
    }

    #deck-container {
        flex-direction: row; /* Decks side-by-side */
        justify-content: center; /* Align to the start */
        gap: 0.1rem;
        overflow-x: auto; /* Enable horizontal scrolling */
        padding-bottom: 5px; /* Space for scrollbar */
        /* Hide scrollbar for a cleaner look, but keep functionality */
        -ms-overflow-style: none;  /* IE and Edge */
        scrollbar-width: none;  /* Firefox */
    }
    #deck-container::-webkit-scrollbar {
        display: none; /* Chrome, Safari, and Opera */
    }

    .deck {
        flex-grow: 0; /* Do not grow */
        flex-shrink: 0; /* Do not shrink */
        padding: 0.5rem 0.8rem; /* A bit more padding for easier tapping */
        min-width: auto;
    }

    .deck-name {
        font-size: 0.8rem;
    }

    .deck-count {
        font-size: 1.1rem;
    }

    #definition-display p {
        font-size: 1.2rem; /* Smaller text for smaller screens */
    }

    #example-sentence p {
        font-size: 0.9rem;
    }

    .letter-box {
        width: 35px;
        height: 35px;
        font-size: 1.5rem;
    }

    #action-buttons {
        flex-wrap: wrap;
        justify-content: center;
    }

    button {
        padding: 0.6rem 1.2rem;
        font-size: 0.9rem;
    }

    /* --- Responsive Deck Management Panel --- */
    #deck-panel-content {
        width: 95%;
        height: 85%;
        padding: 1rem;
    }

    .deck-word-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .word-item-definition {
        white-space: normal; /* Allow definition to wrap */
    }

    .word-item-controls {
        margin-left: 0; /* Align to the left */
        align-self: flex-end; /* Push to the right of the column */
    }
}

@media (max-width: 480px) {
    #game-container {
        padding: 0.5rem;
    }

    .panel {
        padding: 1rem;
    }

    #definition-display p {
        font-size: 1.1rem;
    }

    .letter-box {
        width: 30px;
        height: 30px;
        font-size: 1.2rem;
    }

    #hint-metrics-container {
        flex-wrap: wrap;
    }

    .hint-metric {
        min-width: 100px;
    }
}

/* --- Tutorial Banner --- */
#tutorial-banner {
    width: 100%;
    padding: 0.3rem 0.5rem;
    background-color: rgba(10, 46, 54, 0.7);
    border: 1px solid var(--accent-color);
    border-radius: 12px;
    text-align: center;
    font-size: .8rem;
    color: #8bc34a;
    box-sizing: border-box;
    min-height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.5s ease-in-out;
}

#tutorial-banner.hidden {
    opacity: 0;
    /* We don't use display:none so the space is reserved */
    pointer-events: none; 
}

/* --- Tutorial Styles --- */
#tutorial-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 999;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    color: white;
    text-align: center;
}

#tutorial-overlay.transparent {
    background-color: transparent;
    pointer-events: none; /* Allow clicks to pass through the overlay */
}

#tutorial-content {
    background-color: var(--ui-panel-bg);
    padding: 2rem 3rem;
    border-radius: 15px;
    max-width: 500px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    pointer-events: auto; /* The modal content itself should be interactive */
}

#tutorial-content h2 {
    color: var(--accent-color);
    margin-top: 0;
}

#tutorial-content p {
    font-size: 1.1rem;
    line-height: 1.6;
}

.tutorial-highlight {
    position: relative;
    z-index: 1001;
    pointer-events: auto; /* CRITICAL: Make the highlighted element clickable again */
    box-shadow: 0 0 0 4px var(--accent-hover), 0 0 20px 10px var(--accent-hover);
    border-radius: 8px;
    transition: box-shadow 0.3s ease-in-out;
}

.tutorial-tooltip {
    position: absolute;
    z-index: 1002; /* Above the highlight */
    background-color: var(--accent-color);
    color: #000;
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    font-weight: bold;
    max-width: 300px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    pointer-events: none; /* The tooltip itself should not block clicks */
}

/* --- Virtual Keyboard --- */
#virtual-keyboard {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: #1c1c1c; /* Solid background to intercept clicks */
    padding: 0.5rem;
    box-sizing: border-box;
    z-index: 9999; /* Extremely high z-index to ensure it's on top */
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    touch-action: manipulation; /* Prevents double-tap zoom on buttons */
}

.keyboard-layout {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

.key {
    font-family: inherit;
    font-weight: bold;
    font-size: 1rem;
    color: white;
    background-color: #555;
    border: none;
    border-radius: 5px;
    padding: 0;
    width: 35px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on iOS */
    user-select: none; /* Prevent text selection */
    -webkit-user-select: none; /* For Safari */
    transition: background-color 0.1s ease, transform 0.1s ease; /* Add transition for smooth effect */
}

.key:active, .key.pressed {
    background-color: var(--accent-hover); /* Use a bright accent color */
    transform: scale(1.1); /* Make the key slightly larger */
    color: #000; /* Change text color for better contrast on the bright background */
}

.special-key {
    min-width: 50px;
}

#keyboard-action-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.keyboard-action-button {
    flex-grow: 1;
    padding: 1rem 0.5rem;
    border: none;
    border-radius: 5px;
    background-color: var(--accent-color);
    color: #000;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
}

.keyboard-action-button:active {
    background-color: var(--accent-hover);
}

/* --- Mobile-specific button order --- */
@media (max-width: 768px) {
    #keyboard-submit-button { order: 3; }
    #keyboard-skip-button { order: 2; }
    #keyboard-remove-button { order: 1; }
}

/* --- Accent Key Pop-up --- */
.accent-menu {
    position: fixed; /* Use fixed to position relative to the viewport */
    display: flex;
    gap: 5px;
    background-color: #777; /* Slightly lighter than the keys */
    padding: 8px;
    border-radius: 10px;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.3);
    z-index: 160; /* Above the keyboard */
    transform: translate(-50%, -100%); /* Center horizontally, position above the key */
    transition: opacity 0.1s ease-in-out;
}

.accent-menu.hidden {
    display: none;
}

.accent-menu .key {
    background-color: #555;
    width: 40px; /* Slightly larger for easier tapping */
    height: 55px;
}

.accent-menu .key:active {
    background-color: var(--accent-hover);
    color: #000;
}

/* Initially hide keyboard on desktop */
@media (min-width: 769px) {
    #virtual-keyboard {
        display: none !important;
    }
}

/* Adjustments for when keyboard is visible on mobile */
@media (max-width: 768px) {
    body {
        /* Add padding to the bottom to prevent content from being hidden by the keyboard */
        padding-bottom: 220px; /* Adjust this value based on the keyboard's final height */
    }

    #virtual-keyboard.hidden {
        display: none !important;
    }

    #action-buttons {
        display: none; /* Hide the original action buttons on mobile */
    }
}

