/**
 * Xwordle Game Styles
 * Wordle-inspired styling with crossword clue integration
 * Mobile-first responsive design with optimized organization
 */

@font-face {
    font-family: "franklin";
    src: url("./fonts/franklin-gothic-med.woff2") format("woff2");
    font-style: normal;
    font-weight: 400;
}

@font-face {
    font-family: "karnak";
    src: url("./fonts/karnak.woff2") format("woff2");
    font-style: normal;
    font-weight: 700;
}

/* Root Variables & Base Styles */
:root {
    --primary-color: #2563eb;
    --primary-dark: #446df2;
    --secondary-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #f3f4f6;
    --surface: #ffffff;
    --text-primary: #000;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --letter-correct: #10b981;
    --letter-present: #f59e0b;
    --letter-absent: #d1d5db;
}

body.dark-mode {
    --background: #1a1a1a;
    --surface: #2d2d2d;
    --text-primary: #fff;
    --text-secondary: #a0a0a0;
    --border-color: #404040;
    --letter-absent: #505050;
}

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

body {
    font-family: "franklin", "Arial";
    background-color: var(--background);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Container & Layout */
.container {
    max-width: 900px;
    min-width: min(900px, 90vw);
    margin: 0 auto;
    padding: 5px 1vw;
    flex: 1;
    overflow-y: auto;
}

main {
    flex: 1;
    padding-bottom: 16px; /* Space above keyboard */
}

.game-area {
    background: var(--surface);
    border-radius: 8px;
    padding: 20px 3vw;
    box-shadow: var(--shadow-lg);
    margin-bottom: 20px;
}

/* Header */
header {
    text-align: center;
    border-bottom: 2px solid var(--text-primary);
    margin-bottom: 20px;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

header h1 {
    font-size: clamp(1.8rem, 5vw, 2.5rem);
    font-weight: 800;
    color: var(--text-primary);
    font-family: "karnak", serif;
    margin: 10px 0;
    letter-spacing: -1px;
}

header h1 a {
    color: var(--text-primary);
}

/* Game Options */
.game-options {
    display: flex;
    flex-direction: row;
    gap: 8px;
    padding: 12px 0;
    justify-content: center;
    align-items: center;
}

.option-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.option-toggle input[type="checkbox"] {
    cursor: pointer;
    width: 18px;
    height: 18px;
    accent-color: var(--primary-color);
}

.option-toggle:hover {
    color: var(--text-primary);
}

.option-toggle input[type="checkbox"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.option-toggle:has(input[type="checkbox"]:disabled) {
    opacity: 0.6;
    cursor: not-allowed;
}

.option-toggle:has(input[type="checkbox"]:disabled):hover {
    color: var(--text-secondary);
}

/* Modal Options */
.modal-options {
    display: flex;
    justify-content: center;
    margin: 15px 0;
    padding: 10px;
    background: var(--background);
    border-radius: 6px;
}

.modal-options .option-toggle {
    font-size: 0.9rem;
}

.dark-mode-toggle {
    background: var(--primary-color);
    border: none;
    font-size: 0.8em;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease;
}

.dark-mode-toggle:hover {
    background-color: var(--primary-dark);
}

/* Header Buttons */
.header-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-button {
    background: var(--primary-color);
    border: none;
    border-radius: 16px;
    min-width: 32px;
    min-height: 32px;
    font-size: 1em;
    font-weight: bold;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.wide-header-button {
    font-size: 0.9em;
    padding: 0px 8px;
}

.header-button:hover {
    background-color: var(--primary-dark);
    transform: scale(1.05);
}

.header-button:active {
    transform: scale(0.95);
}

.gamemode-button {
    background-color: #eb2c25;
}

.gamemode-button:hover {
    background-color: #d61811;
}

/* Stats Bar */
.stats-bar {
    display: none;
    gap: 16px;
    margin-bottom: 16px;
    padding: 12px;
    background: var(--background);
    border-radius: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.stat {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    font-size: 0.9rem;
}

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

.stat span:last-child {
    color: var(--primary-color);
}

/* Clues Section */
.clues-section {
    margin-bottom: 16px;
}

.clues-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    padding: 4px;
}

.clue-item {
    display: flex;
    gap: 10px;
    padding: 5px;
    background: var(--surface);
    border-left: 4px solid var(--primary-color);
    border-radius: 4px;
    transition: all 0.3s ease;
    animation: slideIn 0.3s ease;
    box-shadow: 0px 1px 1px 1px rgba(0, 0, 0, 0.07);
    font-weight: 400;
}

.clue-number {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    font-weight: 600;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.clue-text {
    flex: 1;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    font-size: 0.9rem;
    flex-wrap: wrap;
    gap: 6px;
}

.clue-metadata {
    color: var(--text-secondary);
    font-size: 0.9rem;
    opacity: 0.7;
    font-style: italic;
    display: flex;
    align-items: center;
    margin-right: 1vw;
}

/* Input Section - Wordle-style */
.input-section {
    margin-bottom: 16px;
    padding: 0.5em 2vw;
    background: var(--background);
    border-radius: 6px;
}

.letter-boxes {
    display: flex;
    gap: 1vw;
    justify-content: center;
    width: 100%;
}

.letter-box {
    flex: 1;
    aspect-ratio: 1 / 1;
    font-size: clamp(6px, 4.5vw, 2.5rem);
    font-weight: 700;
    text-align: center;
    text-transform: uppercase;

    border: 2px solid var(--border-color);
    border-radius: 4px;

    background: var(--surface);
    color: var(--text-primary);

    transition: all 0.2s ease;
    outline: none;
    max-width: min(2em, 65px);
    max-height: min(2em, 65px);
}

.letter-box:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.letter-box.locked-letter {
    cursor: default;
    background-image: linear-gradient(
        to bottom left,
        var(--primary-color) 11%,
        transparent 11%
    );
    background-repeat: no-repeat;
    font-weight: 600;
    border-color: var(--border-color);
}

.error-message {
    color: var(--danger-color);
    font-size: 0.85rem;
    font-weight: 500;
    text-align: center;
}

/* Software Keyboard */
.software-keyboard {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
    background: var(--surface);
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.keyboard-row {
    display: flex;
    gap: clamp(3px, 0.8vw, 6px);
    justify-content: center;
}

.key {
    min-width: clamp(28px, 8.5vw, 52px);
    height: clamp(40px, 9vw, 50px);
    padding: 0;
    font-size: clamp(0.7rem, 5vw, 0.75rem);
    font-weight: 600;
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.1s ease;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.widekey {
    min-width: clamp(52px, 12.75vw, 100px);
}

.key:active {
    background: var(--primary-color);
    color: white;
    transform: scale(0.95);
}

#enterKey {
    background: var(--secondary-color);
    color: white;
}

#enterKey:active {
    background: #059669;
}

#backspaceKey {
    background: var(--danger-color);
    color: white;
    font-size: clamp(0.9rem, 2.5vw, 1rem);
}

#backspaceKey:active {
    background: #dc2626;
}

.key:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Guesses Section */
.guesses-section {
    margin-bottom: 16px;
    display: none;
}

.previous-guesses {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 120px;
    overflow-y: auto;
    padding: 4px;
}

.guess-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--background);
    border-radius: 4px;
    border-left: 3px solid var(--border-color);
}

.guess-number {
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    min-width: 24px;
}

.guess-word {
    flex: 1;
    display: flex;
    gap: 3px;
}

.letter-correct,
.letter-present,
.letter-absent {
    display: flex;
    align-items: center;
    justify-content: center;
    width: clamp(24px, 6vw, 30px);
    height: clamp(24px, 6vw, 30px);
    font-weight: 600;
    border-radius: 3px;
    font-size: 0.75rem;
}

/* Letters the player has guessed correctly (player-locked inputs) */
.letter-box.player-locked {
    color: var(--letter-correct);
    background-color: var(--surface);
    font-weight: 700;
    border-color: var(--border-color);
}

/* Correct letters used in guess history or other displays */
.letter-correct {
    background: transparent;
    color: var(--letter-correct);
    font-weight: 700;
}

.letter-present {
    background: var(--letter-present);
    color: white;
}

.letter-absent {
    background: var(--letter-absent);
    color: var(--text-secondary);
}

.empty-message {
    color: var(--text-secondary);
    text-align: center;
    padding: 16px;
    font-style: italic;
    font-size: 0.9rem;
}

/* Buttons */
.btn {
    padding: 12px 20px;
    font-size: clamp(0.85rem, 2vw, 0.95rem);
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--background);
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-secondary:hover {
    background: var(--primary-color);
    color: white;
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    padding: clamp(20px, 5vw, 40px);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    max-width: 500px;
    width: 100%;
    animation: slideUp 0.3s ease;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 5px 10px;
    line-height: 1;
    transition: color 0.2s ease;
}

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

#gameOverTitle {
    font-size: clamp(1.5rem, 4vw, 1.8rem);
    margin-bottom: 15px;
    color: var(--primary-color);
}

