/* style.css */

/* Theme Variables */
:root {
    /* Light/Gray Theme (Default) */
    --bg-primary: #e8e8e8;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --accent-green: #00a855;
    --accent-blue: #0077cc;
    --accent-purple: #6b5ce7;
    --accent-gold: #cc8800;
    --accent-red: #cc3333;
    --border-color: #cccccc;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --key-bg: #d4d4d4;
    --key-text: #1a1a1a;
}

/* Dark/Night Theme */
body.dark-theme {
    --bg-primary: #0f0f23;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252542;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent-green: #00d26a;
    --accent-blue: #00b4d8;
    --accent-purple: #7b68ee;
    --accent-gold: #ffd700;
    --accent-red: #ff6b6b;
    --border-color: #333355;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --key-bg: #3a3a5c;
    --key-text: #e0e0e0;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 20px;
    transition: background 0.3s, color 0.3s;
}

.container {
    max-width: 500px;
    width: 100%;
}

/* Header */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 0;
    position: relative;
}

.header-left,
.header-right {
    display: flex;
    gap: 10px;
}

.header-center {
    text-align: center;
    flex: 1;
}

header h1 {
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 2px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-blue);
}

.theme-icon {
    font-size: 1.3rem;
}

/* Main Game Area */
main {
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 25px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 20px var(--shadow-color);
    transition: background 0.3s, border-color 0.3s;
}

.puzzle-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
}

.word-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 25px;
    border-radius: 12px;
    min-width: 180px;
}

.start-word {
    background: linear-gradient(135deg, rgba(0, 119, 204, 0.15), rgba(0, 119, 204, 0.08));
    border: 2px solid var(--accent-blue);
}

.goal-word {
    background: linear-gradient(135deg, rgba(0, 168, 85, 0.15), rgba(0, 168, 85, 0.08));
    border: 2px solid var(--accent-green);
}

