/* ─── SCRABBLE THEME ─── */
:root {
    --bg: #c5cfb0;
    --app-bg: #d3ddbf;
    --tile-bg: #fcf9f3;
    --tile-border: #c4b99e;
    --tile-shadow: #b0a58a;
    --tile-text: #1a1a1a;
    --primary: #4a7c59;
    --primary-hover: #3d6a4b;
    --text: #1a1a1a;
    --text-secondary: #6b7a5a;
    --border: #c4b99e;
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.4;
    -webkit-tap-highlight-color: transparent;
}

/* ═══ TOP BAR ═══ */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--app-bg);
    border-bottom: 1px solid var(--border);
}

.top-title-tiles {
    display: flex;
    gap: 3px;
    align-items: center;
}

.top-title-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 28px;
    background: var(--tile-bg);
    border: 1px solid var(--tile-border);
    border-radius: 3px;
    font-family: 'Georgia', serif;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--tile-text);
    text-transform: uppercase;
    box-shadow: 0 1px 0 var(--tile-shadow);
    line-height: 1;
}

.top-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--tile-bg);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    font-family: var(--font);
}

.top-btn:active { transform: scale(0.92); }

/* ═══ APP ═══ */
.app {
    height: calc(100vh - 55px);
    display: flex;
    flex-direction: column;
    background: var(--app-bg);
    overflow: hidden;
}

/* ═══ TOP HALF ═══ */
.top-half {
    height: 50vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    flex-shrink: 0;
}

.tiles-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.tiles-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    align-items: center;
}

.tile-placeholder {
    color: var(--text-secondary);
    font-size: 0.9rem;
    opacity: 0.45;
    font-weight: 400;
}

/* Scrabble tile */
.letter-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 62px;
    background: var(--tile-bg);
    border: 1.5px solid var(--tile-border);
    border-radius: 6px;
    font-family: 'Georgia', serif;
    font-size: 1.85rem;
    font-weight: 700;
    color: var(--tile-text);
    text-transform: uppercase;
    box-shadow: 0 1px 0 var(--tile-shadow), inset 0 1px 0 rgba(255,255,255,0.8);
    animation: tile-pop 0.18s ease-out;
    position: relative;
    line-height: 1;
}

.letter-tile::after {
    content: attr(data-points);
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 0.52rem;
    font-weight: 600;
    color: var(--text-secondary);
    font-family: var(--font);
}

@keyframes tile-pop {
    0% { transform: scale(0.7) translateY(8px); opacity: 0; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}

.tiles-count {
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 2px;
}

.tiles-count #letterCount {
    font-weight: 700;
    color: var(--primary);
    font-size: 1rem;
}

/* Hidden input */
.letters-input {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    opacity: 0;
    cursor: text;
    font-size: 16px;
}

/* ═══ FIND WORDS BUTTON ═══ */
.btn-wrapper {
    display: flex;
    justify-content: center;
    margin-top: 10px;
}

.btn-find {
    padding: 10px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    font-family: var(--font);
    box-shadow: 0 3px 10px rgba(27,138,61,0.25);
    transition: all 0.12s;
}

.btn-find:active { transform: scale(0.96); }
.btn-find:disabled {
    opacity: 0.3;
    cursor: default;
    transform: none;
    box-shadow: none;
}

/* ═══ RESULTS ═══ */
.results-area {
    display: none;
    padding: 6px 16px 0;
    flex-shrink: 0;
}

.results-area.visible { display: block; }

.result-badge {
    text-align: center;
    margin-bottom: 4px;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: 0.5px;
}

.word-scroll {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.word-scroll::-webkit-scrollbar { display: none; }

.word-list {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    gap: 6px 8px;
    align-content: flex-start;
    min-width: min-content;
    max-height: 84px;
}

.word-list.scrollable::after {
    content: '→';
    display: flex;
    align-items: center;
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 700;
    opacity: 0.4;
    flex-shrink: 0;
    height: 30px;
}

.word-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--tile-bg);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    font-family: 'Georgia', serif;
    color: var(--tile-text);
    border: 1px solid var(--tile-border);
    letter-spacing: 1px;
    min-height: 36px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* ═══ BOTTOM BAR ═══ */
