@import "tailwindcss";

html {
    height: 100%;
}
body { 
    margin: 0; 
    height: 100vh; 
    height: 100dvh; /* dynamic viewport height: accounts for iOS/Android browser chrome */
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
    overscroll-behavior: none; /* prevent pull-to-refresh on mobile */
    background: #000;
    color: #fff;
    -webkit-tap-highlight-color: transparent;
}
canvas { 
    touch-action: none; 
    -webkit-user-select: none;
    -webkit-touch-callout: none; /* prevent iOS long-press save/context menu over the drawing canvas */
    user-select: none;
}
button {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    touch-action: manipulation; /* avoid double-tap-to-zoom delay on buttons */
}

/* Cross-browser range slider thumbs sized for touch */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    touch-action: manipulation;
}
input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    background: rgba(255,255,255,0.15);
    border-radius: 4px;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    margin-top: -8px;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
}
input[type="range"]::-moz-range-track {
    height: 4px;
    background: rgba(255,255,255,0.15);
    border-radius: 4px;
}
input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
}
.char-thumb { 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background-size: contain; 
    background-repeat: no-repeat; 
    background-position: center; 
    pointer-events: none; 
    filter: invert(1);
    mix-blend-mode: screen;
    opacity: 0.8;
}
.char-item.active { 
    background-color: rgba(255,255,255,0.2); 
    border-color: white; 
    font-weight: bold; 
}

/* Custom scrollbar for char grid */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.4);
}

/* ─── Mobile Bottom Toolbar ─────────────────────────────────────────── */
.mobile-bottom-bar {
    display: none; /* hidden by default (desktop); shown below <768px */
}
@media (max-width: 767px) {
    .mobile-bottom-bar {
        display: flex;
        align-items: center;
        justify-content: space-around;
        background: #121212;
        border-top: 1px solid rgba(255,255,255,0.1);
        padding: 4px 0;
        padding-bottom: env(safe-area-inset-bottom, 4px);
        z-index: 40;
        flex-shrink: 0;
    }

    .mobile-tool-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 6px 8px;
        border: none;
        background: transparent;
        color: rgba(255,255,255,0.5);
        border-radius: 8px;
        transition: all 0.15s ease;
        -webkit-tap-highlight-color: transparent;
        min-width: 44px; /* Slightly smaller for tight screens */
    }
    .mobile-tool-btn.active {
        color: #fff;
        background: rgba(255,255,255,0.1);
    }
    .mobile-tool-btn:active {
        transform: scale(0.92);
    }

    /* ─── Mobile More Panel ─────────────────────────────────────────────── */
    .mobile-more-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #1a1a1a;
        border-top: 1px solid rgba(255,255,255,0.15);
        border-radius: 16px 16px 0 0;
        z-index: 60;
        padding-bottom: env(safe-area-inset-bottom, 8px);
        animation: slideUp 0.25s ease-out;
    }
    .mobile-more-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 12px 8px;
        border: none;
        background: rgba(255,255,255,0.05);
        color: rgba(255,255,255,0.7);
        border-radius: 12px;
        transition: all 0.15s ease;
        -webkit-tap-highlight-color: transparent;
    }
}
.mobile-more-item:active {
    background: rgba(255,255,255,0.15);
    transform: scale(0.95);
}

/* ─── Mobile Header Icon Buttons ────────────────────────────────────── */
@media (max-width: 768px) {
    .mobile-icon-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        padding: 0;
        background: rgba(255,255,255,0.06);
        border: 1px solid rgba(255,255,255,0.1);
        border-radius: 8px;
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-icon-btn:active {
        background: rgba(255,255,255,0.2);
    }
}

/* ─── Sidebar Drawers for Mobile ────────────────────────────────────── */
.sidebar-drawer {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (max-width: 768px) {
    .sidebar-drawer {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        max-height: 65vh;
        min-height: 40vh;
        z-index: 55;
        background: #111;
        border-top: 1px solid rgba(255,255,255,0.15);
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
        box-shadow: 0 -8px 30px rgba(0,0,0,0.6);
    }
    .sidebar-drawer.open {
        transform: translateY(0);
    }
}

/* ─── Drawer Backdrop ───────────────────────────────────────────────── */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 54;
    -webkit-tap-highlight-color: transparent;
}

