/* ============================================
   Typographic — Word Portrait Studio
   Editorial / Ink & Paper aesthetic
   ============================================ */

/* Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Paper tones */
    --bg: #f4f1eb;
    --bg-sidebar: #eae7e0;
    --bg-input: #ffffff;
    --bg-canvas: #ffffff;

    /* Borders */
    --border: #d4cfc6;
    --border-light: #e5e1d9;

    /* Ink palette */
    --ink: #1a1816;
    --ink-warm: #2c2420;
    --ink-secondary: #5c5650;
    --ink-muted: #9b9389;
    --ink-faint: #c4bdb3;

    /* Accent: Burnt Vermillion */
    --accent: #c44d2b;
    --accent-hover: #a83d1f;
    --accent-light: rgba(196, 77, 43, 0.08);
    --accent-glow: rgba(196, 77, 43, 0.15);

    /* Featured: Deep Gold */
    --featured: #b8860b;
    --featured-bg: rgba(184, 134, 11, 0.06);

    /* Typography */
    --font-display: 'Cormorant Garamond', Georgia, serif;
    --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'DM Mono', 'SF Mono', monospace;

    /* Layout */
    --sidebar-width: 360px;
    --radius: 8px;
    --radius-lg: 12px;
    --transition: 0.2s ease;
}

html {
    font-size: 15px;
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* ── Layout ─────────────────────────────────── */

.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ────────────────────────────────── */

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Custom scrollbar for sidebar */
.sidebar::-webkit-scrollbar {
    width: 5px;
}

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

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--ink-faint);
}

/* ── Brand ──────────────────────────────────── */

.brand {
    padding: 1.5rem 1.5rem 1.25rem;
    border-bottom: 1px solid var(--border);
    animation: slideIn 0.5s ease both;
}

.brand h1 {
    font-family: var(--font-display);
    font-size: 2.6rem;
    font-weight: 500;
    letter-spacing: -0.02em;
    line-height: 1;
    color: var(--ink-warm);
    display: inline-block;
}

.brand h1::after {
    content: '';
    display: block;
    width: 40px;
    height: 3px;
    background: var(--accent);
    border-radius: 2px;
    margin-top: 0.5rem;
}

.tagline {
    font-family: var(--font-mono);
    font-style: normal;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-muted);
    margin-top: 0.5rem;
}

/* ── Controls area ──────────────────────────── */

.controls {
    flex: 1;
    padding: 0.5rem 0;
    overflow-y: auto;
}

.panel {
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border-light);
}

.panel-label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-muted);
    margin-bottom: 0.5rem;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.panel-header .panel-label {
    margin-bottom: 0;
}

/* ── Upload Zone ────────────────────────────── */

.upload-zone {
    border: 1.5px dashed var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-input);
    position: relative;
    overflow: hidden;
}

.upload-zone:hover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-light);
    transform: scale(1.01);
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: var(--ink-muted);
}

.upload-placeholder svg {
    opacity: 0.5;
}

.upload-placeholder span {
    font-size: 0.8rem;
}

.preview-image {
    max-width: 100%;
    max-height: 120px;
    border-radius: var(--radius);
    object-fit: contain;
}

/* ── Feature Button ─────────────────────────── */

.feature-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.25rem 0.6rem;
    font-family: var(--font-body);
    font-size: 0.7rem;
    color: var(--ink-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.feature-btn:hover {
    color: var(--featured);
    border-color: var(--featured);
    background: var(--featured-bg);
}

/* ── Word Editor ────────────────────────────── */

.word-editor {
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 0.95rem;
    min-height: 80px;
    max-height: 140px;
    overflow-y: auto;
    outline: none;
    transition: all var(--transition);
    line-height: 1.7;
}

.word-editor:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.word-line {
    padding: 1px 0;
}

.word-line.featured {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.05em;
    color: var(--featured);
}

.word-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.4rem;
}

.word-count {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--ink-faint);
}

.word-hint {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--ink-faint);
}

/* ── Settings ───────────────────────────────── */

.settings {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.setting-row label {
    font-size: 0.85rem;
    color: var(--ink-secondary);
    flex-shrink: 0;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

input[type="text"] {
    padding: 0.45rem 0.65rem;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    color: var(--ink);
    font-size: 0.8rem;
    font-family: var(--font-body);
    outline: none;
    transition: all var(--transition);
    max-width: 160px;
}

input[type="text"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.select-with-preview {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    max-width: 160px;
}

/* ── Custom Select ──────────────────────────── */

.custom-select {
    position: relative;
    max-width: 160px;
    width: 160px;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.45rem 0.65rem;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    color: var(--ink);
    font-size: 0.8rem;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
}

.custom-select-trigger:hover {
    border-color: var(--ink-faint);
}

.custom-select.open .custom-select-trigger {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.custom-select-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-select-arrow {
    display: flex;
    align-items: center;
    color: var(--ink-muted);
    transition: transform var(--transition);
    margin-left: 0.5rem;
    flex-shrink: 0;
}

.custom-select.open .custom-select-arrow {
    transform: rotate(180deg);
}

.custom-select-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    box-shadow:
        0 4px 16px rgba(0, 0, 0, 0.08),
        0 1px 4px rgba(0, 0, 0, 0.04);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: all 0.15s ease;
    overflow: hidden;
}

.custom-select.open .custom-select-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.custom-select-option {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    font-family: var(--font-body);
    color: var(--ink-secondary);
    cursor: pointer;
    transition: all 0.1s ease;
}

.custom-select-option:hover {
    background: var(--accent-light);
    color: var(--accent);
}

.custom-select-option.selected {
    color: var(--accent);
    font-weight: 500;
    background: var(--accent-light);
}

/* Text size options — visually represent their size */
.custom-select-option[data-value="small"] { font-size: 0.7rem; }
.custom-select-option[data-value="large"] { font-size: 0.95rem; }

/* Color palette gradient bars in dropdown options */
.custom-select-option:has(.option-gradient-bar) {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.6rem;
}

.option-gradient-bar {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05) inset;
}

/* Color Preview */
.color-preview {
    display: flex;
    gap: 2px;
    border-radius: 2px;
    overflow: hidden;
}

.color-swatch {
    flex: 1;
    height: 4px;
    border-radius: 0;
}

/* ── Range Slider ───────────────────────────── */

.range-control {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    max-width: 160px;
    flex: 1;
}

input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    border: none;
    cursor: pointer;
}

.range-value {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--ink-muted);
    min-width: 32px;
    text-align: right;
}

