/* Sentence Builder - Mobile-First Styles */

:root {
    --bg-dark: #1a1a2e;
    --surface: #16213e;
    --surface-light: #1f2b47;
    --primary: #e94560;
    --secondary: #0f3460;
    --accent: #f1c40f;
    --success: #2ecc71;
    --error: #e74c3c;
    --text: #ffffff;
    --text-muted: #a0a0a0;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ===== MAIN MENU ===== */
.main-menu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 3000;
}

.main-menu.hidden {
    display: none;
}

.menu-title {
    text-align: center;
    margin-bottom: 40px;
}

.menu-title h1 {
    font-size: 2.2rem;
    color: var(--primary);
    margin-bottom: 8px;
}

.menu-title .subtitle {
    font-size: 1rem;
    color: var(--text-muted);
}

.menu-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    max-width: 400px;
    width: 100%;
}

.menu-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 12px;
    background: var(--surface);
    border-radius: 16px;
    text-decoration: none;
    color: var(--text);
    transition: transform 0.2s, background 0.2s;
    cursor: pointer;
}

.menu-item:active {
    transform: scale(0.95);
    background: var(--surface-light);
}

.menu-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.menu-label {
    font-size: 0.85rem;
    text-align: center;
}

/* ===== GROUPS VIEW ===== */
.groups-view {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    z-index: 2500;
    overflow-y: auto;
}

.groups-view.hidden {
    display: none;
}

.groups-header {
    display: flex;
    align-items: center;
    padding: 16px;
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 10;
}

.groups-back-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--surface-light);
    color: var(--text);
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    margin-right: 16px;
}

.groups-title {
    font-size: 1.3rem;
    color: var(--text);
}

.groups-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 16px;
}

.group-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.group-card:active {
    transform: scale(0.97);
    background: var(--surface-light);
}

.group-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.group-name {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
    text-align: center;
}

.group-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-dark);
    padding: 4px 10px;
    border-radius: 12px;
}

/* ===== GAME CONTAINER ===== */
.game-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
}

/* ===== HEADER ===== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface);
    flex-shrink: 0;
}

.home-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--surface-light);
    color: var(--text);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.header-title {
    font-size: 1.1rem;
    color: var(--text);
    flex: 1;
    text-align: center;
    margin: 0 12px;
}

.header-controls {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 1.2rem;
    cursor: pointer;
    border-radius: 50%;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 12px;
    gap: 12px;
}

/* ===== MODE INDICATOR ===== */
.mode-indicator {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-shrink: 0;
}

