/* =============================================================================
   CSS VARIABLES & RESET
   ============================================================================= */
:root { 
    color-scheme: light dark; 
    --bg-light: #f7f7f8;
    --bg-dark: #0b0f14;
    --text-light: #111827;
    --text-dark: #e5e7eb;
    --border-light: #e5e7eb;
    --border-dark: #1f2937;
    --control-bg-light: #ffffff;
    --control-bg-dark: #0f172a;
}

* { box-sizing: border-box; }

/* =============================================================================
   FONTS
   ============================================================================= */
@font-face {
    font-family: "AlefMultiGenderHebrew";
    src: url("fonts/AlefMultiGndr-Regular.woff") format("woff"),
         url("fonts/AlefMultiGndr-Regular.ttf") format("truetype");
    font-display: swap;
    font-weight: normal;
    font-style: normal;
}

/* =============================================================================
   BASE STYLES
   ============================================================================= */
body {
    font-family: "AlefMultiGenderHebrew", -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    margin: 0;
    padding: 0;
    background: var(--bg-light);
    color: var(--text-light);
    line-height: 1.5;
}

body.dark { 
    background: var(--bg-dark); 
    color: var(--text-dark); 
}

/* =============================================================================
   LAYOUT
   ============================================================================= */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    text-align: center;
}

.header-controls {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 100;
    display: flex;
    gap: 8px;
    align-items: center;
}

.theme-toggle {
    background: var(--control-bg-light);
    border: 1px solid var(--border-light);
    color: var(--text-light);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    font-family: "AlefMultiGenderHebrew", sans-serif;
}

.theme-toggle:hover {
    background: rgba(0,0,0,0.05);
    transform: translateY(-1px);
}

body.dark .theme-toggle {
    background: var(--control-bg-dark);
    border-color: var(--border-dark);
    color: var(--text-dark);
}

body.dark .theme-toggle:hover {
    background: rgba(255,255,255,0.05);
}

.share-button {
    background-color: #25D366;
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    font-family: "AlefMultiGenderHebrew", sans-serif;
    box-shadow: 0 2px 4px rgba(37, 211, 102, 0.3);
}

.share-button:hover {
    background-color: #128C7E;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(37, 211, 102, 0.4);
}

.share-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(37, 211, 102, 0.3);
}

h1 {
    margin: 0 0 20px 0;
    font-size: 2rem;
    font-weight: 600;
}

/* =============================================================================
   TEXT INPUT (Simplified like test file)
   ============================================================================= */
.text-input {
    width: 100%;
    max-width: 1200px;
    height: 180px; /* 200px visual incl. 10px padding top/bottom */
    min-height: 180px;
    max-height: 1600px;
    padding: 10px;
    border: none;
    border-radius: 8px;
    font-family: "AlefMultiGenderHebrew", sans-serif;
    direction: rtl;
    text-align: right;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 22px;
    line-height: 1.4;
    box-sizing: border-box;
    background: white;
    outline: none;
    margin: 0 auto 20px auto;
    overflow-y: hidden;
    resize: none;
    /* Maintain 1:6 aspect ratio on smaller screens */
    aspect-ratio: 6 / 1;
}

.text-input:empty:before {
    content: attr(placeholder);
    color: #999;
    pointer-events: none;
}

.text-input:focus {
    outline: none;
    box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
}

body.dark .text-input {
    background: var(--control-bg-dark);
    color: var(--text-dark);
}

/* =============================================================================
   CHARACTER KEYBOARD
   ============================================================================= */
.char-keyboard {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    margin: 20px 0;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
}

.char-button {
    background: var(--control-bg-light);
    border: 1px solid var(--border-light);
    color: var(--text-light);
    padding: 8px 4px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    font-family: "AlefMultiGenderHebrew", sans-serif;
    transition: all 0.2s ease;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.char-button:hover {
    background: rgba(0,0,0,0.05);
    transform: translateY(-1px);
}

body.dark .char-button {
    background: var(--control-bg-dark);
    border-color: var(--border-dark);
    color: var(--text-dark);
}

body.dark .char-button:hover {
    background: rgba(255,255,255,0.05);
}

/* =============================================================================
   CANVAS
   ============================================================================= */
canvas {
    border: none;
    border-radius: 8px;
    max-width: 100%;
    margin-top: 20px;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    display: none; /* Hidden - only used for sharing */
}


/* =============================================================================
   FOOTER
   ============================================================================= */
.footer-info {
    position: fixed;
    bottom: 10px;
    left: 20px;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 8px;
}

.version-small {
    font-size: 12px;
    font-weight: 400;
    opacity: 0.5;
    color: var(--text-light);
    font-family: 'AlefMultiGenderHebrew', monospace;
}

.footer-divider {
    font-size: 12px;
    opacity: 0.3;
    color: var(--text-light);
}

.mg-logo {
    font-size: 12px;
    color: var(--text-light);
    text-decoration: none;
    opacity: 0.6;
    font-family: 'AlefMultiGenderHebrew', monospace;
    transition: opacity 0.2s ease;
}

.mg-logo:hover {
    opacity: 1;
    text-decoration: underline;
}

body.dark .version-small {
    color: var(--text-dark);
    opacity: 0.8;
}

body.dark .footer-divider {
    color: var(--text-dark);
    opacity: 0.6;
}

body.dark .mg-logo {
    color: var(--text-dark);
    opacity: 0.8;
}

/* =============================================================================
   RESPONSIVE BREAKPOINTS
   ============================================================================= */

/* Large screens - maintain 1200px max width with 200px height */
@media (min-width: 1200px) {
    .text-input {
        width: 1200px;
        height: 180px; /* keep 200px visual incl. padding */
        margin: 0 auto 20px auto;
    }
}

/* Medium screens - proportional sizing */
@media (max-width: 1199px) and (min-width: 769px) {
    .text-input {
        width: 100%;
        max-width: 1200px;
        height: calc(100vw / 6 - 20px); /* subtract padding for visual match */
        min-height: 180px;
        margin: 0 auto 20px auto;
    }
}

/* =============================================================================
   MOBILE RESPONSIVE
   ============================================================================= */
@media (max-width: 768px) {
    .container {
        padding: 60px 12px 32px;
    }
    
    .char-keyboard {
        grid-template-columns: repeat(6, 1fr);
        gap: 4px;
        max-width: 360px;
    }
    
    .char-button {
        padding: 6px 3px;
        font-size: 14px;
        min-height: 32px;
    }
    
    .text-input {
        font-size: 22px;
        padding: 10px;
        /* Maintain 1:6 aspect ratio on mobile */
        width: 100%;
        height: calc(100vw / 6 - 20px); /* Account for container padding */
        min-height: calc(100vw / 6 - 20px);
        max-height: 1600px;
        aspect-ratio: 6 / 1;
        overflow-y: hidden;
    }
    
    canvas {
        width: 100%;
        max-width: 100%;
    }
}

/* Very small screens - ensure minimum usable height */
@media (max-width: 480px) {
    .text-input {
        min-height: 60px; /* Minimum usable height on very small screens */
        height: max(calc(100vw / 6 - 20px), 60px);
    }
}