/* CSS Variables & Theme Setup */
:root {
    --bg-gradient: linear-gradient(135deg, #050614 0%, #0d0f30 50%, #170d38 100%);
    --bg-light-gradient: linear-gradient(135deg, #f1f5f9 0%, #cbd5e1 100%);
    
    --color-correct: #00ff87;
    --color-present: #ffb300;
    --color-absent: #3a3b4c;
    
    --glow-correct: 0 0 15px rgba(0, 255, 135, 0.6);
    --glow-present: 0 0 15px rgba(255, 179, 0, 0.6);
    
    --text-primary: #ffffff;
    --text-secondary: #9ea2c0;
    --text-dark: #12131a;
    --text-absent: rgba(255, 255, 255, 0.4);
    
    --cell-border: #2b2d42;
    --cell-border-active: #00e5ff;
    --cell-bg: rgba(18, 20, 38, 0.65);
    --cell-glow-active: 0 0 12px rgba(0, 229, 255, 0.5);
    
    --glass-bg: rgba(13, 16, 37, 0.75);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    
    --font-primary: 'Outfit', sans-serif;
    --font-display: 'Orbitron', sans-serif;
}

/* Light Theme Variables */
.light-theme {
    --bg-gradient: var(--bg-light-gradient);
    
    --color-correct: #10b981; /* Soft Emerald Green */
    --color-present: #f59e0b; /* Soft Amber Orange */
    --color-absent: #cbd5e1;  /* Soft Slate Grey */
    
    --glow-correct: none;
    --glow-present: none;
    
    --text-primary: #1e293b;   /* Slate 800 */
    --text-secondary: #475569; /* Slate 600 */
    --text-dark: #0f172a;      /* Slate 900 */
    --text-absent: #94a3b8;    /* Muted Slate 400 */
    
    --cell-border: #cbd5e1;
    --cell-border-active: #3b82f6; /* Soft blue */
    --cell-bg: rgba(255, 255, 255, 0.45); /* Soft glass transparency */
    --cell-glow-active: none;
    
    --glass-bg: rgba(255, 255, 255, 0.5);
    --glass-border: rgba(0, 0, 0, 0.06);
    --glass-shadow: 0 8px 24px 0 rgba(148, 163, 184, 0.08);
}

/* General Resets */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    font-family: var(--font-primary);
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: -webkit-fill-available; /* Mobile height fix */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    transition: background 0.4s ease, color 0.4s ease;
}

html {
    height: -webkit-fill-available;
}

.app-container {
    width: 100%;
    max-width: 500px;
    height: 100vh;
    height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 20px;
    padding: 20px 15px;
    overflow: hidden; /* Prevent vertical scrolling */
}

/* Header Section */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 12px;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 42px;
    height: 42px;
    background: var(--cell-bg);
    border: 2px solid var(--color-correct);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--color-correct);
    text-shadow: var(--glow-correct);
    box-shadow: var(--glow-correct);
    animation: pulse-glow 2s infinite alternate;
}

.logo-text-group {
    display: flex;
    flex-direction: column;
}

.logo-text {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 900;
    letter-spacing: 2px;
    line-height: 1;
}

.logo-part1 {
    color: #00f5ff;
    text-shadow: 0 0 8px rgba(0, 245, 255, 0.4);
}

.logo-part2 {
    color: #00ff87;
    text-shadow: 0 0 8px rgba(0, 255, 135, 0.4);
}

.logo-subtext {
    font-family: var(--font-display);
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--text-secondary);
    margin-top: 3px;
}

@keyframes pulse-glow {
    0% {
        box-shadow: 0 0 5px rgba(0, 255, 135, 0.3);
        border-color: rgba(0, 255, 135, 0.5);
    }
    100% {
        box-shadow: 0 0 15px rgba(0, 255, 135, 0.7);
        border-color: rgba(0, 255, 135, 1);
    }
}

.header-actions {
    display: flex;
    gap: 10px;
}

.icon-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 1.25rem;
    transition: all 0.2s ease;
    box-shadow: var(--glass-shadow);
}

.icon-btn:hover {
    background: var(--cell-border-active);
    color: var(--text-dark);
    transform: translateY(-2px);
    box-shadow: var(--cell-glow-active);
}

