:root {
    /* Theme colors - Dark Mode (default) */
    --color-bg-dark: #121213;
    --color-bg-card: #1e1e1f;
    --color-text-primary: #ffffff;
    --color-text-muted: #818384;
    --color-border: #3a3a3c;
    --color-border-hover: #565758;

    /* Theme-independent colors */
    --color-green-light: #538d4e;
    --color-yellow: #b59f3b;

    /* Border radius */
    --border-radius-sm: 6px;
    --border-radius-md: 8px;
    --border-radius-lg: 12px;
}

/* Light Mode */
body.light-mode {
    --color-bg-dark: #f5f5f5;
    --color-bg-card: #ffffff;
    --color-text-primary: #1a1a1b;
    --color-text-muted: #6e6e6e;
    --color-border: #d3d6da;
    --color-border-hover: #b0b3b8;
}

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

body {
    font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--color-bg-dark);
    color: var(--color-text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    padding-top: 80px;
    padding-bottom: 20px;
}

/* Top Navigation Bar */
.top-navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: var(--color-bg-dark);
    border-bottom: 1px solid var(--color-border);
    padding: 15px 20px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    z-index: 100;
}

.help-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--color-bg-card);
    border: 2px solid var(--color-border);
    color: var(--color-text-primary);
    font-size: 1.3rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.help-btn:hover {
    background-color: var(--color-border-hover);
    border-color: var(--color-border-hover);
    transform: scale(1.05);
}

.settings-btn {
    width: 40px;
    height: 40px;
    background-color: transparent;
    border: none;
    color: var(--color-text-primary);
    font-size: 2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-btn:hover {
    transform: scale(1.1);
    color: var(--color-text-muted);
}

.container {
    max-width: 600px;
    width: 100%;
    display: flex;
    flex-direction: column;
    max-height: 100%;
    overflow: hidden;
}

header {
    text-align: center;
    margin-bottom: 30px;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 20px;
    flex-shrink: 0;
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 15px;
}

.puzzle-navigation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-top: 15px;
}

