/* ==========================================================================
   Grind Media - Russian Stress Accentuation App Styles
   Precision Polished: Desktop & Mobile WebApp
   ========================================================================== */

:root {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    /* Dark Theme Colors (Default) */
    --bg-main: #0b0f19;
    --bg-card: rgba(18, 24, 38, 0.85);
    --bg-card-hover: rgba(26, 34, 52, 0.95);
    --bg-input: #111827;
    --bg-toolbar: #151d30;
    
    --border-color: rgba(255, 255, 255, 0.08);
    --border-focus: #6366f1;
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.25);
    
    --accent-cyan: #06b6d4;
    --accent-emerald: #10b981;
    --accent-amber: #f59e0b;
    --accent-amber-bg: rgba(245, 158, 11, 0.14);
    --accent-amber-border: rgba(245, 158, 11, 0.4);
    
    --vowel-stress: #38bdf8;
    --vowel-stress-bg: rgba(56, 189, 248, 0.15);
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 36px rgba(0, 0, 0, 0.5);
    
    /* Subtle modern corner roundings */
    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

body.theme-light {
    --bg-main: #f1f5f9;
    --bg-card: rgba(255, 255, 255, 0.92);
    --bg-card-hover: #ffffff;
    --bg-input: #f8fafc;
    --bg-toolbar: #e2e8f0;
    
    --border-color: rgba(0, 0, 0, 0.08);
    --border-focus: #4f46e5;
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-glow: rgba(79, 70, 229, 0.15);
    
    --accent-amber: #d97706;
    --accent-amber-bg: rgba(217, 119, 6, 0.12);
    --accent-amber-border: rgba(217, 119, 6, 0.3);
    
    --vowel-stress: #0284c7;
    --vowel-stress-bg: rgba(2, 132, 199, 0.1);
    
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.08);
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    transition: background-color 0.25s ease, color 0.25s ease;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    max-width: 1380px;
    margin: 0 auto;
    padding: 24px 20px 48px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #4f46e5 0%, #06b6d4 100%);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.2rem;
    color: #ffffff;
    box-shadow: 0 4px 14px var(--primary-glow);
    flex-shrink: 0;
}

.logo-accent {
    color: #fbbf24;
}

.brand-titles h1 {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.brand-titles .subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.db-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: #34d399;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-weight: 500;
    white-space: nowrap;
}

.db-text-mobile {
    display: none;
}

.pulse-dot {
    width: 7px;
    height: 7px;
    background-color: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 6px #10b981;
    animation: pulse 2s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.8; }
    50% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(0.95); opacity: 0.8; }
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-icon:hover {
    color: var(--text-primary);
    background: var(--border-color);
}

body.theme-dark .icon-moon { display: none; }
body.theme-light .icon-sun { display: none; }

/* Workspace Grid */
.workspace-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

/* Cards */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.card:hover {
    border-color: rgba(99, 102, 241, 0.2);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.02);
    gap: 8px;
}

.card-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.card-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Examples Row */
.examples-row {
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.015);
}

.select-full {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    transition: all 0.2s;
}

.select-full:hover, .select-full:focus {
    color: var(--text-primary);
    border-color: var(--primary);
}

.btn-text-action {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 4px 9px;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-text-action:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

/* Textarea Wrapper */
.textarea-wrapper {
    flex: 1;
    min-height: 260px;
    display: flex;
}

textarea#inputText {
    width: 100%;
    min-height: 260px;
    padding: 16px;
    background: var(--bg-input);
    border: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.65;
    resize: vertical;
    outline: none;
    transition: background 0.2s;
}

textarea#inputText::placeholder {
    color: var(--text-muted);
}

/* Card Footer */
.card-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.02);
    gap: 10px;
}

.counters {
    display: flex;
    gap: 14px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: #ffffff;
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    box-shadow: 0 3px 12px var(--primary-glow);
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 16px var(--primary-glow);
    background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
}

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

