* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1em;
    opacity: 0.9;
}

.tabs {
    display: flex;
    background: #f5f5f5;
    border-bottom: 2px solid #ddd;
}

.tab-button {
    flex: 1;
    padding: 15px 20px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1em;
    font-weight: 500;
    color: #666;
    transition: all 0.3s ease;
    position: relative;
}

.tab-button:hover {
    background: #e8e8e8;
    color: #333;
}

.tab-button.active {
    color: #667eea;
    background: white;
}

.tab-button.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 3px;
    background: #667eea;
}

main {
    padding: 30px;
    min-height: 600px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease-in;
}

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

h2 {
    color: #667eea;
    font-size: 2em;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 3px solid #667eea;
}

h3 {
    color: #764ba2;
    font-size: 1.5em;
    margin: 25px 0 15px 0;
}

h4 {
    color: #555;
    font-size: 1.2em;
    margin: 20px 0 10px 0;
}

.lesson-section {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
    border-left: 4px solid #667eea;
}

.lesson-section ul {
    margin: 15px 0;
    padding-left: 30px;
}

.lesson-section li {
    margin: 8px 0;
}

.lesson-section code {
    background: #e8e8e8;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    color: #c7254e;
}

.example-block {
    margin: 30px 0;
    padding: 25px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.description {
    color: #666;
    font-style: italic;
    margin-bottom: 15px;
}

.editor-preview {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 15px;
}

@media (max-width: 768px) {
    .editor-preview {
        grid-template-columns: 1fr;
    }
}

.editor, .preview {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.editor label, .preview label {
    font-weight: 600;
    color: #555;
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

textarea, input[type="text"], select {
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 1em;
    font-family: 'Courier New', monospace;
    transition: border-color 0.3s ease;
    width: 100%;
}

textarea:focus, input[type="text"]:focus, select:focus {
    outline: none;
    border-color: #667eea;
}

/* Direction Controls */
.direction-controls {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.direction-controls label {
    font-size: 0.85em;
    font-weight: normal;
    text-transform: none;
}

.direction-select {
    padding: 6px 10px;
    font-size: 0.9em;
    flex: 1;
}


/* Bidi Editor for Tab 1 */
.bidi-editor {
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 1em;
    font-family: 'Courier New', monospace;
    transition: border-color 0.3s ease;
    width: 100%;
    min-height: 80px;
    background: white;
    direction: ltr;
    unicode-bidi: bidi-override;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.bidi-editor:focus {
    outline: none;
    border-color: #667eea;
}

.bidi-editor:empty:before {
    content: attr(data-placeholder);
    color: #999;
    font-style: italic;
}

/* Bidi control character visualization */
.bidi-char {
    display: inline-block;
    background: #667eea;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.75em;
    font-weight: 600;
    margin: 0 1px;
    vertical-align: middle;
    cursor: text;
    user-select: all;
    white-space: nowrap;
}

.bidi-char[data-char="\u200E"] { background: #4CAF50; }  /* LRM - Green */
.bidi-char[data-char="\u200F"] { background: #F44336; }  /* RLM - Red */
.bidi-char[data-char="\u202A"] { background: #2196F3; }  /* LRE - Blue */
.bidi-char[data-char="\u202B"] { background: #FF5722; }  /* RLE - Deep Orange */
.bidi-char[data-char="\u202D"] { background: #00BCD4; }  /* LRO - Cyan */
.bidi-char[data-char="\u202E"] { background: #E91E63; }  /* RLO - Pink */
.bidi-char[data-char="\u202C"] { background: #9C27B0; }  /* PDF - Purple */
.bidi-char[data-char="\u2066"] { background: #8BC34A; }  /* LRI - Light Green */
.bidi-char[data-char="\u2067"] { background: #FF9800; }  /* RLI - Orange */
.bidi-char[data-char="\u2068"] { background: #009688; }  /* FSI - Teal */
.bidi-char[data-char="\u2069"] { background: #673AB7; }  /* PDI - Deep Purple */
.bidi-char[data-char="\u061C"] { background: #795548; }  /* ALM - Brown */


.output-box {
    padding: 15px;
    background: #f9f9f9;
    border: 2px solid #667eea;
    border-radius: 6px;
    min-height: 60px;
    font-family: 'Courier New', monospace;
    font-size: 1.1em;
    line-height: 1.8;
    word-wrap: break-word;
}

.control-btn {
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: background 0.3s ease;
}

.control-btn:hover {
    background: #5568d3;
}

.control-btn:active {
    transform: translateY(1px);
}

.output-list {
    list-style: none;
    padding: 0;
}

.output-list li {
    padding: 12px;
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 6px;
    margin: 8px 0;
    font-family: 'Courier New', monospace;
}

/* UI Interface Example Styles */
.output-interface {
    border: 2px solid #667eea;
    border-radius: 8px;
    overflow: hidden;
    background: white;
    transition: direction 0.3s ease;
}

.interface-header {
    background: #667eea;
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

.menu-icon, .user-icon {
    font-size: 1.5em;
    cursor: pointer;
}

.interface-content {
    display: flex;
    min-height: 250px;
}

.sidebar {
    width: 200px;
    background: #f5f5f5;
    border-inline-end: 1px solid #ddd;
    padding: 15px;
}

.menu-item {
    padding: 12px;
    margin: 8px 0;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.menu-item:hover {
    background: #667eea;
    color: white;
}

.main-content {
    flex: 1;
    padding: 20px;
}

.main-content h3 {
    margin-top: 0;
}

/* RTL Support */
[dir="rtl"] .sidebar {
    border-inline-start: 1px solid #ddd;
    border-inline-end: none;
}

footer {
    background: #333;
    color: white;
    text-align: center;
    padding: 20px;
    font-size: 0.9em;
}

/* Checkbox styling */
input[type="checkbox"] {
    width: auto;
    margin-inline-end: 8px;
    cursor: pointer;
}

label:has(input[type="checkbox"]) {
    display: flex;
    align-items: center;
    cursor: pointer;
    text-transform: none;
    font-weight: normal;
    font-size: 1em;
}

/* Utility classes */
.rtl {
    direction: rtl;
}

.ltr {
    direction: ltr;
}

/* Floating Character Palette */
.char-palette {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    max-height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.char-palette.minimized {
    max-height: 60px;
}

.char-palette.minimized .palette-content {
    display: none;
}

.palette-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 20px;
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: move;
}

.palette-header h3 {
    margin: 0;
    font-size: 1.2em;
    color: white;
}

.palette-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.3em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
    font-weight: bold;
}

.palette-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
}

.palette-content {
    padding: 15px;
    overflow-y: auto;
    flex: 1;
}

.palette-section {
    margin-bottom: 20px;
}

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

.palette-section h4 {
    font-size: 0.9em;
    color: #764ba2;
    margin: 0 0 10px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.char-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
}

.char-btn {
    padding: 10px;
    background: #f5f5f5;
    border: 2px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    color: #667eea;
    transition: all 0.2s ease;
    position: relative;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.char-btn.visible-char {
    font-size: 1.3em;
    font-weight: normal;
    color: #333;
}

.char-btn:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.char-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.char-btn::after {
    content: attr(data-code);
    position: absolute;
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.7em;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 10;
}

.char-btn:hover::after {
    opacity: 1;
}

/* Responsive adjustments for palette */
@media (max-width: 768px) {
    .char-palette {
        width: calc(100% - 40px);
        right: 20px;
        left: 20px;
    }

    .char-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}