.nav-btn {
    background-color: var(--color-text-muted);
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    color: var(--color-text-primary);
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-btn:hover {
    background-color: var(--color-border-hover);
    border-color: var(--color-border-hover);
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-btn:disabled:hover {
    background-color: var(--color-text-muted);
    border-color: var(--color-border);
}

.puzzle-info {
    color: var(--color-text-primary);
    font-size: 0.9rem;
    min-width: 200px;
    text-align: center;
}

main {
    display: flex;
    flex-direction: column;
    gap: 30px;
    flex-grow: 1;
    min-height: 0;
    overflow: visible;
    position: relative;
    z-index: 1;
}

.word-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    column-gap: 23px;
    row-gap: 15px;
    padding: 0 10px;
    flex-shrink: 0;
}

.word-box {
    background-color: var(--color-text-muted);
    border: 3px solid var(--color-border);
    border-radius: var(--border-radius-md);
    padding: 30px 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

.word-box:hover {
    transform: scale(1.02);
    border-color: var(--color-border-hover);
}

.word-box.revealed {
    background-color: var(--color-yellow);
    border-color: var(--color-yellow);
}

.word-box.selected {
    background-color: var(--color-green-light);
    border-color: var(--color-green-light);
    transform: scale(1.05);
}

.word-box.awaiting {
    background-color: var(--color-green-light);
    border-color: rgba(255, 255, 255, 0.6);
    border-style: dashed;
}

.word-box.selected.awaiting {
    transform: scale(1.05);
}

/* Keyboard focus always takes priority for border */
.word-box.keyboard-focused {
    border-color: #ffffff !important;
}

/* Black border in light mode for visibility */
body.light-mode .word-box.keyboard-focused {
    border-color: #121213 !important;
}

/* White border in light mode only when awaiting (first selection) */
body.light-mode .word-box.awaiting.keyboard-focused {
    border-color: #ffffff !important;
}

.word-box.revealed {
    cursor: pointer;
    background-color: var(--color-yellow);
    border-color: var(--color-yellow);
}

/* Selected state overrides revealed (yellow) */
.word-box.revealed.selected {
    background-color: var(--color-green-light);
    border-color: var(--color-green-light);
}

.word-box.revealed.awaiting {
    background-color: var(--color-green-light);
    border-color: rgba(255, 255, 255, 0.6);
}

.word-box.puzzle-complete {
    cursor: default;
}

.word-box.shake {
    animation: shake 0.75s;
}

.word-box::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    width: 20px;
    height: 20px;
    background-image: url('data:image/svg+xml;utf8,<svg width="20" height="20" viewBox="0 0 24 24" fill="%23ffffff" xmlns="http://www.w3.org/2000/svg"><polygon points="12,2 15.09,8.26 22,9.27 17,14.14 18.18,21.02 12,17.77 5.82,21.02 7,14.14 2,9.27 8.91,8.26"/></svg>');
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.word-box.revealed::before {
    opacity: 1;
}

.word-display {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: 2px;
}

/* White text color for word display in light mode */
body.light-mode .word-display {
    color: #ffffff;
}

.relationship-display {
    background-color: var(--color-bg-card);
    border-radius: var(--border-radius-md);
    padding: 25px;
    height: 240px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 15px;
    overflow-y: auto;
    flex-shrink: 0;
}

.relationship-display.all-revealed {
    height: auto;
    flex-grow: 1;
    flex-shrink: 1;
    min-height: 240px;
    justify-content: flex-start;
}

.hint-text {
    color: var(--color-text-muted);
    text-align: center;
    font-style: italic;
}

.relationship-pair {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 25px;
    font-size: 1.3rem;
    padding: 10px;
    background-color: var(--color-bg-dark);
    border-radius: var(--border-radius-sm);
}

.relationship-emoji {
    font-size: 3.5rem;
}

.relationship-image {
    height: 3.5rem;
    width: auto;
    vertical-align: middle;
}

.relationship-word {
    font-weight: 600;
    font-size: 1.5rem;
    min-width: 100px;
    text-align: center;
}

/* Center relationships on emoji for victory screen */
.all-revealed .relationship-pair {
    justify-content: space-between;
}

.all-revealed .relationship-word {
    flex: 1;
    min-width: 0;
}

.all-revealed .relationship-word:first-child {
    text-align: right;
}

.all-revealed .relationship-word:last-child {
    text-align: left;
}

.game-status {
    text-align: center;
    font-size: 1.1rem;
    color: var(--color-green-light);
    font-weight: 600;
    min-height: 30px;
    flex-shrink: 0;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: var(--color-bg-card);
    border-radius: var(--border-radius-lg);
    padding: 30px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    user-select: none;
    position: relative;
}

.modal-content.shake {
    animation: shake 0.75s;
}

.error-message {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #f5f5f5;
    color: #000000;
    padding: 12px 20px;
    border-radius: var(--border-radius-md);
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s;
}

.error-message.show {
    opacity: 1;
}

.modal-content h2 {
    margin-bottom: 15px;
    text-align: center;
}

.modal-content p {
    color: var(--color-text-muted);
    margin-bottom: 20px;
    text-align: center;
}

.letter-inputs {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 25px;
    flex-wrap: nowrap;
    max-width: 100%;
    padding: 0 10px;
}

.letter-input {
    width: 45px;
    height: 55px;
    font-size: 1.5rem;
    font-weight: 700;
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    background-color: var(--color-bg-dark);
    color: var(--color-text-primary);
    text-align: center;
    text-transform: uppercase;
    caret-color: transparent;
    flex-shrink: 1;
    min-width: 30px;
}

/* Adjust size for longer words */
.letter-inputs.long-word .letter-input {
    width: 38px;
    height: 48px;
    font-size: 1.3rem;
}

.letter-inputs.very-long-word {
    gap: 6px;
}

.letter-inputs.very-long-word .letter-input {
    width: 30px;
    height: 40px;
    font-size: 1rem;
}

.letter-input:focus {
    outline: none;
    border-color: var(--color-green-light);
}

.letter-input:disabled {
    background-color: var(--color-border);
    color: #d3d6da;
    cursor: not-allowed;
}

/* Make disabled letter visible in light mode */
body.light-mode .letter-input:disabled {
    color: var(--color-text-primary);
}

.modal-buttons {
    display: flex;
    gap: 10px;
}

.modal-buttons button {
    flex: 1;
    padding: 15px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: background-color 0.2s;
}

#submitGuess {
    background-color: var(--color-green-light);
    color: white;
}

#cancelGuess {
    background-color: var(--color-border);
    color: white;
}

