/* ========================================
   TEXTIFY - CSS Styles
   Version 3.2 - All fixes
   ======================================== */

:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --accent-violet: #6366f1;
    --accent-pink: #ec4899;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #ec4899 100%);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: rgba(99, 102, 241, 0.2);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(99, 102, 241, 0.15);
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.3);
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --header-height: 60px;
    --controls-width: 320px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    line-height: 1.5;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-violet); }

/* ========================================
   MODAL
   ======================================== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--spacing-md);
    padding-top: calc(var(--spacing-md) + var(--safe-top));
    opacity: 1;
    transition: opacity 0.3s;
}

.modal.hidden { opacity: 0; pointer-events: none; }

.modal-content {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    padding: var(--spacing-xl);
    max-width: 420px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    animation: modalSlideIn 0.4s ease;
}

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

.modal-header { margin-bottom: var(--spacing-lg); }
.modal-logo { font-size: 3rem; margin-bottom: var(--spacing-sm); animation: float 3s ease-in-out infinite; }

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.modal-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-content > p { color: var(--text-secondary); margin-bottom: var(--spacing-lg); font-size: 0.95rem; }

.modal-links { display: flex; flex-direction: column; gap: var(--spacing-sm); margin-bottom: var(--spacing-lg); }

.modal-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all var(--transition-base);
}

.modal-link:hover { background: var(--bg-tertiary); border-color: var(--accent-violet); }
.modal-link.kofi { background: linear-gradient(135deg, #ff5e5b 0%, #ff9966 100%); border-color: transparent; font-weight: 600; }
.link-icon { font-size: 1.1rem; }

/* ========================================
   BUTTONS
   ======================================== */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    background: var(--accent-gradient);
    color: white;
    border: none;
    padding: var(--spacing-md) var(--spacing-xl);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-md);
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg), 0 0 30px rgba(99, 102, 241, 0.4); }

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: var(--spacing-md) var(--spacing-xl);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
}

.btn-secondary:hover { background: var(--bg-tertiary); border-color: var(--accent-violet); }

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-base);
}

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

/* ========================================
   APP LAYOUT
   ======================================== */
.app-container {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-top: var(--safe-top);
}

.app-header {
    height: var(--header-height);
    min-height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-lg);
    background: var(--glass-bg);
    border-bottom: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 100;
    flex-shrink: 0;
}

.logo { display: flex; align-items: center; gap: var(--spacing-sm); }
.logo-icon { font-size: 1.5rem; }
.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions { display: flex; align-items: center; gap: var(--spacing-sm); }

.lang-select {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: var(--spacing-xs) var(--spacing-sm);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

@media (min-width: 900px) {
    .main-content { flex-direction: row; }
}

/* ========================================
   CONTROLS PANEL - FIXED BLUE BLOCK
   ======================================== */
.controls-panel {
    background: var(--bg-secondary);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-height: 180px;
    max-height: 45vh;
    position: relative;
    z-index: 50;
    overflow: hidden;
}

@media (max-width: 899px) {
    .controls-panel { order: -1; border-bottom: 1px solid var(--glass-border); }
}

@media (min-width: 900px) {
    .controls-panel {
        width: var(--controls-width);
        min-width: var(--controls-width);
        max-height: none;
        height: auto;
        border-right: 1px solid var(--glass-border);
        overflow-y: auto;
        overflow-x: hidden;
    }
}

@media (min-width: 768px) and (max-width: 899px) {
    .controls-panel { min-height: 220px; max-height: 50vh; }
}

.controls-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--spacing-md);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

@media (min-width: 900px) {
    .controls-scroll {
        overflow-y: visible;
        overflow-x: visible;
    }
}

.control-section {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.control-section h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-md);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.control-section h3::before {
    content: '';
    width: 3px;
    height: 1em;
    background: var(--accent-gradient);
    border-radius: 2px;
}

.control-group { margin-bottom: var(--spacing-md); }
.control-group:last-child { margin-bottom: 0; }

.control-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
}

.control-group select,
.control-group input[type="color"] {
    width: 100%;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: var(--spacing-sm);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
}

