/* =============================================
   Tell Pal – Communication Aid App
   ============================================= */

:root {
    --bg-color: #f0f4f8;
    --header-bg: #2563eb;
    --header-text: #ffffff;
    --card-bg: #ffffff;
    --card-border: #e2e8f0;
    --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --card-hover: 0 4px 16px rgba(0, 0, 0, 0.15);
    --text-color: #1e293b;
    --text-secondary: #64748b;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --recording: #dc2626;
    --border-radius: 16px;
    --transition: 0.2s ease;
}

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

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    touch-action: manipulation;
}

/* Header */
#app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--header-bg);
    color: var(--header-text);
    flex-shrink: 0;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

#page-title {
    font-size: 1.3rem;
    font-weight: 700;
    text-align: center;
    flex: 1;
}

.header-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: var(--header-text);
    font-size: 1.5rem;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}

.header-btn-placeholder {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

.offline-btn {
    width: auto;
    padding: 0 10px;
    gap: 4px;
}

.offline-icon {
    font-size: 1.3rem;
}

.offline-label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

#btn-offline-info.cache-ready {
    background: rgba(22, 163, 74, 0.3);
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.header-btn:active {
    background: rgba(255, 255, 255, 0.4);
}

/* Back card – same shape as symbol cards, shrinks first */
.back-card {
    background: var(--header-bg);
    border-color: var(--header-bg);
    color: var(--header-text);
    cursor: pointer;
    min-height: 80px;
    aspect-ratio: auto;
}

.back-card:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: var(--card-hover);
}

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

.back-card .card-emoji {
    font-size: 3rem;
}

.back-card .card-label {
    color: var(--header-text);
    font-weight: 700;
}

.settings-icon {
    font-size: 1.4rem;
}

/* Main Grid */
#grid-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    align-content: start;
    -webkit-overflow-scrolling: touch;
}

/* Cards */
.card {
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 8px;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    user-select: none;
    position: relative;
    min-height: 120px;
    aspect-ratio: 1 / 1;
}

.card:hover {
    box-shadow: var(--card-hover);
}

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

.card.speaking {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3);
    animation: pulse 0.6s ease-in-out;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.card-emoji {
    font-size: 3.5rem;
    line-height: 1;
    margin-bottom: 8px;
}

.card-image {
    width: 80px;
    height: 80px;
    object-fit: contain;
    margin-bottom: 8px;
    border-radius: 8px;
}

.card-label {
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    color: var(--text-color);
    line-height: 1.2;
    word-break: break-word;
}

.card-edit-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 0.9rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.card-edit-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

body.edit-mode .card-edit-btn {
    display: flex;
}

/* Add new symbol card (edit mode only) */
.add-card {
    border: 3px dashed var(--accent);
    background: #eef2ff;
    cursor: pointer;
}

.add-card:hover {
    background: #dbeafe;
    box-shadow: var(--card-hover);
}

.add-card .card-emoji {
    font-size: 2.8rem;
    opacity: 0.7;
}

.add-card .card-label {
    font-size: 0.9rem;
    color: var(--accent);
    font-weight: 600;
}

/* Danger button */
.danger-btn {
    padding: 10px 16px;
    background: #fef2f2;
    color: var(--danger);
    border: 2px solid var(--danger);
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}

.danger-btn:hover {
    background: #fee2e2;
}

body.edit-mode .card:active {
    transform: none;
}

