* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.hidden {
    display: none !important;
}

/* Game color variables */
:root {
    --bg-primary: #214555;
    --bg-secondary: #214555;
    --text-primary: #C7ECFF;
    --text-secondary: #C7ECFF;
    --bg-cell: #5EB3B8;
    --bg-cell-hover: #6ec3c8;
    --bg-cell-selected: #FFBB00;
    --text-cell: #001C29;
    --count-cell: #001C29;
    --color-wall: #FF7900;
    --btn-bg: #FF2D74;
    --btn-hover-bg: #FF4B8F;
    --btn-text: #FFFFFF;
    --btn-shadow: rgba(255, 45, 116, 0.3);
    --found-word-bg: #EB8C00;
    --found-word-text: #000000;
    --current-word-bg: #1C3642;
    --current-word-text: #FFBB00;
    --border-selected: #FFD033;
    --accent-warning: #FFBB00;
    --shadow-color: rgba(0, 0, 0, 0.3);

    --icon-color: #FF2D74;
    --next-button-text: #FFFFFF;
    --level-completed-text: #FFBB00;
    --level-completed-shadow: #FF5600;

    /* Footer colors */
    --footer-bg: #FF2D74;
    --footer-text: #FFFFFF;

    /* Tutorial colors */
    --tutorial-bg: #FFBB00;
    --tutorial-text: #000000;
    --tutorial-border: #1C3642;

    /* Menu colors */
    --menu-bg: #122F3D;
    --menu-completed-bg: #5EB3B8;
    --menu-selected-bg: #EB8C00;
    --menu-locked-bg: #122F3D;
    --menu-locked-border: #5EB3B8;
    --menu-hover-bg: #8CDCE1;
    --menu-hover-text: #001C29;

    /* Overlay */
    --bg-overlay: rgba(18, 47, 61, 0.95);
}

/* Light theme */
[data-theme="light"] {
    --bg-primary: #F5F0E8;
    --bg-secondary: #F5F0E8;
    --text-primary: #2C3E50;
    --text-secondary: #4A5568;
    --bg-cell: #3ED3DC;
    --bg-cell-hover: #5DF6FF;
    --bg-cell-selected: #FFBB00;
    --text-cell: #000000;
    --count-cell: #000000;
    --color-wall: #FF2D74;
    --btn-bg: #E8366D;
    --btn-hover-bg: #FF4B8F;
    --btn-text: #FFFFFF;
    --btn-shadow: rgba(232, 54, 109, 0.25);
    --found-word-bg: #FF2D74;
    --found-word-text: #FFFFFF;
    --current-word-bg: #E8E0D4;
    --current-word-text: #000000;
    --border-selected: #FFD033;
    --accent-warning: #D4850A;
    --shadow-color: rgba(0, 0, 0, 0.12);

    --icon-color: #E8366D;
    --next-button-text: #2C3E50;
    --level-completed-text: #D4850A;
    --level-completed-shadow: #C26B00;

    /* Footer colors */
    --footer-bg: #E8366D;
    --footer-text: #FFFFFF;

    /* Tutorial colors */
    --tutorial-bg: #FFD566;
    --tutorial-text: #2C3E50;
    --tutorial-border: #D4A020;

    /* Menu colors */
    --menu-bg: #EDE8DF;
    --menu-completed-bg: #3ED3DC;
    --menu-selected-bg: #EB8C00;
    --menu-locked-bg: #E8E0D4;
    --menu-locked-border: #C8BFB3;
    --menu-hover-bg: #5DF6FF;
    --menu-hover-text: #FFFFFF;

    /* Overlay */
    --bg-overlay: rgba(245, 240, 232, 0.95);
}