/* Toolbar Section */
.toolbar-section {
    grid-column: 1 / -1;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    box-shadow: var(--shadow-sm);
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toolbar-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Segmented Control */
.segmented-control {
    display: flex;
    background: var(--bg-input);
    padding: 3px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.seg-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 5px 12px;
    border-radius: var(--radius-xs);
    font-size: 0.82rem;
    font-weight: 500;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.seg-icon {
    font-family: var(--font-mono);
    font-weight: 700;
}

.seg-label-mobile {
    display: none;
}

.seg-btn:hover {
    color: var(--text-primary);
}

.seg-btn.active {
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 2px 6px var(--primary-glow);
}

/* Custom Checkbox */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-secondary);
    user-select: none;
    white-space: nowrap;
}

.checkbox-label input {
    display: none;
}

.checkbox-custom {
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--text-muted);
    border-radius: var(--radius-xs);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.checkbox-label input:checked + .checkbox-custom {
    background: var(--primary);
    border-color: var(--primary);
}

.checkbox-label input:checked + .checkbox-custom::after {
    content: "✓";
    color: white;
    font-size: 10px;
    font-weight: bold;
}

/* Interactive Output Section */
.badge-omographs {
    background: var(--accent-amber-bg);
    border: 1px solid var(--accent-amber-border);
    color: var(--accent-amber);
    padding: 2px 6px;
    border-radius: var(--radius-xs);
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.btn-action-copy {
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #10b981;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-action-copy:hover {
    background: #10b981;
    color: #ffffff;
    box-shadow: 0 3px 10px rgba(16, 185, 129, 0.3);
}

.btn-icon-action {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-icon-action:hover {
    color: var(--text-primary);
    background: var(--border-color);
}

.output-canvas-wrapper {
    flex: 1;
    min-height: 260px;
    padding: 16px;
    background: var(--bg-input);
    overflow-y: auto;
    max-height: 480px;
}

.interactive-canvas {
    font-size: 1rem;
    line-height: 1.75;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

/* Precision Typography Word Tokens */
.word-token {
    display: inline;
    padding: 0 1px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: background-color 0.15s;
    position: relative;
}

.word-token:hover {
    background-color: rgba(99, 102, 241, 0.15);
}

/* Homograph Word Token: Natural Underline Highlight (NO punctuation gaps) */
.word-token.is-omograph {
    background: var(--accent-amber-bg);
    border-bottom: 2px solid var(--accent-amber);
    color: #fbbf24;
    font-weight: 500;
    padding: 1px 2px;
    border-radius: 2px;
}

.word-token.is-omograph:hover {
    background: rgba(245, 158, 11, 0.28);
    color: #ffffff;
}

.stress-vowel {
    color: var(--vowel-stress);
    background: var(--vowel-stress-bg);
    padding: 0 1px;
    border-radius: 2px;
    font-weight: 600;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 36px 16px;
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 2.2rem;
    margin-bottom: 10px;
}

.empty-state h3 {
    font-size: 1.05rem;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.empty-state p {
    font-size: 0.88rem;
    max-width: 400px;
    margin: 0 auto;
    line-height: 1.55;
    color: var(--text-muted);
}

/* Stats Summary */
.stats-summary {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.stat-pill {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.stat-num {
    font-weight: 700;
    color: var(--text-primary);
}

.stat-pill.pill-omo .stat-num {
    color: var(--accent-amber);
}

.output-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Popover for Homographs */
.popover {
    position: fixed;
    z-index: 1000;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    width: 260px;
    padding: 12px;
    animation: popIn 0.15s ease-out;
}

body.theme-light .popover {
    border-color: rgba(0, 0, 0, 0.12);
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.94); }
    to { opacity: 1; transform: scale(1); }
}

.popover-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.popover-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.popover-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    line-height: 1;
}

.popover-close-btn:hover {
    color: var(--text-primary);
}

.popover-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.popover-item {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.15s;
}

.popover-item:hover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.15);
    color: #ffffff;
}

.popover-item.active {
    border-color: var(--accent-amber);
    background: var(--accent-amber-bg);
    color: var(--accent-amber);
}

.popover-divider {
    height: 1px;
    background: var(--border-color);
    margin: 8px 0;
}

.popover-subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 5px;
    display: block;
}