/* ── Toggle Switch ──────────────────────────── */

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--ink-secondary);
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.toggle-switch {
    width: 32px;
    height: 18px;
    background: var(--border);
    border-radius: 9px;
    position: relative;
    transition: all var(--transition);
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    width: 14px;
    height: 14px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform var(--transition);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle-label input:checked+.toggle-switch {
    background: var(--accent);
}

.toggle-label input:checked+.toggle-switch::after {
    transform: translateX(14px);
}

/* ── Custom Colors ──────────────────────────── */

.custom-colors {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.custom-colors label {
    font-size: 0.8rem;
    color: var(--ink-secondary);
}

.custom-colors input {
    max-width: 100%;
}

/* ── Sidebar Actions ────────────────────────── */

.sidebar-actions {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    animation: slideIn 0.5s ease 0.35s both;
}

.btn-generate {
    width: 100%;
    padding: 0.9rem 1.5rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font-display);
    font-size: 1.15rem;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    letter-spacing: 0.01em;
}

.btn-generate:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-generate:active:not(:disabled) {
    transform: translateY(0);
}

.btn-generate:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-download {
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: var(--bg-input);
    color: var(--ink);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-download:hover {
    border-color: var(--ink);
    background: var(--ink);
    color: white;
}

/* ── Spinner ────────────────────────────────── */

.spinner {
    width: 18px;
    height: 18px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.btn-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-loading span {
    font-family: var(--font-body);
    font-size: 0.85rem;
}

/* ── Canvas Area ────────────────────────────── */

.canvas-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    overflow: hidden;
    position: relative;
    /* Subtle grid pattern for the workspace */
    background-image:
        radial-gradient(circle, var(--border-light) 0.5px, transparent 0.5px);
    background-size: 24px 24px;
}

.canvas {
    background: var(--bg-canvas);
    border-radius: var(--radius-lg);
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.04),
        0 8px 40px rgba(0, 0, 0, 0.07);
    min-height: 400px;
    width: 85%;
    max-width: 900px;
    height: 75vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    transition: box-shadow var(--transition);
    animation: scaleIn 0.6s ease 0.2s both;
}

.canvas:hover {
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.04),
        0 12px 48px rgba(0, 0, 0, 0.09);
}

.canvas.checkerboard {
    background-image:
        linear-gradient(45deg, #f0ede6 25%, transparent 25%),
        linear-gradient(-45deg, #f0ede6 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f0ede6 75%),
        linear-gradient(-45deg, transparent 75%, #f0ede6 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
    background-color: var(--bg-canvas);
}

/* ── Canvas Placeholder ─────────────────────── */

.canvas-placeholder {
    text-align: center;
    padding: 3rem;
}

.placeholder-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.placeholder-icon {
    font-family: var(--font-display);
    font-size: 3.5rem;
    color: var(--ink-faint);
    opacity: 0.7;
    user-select: none;
    line-height: 1;
}

.canvas-placeholder p {
    font-size: 0.9rem;
    color: var(--ink-muted);
    line-height: 1.6;
}

.canvas.has-result {
    height: auto;
    min-height: 0;
    width: auto;
    max-width: 90%;
}

.canvas-result {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    display: block;
}

/* ── Utility ────────────────────────────────── */

.hidden {
    display: none !important;
}

/* ── Page load animations ───────────────────── */

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-16px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.97);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.panel:nth-child(1) {
    animation: slideIn 0.5s ease 0.1s both;
}

.panel:nth-child(2) {
    animation: slideIn 0.5s ease 0.2s both;
}

.panel:nth-child(3) {
    animation: slideIn 0.5s ease 0.3s both;
}

/* ── Responsive ─────────────────────────────── */

@media (max-width: 768px) {
    .app {
        flex-direction: column;
        height: auto;
        overflow: auto;
    }

    body {
        overflow: auto;
    }

    .sidebar {
        width: 100%;
        min-width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .canvas-area {
        padding: 1.5rem;
        min-height: 50vh;
    }

    .canvas {
        min-height: 300px;
    }

    .brand h1 {
        font-size: 1.6rem;
    }
}

@media (max-width: 480px) {
    .panel {
        padding: 1rem 1.25rem;
    }

    .brand {
        padding: 1.5rem 1.25rem 1.25rem;
    }

    .sidebar-actions {
        padding: 1rem 1.25rem;
    }

    .canvas-area {
        padding: 1rem;
    }
}