.word-display .label {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 2px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.word-display .word {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 4px;
    font-family: 'Courier New', monospace;
}

.arrow {
    font-size: 1.3rem;
    color: var(--text-secondary);
}

/* Game Stats */
.game-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent-gold);
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Ladder - NO SCROLL, expands naturally */
.ladder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-height: 60px;
    margin-bottom: 20px;
    padding: 15px;
    background: var(--bg-primary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.ladder:empty::before {
    content: 'Your word chain will appear here';
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-style: italic;
}

.ladder-word {
    display: flex;
    gap: 5px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ladder-letter {
    width: 38px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 2px solid var(--border-color);
    transition: all 0.2s;
}

.ladder-letter.changed {
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
    border-color: var(--accent-purple);
    color: white;
}

.ladder-letter.goal-match {
    background: linear-gradient(135deg, var(--accent-green), #00884a);
    border-color: var(--accent-green);
    color: white;
}

/* Input Area */
.input-area {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

#wordInput {
    flex: 1;
    padding: 14px 18px;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 3px;
    text-transform: uppercase;
    font-family: 'Courier New', monospace;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s;
}

#wordInput:focus {
    border-color: var(--accent-blue);
}

#wordInput::placeholder {
    color: var(--text-secondary);
    letter-spacing: 1px;
    text-transform: none;
    font-size: 0.95rem;
}

.submit-btn {
    padding: 14px 22px;
    font-size: 1.4rem;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    border: none;
    border-radius: 12px;
    color: white;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
}

.submit-btn:hover {
    transform: scale(1.05);
}

.submit-btn:active {
    transform: scale(0.95);
}

.keyboard-toggle-btn {
    padding: 14px 16px;
    font-size: 1.2rem;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
}

.keyboard-toggle-btn:hover {
    border-color: var(--accent-blue);
    background: var(--bg-primary);
}

.keyboard-toggle-btn.active {
    border-color: var(--accent-purple);
    background: var(--accent-purple);
    color: white;
}

/* Message */
.message {
    text-align: center;
    min-height: 24px;
    font-weight: 600;
    padding: 10px;
    border-radius: 8px;
    transition: all 0.2s;
}

.message.error {
    color: var(--accent-red);
    background: rgba(204, 51, 51, 0.1);
}

.message.success {
    color: var(--accent-green);
    background: rgba(0, 168, 85, 0.1);
}

/* Undo Button */
.undo-btn {
    display: block;
    width: 100%;
    margin-top: 15px;
    padding: 12px;
    background: transparent;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.undo-btn:hover {
    border-color: var(--accent-red);
    color: var(--accent-red);
}

/* Keyboard */
.keyboard-container {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.keyboard {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.keyboard-row {
    display: flex;
    gap: 5px;
    justify-content: center;
}

.key {
    min-width: 32px;
    height: 48px;
    padding: 0 10px;
    font-size: 0.95rem;
    font-weight: 600;
    background: var(--key-bg);
    border: none;
    border-radius: 6px;
    color: var(--key-text);
    cursor: pointer;
    transition: all 0.1s;
    font-family: 'Inter', sans-serif;
}

.key:hover {
    background: var(--accent-blue);
    color: white;
}

.key:active {
    transform: scale(0.95);
}

.key-wide {
    min-width: 60px;
    font-size: 0.75rem;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 30px;
    max-width: 400px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 1.4rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.close-btn:hover {
    background: var(--accent-red);
    color: white;
}

.modal h2 {
    text-align: center;
    margin-bottom: 20px;
    color: var(--accent-gold);
}

.modal h3 {
    margin: 20px 0 10px;
    color: var(--accent-blue);
    font-size: 1rem;
}

/* Help Content */
.help-content ul {
    padding-left: 20px;
    color: var(--text-secondary);
}

.help-content li {
    margin: 8px 0;
}

.example {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 15px;
    background: var(--bg-primary);
    border-radius: 10px;
    margin: 10px 0;
}

.example-word {
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-weight: 700;
    font-size: 0.9rem;
}

.example-arrow {
    color: var(--text-secondary);
}

.example-note {
    text-align: center;
    color: var(--accent-green);
    font-weight: 600;
}

/* Win Screen */
.win-content {
    text-align: center;
}

.win-stats {
    margin: 20px 0;
}

.big-number {
    font-size: 3.5rem;
    font-weight: 800;
    color: var(--accent-gold);
    line-height: 1;
}

.comparison {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin: 20px 0;
    padding: 15px;
    background: var(--bg-primary);
    border-radius: 12px;
}

.compare-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.compare-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-blue);
}

.compare-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* Distribution */
.distribution {
    margin: 20px 0;
}

.dist-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 5px 0;
}

.dist-label {
    width: 30px;
    text-align: right;
    font-weight: 600;
    color: var(--text-secondary);
}

.dist-bar-container {
    flex: 1;
    height: 24px;
    background: var(--bg-primary);
    border-radius: 4px;
    overflow: hidden;
}

.dist-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 8px;
    min-width: 30px;
    transition: width 0.5s ease-out;
}

.dist-bar.highlight {
    background: linear-gradient(90deg, var(--accent-green), #00884a);
}

.dist-count {
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
}

/* Share Button */
.share-btn {
    width: 100%;
    padding: 15px;
    font-size: 1.1rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent-green), #00884a);
    border: none;
    border-radius: 12px;
    color: white;
    cursor: pointer;
    transition: transform 0.2s;
}

.share-btn:hover {
    transform: scale(1.02);
}

.next-puzzle {
    margin-top: 20px;
    color: var(--text-secondary);
}

#countdown {
    font-weight: 700;
    color: var(--accent-blue);
    font-family: 'Courier New', monospace;
}

/* User Stats Modal */
.user-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px 10px;
    background: var(--bg-primary);
    border-radius: 10px;
}

.stat-big {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent-gold);
}

.stat-small {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* Completed State */
.completed-message {
    text-align: center;
    padding: 20px;
}

.completed-message h3 {
    color: var(--accent-green);
    margin-bottom: 10px;
}

.view-solution {
    margin-top: 20px;
    padding: 12px 24px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.view-solution:hover {
    border-color: var(--accent-blue);
}

/* Shake Animation */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.3s ease-out;
}

/* Responsive */
@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    header h1 {
        font-size: 1.6rem;
    }
    
    .tagline {
        font-size: 0.75rem;
    }
    
    .icon-btn {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }
    
    main {
        padding: 20px 15px;
    }
    
    .word-display .word {
        font-size: 1.5rem;
        letter-spacing: 3px;
    }
    
    .game-stats {
        gap: 15px;
        padding: 10px;
    }
    
    .stat-value {
        font-size: 1.2rem;
    }
    
    .ladder-letter {
        width: 32px;
        height: 40px;
        font-size: 1.2rem;
    }
    
    .key {
        min-width: 28px;
        height: 44px;
        font-size: 0.85rem;
    }
    
    .key-wide {
        min-width: 50px;
        font-size: 0.7rem;
    }
    
    .user-stats {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .stat-big {
        font-size: 1.4rem;
    }
    
    .big-number {
        font-size: 3rem;
    }
}