.control-group select:focus,
.control-group input[type="color"]:focus { border-color: var(--accent-violet); }
.control-group input[type="color"] { height: 40px; padding: 4px; }

.control-group input[type="range"] {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-primary);
    border-radius: 3px;
    cursor: pointer;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-gradient);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow-md);
}

.range-value {
    display: inline-block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: var(--spacing-xs);
}

#textInput {
    width: 100%;
    min-height: 50px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: var(--spacing-sm);
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
    outline: none;
}

#textInput:focus { border-color: var(--accent-violet); }

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
    font-size: 0.9rem !important;
    color: var(--text-primary) !important;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-violet);
    cursor: pointer;
}

input[type="file"] { display: none; }

.file-label {
    display: block;
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    padding: var(--spacing-md);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-base);
}

.file-label:hover { border-color: var(--accent-violet); color: var(--text-primary); }

/* Texture Grid */
.texture-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--spacing-xs);
}

.texture-item {
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 2px solid transparent;
    overflow: hidden;
    transition: all var(--transition-base);
    position: relative;
}

.texture-item::before {
    content: attr(data-name);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 0.55rem;
    padding: 2px;
    text-align: center;
    opacity: 0;
    transition: opacity var(--transition-base);
}

.texture-item:hover::before { opacity: 1; }
.texture-item:hover { transform: scale(1.05); }
.texture-item.selected { border-color: var(--accent-violet); box-shadow: 0 0 10px rgba(99, 102, 241, 0.5); }

/* ========================================
   PREVIEW PANEL
   ======================================== */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: var(--spacing-md);
    min-height: 0;
    overflow: hidden;
}

.preview-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: 
        linear-gradient(45deg, var(--bg-tertiary) 25%, transparent 25%),
        linear-gradient(-45deg, var(--bg-tertiary) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--bg-tertiary) 75%),
        linear-gradient(-45deg, transparent 75%, var(--bg-tertiary) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    background-color: var(--bg-secondary);
    border-radius: var(--radius-lg);
    min-height: 150px;
    position: relative;
    overflow: hidden;
}

.preview-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: var(--spacing-lg);
}

