/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Warm color palette */
    --primary-orange: #FF9966;
    --primary-yellow: #FFD966;
    --warm-peach: #FFCC99;
    --warm-brown: #D4A574;
    --cream-bg: #FFF5E6;
    --warm-white: #FFFBF5;
    --text-dark: #4A4A4A;
    --text-light: #FFFFFF;
    --shadow-light: rgba(212, 165, 116, 0.2);
    --shadow-medium: rgba(212, 165, 116, 0.3);
    
    /* Spacing */
    --spacing-xs: 8px;
    --spacing-sm: 4px;
    --spacing-md: 10px;
    --spacing-lg: 32px;
    --spacing-xl: 48px;
    
    /* Border radius */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    
    /* Transitions */
    --transition-fast: 0.2s ease;
    --transition-medium: 0.3s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--cream-bg);
    color: var(--text-dark);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Sticky wrapper: header + pinned bar + sentence bar all stick as one unit */
.sticky-header-area {
    position: sticky;
    top: 0;
    z-index: 100;
}

/* Header auto-hide mode */
body.header-auto-hide .app-header {
    display: none;
}

body.header-auto-hide.sentence-mode-active .app-header {
    display: flex;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px var(--spacing-sm);
    background: linear-gradient(135deg, var(--primary-orange) 0%, var(--primary-yellow) 100%);
    box-shadow: 0 4px 12px var(--shadow-light);
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.app-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-light);
    text-align: center;
    flex: 1;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sentence mode: hide title, show word chips */
body.sentence-mode-active .app-title {
    display: none;
}

/* Sentence word chips live in the header in sentence mode */
#sentence-words {
    display: none;
    flex: 1;
    min-width: 0;
    background: rgba(255, 255, 255, 0.25);
    border-radius: var(--radius-md);
    padding: 4px 8px;
    height: 40px;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
}

body.sentence-mode-active #sentence-words {
    display: flex;
}

/* Sentence mode: show speak/clear, hide refresh/settings */
#speak-sentence-button,
#clear-sentence-button {
    display: none;
}

body.sentence-mode-active #speak-sentence-button,
body.sentence-mode-active #clear-sentence-button {
    display: flex;
}



/* Speak button highlighted state */
.btn-speak:not(:disabled) {
    background: rgba(255, 255, 255, 0.35);
}

.btn-speak:disabled {
    opacity: 0.4;
}

.icon-button {
    width: 48px;
    height: 48px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
    color: var(--text-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    backdrop-filter: blur(10px);
}

.icon-button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.icon-button:active {
    transform: scale(0.95);
}

.icon-button.active {
    background: rgba(255, 255, 255, 0.4);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.icon-button .material-icons {
    font-size: 28px;
}

.icon-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.spin {
    animation: spin 0.8s linear infinite;
}

/* Pinned Words Bar */
.pinned-bar {
    display: flex;
    align-items: center;
    min-height: 60px;
    max-height: 100px;
    background: var(--warm-white);
    border-bottom: 2px solid var(--warm-peach);
}

/* Pinned sentence-mode toggle (rightmost in pinned bar) */
.pinned-sentence-toggle {
    flex-shrink: 0;
    align-self: stretch;
    width: 52px;
    border-radius: 0;
    border: none;
    border-left: 2px solid var(--warm-peach);
    background: transparent;
    color: var(--warm-brown);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.pinned-sentence-toggle:hover {
    background: var(--warm-peach);
}

.pinned-sentence-toggle.active {
    background: var(--warm-brown);
    color: white;
}

.pinned-bar-scroll {
    display: flex;
    flex: 1;
    gap: 8px;
    padding: 8px 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    min-width: 0;
}

.pinned-word-card {
    flex: 1;
    min-width: 0;
    max-width: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: var(--cream-bg);
    border: none;
    border-radius: var(--radius-md);
    padding: 0;
    cursor: pointer;
    overflow: hidden;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    box-shadow: 0 2px 6px var(--shadow-light);
    min-height: 0;
    max-height: 84px;
}

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

.pinned-word-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.pinned-word-icon {
    font-size: 36px !important;
    color: var(--primary-orange);
}

.pinned-word-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dark);
    text-align: center;
    word-break: break-word;
    line-height: 1.2;
    width: 100%;
}

/* Pin indicator on main grid cards */
.pin-indicator {
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 16px !important;
    color: var(--primary-orange);
    background: white;
    border-radius: 50%;
    padding: 2px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transform: rotate(45deg);
}

/* Parent category card */
.parent-category-card {
    opacity: 0.75;
}

.parent-card-back-badge {
    position: absolute;
    bottom: 4px;
    left: 4px;
    font-size: 18px !important;
    color: white;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 50%;
    padding: 3px;
}

/* Long-press feedback */
.category-card.pressing,
.pinned-word-card.pressing {
    transform: scale(1.06);
    box-shadow: 0 8px 24px var(--shadow-medium);
}

/* Settings FAB */
.settings-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--warm-brown);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px var(--shadow-medium);
    z-index: 90;
    transition: background var(--transition-fast), transform var(--transition-fast);
}

.settings-fab:hover {
    background: var(--text-dark);
    transform: scale(1.08);
}

/* Toast notification */
.app-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(74, 74, 74, 0.9);
    color: white;
    padding: 10px 20px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    z-index: 300;
    pointer-events: none;
    animation: fadeInOut 2.5s ease forwards;
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translateX(-50%) translateY(8px); }
    15% { opacity: 1; transform: translateX(-50%) translateY(0); }
    75% { opacity: 1; }
    100% { opacity: 0; }
}



.sentence-placeholder {
    color: rgba(255, 255, 255, 0.7);
    font-style: italic;
    font-size: 14px;
    white-space: nowrap;
}