.mode-btn {
    padding: 10px 20px;
    border-radius: 25px;
    border: 2px solid var(--primary);
    background: transparent;
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

.mode-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.mode-btn:not(:disabled):active {
    transform: scale(0.95);
}

/* ===== UNLOCKED INDICATOR ===== */
.unlocked-indicator {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.unlocked-indicator #unlocked-count {
    color: var(--success);
    font-weight: 700;
}

/* ===== TARGET AREA ===== */
.target-area {
    background: var(--secondary);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    border: 2px dashed var(--accent);
}

.target-label {
    font-size: 0.75rem;
    color: var(--accent);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.target-display {
    font-size: 1.6rem;
    color: var(--text);
    font-weight: 600;
}

.target-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 8px;
    font-style: italic;
}

/* ===== WORD BUILDING AREA (Level 1) ===== */
.word-build-area {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    min-height: 80px;
}

.word-display {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 50px;
    align-items: center;
    justify-content: center;
}

.word-letter {
    background: var(--primary);
    color: white;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    animation: letterPop 0.2s ease;
}

.word-letter.chinese {
    width: 56px;
    height: 56px;
    font-size: 1.8rem;
}

@keyframes letterPop {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.word-letter:active {
    transform: scale(0.95);
}

.word-letter.removing {
    animation: letterRemove 0.2s ease forwards;
}

@keyframes letterRemove {
    to {
        transform: scale(0);
        opacity: 0;
    }
}

/* ===== LETTER BANK (Level 1) ===== */
.letter-bank {
    flex: 1;
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    overflow-y: auto;
}

.letter-bank-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.letter-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.letter-chip {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: bold;
    border-radius: 10px;
    background: var(--surface-light);
    border: 2px solid var(--secondary);
    color: var(--text);
    cursor: pointer;
    transition: transform 0.15s, background 0.15s, border-color 0.15s;
    text-transform: lowercase;
}

.letter-chip.uppercase {
    text-transform: uppercase;
}

.letter-chip.chinese {
    width: 56px;
    height: 56px;
    font-size: 1.8rem;
}

.letter-chip:active {
    transform: scale(0.92);
    background: var(--primary);
    border-color: var(--primary);
}

.letter-chip.used {
    opacity: 0.3;
}

/* ===== SENTENCE AREA (Level 2) ===== */
.sentence-area {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    min-height: 100px;
}

.sentence-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sentence-display {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 50px;
    align-items: center;
    justify-content: center;
}

.empty-hint {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
}

.sentence-word {
    background: var(--primary);
    color: white;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 1.3rem;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
    animation: wordPop 0.2s ease;
}

@keyframes wordPop {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.sentence-word:active {
    transform: scale(0.95);
}

.sentence-word.removing {
    animation: wordRemove 0.2s ease forwards;
}

@keyframes wordRemove {
    to {
        transform: scale(0);
        opacity: 0;
    }
}

/* ===== ACTION BUTTONS ===== */
.action-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-shrink: 0;
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    background: var(--surface);
    color: var(--text);
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    min-width: 80px;
}

.action-btn:active {
    transform: scale(0.95);
}

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

.action-btn.success {
    background: var(--success);
}

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

.btn-icon {
    font-size: 1.3rem;
    margin-bottom: 4px;
}

.btn-text {
    font-size: 0.75rem;
    font-weight: 600;
}

/* ===== WORD BANK ===== */
.word-bank {
    flex: 1;
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    overflow-y: auto;
}

.word-bank-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.word-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.word-chip {
    background: var(--surface-light);
    color: var(--text);
    padding: 12px 18px;
    border-radius: 25px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s, opacity 0.2s;
    border: 2px solid transparent;
}

.word-chip:active {
    transform: scale(0.95);
}

.word-chip.used {
    opacity: 0.35;
    border-color: var(--success);
}

.word-chip.locked {
    opacity: 0.35;
    cursor: not-allowed;
    border: 2px dashed var(--text-muted);
}

.word-chip.unlocked {
    position: relative;
    border-color: var(--success);
}

.word-chip.unlocked::after {
    content: '\2713';
    position: absolute;
    top: -6px;
    right: -6px;
    background: var(--success);
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Word unlock celebration animation */
@keyframes wordUnlock {
    0% { transform: scale(1); }
    25% { transform: scale(1.15); }
    50% { transform: scale(0.95); }
    75% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.word-chip.just-unlocked {
    animation: wordUnlock 0.5s ease;
}

/* ===== MODALS ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4000;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    border-radius: 20px;
    width: 100%;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
}

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

.modal-header h2 {
    font-size: 1.2rem;
}

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.setting-row label {
    font-size: 0.95rem;
}

.setting-row select {
    padding: 8px;
    border-radius: 8px;
    background: var(--surface-light);
    color: white;
    border: none;
    max-width: 150px;
}

.slider-with-labels {
    display: flex;
    align-items: center;
    gap: 6px;
}

.slider-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.slider-with-labels input[type="range"] {
    width: 70px;
    accent-color: var(--primary);
}

/* ===== CELEBRATION ===== */
.celebration {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5000;
}

.celebration.hidden {
    display: none;
}

.celebration-content {
    text-align: center;
    animation: celebrationPop 0.4s ease;
    padding: 20px;
}

@keyframes celebrationPop {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.celebration-emoji {
    font-size: 4rem;
    display: block;
    margin-bottom: 16px;
}

.celebration-text {
    font-size: 1.6rem;
    color: var(--accent);
    display: block;
    margin-bottom: 20px;
}

.celebration-sentence {
    font-size: 1.8rem;
    color: var(--text);
    margin-bottom: 8px;
}

.celebration-hint {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.celebration-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
}

.celebration-btn {
    padding: 14px 28px;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
}

.celebration-btn:active {
    transform: scale(0.95);
}

.celebration-btn.retry {
    background: var(--surface);
    color: var(--text);
}

.celebration-btn.next {
    background: var(--success);
    color: white;
}

/* ===== SAVED VIEW ===== */
.custom-sentences {
    padding: 16px;
}

.custom-sentence-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}

.custom-sentence-card:active {
    background: var(--surface-light);
}

.custom-sentence-text {
    font-size: 1.2rem;
}

.custom-sentence-delete {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--error);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    flex-shrink: 0;
    margin-left: 12px;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    display: block;
}

/* ===== RESPONSIVE ===== */
@media (min-width: 500px) {
    .groups-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .word-chip {
        font-size: 1.3rem;
        padding: 14px 22px;
    }

    .sentence-word {
        font-size: 1.4rem;
    }
}