/* ─── Canvas wrapper mobile sizing ──────────────────────────────────── */
@media (max-width: 768px) {
    .canvas-wrapper {
        max-width: calc(100vw - 16px) !important;
        /* Budget: header (~48px) + glyph label + guides toggle row + paddings
           + mobile bottom toolbar (~56px) + safe-area inset */
        max-height: calc(100vh - 210px) !important;
        max-height: calc(100dvh - 210px) !important;
    }
}

/* ─── Live Preview relocated into the mobile Settings drawer ───────────── */
.mobile-in-drawer {
    height: auto !important;
    border-top: none !important;
    padding: 0 !important;
    background: transparent !important;
}
.mobile-in-drawer #preview-render {
    min-height: 64px;
}

/* ─── Animations ────────────────────────────────────────────────────── */
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* ─── Utilities ─────────────────────────────────────────────────────── */
.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.hide-scrollbar::-webkit-scrollbar {
    display: none;
}

/* ─── Welcome Screen ───────────────────────────────────────────────── */
#welcome-screen {
    animation: welcomeFadeIn 0.5s ease-out;
}
.welcome-container {
    animation: welcomeSlideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes welcomeFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes welcomeSlideUp {
    from { opacity: 0; transform: translateY(30px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
#welcome-screen.closing {
    animation: welcomeFadeOut 0.35s ease-in forwards;
}
#welcome-screen.closing .welcome-container {
    animation: welcomeSlideDown 0.35s ease-in forwards;
}
@keyframes welcomeFadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}
@keyframes welcomeSlideDown {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(20px) scale(0.97); }
}

/* ─── Auto-Save Status ─────────────────────────────────────────────── */
@keyframes autoSavePulse {
    0% { opacity: 0; transform: translateY(4px); }
    20% { opacity: 1; transform: translateY(0); }
    80% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-4px); }
}
.auto-save-flash {
    animation: autoSavePulse 2s ease forwards;
}

/* ─── Preview Marquee (Seamless Infinite Loop) ──────────────────── */
.marquee-container {
    overflow: hidden;
    white-space: nowrap;
    width: 100%;
    position: relative;
}
.marquee-track {
    display: inline-flex;
    animation: marquee-scroll 60s linear infinite;
    will-change: transform;
}
.marquee-track .marquee-segment {
    display: inline-block;
    padding-right: 0.5em;
}
@keyframes marquee-scroll {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}
.marquee-track.paused {
    animation-play-state: paused;
}

/* ─── Preview Font Item (Brutalist) ─────────────────────────────── */
.font-preview-item {
    border-bottom: 1px solid rgba(255,255,255,0.06);
    cursor: default;
    transition: background-color 0.2s ease;
}
.font-preview-item:hover {
    background-color: rgba(255,255,255,0.03);
}
.font-preview-item .preview-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 16px;
}
.font-preview-item .preview-meta .meta-left {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}
.font-preview-item .preview-meta .font-title {
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.02em;
}
.font-preview-item .preview-meta .font-author {
    font-size: 10px;
    color: #777;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
.font-preview-item .preview-meta .font-date {
    font-size: 9px;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.15em;
}
.font-preview-item .preview-meta .meta-right a {
    font-size: 10px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-decoration: none;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}
.font-preview-item .preview-meta .meta-right a:hover {
    color: #fff;
}

/* ─── Preview Mobile Responsive ─────────────────────────────────── */
@media (max-width: 640px) {
    .font-preview-item .preview-meta {
        padding: 4px 10px;
        gap: 4px;
    }
    .font-preview-item .preview-meta .meta-left {
        gap: 6px;
        overflow: hidden;
    }
    .font-preview-item .preview-meta .font-title {
        font-size: 11px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 120px;
    }
    .font-preview-item .preview-meta .font-author {
        font-size: 8px;
        display: none; /* Hide on very small screens to save space */
    }
    .font-preview-item .preview-meta .font-date {
        font-size: 8px;
    }
    .font-preview-item .preview-meta .meta-right a {
        font-size: 0; /* Hide text, keep icon */
        gap: 0;
    }
    .font-preview-item .preview-meta .meta-right a .material-symbols-outlined {
        font-size: 16px;
    }
    
    /* Speed is handled by JS for consistent reading pace */
}

@media (min-width: 641px) and (max-width: 768px) {
    .font-preview-item .preview-meta .font-title {
        font-size: 12px;
        max-width: 200px;
    }
    .font-preview-item .preview-meta .font-author {
        font-size: 9px;
    }
}