.vowels-selector {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.vowel-btn {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 4px 7px;
    border-radius: var(--radius-xs);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.vowel-btn:hover {
    background: var(--primary);
    color: white;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #10b981;
    color: #ffffff;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 2000;
    animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* ==========================================================================
   📱 Mobile WebApp Precision (@media max-width: 768px & 480px)
   ========================================================================== */

@media (max-width: 768px) {
    .app-container {
        padding: 10px 10px 28px;
        gap: 12px;
    }

    .header {
        padding: 8px 12px;
        border-radius: var(--radius-md);
    }

    .brand-logo {
        width: 34px;
        height: 34px;
        font-size: 1.05rem;
    }

    .brand-titles h1 {
        font-size: 0.98rem;
        white-space: nowrap;
    }

    .brand-titles .subtitle {
        display: none;
    }

    .db-text-full {
        display: none;
    }

    .db-text-mobile {
        display: inline;
    }

    .db-badge {
        padding: 4px 7px;
        font-size: 0.72rem;
    }

    .btn-icon {
        width: 32px;
        height: 32px;
    }

    .workspace-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .card {
        border-radius: var(--radius-md);
    }

    .card-header {
        padding: 9px 12px;
    }

    .card-title {
        font-size: 0.88rem;
    }

    .examples-row {
        padding: 6px 12px;
    }

    .select-full {
        padding: 6px 10px;
        font-size: 0.8rem;
    }

    .btn-text-action {
        padding: 4px 8px;
        font-size: 0.75rem;
    }

    .textarea-wrapper, textarea#inputText {
        min-height: 170px;
    }

    textarea#inputText {
        padding: 12px;
        font-size: 0.95rem;
        line-height: 1.6;
    }

    .input-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 9px 12px;
    }

    .counters {
        justify-content: space-between;
        font-size: 0.75rem;
    }

    .btn-primary {
        width: 100%;
        justify-content: center;
        padding: 10px;
        font-size: 0.9rem;
    }

    /* Toolbar on mobile */
    .toolbar-section {
        padding: 10px 12px;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        border-radius: var(--radius-md);
    }

    .toolbar-group {
        width: 100%;
    }

    .format-group {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .toolbar-label {
        font-size: 0.75rem;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }

    .segmented-control {
        width: 100%;
        display: flex;
    }

    .seg-btn {
        flex: 1;
        padding: 6px 4px;
        font-size: 0.78rem;
        justify-content: center;
        gap: 4px;
    }

    .seg-label-full {
        display: none;
    }

    .seg-label-mobile {
        display: inline;
    }

    .options-group {
        display: flex;
        justify-content: space-between;
        gap: 10px;
        padding-top: 4px;
        border-top: 1px solid var(--border-color);
    }

    .checkbox-label {
        font-size: 0.78rem;
    }

    /* Output Card on Mobile */
    .output-card .card-header {
        padding: 9px 12px;
    }

    .btn-action-copy {
        padding: 4px 8px;
        font-size: 0.75rem;
    }

    .output-canvas-wrapper {
        min-height: 170px;
        max-height: 380px;
        padding: 12px;
    }

    .interactive-canvas {
        font-size: 0.95rem;
        line-height: 1.65;
    }

    .output-footer {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        padding: 9px 12px;
    }

    .stats-summary {
        width: 100%;
        justify-content: flex-start;
    }

    .output-hint {
        font-size: 0.72rem;
    }

    /* Popover on Mobile */
    .popover {
        width: 90vw;
        max-width: 320px;
    }

    .toast {
        left: 12px;
        right: 12px;
        bottom: 12px;
        justify-content: center;
        font-size: 0.82rem;
    }
}