#gameOverMessage {
    color: var(--text-secondary);
    margin-bottom: 25px;
    line-height: 1.8;
    font-size: clamp(0.9rem, 2.5vw, 1rem);
}

#gameOverMessage strong {
    color: var(--text-primary);
    font-size: 1.1em;
}

.emoji-summary {
    margin: 20px 0;
    padding: 15px;
    background: var(--background);
    border-radius: 6px;
    text-align: left;
}

.emoji-summary pre {
    font-family: monospace;
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
    text-align: center;
}

.modal-content .btn {
    display: block;
    margin: 10px auto;
    width: 100%;
    max-width: 200px;
}

/* How to Play Modal */
.how-to-content {
    text-align: left;
    max-height: 70vh;
    overflow-y: auto;
    padding-right: 10px;
    margin-bottom: 20px;
}

.how-to-content h3 {
    color: var(--primary-color);
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: clamp(1.1rem, 3vw, 1.3rem);
}

.how-to-content p {
    margin-bottom: 15px;
    line-height: 1.6;
}

.how-to-content a {
    color: var(--primary-dark);
    text-decoration: underline;
}

.how-to-content ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.how-to-content li {
    margin-bottom: 8px;
    line-height: 1.5;
}

.color-examples {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 15px 0;
}

.color-example {
    display: flex;
    align-items: center;
    gap: 15px;
}