/* Light theme overrides for hardcoded colors */
[data-theme="light"] .header-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .cancel-icon-btn {
    background: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .cancel-icon-btn:hover {
    background: rgba(0, 0, 0, 0.14);
}

[data-theme="light"] .menu-tab:hover:not(.active) {
    background: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .level-row.locked {
    color: rgba(0, 0, 0, 0.35);
}

[data-theme="light"] .level-row.current {
    color: #FFFFFF;
}

[data-theme="light"] .menu-tabs {
    background: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .cell.stacked::before {
    border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .cell .stack-layer-2 {
    border-color: rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Quicksand', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-weight: 700;
    background: var(--bg-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-primary);
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    min-height: 100vh;
    position: relative;
}

/* ===== Top Bar ===== */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
    padding: 12px 12px;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 100;
    pointer-events: none;
}

.top-bar-left {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    pointer-events: auto;
}

.top-bar-right {
    display: flex;
    align-items: flex-start;
    pointer-events: auto;
}

.header-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s ease, color 0.2s ease;
    gap: 4px;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.header-icon {
    width: 28px;
    height: 28px;
    transition: transform 0.2s ease;
}

.header-btn:hover .header-icon {
    transform: scale(1.1);
}

.btn-label {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.header-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

#puzzleInfo .header-icon,
#resetBtn .header-icon {
    fill: var(--icon-color);
}

#settingsBtn .header-icon {
    fill: var(--text-primary);
}

#helpBtn .header-icon {
    filter: brightness(0) saturate(100%) invert(25%) sepia(93%) saturate(1700%) hue-rotate(316deg) brightness(100%) contrast(100%);
}

/* ===== Help Content ===== */
.help-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding-bottom: 20px;
}

.help-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.help-section-title {
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--accent-warning);
}

.help-section-body {
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-primary);
    line-height: 1.6;
    opacity: 0.85;
}

.help-definition-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.help-definition-list dt {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.help-definition-list dd {
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-primary);
    line-height: 1.6;
    opacity: 0.85;
    margin-left: 12px;
    border-left: 2px solid var(--menu-locked-border);
    padding-left: 10px;
}

.help-tips-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.help-tips-list li {
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-primary);
    line-height: 1.6;
    opacity: 0.85;
    padding-left: 16px;
    position: relative;
}

.help-tips-list li::before {
    content: '›';
    position: absolute;
    left: 0;
    color: var(--accent-warning);
    font-weight: 700;
}

/* ===== Level Header ===== */
.level-header {
    text-align: center;
    margin-bottom: 20px;
    margin-top: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.level-number {
    font-size: 0.80rem;
    color: var(--text-primary);
    letter-spacing: 2px;
    opacity: 0.7;
}

.level-title {
    font-size: 2rem;
    color: var(--text-primary);
    letter-spacing: 1px;
}

/* ===== Footer ===== */
.game-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 30px;
    background: var(--footer-bg);
    color: var(--footer-text);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.9rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    z-index: 100;
}

/* ===== Game Area ===== */
.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    width: 100%;
    max-width: 600px;
    padding: 20px 60px;
    /* Padding reduced as header is relatively positioned */
}

.word-display-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
    height: 48px;
}

.current-word {
    font-size: 1.8rem;
    min-height: 44px;
    padding: 8px 24px;
    background: var(--current-word-bg);
    color: var(--current-word-text);
    border-radius: 22px;
    letter-spacing: 4px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 100px;
}

.submit-icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--btn-bg);
    color: var(--btn-text);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(255, 45, 116, 0.3);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.submit-icon-btn:hover {
    transform: scale(1.1);
    background: var(--btn-hover-bg);
    box-shadow: 0 6px 15px rgba(255, 45, 116, 0.5);
}

.submit-icon-btn:active {
    transform: scale(0.95);
}

.cancel-icon-btn {
    background: rgba(255, 255, 255, 0.15);
    box-shadow: none;
    margin-right: 8px;
}

.cancel-icon-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    box-shadow: none;
}

#submitBtnContainer {
    display: flex;
    align-items: center;
}

/* ===== Board ===== */
.board {
    display: grid;
    gap: 8px;
    padding: 0;
}

.cell {
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: transparent;
    border-radius: 0;
    font-size: 1.8rem;
    font-weight: bold;
    cursor: pointer;
    position: relative;
    user-select: none;
    color: var(--text-cell);
    border: none;
    transition: transform 0.2s ease;
}

.cell::after {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--bg-cell);
    border: 2px solid transparent;
    z-index: -1;
    transition: all 0.2s ease;
}

.cell:hover::after {
    background: var(--bg-cell-hover);
}

.cell.selected::after {
    background: var(--bg-cell-selected);
    border-color: var(--border-selected);
    box-shadow: 0 0 15px rgba(255, 187, 0, 0.5);
}

.cell.selected {
    color: var(--text-cell);
}

.cell.used {
    opacity: 0.3;
    cursor: not-allowed;
}

.cell.empty {
    visibility: hidden;
}

.cell .count {
    position: absolute;
    bottom: 2px;
    right: 5px;
    font-size: 0.8rem;
    color: var(--count-cell);
}