.bottom-bar {
    display: flex;
    justify-content: center;
    gap: 28px;
    padding: 10px 16px 14px;
    border-top: 1px solid var(--border);
    background: var(--app-bg);
    flex-shrink: 0;
    margin-top: auto;
}

.btn-ghost {
    background: none;
    border: none;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px 0;
    font-family: var(--font);
}

.btn-ghost:active { color: var(--text); }

/* ═══ LOADING ═══ */
.loading-overlay {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 10;
}

.loading-overlay.visible { display: block; }

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--tile-border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin: 0 auto 4px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay p { font-size: 0.78rem; color: var(--text-secondary); }

/* ═══ TOAST ═══ */
.toast {
    display: none;
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: #ff4444;
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 500;
    z-index: 20;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    white-space: nowrap;
}

.toast.visible { display: block; }

/* ═══ MODAL ═══ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-overlay.visible { display: flex; }

.modal {
    background: var(--tile-bg);
    border-radius: 16px;
    max-width: 440px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 1.05rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-secondary); padding: 4px; font-family: var(--font); }
.modal-body { padding: 16px 20px 20px; }
.modal-body p { font-size: 0.9rem; color: var(--text-secondary); line-height: 1.6; margin-bottom: 10px; }
.modal-body ul { list-style: none; padding: 0; }
.modal-body li { padding: 4px 0; font-size: 0.88rem; color: var(--text-secondary); }

.modal-body .faq-item { border-bottom: 1px solid var(--border); }
.modal-body .faq-item:last-child { border-bottom: none; }
.modal-body .faq-question {
    width: 100%; text-align: left; background: none; border: none;
    padding: 11px 0; font-size: 0.88rem; font-weight: 600;
    cursor: pointer; color: var(--text); font-family: var(--font);
    position: relative; padding-right: 26px;
}
.modal-body .faq-question::after { content: '+'; position: absolute; right: 0; top: 50%; transform: translateY(-50%); font-size: 1rem; color: var(--primary); }
.modal-body .faq-item.active .faq-question::after { content: '−'; }
.modal-body .faq-answer { display: none; padding-bottom: 10px; font-size: 0.84rem; color: var(--text-secondary); line-height: 1.5; }
.modal-body .faq-item.active .faq-answer { display: block; }

/* ═══ SETTINGS ═══ */
.settings-panel {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--tile-bg);
    z-index: 100;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 30px rgba(0,0,0,0.12);
    max-height: 70vh;
    overflow-y: auto;
    animation: slide-up 0.25s ease-out;
}
.settings-panel.visible { display: block; }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.settings-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px 10px; border-bottom: 1px solid var(--border); }
.settings-header h2 { font-size: 0.95rem; font-weight: 700; }
.settings-body { padding: 14px 20px 22px; }
.settings-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.set-group label { display: block; font-size: 0.7rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 3px; text-transform: uppercase; letter-spacing: 0.5px; }
.set-group input { width: 100%; padding: 7px 9px; border: 2px solid var(--border); border-radius: 8px; font-size: 0.85rem; outline: none; font-family: var(--font); background: var(--bg); transition: border-color 0.15s; }
.set-group input:focus { border-color: var(--primary); }
.set-toggle { padding-top: 10px; border-top: 1px solid var(--border); }

.toggle-row { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.toggle-row input { display: none; }
.toggle-slider { position: relative; width: 36px; height: 20px; background: #d4cec0; border-radius: 10px; transition: background 0.2s; flex-shrink: 0; }
.toggle-slider::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: white; border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 2px rgba(0,0,0,0.12); }
.toggle-row input:checked + .toggle-slider { background: var(--primary); }
.toggle-row input:checked + .toggle-slider::after { transform: translateX(16px); }
.toggle-label { font-size: 0.82rem; color: var(--text-secondary); font-weight: 500; }

@media (max-width: 500px) {
    .letter-tile { width: 46px; height: 52px; font-size: 1.6rem; }
    .letter-tile::after { font-size: 0.5rem; }
    .btn-find { padding: 9px 20px; font-size: 0.92rem; letter-spacing: 1.5px; }
    .word-list { max-height: 74px; gap: 5px 7px; }
    .word-chip { padding: 5px 11px; font-size: 0.92rem; min-height: 30px; }
}

@media (max-width: 380px) {
    .letter-tile { width: 38px; height: 44px; font-size: 1.35rem; }
    .tiles-row { gap: 5px; }
}
