/* ============================================================================
   style.css — Design System & Layout
   Keyboard Arab Melayu Digital (TAM)
   
   Theme: Dark Islami — Gold & Turquoise accents
   Fonts: Outfit (UI Latin), Amiri (Arabic text)
   ============================================================================ */

/* ============================================================================
   0. CSS CUSTOM PROPERTIES (Design Tokens)
   ============================================================================ */
:root {
    /* --- Background & Surface Colors --- */
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-surface: #1a2035;
    --bg-surface-hover: #222b45;
    --bg-glass: rgba(26, 32, 53, 0.7);
    --bg-glass-hover: rgba(34, 43, 69, 0.85);
    
    /* --- Accent Colors --- */
    --accent-gold: #d4a843;
    --accent-gold-light: #f0d078;
    --accent-gold-dim: rgba(212, 168, 67, 0.15);
    --accent-turquoise: #2dd4bf;
    --accent-turquoise-light: #5eead4;
    --accent-turquoise-dim: rgba(45, 212, 191, 0.12);
    --accent-emerald: #10b981;
    --accent-rose: #f43f5e;
    --accent-amber: #f59e0b;
    
    /* --- Text Colors --- */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-arab: #f8fafc;
    --text-gold: #d4a843;
    --text-khas: #2dd4bf;
    
    /* --- Border & Divider --- */
    --border-subtle: rgba(148, 163, 184, 0.1);
    --border-medium: rgba(148, 163, 184, 0.2);
    --border-focus: rgba(212, 168, 67, 0.5);
    --border-glow: rgba(45, 212, 191, 0.3);
    
    /* --- Shadows --- */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow-gold: 0 0 20px rgba(212, 168, 67, 0.2);
    --shadow-glow-turquoise: 0 0 20px rgba(45, 212, 191, 0.15);
    
    /* --- Typography --- */
    --font-ui: 'Outfit', 'Inter', system-ui, sans-serif;
    --font-arab: 'Times New Roman', 'Amiri', 'Traditional Arabic', 'Noto Naskh Arabic', serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    
    /* --- Sizing --- */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    /* --- Keyboard key sizing --- */
    --key-size: 52px;
    --key-gap: 5px;
    --key-radius: 8px;
    
    /* --- Transitions --- */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================================
   1. RESET & BASE
   ============================================================================ */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-ui);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

/* Subtle Islamic geometric pattern background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        radial-gradient(circle at 20% 20%, rgba(212, 168, 67, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(45, 212, 191, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(212, 168, 67, 0.02) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

/* ============================================================================
   2. NAVBAR / HEADER
   ============================================================================ */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0.75rem 1.5rem;
}

.navbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    text-decoration: none;
    color: var(--text-primary);
}

.navbar-logo-img {
    height: 46px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
    transition: transform var(--transition-fast);
}

.navbar-brand:hover .navbar-logo-img {
    transform: scale(1.05);
}

.navbar-brand-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.navbar-title {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    line-height: 1.2;
}

.navbar-subtitle {
    font-size: 0.72rem;
    color: var(--accent-gold);
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    line-height: 1.2;
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ============================================================================
   3. MAIN CONTAINER
   ============================================================================ */
.main-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* ============================================================================
   4. TEXTAREA AREA — Editor Panel
   ============================================================================ */
.editor-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    transition: border-color var(--transition-normal);
}

.editor-panel:focus-within {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-lg), var(--shadow-glow-gold);
}

.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(0, 0, 0, 0.15);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.toolbar-btn:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    border-color: var(--border-medium);
}

.toolbar-btn:active {
    transform: scale(0.96);
}

.toolbar-btn.active {
    background: var(--accent-gold-dim);
    color: var(--accent-gold);
    border-color: rgba(212, 168, 67, 0.3);
}

.toolbar-btn.success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-emerald);
    border-color: rgba(16, 185, 129, 0.3);
}

.toolbar-btn--primary {
    background: linear-gradient(135deg, rgba(212, 168, 67, 0.2), rgba(212, 168, 67, 0.1));
    color: var(--accent-gold);
    border-color: rgba(212, 168, 67, 0.25);
}

.toolbar-btn--primary:hover {
    background: linear-gradient(135deg, rgba(212, 168, 67, 0.3), rgba(212, 168, 67, 0.15));
    color: var(--accent-gold-light);
    box-shadow: var(--shadow-glow-gold);
}

.toolbar-btn--danger {
    color: var(--text-muted);
}

.toolbar-btn--danger:hover {
    background: rgba(244, 63, 94, 0.15);
    color: var(--accent-rose);
    border-color: rgba(244, 63, 94, 0.3);
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border-subtle);
    margin: 0 0.25rem;
}