/* Category-specific colors */
.card[data-color="red"] { border-left: 5px solid #ef4444; }
.card[data-color="orange"] { border-left: 5px solid #f97316; }
.card[data-color="yellow"] { border-left: 5px solid #eab308; }
.card[data-color="green"] { border-left: 5px solid #22c55e; }
.card[data-color="blue"] { border-left: 5px solid #3b82f6; }
.card[data-color="purple"] { border-left: 5px solid #a855f7; }
.card[data-color="pink"] { border-left: 5px solid #ec4899; }
.card[data-color="teal"] { border-left: 5px solid #14b8a6; }

/* HILFE card - special styling */
.card.help-card {
    background: #fef2f2;
    border: 3px solid #dc2626;
    animation: help-glow 2s ease-in-out infinite;
}

@keyframes help-glow {
    0%, 100% { box-shadow: 0 0 5px rgba(220, 38, 38, 0.2); }
    50% { box-shadow: 0 0 15px rgba(220, 38, 38, 0.4); }
}

.card.help-card .card-emoji {
    font-size: 4rem;
}

/* Offline info */
.offline-info {
    line-height: 1.5;
}

.offline-platform {
    margin-bottom: 14px;
    padding: 14px;
    background: var(--bg-color);
    border-radius: 12px;
    font-size: 0.92rem;
    line-height: 1.7;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}

.modal[hidden] {
    display: none;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

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

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

.close-btn {
    background: none;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.close-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

/* Settings Modal */
.settings-list {
    list-style: none;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--card-border);
    cursor: pointer;
}

.settings-item:last-child {
    border-bottom: none;
}

.settings-item label {
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
}

/* Language Picker */
.lang-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 0 4px;
}

.lang-btn {
    flex: 1 1 auto;
    min-width: 100px;
    padding: 10px 12px;
    font-size: 0.95rem;
    border: 2px solid var(--card-border);
    border-radius: 10px;
    background: var(--card-bg);
    cursor: pointer;
    transition: all var(--transition);
}

.lang-btn:hover {
    border-color: var(--accent);
    background: #eef2ff;
}

.lang-btn.active {
    border-color: var(--accent);
    background: #dbeafe;
    font-weight: 600;
}

/* Toggle Switch */
.toggle {
    position: relative;
    width: 52px;
    height: 28px;
}

.toggle input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
    z-index: 2;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: #cbd5e1;
    border-radius: 28px;
    cursor: pointer;
    transition: background var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform var(--transition);
}

.toggle input:checked + .toggle-slider {
    background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(24px);
}

/* Edit Modal */
.edit-section {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--card-border);
}

.edit-section:last-of-type {
    border-bottom: none;
}

.edit-section h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.edit-preview {
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    background: var(--bg-color);
    border-radius: 12px;
    margin-bottom: 10px;
    overflow: hidden;
}

.edit-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.text-input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--card-border);
    border-radius: 10px;
    font-size: 1rem;
    margin-bottom: 8px;
    outline: none;
    transition: border-color var(--transition);
}

.text-input:focus {
    border-color: var(--accent);
}

.file-upload-btn {
    display: inline-block;
    padding: 10px 16px;
    background: var(--accent);
    color: white;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 8px;
    transition: background var(--transition);
}

.file-upload-btn:hover {
    background: var(--accent-hover);
}

.primary-btn {
    padding: 12px 24px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}

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

.secondary-btn {
    padding: 10px 16px;
    background: var(--bg-color);
    color: var(--text-color);
    border: 2px solid var(--card-border);
    border-radius: 10px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background var(--transition);
}

.secondary-btn:hover {
    background: #e2e8f0;
}

.record-btn {
    padding: 12px 20px;
    background: white;
    border: 2px solid var(--card-border);
    border-radius: 10px;
    font-size: 1rem;
    cursor: pointer;
    transition: all var(--transition);
}

.record-btn:hover {
    background: var(--bg-color);
}

.record-btn.recording {
    background: #fef2f2;
    border-color: var(--recording);
    animation: rec-pulse 1s ease-in-out infinite;
}

@keyframes rec-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.3); }
    50% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
}

.recording-status {
    margin-top: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.edit-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    padding-top: 10px;
}

/* Responsive */
@media (min-width: 480px) {
    #grid-container {
        grid-template-columns: repeat(3, 1fr);
        padding: 16px;
        gap: 16px;
    }

    .card {
        min-height: 140px;
    }

    .card-emoji {
        font-size: 4rem;
    }

    .card-label {
        font-size: 1.1rem;
    }
}

@media (min-width: 768px) {
    #grid-container {
        grid-template-columns: repeat(4, 1fr);
        padding: 20px;
        gap: 20px;
    }

    .card {
        min-height: 160px;
        padding: 16px;
    }

    .card-emoji {
        font-size: 4.5rem;
    }

    .card-label {
        font-size: 1.2rem;
    }

    #page-title {
        font-size: 1.6rem;
    }
}

@media (min-width: 1024px) {
    #grid-container {
        grid-template-columns: repeat(5, 1fr);
        max-width: 1200px;
        margin: 0 auto;
    }
}

/* Animations */
.card {
    animation: fadeIn 0.3s ease forwards;
    opacity: 0;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.card:nth-child(1) { animation-delay: 0.02s; }
.card:nth-child(2) { animation-delay: 0.04s; }
.card:nth-child(3) { animation-delay: 0.06s; }
.card:nth-child(4) { animation-delay: 0.08s; }
.card:nth-child(5) { animation-delay: 0.10s; }
.card:nth-child(6) { animation-delay: 0.12s; }
.card:nth-child(7) { animation-delay: 0.14s; }
.card:nth-child(8) { animation-delay: 0.16s; }
.card:nth-child(9) { animation-delay: 0.18s; }
.card:nth-child(10) { animation-delay: 0.20s; }
.card:nth-child(11) { animation-delay: 0.22s; }
.card:nth-child(12) { animation-delay: 0.24s; }

/* Scrollbar */
#grid-container::-webkit-scrollbar {
    width: 6px;
}

#grid-container::-webkit-scrollbar-track {
    background: transparent;
}

#grid-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}