/* Stats Bar */
.stats-bar {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
}

.stat-item {
    flex: 1;
    background: var(--glass-bg);
    padding: 10px 8px;
    border-radius: 14px;
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    box-shadow: var(--glass-shadow);
}

.stat-label {
    font-family: var(--font-display);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--text-secondary);
}

.stat-value {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 900;
    color: var(--color-present);
    text-shadow: 0 0 5px rgba(255, 179, 0, 0.4);
    text-align: center;
}

#level-val {
    color: var(--cell-border-active);
    text-shadow: 0 0 5px rgba(0, 229, 255, 0.4);
}

#progress-val {
    color: var(--color-correct);
    text-shadow: 0 0 5px rgba(0, 255, 135, 0.4);
}

/* Game Board */
.game-main {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px 0;
}

.board-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: calc(var(--word-length, 5) * 64px);
    transition: max-width 0.4s ease, filter 0.3s ease;
}

.board-grid.blur-board {
    filter: blur(10px) grayscale(40%);
    pointer-events: none;
}

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

.tile {
    width: 100%;
    aspect-ratio: 1/1;
    background: var(--cell-bg);
    border: 2px solid var(--cell-border);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 900;
    color: var(--text-primary);
    text-transform: uppercase;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

/* Active and Locked Statuses */
.tile.t-active {
    border-color: var(--cell-border-active);
    box-shadow: var(--cell-glow-active);
}

.tile.t-locked {
    background: var(--color-correct);
    border-color: var(--color-correct);
    color: var(--text-dark);
    box-shadow: var(--glow-correct);
}

/* Evaluation States (Colors after Enter) */
.tile.correct {
    background: var(--color-correct) !important;
    border-color: var(--color-correct) !important;
    color: var(--text-dark) !important;
    box-shadow: var(--glow-correct) !important;
}

.tile.present {
    background: var(--color-present) !important;
    border-color: var(--color-present) !important;
    color: var(--text-dark) !important;
    box-shadow: var(--glow-present) !important;
}

.tile.absent {
    background: var(--color-absent) !important;
    border-color: var(--color-absent) !important;
    color: var(--text-absent) !important;
    box-shadow: none !important;
}

/* Timer Draining Bar Styles */
.timer-bar-container {
    width: 100%;
    max-width: calc(var(--word-length, 5) * 64px);
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    margin: 5px auto 10px auto;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
    transition: max-width 0.4s ease;
}

.timer-bar {
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, #00f5ff, #00ff87);
    box-shadow: 0 0 8px rgba(0, 245, 255, 0.5);
    transition: width 0.1s linear, background 0.3s ease, box-shadow 0.3s ease;
}

/* Toast Notification Styles */
.toast-message {
    position: fixed;
    top: 15%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: linear-gradient(135deg, #00f5ff, #00ff87);
    color: #12131a;
    padding: 14px 28px;
    border-radius: 12px;
    font-family: var(--font-display);
    font-weight: 900;
    font-size: 1.1rem;
    box-shadow: 0 0 25px rgba(0, 245, 255, 0.6);
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-align: center;
    letter-spacing: 1px;
}

.toast-message.show {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

/* Animations */
.tile.t-pop {
    animation: pop-in 0.15s ease-out;
}

.tile.t-flip {
    animation: flip-in 0.5s ease-in-out forwards;
}

.board-row.r-shake, #final-guess-input.r-shake {
    animation: shake-row 0.5s ease-in-out;
}

@keyframes pop-in {
    0% {
        transform: scale(0.9);
        opacity: 0.8;
    }
    60% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes flip-in {
    0% {
        transform: rotateX(0deg);
    }
    45% {
        transform: rotateX(90deg);
    }
    55% {
        transform: rotateX(90deg);
    }
    100% {
        transform: rotateX(0deg);
    }
}

@keyframes shake-row {
    0%, 100% { transform: translateX(0); }
    15%, 45%, 75% { transform: translateX(-6px); }
    30%, 60%, 90% { transform: translateX(6px); }
}

/* Modals Overlay & Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(4, 5, 15, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
}

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

.glassmorphism {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: 20px;
}

.modal-content {
    width: 90%;
    max-width: 420px;
    max-height: 85vh;
    padding: 24px 20px;
    position: relative;
    text-align: center;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-overlay:not(.hidden) .modal-content {
    transform: scale(1);
}

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

.modal-close:hover {
    color: var(--text-primary);
}

.modal-title {
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 20px;
    letter-spacing: 1px;
}

/* Rules Modal Styling */
.modal-body {
    text-align: left;
    font-size: 0.9rem;
    line-height: 1.4;
    color: var(--text-secondary);
    overflow-y: auto;
    flex-grow: 1;
    margin-bottom: 15px;
    padding-right: 6px;
}

.modal-body::-webkit-scrollbar {
    width: 6px;
}
.modal-body::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}
.modal-body::-webkit-scrollbar-thumb {
    background: rgba(0, 229, 255, 0.3);
    border-radius: 3px;
}
.modal-body::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 229, 255, 0.5);
}