.cell .letter {
    z-index: 1;
}

.cell.stacked {
    box-shadow: none;
    position: relative;
    top: -1px;
    left: -1px;
}

.cell.stacked-2 {
    top: -3px;
    left: -3px;
}

/* Stacked card layers */
.cell.stacked::before {
    content: '';
    display: block;
    position: absolute;
    inset: 0;
    background: var(--bg-cell);
    border: 1px solid rgba(0, 28, 41, 0.3);
    z-index: -2;
    transform: translate(2px, 2px);
    filter: brightness(90%);
}

.cell .stack-layer-2 {
    position: absolute;
    inset: 0;
    background: var(--bg-cell);
    border: 1px solid rgba(0, 28, 41, 0.3);
    z-index: -3;
    transform: translate(4px, 4px);
    filter: brightness(95%);
}

.cell.stacked-2::before {
    transform: translate(2px, 2px);
}

.cell.empty::after,
.cell.empty::before {
    display: none;
}

/* ===== Disappear Animation ===== */
.cell.disappear {
    animation: cellDisappear 0.5s cubic-bezier(0.55, 0.085, 0.68, 0.53) forwards;
    pointer-events: none;
}

@keyframes cellDisappear {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    20% {
        transform: scale(1.1);
        opacity: 0.9;
    }

    100% {
        transform: scale(0.5);
        opacity: 0;
    }
}

/* ===== Wall styles ===== */
.wall {
    position: absolute;
    background-color: var(--color-wall);
    border-radius: 3px;
    z-index: 10;
    pointer-events: none;
}

.wall-down {
    height: 6px;
    left: -4px;
    right: -4px;
    bottom: -7px;
}

.wall-right {
    width: 6px;
    top: -4px;
    bottom: -4px;
    right: -7px;
}

/* ===== Words Found ===== */
.words-found {
    margin-top: 24px;
    text-align: center;
}

.words-found ul {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.words-found li {
    background: var(--found-word-bg);
    padding: 5px 10px 5px 15px;
    border-radius: 15px;
    color: var(--found-word-text);
    font-weight: bold;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.words-found li:hover {
    filter: brightness(1.1);
}

.found-word-cancel {
    font-size: 0.65rem;
    opacity: 0.5;
    transition: opacity 0.2s ease;
    line-height: 1;
}

.words-found li:hover .found-word-cancel {
    opacity: 1;
}

/* ===== Message ===== */
.message {
    margin-top: 20px;
    font-size: 1.2rem;
    min-height: 30px;
    color: var(--accent-warning);
}

.message.error {
    color: #ff6b6b;
}

.message.success {
    color: var(--bg-cell);
}

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

    50% {
        transform: scale(1.1);
    }

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

/* ===== Menu Overlay ===== */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-overlay);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

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

.menu-content {
    position: relative;
    width: 100%;
    max-width: 450px;
    height: 100%;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    border-radius: 0;
    background: var(--menu-bg);
    box-shadow: none;
    overflow: hidden;
    border: none;
}

.menu-close {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.8rem;
    cursor: pointer;
    transition: color 0.2s ease;
    z-index: 10;
}

.menu-close:hover {
    color: var(--btn-bg);
}

.menu-title {
    font-size: 1.8rem;
    color: var(--text-primary);
    text-align: left;
    margin-bottom: 20px;
    font-weight: bold;
    flex-shrink: 0;
}

/* ===== Menu List Layout ===== */
.menu-list-layout {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* ===== Category Tabs ===== */
.menu-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    margin: 0 -20px;
    padding: 10px 20px;
    gap: 10px;
}

.menu-tab {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: bold;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.menu-tab.active {
    background: var(--menu-selected-bg);
    color: #000000;
}

.menu-tab:hover:not(.active) {
    background: rgba(255, 255, 255, 0.1);
}

/* ===== Levels List ===== */
.menu-levels-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
}

.levels-list {
    display: flex;
    flex-direction: column;
}

.level-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 10px;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--menu-locked-border);
    color: var(--text-primary);
    font-size: 1.15rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.level-row:hover:not(:disabled) {
    background: var(--menu-hover-bg);
    color: var(--menu-hover-text);
}

.level-row.locked {
    color: rgba(255, 255, 255, 0.4);
    cursor: not-allowed;
}

.level-row.current {
    background: var(--menu-completed-bg);
    color: #001C29;
    border-bottom-color: var(--menu-completed-bg);
}