.preview-canvas {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Text Wrapper */
.text-wrapper {
    position: relative;
    cursor: move;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    display: inline-block;
    padding: 20px;
    will-change: transform;
}

.text-wrapper.selected { outline: 2px dashed var(--accent-violet); outline-offset: 15px; }
.text-wrapper.dragging { cursor: grabbing; }

/* Corner Handles */
.handle {
    position: absolute;
    width: 16px;
    height: 16px;
    background: var(--accent-violet);
    border: 2px solid white;
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    z-index: 10;
    touch-action: none;
    will-change: transform;
}

.text-wrapper.selected .handle { opacity: 1; pointer-events: auto; }

.handle-tl { top: -4px; left: -4px; cursor: nwse-resize; }
.handle-tr { top: -4px; right: -4px; cursor: nesw-resize; }
.handle-bl { bottom: -4px; left: -4px; cursor: nesw-resize; }
.handle-br { bottom: -4px; right: -4px; cursor: nwse-resize; }

/* Rotate Handle */
.handle-rotate {
    top: -45px;
    left: 50%;
    transform: translateX(-50%);
    cursor: grab;
    background: var(--accent-pink);
}

.handle-rotate::before {
    content: '';
    position: absolute;
    top: 16px;
    left: 50%;
    width: 2px;
    height: 27px;
    background: var(--accent-pink);
    transform: translateX(-50%);
}

/* 3D Axis Ball - Center Handle */
.handle-3d {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    background: radial-gradient(circle at 30% 30%, #22d3ee, #0891b2);
    cursor: move;
    border: 3px solid white;
    box-shadow: 0 0 15px rgba(34, 211, 238, 0.6);
}

.handle-3d::before,
.handle-3d::after {
    content: '';
    position: absolute;
    background: rgba(255,255,255,0.5);
}

.handle-3d::before {
    width: 100%;
    height: 2px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.handle-3d::after {
    width: 2px;
    height: 100%;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

/* Touch devices - larger handles */
@media (pointer: coarse) {
    .handle { width: 26px; height: 26px; }
    .handle-tl { top: -10px; left: -10px; }
    .handle-tr { top: -10px; right: -10px; }
    .handle-bl { bottom: -10px; left: -10px; }
    .handle-br { bottom: -10px; right: -10px; }
    .handle-rotate { top: -55px; width: 30px; height: 30px; }
    .handle-3d { width: 40px; height: 40px; }
}

/* Text Display */
.text-display {
    font-size: 72px;
    font-weight: 700;
    color: #ffffff;
    white-space: nowrap;
    text-align: center;
    line-height: 1.1;
    display: inline-block;
}

/* Font classes for iOS compatibility */
.font-montserrat { font-family: 'Montserrat', sans-serif !important; }
.font-abril-fatface { font-family: 'Abril Fatface', serif !important; }
.font-anton { font-family: 'Anton', sans-serif !important; }
.font-bebas-neue { font-family: 'Bebas Neue', sans-serif !important; }
.font-black-ops-one { font-family: 'Black Ops One', cursive !important; }
.font-bungee { font-family: 'Bungee', cursive !important; }
.font-caveat { font-family: 'Caveat', cursive !important; }
.font-cinzel { font-family: 'Cinzel', serif !important; }
.font-comfortaa { font-family: 'Comfortaa', cursive !important; }
.font-dancing-script { font-family: 'Dancing Script', cursive !important; }
.font-fredoka-one { font-family: 'Fredoka One', cursive !important; }
.font-great-vibes { font-family: 'Great Vibes', cursive !important; }
.font-josefin-sans { font-family: 'Josefin Sans', sans-serif !important; }
.font-lobster { font-family: 'Lobster', cursive !important; }
.font-orbitron { font-family: 'Orbitron', sans-serif !important; }
.font-oswald { font-family: 'Oswald', sans-serif !important; }
.font-pacifico { font-family: 'Pacifico', cursive !important; }
.font-permanent-marker { font-family: 'Permanent Marker', cursive !important; }
.font-playfair-display { font-family: 'Playfair Display', serif !important; }
.font-poppins { font-family: 'Poppins', sans-serif !important; }
.font-press-start-2p { font-family: 'Press Start 2P', cursive !important; }
.font-righteous { font-family: 'Righteous', cursive !important; }
.font-roboto-slab { font-family: 'Roboto Slab', serif !important; }
.font-rock-salt { font-family: 'Rock Salt', cursive !important; }
.font-russo-one { font-family: 'Russo One', sans-serif !important; }
.font-sacramento { font-family: 'Sacramento', cursive !important; }
.font-satisfy { font-family: 'Satisfy', cursive !important; }
.font-shadows-into-light { font-family: 'Shadows Into Light', cursive !important; }
.font-staatliches { font-family: 'Staatliches', cursive !important; }
.font-titan-one { font-family: 'Titan One', cursive !important; }
.font-ultra { font-family: 'Ultra', serif !important; }

/* Export Actions */
.export-actions {
    display: flex;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    padding-bottom: calc(var(--spacing-md) + var(--safe-bottom));
    flex-shrink: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--glass-border);
    margin: 0 calc(-1 * var(--spacing-md));
    margin-bottom: calc(-1 * var(--spacing-md));
    margin-top: var(--spacing-sm);
}

.export-actions button { flex: 1; padding: var(--spacing-sm) var(--spacing-md); font-size: 0.85rem; }

/* ========================================
   TOAST
   ======================================== */
.toast {
    position: fixed;
    bottom: calc(80px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--accent-gradient);
    color: white;
    padding: var(--spacing-md) var(--spacing-xl);
    border-radius: var(--radius-md);
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all 0.3s;
    z-index: 1000;
    pointer-events: none;
}

.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 480px) {
    .modal-content { padding: var(--spacing-lg); }
    .modal-header h2 { font-size: 1.5rem; }
    .text-display { font-size: 48px !important; }
    .texture-grid { grid-template-columns: repeat(5, 1fr); }
    .export-actions button span { font-size: 0.75rem; }
}

@media (min-width: 1200px) {
    :root { --controls-width: 380px; }
    .text-display { font-size: 100px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
