/* Spelling Bee Solver - Optimized Mobile-First CSS */

/* ========== CSS VARIABLES ========== */
:root {
    --primary: #f7da21;
    --primary-dark: #e5c919;
    --secondary: #1a1a1a;
    --text: #333;
    --text-light: #666;
    --border: #e0e0e0;
    --success: #4caf50;
    --error: #f44336;
    --bg: #f5f5f5;
    --white: #fff;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
}

/* ========== RESET & BASE ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    padding: 12px;
    font-size: 16px;
}

/* ========== CONTAINER ========== */
.container {
    max-width: 900px;
    margin: 0 auto;
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-lg);
}

/* ========== HEADER ========== */
header {
    text-align: center;
    padding-bottom: 20px;
    margin-bottom: 24px;
    border-bottom: 3px solid var(--primary);
}

h1 {
    font-size: clamp(1.75rem, 5vw, 2.5rem);
    color: var(--secondary);
    font-weight: 700;
    margin-bottom: 4px;
}

.subtitle {
    font-size: clamp(0.9rem, 3vw, 1.1rem);
    color: var(--text-light);
}

/* ========== INPUT SECTION ========== */
.input-section {
    background: var(--bg);
    padding: 20px;
    border-radius: var(--radius);
    margin-bottom: 20px;
}

.input-grid {
    display: grid;
    gap: 16px;
    margin-bottom: 16px;
}

.input-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--secondary);
    font-size: 0.9rem;
}

input[type="text"] {
    width: 100%;
    padding: 14px;
    font-size: 1.25rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: center;
    text-transform: uppercase;
    font-weight: 600;
    transition: all var(--transition);
    background: var(--white);
    letter-spacing: 2px;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(247, 218, 33, 0.15);
}

input[type="text"]::placeholder {
    color: #bbb;
    font-weight: 400;
    letter-spacing: 1px;
}

/* ========== BUTTONS ========== */
.btn-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.btn {
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

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

.btn-solve:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.btn-clear {
    background: var(--white);
    color: var(--text);
    border: 2px solid var(--border);
}

.btn-clear:hover {
    background: var(--bg);
    border-color: var(--text-light);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.btn-loader {
    display: none;
}

.btn.loading .btn-text {
    display: none;
}

.btn.loading .btn-loader {
    display: inline;
}

/* ========== TOGGLE ========== */
.toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    justify-content: center;
}

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

.toggle-text {
    font-size: 0.9rem;
    color: var(--text-light);
}

/* ========== ERROR MESSAGE ========== */
.error-msg {
    display: none;
    background: #ffebee;
    color: var(--error);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--error);
    margin-bottom: 16px;
    font-size: 0.9rem;
    animation: slideDown 0.3s ease;
}

.error-msg:empty {
    display: none !important;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========== RESULTS ========== */
.results {
    display: none;
    animation: fadeIn 0.4s ease;
}

.results.show {
    display: block;
}

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

/* ========== STATS ========== */
.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.stat {
    background: linear-gradient(135deg, var(--primary), #f9e54e);
    padding: 16px;
    border-radius: var(--radius-sm);
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.stat-num {
    font-size: clamp(1.75rem, 5vw, 2.5rem);
    font-weight: 700;
    color: var(--secondary);
    line-height: 1;
}

.stat-lbl {
    font-size: 0.85rem;
    color: #555;
    margin-top: 4px;
    font-weight: 500;
}

/* ========== CARDS ========== */
.card {
    display: none;
    background: var(--bg);
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.card.show {
    display: block;
}

.card-title {
    font-size: 1.2rem;
    color: var(--secondary);
    margin-bottom: 12px;
    font-weight: 600;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 8px;
}

/* ========== WORD GRIDS ========== */
.word-grid,
.hint-grid,
.length-grid {
    display: grid;
    gap: 8px;
}

.word-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

.hint-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
}

.length-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
}

/* ========== WORD ITEMS ========== */
.word-item {
    background: var(--white);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    text-align: center;
    border: 2px solid var(--border);
    font-weight: 600;
    font-size: 0.9rem;
    transition: all var(--transition);
    cursor: default;
}

.word-item:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.word-item.pangram {
    background: var(--success);
    color: var(--white);
    border-color: var(--success);
}

/* ========== HINT ITEMS ========== */
.hint-item {
    background: var(--white);
    padding: 12px;
    border-radius: var(--radius-sm);
    text-align: center;
    border: 2px solid var(--border);
}

.hint-prefix {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--secondary);
}

.hint-count {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 2px;
}

/* ========== LENGTH ITEMS ========== */
.length-item {
    background: var(--white);
    padding: 12px;
    border-radius: var(--radius-sm);
    text-align: center;
    border-left: 4px solid var(--primary);
}

.length-number {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--secondary);
}

.length-count {
    color: var(--text-light);
    margin-top: 4px;
    font-size: 0.85rem;
}

/* ========== ANSWERS ========== */
.answers {
    max-height: 500px;
    overflow-y: auto;
    padding-right: 4px;
}

.answers::-webkit-scrollbar {
    width: 6px;
}

.answers::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.answers::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 10px;
}

.length-group {
    margin-bottom: 16px;
}

.length-group h3 {
    color: var(--secondary);
    font-size: 1rem;
    margin-bottom: 8px;
    padding: 8px 12px;
    background: var(--white);
    border-radius: var(--radius-sm);
    font-weight: 600;
}

.words-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
}

/* ========== RANKS ========== */
.rank-grid {
    display: grid;
    gap: 10px;
}

.rank-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: var(--white);
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--primary);
}

.rank-name {
    font-weight: 600;
    color: var(--secondary);
    font-size: 0.9rem;
}

.rank-points {
    color: var(--text-light);
    font-weight: 600;
    font-size: 0.9rem;
}

/* ========== FOOTER ========== */
footer {
    text-align: center;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 2px solid var(--border);
    color: var(--text-light);
    font-size: 0.85rem;
}

/* ========== TABLET (768px+) ========== */
@media (min-width: 768px) {
    body {
        padding: 20px;
    }
    
    .container {
        padding: 32px;
    }
    
    header {
        padding-bottom: 24px;
        margin-bottom: 28px;
    }
    
    .input-section {
        padding: 24px;
    }
    
    .input-grid {
        grid-template-columns: 1fr 2fr;
        gap: 20px;
    }
    
    .btn-grid {
        grid-template-columns: 3fr 1fr;
    }
    
    .stats {
        gap: 16px;
    }
    
    .stat {
        padding: 20px;
    }
    
    .card {
        padding: 20px;
    }
    
    .rank-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ========== DESKTOP (1024px+) ========== */
@media (min-width: 1024px) {
    .word-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
    
    .hint-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
    
    .length-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    }
    
    .words-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
}

/* ========== PERFORMANCE OPTIMIZATIONS ========== */
/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --text: #e0e0e0;
        --text-light: #aaa;
        --bg: #2a2a2a;
        --white: #1e1e1e;
        --border: #444;
    }
    
    body {
        background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    }
}

/* Print styles */
@media print {
    body {
        background: white;
        padding: 0;
    }
    
    .input-section,
    footer {
        display: none;
    }
}