#submitGuess:hover,
#cancelGuess:hover {
    filter: brightness(0.85);
}

/* Settings Modal Styles */
.settings-content {
    background-color: var(--color-bg-card);
    border-radius: var(--border-radius-lg);
    padding: 40px 35px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
}

.close-settings-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 35px;
    height: 35px;
    background-color: transparent;
    border: none;
    color: var(--color-text-primary);
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.close-settings-btn:hover {
    color: var(--color-text-muted);
    transform: scale(1.1);
}

.settings-content h2 {
    text-align: center;
    font-size: 1.8rem;
    margin-bottom: 25px;
    color: var(--color-text-primary);
}

.settings-body {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.setting-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.setting-label {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-text-primary);
}

.setting-description {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin: 0;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--color-border);
    border-radius: 28px;
    transition: all 0.3s ease;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--color-green-light);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(22px);
}

.settings-credits {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--color-border);
    text-align: center;
}

.settings-credits p {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin: 5px 0;
}

/* Tutorial Modal Styles */
.tutorial-content {
    background-color: var(--color-bg-card);
    border-radius: var(--border-radius-lg);
    padding: 40px 35px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
}

.close-tutorial-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 35px;
    height: 35px;
    background-color: transparent;
    border: none;
    color: var(--color-text-primary);
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.close-tutorial-btn:hover {
    color: var(--color-text-muted);
    transform: scale(1.1);
}

.tutorial-content h2 {
    text-align: center;
    font-size: 1.8rem;
    margin-bottom: 25px;
    color: var(--color-text-primary);
}

.tutorial-section {
    margin-bottom: 25px;
}

.tutorial-section h3 {
    font-size: 1.2rem;
    margin-bottom: 10px;
    color: var(--color-text-primary);
}

.tutorial-section p {
    color: var(--color-text-muted);
    line-height: 1.6;
    font-size: 0.95rem;
}

.tutorial-example {
    background-color: var(--color-bg-dark);
    border-radius: var(--border-radius-sm);
    padding: 15px;
    margin-top: 12px;
}

.example-pair {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    padding: 8px;
    margin: 5px 0;
}

.example-pair span:first-child {
    text-align: right;
}

.example-pair span:last-child {
    text-align: left;
}

.example-emoji {
    font-size: 1.5rem;
    min-width: 40px;
    text-align: center;
}

.start-btn {
    width: 100%;
    padding: 15px;
    font-size: 1.1rem;
    font-weight: 600;
    background-color: var(--color-green-light);
    color: white;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 10px;
}

.start-btn:hover {
    filter: brightness(0.85);
}

/* Completion Modal Styles */
.completion-content {
    background-color: var(--color-bg-card);
    border-radius: var(--border-radius-lg);
    padding: 40px 35px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    max-height: 85vh;
    overflow-y: auto;
}

.completion-content h2 {
    text-align: center;
    font-size: 1.8rem;
    margin-bottom: 25px;
    color: var(--color-text-primary);
}

.summary-stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 25px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background-color: var(--color-bg-dark);
    border-radius: var(--border-radius-sm);
}

.stat-word {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--color-text-primary);
}