.example-letter {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    border: 2px solid var(--border-color);
    flex-shrink: 0;
}

/* Ensure example letters follow the same style as game */
.example-letter.letter-correct {
    background: linear-gradient(
            to bottom left,
            var(--primary-color) 15%,
            transparent 15%
        )
        no-repeat;
    background-position: top right;
    background-size: 20% 20%;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
}

.example-text {
    font-size: 0.9rem;
}

.example-text strong {
    display: block;
    margin-bottom: 3px;
}

/* Footer */
footer {
    text-align: center;
    color: var(--text-secondary);
    font-size: clamp(0.8rem, 2vw, 0.9rem);
    border-top: 1px solid var(--border-color);
    margin-top: 20px;
    padding-bottom: 250px; /* Space for keyboard */
    padding-top: 10px;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes shake {
    0%,
    100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-5px);
    }
    75% {
        transform: translateX(5px);
    }
}

@keyframes flip {
    0% {
        transform: rotateX(0);
    }
    50% {
        transform: rotateX(90deg);
    }
    100% {
        transform: rotateX(0);
    }
}

@keyframes bounce {
    0%,
    100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Utilities */
.hidden {
    display: none !important;
}

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

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Media Queries for larger screens */
@media (min-width: 768px) {
    .container {
        padding: 20px;
    }

    .game-area {
        padding: 30px;
    }

    .modal {
        padding: 0;
    }

    /* Make keyboard non-fixed on larger screens */
    .software-keyboard {
        position: relative;
        bottom: auto;
        left: auto;
        right: auto;
        box-shadow: none;
        margin-bottom: 16px;
        background: var(--background);
        border-radius: 6px;
    }

    main {
        padding-bottom: 0;
    }

    footer {
        padding-bottom: 20px;
    }
}

@media (min-width: 1024px) {
    .container {
        padding: 30px;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Dark mode hover state fixes */
.dark-mode .clue-item:hover {
    background: var(--surface);
}

.dark-mode .btn-secondary:hover {
    background: var(--primary-color);
    color: white;
}

/* Optimized scrollbar for touch devices */
@media (hover: none) and (pointer: coarse) {
    .clues-container,
    .previous-guesses {
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .clues-container::-webkit-scrollbar,
    .previous-guesses::-webkit-scrollbar {
        display: none;
    }
}