.editor-textarea {
    width: 100%;
    min-height: 220px;
    max-height: 50vh;
    resize: vertical;
    background: transparent;
    color: var(--text-arab);
    border: none;
    outline: none;
    padding: 1.25rem 1.5rem;
    font-family: var(--font-arab);
    font-size: 1.65rem;
    line-height: 2.2;
    direction: rtl;
    text-align: right;
    unicode-bidi: bidi-override;
    caret-color: var(--accent-gold);
}

.editor-textarea::placeholder {
    color: var(--text-muted);
    font-size: 1.1rem;
    font-family: var(--font-ui);
    direction: ltr;
    text-align: left;
    unicode-bidi: normal;
}

.editor-textarea::selection {
    background: rgba(212, 168, 67, 0.3);
    color: var(--text-primary);
}

.editor-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--border-subtle);
    background: rgba(0, 0, 0, 0.1);
    font-size: 0.72rem;
    color: var(--text-muted);
}

.editor-stats {
    display: flex;
    gap: 1rem;
}

.editor-stat {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.editor-mode {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.mode-badge {
    padding: 0.15rem 0.5rem;
    border-radius: 100px;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.mode-badge--tam {
    background: var(--accent-gold-dim);
    color: var(--accent-gold);
    border: 1px solid rgba(212, 168, 67, 0.2);
}

.mode-badge--shift {
    background: rgba(45, 212, 191, 0.12);
    color: var(--accent-turquoise);
    border: 1px solid rgba(45, 212, 191, 0.2);
    display: none;
}

.mode-badge--shift.visible {
    display: inline-flex;
}

.mode-badge--numbers {
    background: rgba(245, 158, 11, 0.12);
    color: var(--accent-amber);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

/* ============================================================================
   5. VIRTUAL KEYBOARD
   ============================================================================ */
.keyboard-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1rem;
    box-shadow: var(--shadow-lg);
}

.keyboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    padding: 0 0.25rem;
}

.keyboard-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.keyboard-container {
    display: flex;
    flex-direction: column;
    gap: var(--key-gap);
    align-items: center;
}

.keyboard-row {
    display: flex;
    gap: var(--key-gap);
    justify-content: center;
}

/* Individual Key */
.key {
    position: relative;
    height: var(--key-size);
    min-width: var(--key-size);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-bottom: 3px solid rgba(0, 0, 0, 0.3);
    border-radius: var(--key-radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
    padding: 4px;
    overflow: hidden;
}

.key:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-medium);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.key:active,
.key.pressed {
    transform: translateY(1px);
    border-bottom-width: 1px;
    background: var(--accent-gold-dim);
    border-color: rgba(212, 168, 67, 0.3);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

.key.pressed {
    animation: keyPress 200ms ease-out;
}

@keyframes keyPress {
    0% { 
        transform: translateY(0); 
        background: var(--bg-surface);
    }
    30% { 
        transform: translateY(2px); 
        background: var(--accent-gold-dim);
        box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 12px rgba(212, 168, 67, 0.2);
    }
    100% { 
        transform: translateY(0); 
        background: var(--bg-surface);
    }
}

.key-latin {
    font-size: 0.6rem;
    color: var(--text-muted);
    font-family: var(--font-ui);
    font-weight: 600;
    line-height: 1;
}

.key-arab {
    font-size: 1.15rem;
    color: var(--text-primary);
    font-family: var(--font-arab);
    line-height: 1;
    direction: rtl;
}

/* Special keys */
.key--special {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-family: var(--font-ui);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.key--special .key-arab {
    display: none;
}

.key--special .key-latin {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.key--special:hover {
    background: var(--bg-surface-hover);
}

/* Shift active state */
.key--shift.active {
    background: var(--accent-turquoise-dim);
    border-color: rgba(45, 212, 191, 0.3);
}

.key--shift.active .key-latin {
    color: var(--accent-turquoise);
}

/* Khas Melayu highlight */
.key--khas .key-arab {
    color: var(--accent-turquoise);
}

/* Space key */
.key--space {
    font-family: var(--font-arab);
    color: var(--text-muted);
}

.key--space .key-latin {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-ui);
}

/* ============================================================================
   6. GUIDE / CHEATSHEET PANEL
   ============================================================================ */
.guide-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.guide-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1.25rem;
    cursor: pointer;
    transition: background var(--transition-fast);
    user-select: none;
}

.guide-header:hover {
    background: rgba(255, 255, 255, 0.02);
}

.guide-header-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.guide-icon {
    font-size: 1.1rem;
}

.guide-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.guide-chevron {
    font-size: 0.75rem;
    color: var(--text-muted);
    transition: transform var(--transition-normal);
}

.guide-panel.open .guide-chevron {
    transform: rotate(180deg);
}

.guide-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--transition-slow);
}

.guide-panel.open .guide-content {
    max-height: 2000px;
}

.guide-body {
    padding: 0 1.25rem 1.25rem;
}

.guide-section {
    margin-bottom: 1.25rem;
}

.guide-section:last-child {
    margin-bottom: 0;
}

.guide-section-title {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent-gold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.guide-section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-subtle);
}