.modal-body p {
    margin-bottom: 12px;
}

.rule-highlight {
    background: rgba(0, 229, 255, 0.08);
    border-left: 3px solid var(--cell-border-active);
    padding: 12px;
    border-radius: 0 10px 10px 0;
    margin: 15px 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.rule-highlight p {
    margin-bottom: 0;
    color: var(--text-primary);
}

.rule-icon {
    font-size: 1.3rem;
}

.modal-body h3 {
    font-family: var(--font-display);
    font-size: 1rem;
    color: var(--text-primary);
    margin-top: 20px;
    margin-bottom: 10px;
    letter-spacing: 1px;
}

.color-rules {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 15px;
}

.color-rule-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.color-box {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-display);
    font-weight: 900;
    color: var(--text-dark);
}

.color-box.correct-box {
    background: var(--color-correct);
    box-shadow: var(--glow-correct);
}

.color-box.present-box {
    background: var(--color-present);
    box-shadow: var(--glow-present);
}

.color-box.absent-box {
    background: var(--color-absent);
    color: var(--text-primary);
}

/* Action Button styling */
.action-btn {
    width: 100%;
    padding: 14px;
    margin-top: 20px;
    border-radius: 12px;
    border: none;
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn:not(.neon-btn) {
    background: var(--text-primary);
    color: var(--text-dark);
}

.action-btn:not(.neon-btn):hover {
    opacity: 0.9;
    transform: translateY(-2px);
}

.neon-btn {
    background: linear-gradient(to right, #00f5ff, #00ff87);
    color: var(--text-dark);
    box-shadow: 0 0 15px rgba(0, 245, 255, 0.4);
}

.neon-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 25px rgba(0, 245, 255, 0.6);
}

/* Game Result Modal Styling */
.game-result-content {
    border: 2px solid rgba(0, 245, 255, 0.2);
}

.result-title-text {
    font-family: var(--font-display);
    font-size: 2.2rem;
    font-weight: 900;
    background: linear-gradient(to right, #00f5ff, #00ff87);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 25px;
    letter-spacing: 2px;
}

.secret-word-display {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 25px;
}

.secret-word-display .label {
    font-family: var(--font-display);
    font-size: 0.75rem;
    letter-spacing: 2px;
    color: var(--text-secondary);
}

.word-highlight {
    font-family: var(--font-display);
    font-size: 2.2rem;
    font-weight: 900;
    letter-spacing: 8px;
    color: #ffffff;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    padding-left: 8px; /* Offset to center due to letter-spacing */
}

.stats-summary {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 10px;
}

.summary-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.summary-val {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 900;
    color: var(--color-present);
}

.summary-lbl {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Mobile & Tablet Responsiveness */
@media (max-width: 480px) {
    .app-container {
        padding: 8px 6px;
        gap: 10px;
    }
    
    .logo-container {
        gap: 6px;
    }
    
    .logo-icon {
        width: 32px;
        height: 32px;
        font-size: 1.1rem;
        border-radius: 8px;
    }
    
    .logo-text {
        font-size: 1.25rem;
    }
    
    .logo-subtext {
        font-size: 0.45rem;
        letter-spacing: 2px;
    }
    
    .header-actions {
        gap: 5px;
    }
    
    .icon-btn {
        width: 32px;
        height: 32px;
        font-size: 0.95rem;
    }
    
    .stats-bar {
        gap: 4px;
    }
    
    .stat-item {
        padding: 6px 2px;
        border-radius: 8px;
        gap: 2px;
    }
    
    .stat-label {
        font-size: 0.5rem;
        letter-spacing: 0.5px;
    }
    
    .stat-value {
        font-size: 0.75rem;
    }
    
    .board-grid {
        width: 95%;
        max-width: calc(var(--word-length, 5) * 48px);
        padding: 0;
        gap: 5px;
    }
    
    .board-row {
        gap: 5px;
    }
    
    .timer-bar-container {
        width: 95%;
        max-width: calc(var(--word-length, 5) * 48px);
        padding: 0;
    }
    
    .tile {
        font-size: calc(1rem + 1vw);
        border-width: 1.5px;
        border-radius: 6px;
    }
    
    .modal-content {
        padding: 16px 14px;
        width: 95%;
        max-height: 90vh;
    }
    
    .modal-title {
        font-size: 1.2rem;
        margin-bottom: 10px;
    }
    
    .word-highlight {
        font-size: 1.5rem;
    }
    
    .action-btn {
        padding: 10px;
        font-size: 0.9rem;
    }
}

@media (max-height: 600px) {
    .app-container {
        gap: 8px;
    }
    
    .logo-container {
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }
    
    .logo-subtext {
        margin-top: 0;
    }
    
    .stats-bar {
        padding: 4px;
    }
    
    .game-main {
        padding: 5px 0;
    }
    
    .tile {
        font-size: 1.3rem;
        border-radius: 6px;
    }
}

/* Super Lingo Final Round Styles */
.final-input-container {
    margin: 20px 0;
    display: flex;
    justify-content: center;
}

#final-guess-input {
    width: 100%;
    max-width: 280px;
    padding: 12px;
    background: rgba(18, 20, 38, 0.8);
    border: 2px solid var(--cell-border-active);
    border-radius: 12px;
    font-family: var(--font-display);
    font-size: 1.6rem;
    color: var(--text-primary);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 4px;
    box-shadow: var(--cell-glow-active);
    outline: none;
    transition: all 0.3s ease;
}

#final-guess-input:focus {
    border-color: var(--color-correct);
    box-shadow: var(--glow-correct);
}

.tile.final-reveal-pulse {
    animation: final-reveal-glow 0.8s ease-out;
}

@keyframes final-reveal-glow {
    0% {
        transform: scale(1.1);
        box-shadow: 0 0 25px rgba(0, 229, 255, 1);
        border-color: rgba(0, 229, 255, 1);
    }
    50% {
        box-shadow: 0 0 35px rgba(0, 255, 135, 1);
        border-color: rgba(0, 255, 135, 1);
    }
    100% {
        transform: scale(1);
        box-shadow: none;
        border-color: var(--cell-border);
    }
}

/* Confetti Canvas Layout */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

/* Height-based overrides for Mobile Keyboard viewport shrinking */
@media (max-height: 540px) {
    .app-container {
        padding: 6px 10px;
        gap: 6px;
    }
    header {
        padding-bottom: 6px;
    }
    .logo-icon {
        width: 30px;
        height: 30px;
        font-size: 1rem;
        border-radius: 6px;
    }
    .logo-text {
        font-size: 1.15rem;
    }
    .logo-subtext {
        display: none; /* Hide subtext to save space */
    }
    .icon-btn {
        width: 30px;
        height: 30px;
        font-size: 0.9rem;
    }
    .stats-bar {
        gap: 4px;
    }
    .stat-item {
        padding: 4px 2px;
        border-radius: 8px;
    }
    .stat-label {
        font-size: 0.48rem;
    }
    .stat-value {
        font-size: 0.72rem;
    }
    .timer-bar-container {
        margin: 0 auto;
        height: 4px;
        max-width: calc(var(--word-length, 5) * 36px) !important;
    }
    .game-main {
        padding: 4px 0;
    }
    .board-grid {
        max-width: calc(var(--word-length, 5) * 36px) !important;
        gap: 4px;
    }
    .board-row {
        gap: 4px;
    }
    .tile {
        font-size: 1.1rem !important;
        border-width: 1.5px;
        border-radius: 6px;
    }
}