.sentence-word-chip {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all var(--transition-fast);
    animation: chipAppear 0.2s ease;
    white-space: nowrap;
}

@keyframes chipAppear {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.sentence-word-chip:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.word-chip-text {
    user-select: none;
}

.word-chip-remove {
    background: rgba(0, 0, 0, 0.2);
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 0;
}

.word-chip-remove:hover {
    background: rgba(0, 0, 0, 0.3);
    transform: scale(1.1);
}

.word-chip-remove .material-icons {
    font-size: 18px;
    color: white;
}

#sentence-words.speaking {
    animation: pulseSentence 1s ease-in-out infinite;
}

@keyframes pulseSentence {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Sentence mode active state */
body.sentence-mode-active .category-card::after {
    content: '+';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    background: var(--primary-orange);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: var(--spacing-md);
    overflow-y: auto;
}

/* Welcome Message */
.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--spacing-xl);
    min-height: 50vh;
}

.welcome-icon {
    font-size: 80px;
    color: var(--primary-orange);
    margin-bottom: var(--spacing-md);
    animation: wave 2s ease-in-out infinite;
}

@keyframes wave {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(20deg); }
    75% { transform: rotate(-20deg); }
}

.welcome-message h2 {
    font-size: 32px;
    color: var(--primary-orange);
    margin-bottom: var(--spacing-sm);
}

.welcome-message p {
    font-size: 18px;
    color: var(--text-dark);
    opacity: 0.8;
}

/* Categories Grid */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--spacing-md);
    padding: var(--spacing-sm);
}

@media (max-width: 600px) {
    .categories-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: var(--spacing-sm);
    }
}

/* Category Card */
.category-card {
    background: var(--warm-white);
    border: none;
    border-radius: var(--radius-lg);
    padding: var(--spacing-sm);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    min-height: 200px;
    box-shadow: 0 4px 12px var(--shadow-light);
    transition: all var(--transition-medium);
    position: relative;
    overflow: hidden;
}

.category-card:hover {
    transform: scale(1.02);
    box-shadow: 0 8px 24px var(--shadow-medium);
}

.category-card:active {
    transform: scale(0.98);
}

.card-image-container {
    width: 100%;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--spacing-xs);
}

.card-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: var(--radius-md);
}

.card-icon {
    font-size: 72px !important;
    color: var(--primary-orange);
    opacity: 0.9;
}

.card-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dark);
    text-align: center;
    word-wrap: break-word;
    width: 100%;
}

/* Speaking Indicator */
body.speaking .category-card:hover {
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

/* Settings Panel */
.settings-panel {
    position: fixed;
    top: 0;
    right: -100%;
    width: 100%;
    max-width: 400px;
    height: 100vh;
    background: var(--warm-white);
    box-shadow: -4px 0 24px var(--shadow-medium);
    transition: right var(--transition-medium);
    z-index: 200;
    overflow-y: auto;
}

.settings-panel.open {
    right: 0;
}

.settings-content {
    padding: var(--spacing-md);
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-sm);
    border-bottom: 2px solid var(--warm-peach);
}

.settings-header h2 {
    font-size: 24px;
    color: var(--primary-orange);
}

.settings-header .icon-button {
    color: var(--text-dark);
    background: rgba(0, 0, 0, 0.05);
}

.settings-header .icon-button:hover {
    background: rgba(0, 0, 0, 0.1);
}

.settings-section {
    margin-bottom: var(--spacing-lg);
}

.settings-section label {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: 16px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: var(--spacing-sm);
}

.settings-section label .material-icons {
    color: var(--primary-orange);
    font-size: 24px;
}

.settings-select {
    width: 100%;
    padding: var(--spacing-sm);
    border: 2px solid var(--warm-peach);
    border-radius: var(--radius-sm);
    background: var(--cream-bg);
    color: var(--text-dark);
    font-size: 16px;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.settings-action-button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    border: 2px solid var(--warm-peach);
    border-radius: var(--radius-sm);
    background: var(--cream-bg);
    color: var(--text-dark);
    font-size: 16px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.settings-action-button:hover {
    background: var(--warm-peach);
}

.settings-select:focus {
    outline: none;
    border-color: var(--primary-orange);
}

.settings-slider {
    width: 100%;
    height: 8px;
    border-radius: var(--radius-sm);
    background: var(--warm-peach);
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
}

.settings-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary-orange);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.settings-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px var(--shadow-medium);
}

.settings-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary-orange);
    cursor: pointer;
    border: none;
    transition: all var(--transition-fast);
}

.settings-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px var(--shadow-medium);
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-title {
        font-size: 18px;
    }
    
    .category-card {
        min-height: 180px;
    }
    
    .card-title {
        font-size: 16px;
    }
    
    .settings-panel {
        max-width: 100%;
    }
}

/* Touch-friendly minimum sizes */
@media (hover: none) and (pointer: coarse) {
    .icon-button,
    .category-card {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Print styles */
@media print {
    .app-header,
    .settings-panel {
        display: none;
    }
}

/* Update Banner */
.update-banner {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: 10px var(--spacing-sm);
    background: var(--primary-orange);
    color: var(--text-light);
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 2px 8px var(--shadow-medium);
    position: relative;
    z-index: 100;
}

.update-banner[hidden] {
    display: none;
}

.update-banner-text {
    flex: 1;
}

.update-apply-btn {
    background: white;
    color: var(--primary-orange);
    border: none;
    border-radius: var(--radius-sm);
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.update-apply-btn:hover {
    background: var(--cream-bg);
}

.update-dismiss-btn {
    background: transparent;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 4px;
    opacity: 0.8;
}

.update-dismiss-btn:hover {
    opacity: 1;
}