/* Khas Melayu special chars display */
.khas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.5rem;
}

.khas-card {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.75rem;
    background: var(--accent-turquoise-dim);
    border: 1px solid rgba(45, 212, 191, 0.15);
    border-radius: var(--radius-sm);
}

.khas-char {
    font-family: var(--font-arab);
    font-size: 1.5rem;
    color: var(--accent-turquoise);
    direction: rtl;
    min-width: 30px;
    text-align: center;
}

.khas-info {
    display: flex;
    flex-direction: column;
}

.khas-name {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-primary);
}

.khas-key {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* Example words table */
.examples-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.examples-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-subtle);
}

.examples-table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}

.examples-table tr:last-child td {
    border-bottom: none;
}

.examples-table .arab-cell {
    font-family: var(--font-arab);
    font-size: 1.15rem;
    color: var(--text-arab);
    direction: rtl;
    text-align: right;
}

.examples-table .keys-cell {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--accent-gold);
}

/* ============================================================================
   7. TOAST NOTIFICATIONS
   ============================================================================ */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.65rem 1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toastIn 300ms ease-out, toastOut 300ms ease-in 2700ms forwards;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    backdrop-filter: blur(12px);
}

.toast--success {
    border-color: rgba(16, 185, 129, 0.3);
    background: rgba(16, 185, 129, 0.1);
}

.toast--info {
    border-color: rgba(45, 212, 191, 0.3);
    background: rgba(45, 212, 191, 0.1);
}

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

@keyframes toastOut {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(-10px) scale(0.95); }
}

/* ============================================================================
   8. SCROLLBAR STYLING
   ============================================================================ */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 100px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================================================
   9. UTILITY CLASSES
   ============================================================================ */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

/* ============================================================================
   10. RESPONSIVE DESIGN
   ============================================================================ */
@media (max-width: 1024px) {
    :root {
        --key-size: 46px;
        --key-gap: 4px;
    }
    
    .main-container {
        padding: 1rem;
    }
    
    .editor-textarea {
        font-size: 1.4rem;
        min-height: 180px;
    }
}

@media (max-width: 768px) {
    :root {
        --key-size: 36px;
        --key-gap: 3px;
        --key-radius: 6px;
    }
    
    .navbar-subtitle {
        display: none;
    }
    
    .main-container {
        padding: 0.75rem;
        gap: 1rem;
    }
    
    .editor-textarea {
        font-size: 1.25rem;
        padding: 1rem;
        min-height: 150px;
        line-height: 2;
    }
    
    .editor-toolbar {
        padding: 0.5rem 0.75rem;
    }
    
    .toolbar-btn {
        padding: 0.35rem 0.5rem;
        font-size: 0.7rem;
    }
    
    .toolbar-btn span.btn-text {
        display: none;
    }
    
    .key-latin {
        font-size: 0.5rem;
    }
    
    .key-arab {
        font-size: 0.9rem;
    }
    
    .key--special .key-latin {
        font-size: 0.55rem;
    }
    
    .keyboard-panel {
        padding: 0.5rem;
    }
    
    .khas-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
}

@media (max-width: 480px) {
    :root {
        --key-size: 30px;
        --key-gap: 2px;
        --key-radius: 5px;
    }
    
    .navbar-inner {
        padding: 0;
    }
    
    .navbar-title {
        font-size: 0.95rem;
    }
    
    .editor-textarea {
        font-size: 1.1rem;
        line-height: 1.9;
    }
    
    .key-arab {
        font-size: 0.75rem;
    }
    
    .key-latin {
        font-size: 0.4rem;
    }
    
    .guide-body {
        padding: 0 0.75rem 0.75rem;
    }
}

/* ============================================================================
   11. PRINT STYLES
   ============================================================================ */
@media print {
    .navbar,
    .keyboard-panel,
    .guide-panel,
    .editor-toolbar,
    .editor-footer,
    .toast-container {
        display: none !important;
    }
    
    body {
        background: white;
        color: black;
    }
    
    .editor-panel {
        border: 1px solid #ccc;
        background: white;
    }
    
    .editor-textarea {
        color: black;
        font-size: 14pt;
    }
}