.level-row-name {
    text-align: left;
}

.level-row-icon {
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    font-family: sans-serif;
}

/* ===== Puzzle Categories ===== */
.puzzle-categories {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 0;
}

/* ===== Settings Overlay ===== */
.theme-options {
    display: flex;
    gap: 20px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-primary);
    opacity: 0.7;
    transition: opacity 0.2s;
}

.radio-label:hover {
    opacity: 1;
}

.radio-label input[type="radio"] {
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--text-primary);
    border-radius: 50%;
    position: relative;
    cursor: pointer;
    background: transparent;
}

.radio-label input[type="radio"]:checked {
    border-color: var(--btn-bg);
}

.radio-label input[type="radio"]:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 10px;
    height: 10px;
    background: var(--btn-bg);
    border-radius: 50%;
}

.radio-label:has(input:checked) {
    opacity: 1;
}



/* ===== Mobile: control buttons ===== */
@media (max-width: 600px) {
    .level-header {
        margin-bottom: 15px;
    }

    .level-title {
        font-size: 1.4rem;
    }

    .board {
        gap: 4px;
    }

    .cell {
        width: 42px;
        height: 42px;
        font-size: 1.6rem;
    }
}

/* ===== Success Popup ===== */
.success-content {
    text-align: center;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    width: 90%;
    max-width: 380px;
    height: auto;
    padding: 30px;
}

.play-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--btn-bg);
    color: var(--btn-text);
    border: none;
    padding: 12px 28px;
    border-radius: 30px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 10px var(--btn-shadow);
    letter-spacing: 1px;
    margin-top: 10px;
}

.play-btn:hover {
    transform: translateY(-3px) scale(1.05);
    background: var(--btn-hover-bg);
    box-shadow: 0 6px 20px var(--btn-shadow);
}

.play-btn:active {
    transform: translateY(-1px);
}

.level-complete-title {
    font-size: 1.5rem;
    color: var(--next-button-text);
    margin-bottom: -10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: bold;
}

.level-completed-text {
    font-size: 2.8rem;
    color: var(--level-completed-text);
    margin-bottom: 30px;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: bold;
    text-shadow:
        2px 2px 0 var(--level-completed-shadow), 2px 0px 0 var(--level-completed-shadow), 0px 2px 0 var(--level-completed-shadow);
}

.trophy-container {
    margin-bottom: 30px;
}

.trophy-icon {
    width: 180px;
    height: auto;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.3));
    animation: popIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.next-puzzle-text {
    font-size: 1.1rem;
    color: var(--next-button-text);
    margin-bottom: 20px;
}

#autoNextTimer {
    color: var(--next-button-text);
    font-weight: bold;
}

@keyframes popIn {
    0% {
        opacity: 0;
        transform: scale(0) rotate(-180deg);
    }

    100% {
        opacity: 1;
        transform: scale(1) rotate(0);
    }
}

/* ===== Tutorial Styles ===== */
.tutorial-instruction {
    background: var(--tutorial-bg);
    border: 2px solid var(--tutorial-border);
    color: var(--tutorial-text);
    padding: 15px;
    border-radius: 10px;
    margin-top: 20px;
    margin-bottom: 10px;
    text-align: center;
    font-size: 1.1rem;
    max-width: 90%;
    animation: fadeIn 0.5s ease;
}

.tutorial-instruction.tutorial-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 200;
    box-shadow: 0 10px 30px var(--shadow-color);
    margin: 0;
    width: 85%;
    max-width: 400px;
    animation: fadeInOverlay 0.5s ease forwards;
}

@keyframes fadeInOverlay {
    from {
        opacity: 0;
        transform: translate(-50%, -45%);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cell.highlight {
    animation: pulse-border 1.5s infinite;
    z-index: 5;
    border: 2px solid var(--accent-warning) !important;
}

@keyframes pulse-border {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 187, 0, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(255, 187, 0, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 187, 0, 0);
    }
}

.shake {
    animation: shake 0.5s cubic-bezier(.36, .07, .19, .97) both;
}

@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);
    }
}

/* ===== Tutorial Hand Animation ===== */
.tutorial-hand {
    position: absolute;
    font-size: 2rem;
    pointer-events: none;
    z-index: 100;
    transition: all 0.5s ease-in-out;
    filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.5));
}

@keyframes hand-point {

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

    50% {
        transform: scale(0.9);
    }
}