.stat-details {
    display: flex;
    gap: 15px;
    align-items: center;
    color: var(--color-text-muted);
    font-size: 0.95rem;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Animations */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

@keyframes subtle-pulse {
    0%, 100% { 
        filter: brightness(1);
    }
    50% { 
        filter: brightness(1.2);
    }
}

@keyframes celebrate {
    0% { 
        transform: translateY(0) scale(1);
    }
    50% { 
        transform: translateY(-20px) scale(1.1);
    }
    100% { 
        transform: translateY(0) scale(1.05);
    }
}

@keyframes fadeInRelationship {
    0% {
        opacity: 0;
        transform: translateY(-10px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.word-box.celebrating {
    animation: celebrate 0.4s ease-out forwards;
    z-index: 10;
    position: relative;
}

.relationship-pair.animating {
    opacity: 0;
    animation: fadeInRelationship 0.3s ease-out forwards;
}

/* Mobile Responsive */
@media (max-width: 600px) {
    body {
        padding-top: 70px;
        padding-bottom: 15px;
    }

    .top-navbar {
        padding: 12px 15px;
    }

    .help-btn {
        width: 35px;
        height: 35px;
        font-size: 1.1rem;
    }

    .settings-btn {
        width: 35px;
        height: 35px;
        font-size: 1.7rem;
    }

    header {
        margin-bottom: 20px;
        padding-bottom: 15px;
    }

    h1 {
        font-size: 1.5rem;
    }

    main {
        gap: 20px;
    }

    .word-grid {
        gap: 10px;
    }

    .word-box {
        padding: 20px 15px;
    }

    .word-box::before {
        top: 4px;
        left: 4px;
    }

    .word-display {
        font-size: 1.2rem;
    }

    .relationship-pair {
        font-size: 0.95rem;
        gap: 18px;
    }

    .relationship-emoji {
        font-size: 2.5rem;
    }

    .relationship-image {
        height: 2.5rem;
    }

    .relationship-word {
        font-size: 1.2rem;
        min-width: 80px;
    }

    .relationship-display {
        height: 200px;
    }

    /* Position modal higher on mobile to avoid keyboard */
    .modal {
        align-items: flex-start;
        padding-top: 180px;
    }

    .letter-input {
        width: 38px;
        height: 48px;
        font-size: 1.2rem;
    }

    .letter-inputs.long-word .letter-input {
        width: 32px;
        height: 42px;
        font-size: 1.1rem;
    }

    .letter-inputs.very-long-word {
        gap: 4px;
    }

    .letter-inputs.very-long-word .letter-input {
        width: 26px;
        height: 36px;
        font-size: 0.95rem;
    }

    /* Settings modal adjustments for mobile */
    #settingsModal {
        align-items: flex-start;
        padding-top: 15px;
    }

    .settings-content {
        padding: 30px 25px;
        max-height: calc(100vh - 30px);
        overflow-y: auto;
    }

    .settings-content h2 {
        font-size: 1.5rem;
        margin-bottom: 20px;
    }

    .setting-label {
        font-size: 1rem;
    }

    .setting-description {
        font-size: 0.85rem;
    }

    .toggle-switch {
        width: 45px;
        height: 25px;
    }

    .toggle-slider:before {
        height: 18px;
        width: 18px;
        left: 3.5px;
        bottom: 3.5px;
    }

    .toggle-switch input:checked + .toggle-slider:before {
        transform: translateX(20px);
    }

    /* Tutorial modal adjustments for mobile */
    #tutorialModal {
        align-items: flex-start;
        padding-top: 15px;
    }

    .tutorial-content {
        padding: 30px 25px;
        max-height: calc(100vh - 30px);
        overflow-y: auto;
    }

    .tutorial-content h2 {
        font-size: 1.5rem;
        margin-bottom: 20px;
    }

    .tutorial-section h3 {
        font-size: 1.1rem;
    }

    .tutorial-section p {
        font-size: 0.9rem;
    }

    .example-pair {
        font-size: 0.85rem;
    }

    .example-emoji {
        font-size: 1.3rem;
    }
}

@media (max-width: 400px) {
    .word-display {
        font-size: 1rem;
        letter-spacing: 1px;
    }

    .relationship-pair {
        font-size: 0.85rem;
        flex-wrap: wrap;
    }
}
