/* ── Design Tokens ─────────────────────────────────── */
:root {
    --bg:               #FFFDF5;
    --bg-muted:         #F1F5F9;
    --foreground:       #1E293B;
    --muted-fg:         #64748B;
    --accent:           #8B5CF6;
    --accent-fg:        #FFFFFF;
    --secondary:        #F472B6;
    --tertiary:         #FBBF24;
    --quaternary:       #34D399;
    --border:           #E2E8F0;
    --border-dark:      #1E293B;
    --card:             #FFFFFF;
    --success:          #34D399;
    --warning:          #FBBF24;
    --danger:           #F472B6;

    --radius-sm:        8px;
    --radius-md:        16px;
    --radius-lg:        24px;
    --radius-full:      9999px;

    --border-w:         2px;
    --shadow-pop:       4px 4px 0px 0px #1E293B;
    --shadow-pop-hover: 6px 6px 0px 0px #1E293B;
    --shadow-pop-press: 2px 2px 0px 0px #1E293B;
    --shadow-card:      8px 8px 0px 0px #E2E8F0;
    --shadow-card-pink: 8px 8px 0px 0px #F472B6;

    --font-heading:     'Outfit', system-ui, sans-serif;
    --font-body:        'Plus Jakarta Sans', system-ui, sans-serif;

    --ease-bounce:      cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--foreground);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    line-height: 1.5;
}

/* ── Toolbar ───────────────────────────────────────── */
#toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 60px;
    background: var(--card);
    border-bottom: var(--border-w) solid var(--border-dark);
    flex-shrink: 0;
    z-index: 100;
    box-shadow: 0 2px 0px 0px var(--border-dark);
}

#toolbar h1 {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--foreground);
    line-height: 1;
}

/* Violet accent dot in the title */
#toolbar h1::after {
    content: '.';
    color: var(--accent);
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.toolbar-center {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
}

.toolbar-right {
    display: flex;
    gap: 10px;
}

.filename {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted-fg);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: var(--bg-muted);
    padding: 3px 10px;
    border-radius: var(--radius-full);
    border: var(--border-w) solid var(--border);
}

.separator {
    color: var(--border);
    margin: 0 2px;
}

#page-indicator, #zoom-level {
    min-width: 72px;
    text-align: center;
    color: var(--muted-fg);
    font-weight: 500;
}

/* ── Buttons ───────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 18px;
    border: var(--border-w) solid var(--border-dark);
    border-radius: var(--radius-full);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s var(--ease-bounce);
    position: relative;
    white-space: nowrap;
    text-decoration: none;
    user-select: none;
}

.btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
    box-shadow: none !important;
    transform: none !important;
}

/* Icon-only toolbar buttons */
.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    background: var(--card);
    color: var(--foreground);
    border-color: var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    box-shadow: none;
}

.btn-icon:hover:not(:disabled) {
    background: var(--bg-muted);
    border-color: var(--foreground);
    transform: translateY(-1px);
}

.btn-icon:active:not(:disabled) {
    transform: translateY(1px);
}

/* Primary "Candy" Button */
.btn-primary {
    background: var(--accent);
    color: var(--accent-fg);
    box-shadow: var(--shadow-pop);
}

.btn-primary:hover:not(:disabled) {
    transform: translate(-2px, -2px);
    box-shadow: var(--shadow-pop-hover);
}

.btn-primary:active:not(:disabled) {
    transform: translate(2px, 2px);
    box-shadow: var(--shadow-pop-press);
}

/* Secondary Button */
.btn-secondary {
    background: var(--card);
    color: var(--foreground);
    border-color: var(--border-dark);
    box-shadow: var(--shadow-pop);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--tertiary);
    transform: translate(-2px, -2px);
    box-shadow: var(--shadow-pop-hover);
}

.btn-secondary:active:not(:disabled) {
    transform: translate(2px, 2px);
    box-shadow: var(--shadow-pop-press);
}

/* ── Upload Screen ─────────────────────────────────── */
#upload-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    /* Dot grid background */
    background-color: var(--bg);
    background-image: radial-gradient(circle, #CBD5E1 1px, transparent 1px);
    background-size: 24px 24px;
}

/* Floating decorative shapes */
#upload-screen::before,
#upload-screen::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
}

#upload-screen::before {
    width: 400px;
    height: 400px;
    background: var(--tertiary);
    opacity: 0.18;
    top: -120px;
    left: -100px;
    border: var(--border-w) solid var(--border-dark);
}

#upload-screen::after {
    width: 280px;
    height: 280px;
    background: var(--secondary);
    opacity: 0.14;
    bottom: -80px;
    right: -60px;
    border: var(--border-w) solid var(--border-dark);
}

.upload-deco {
    position: absolute;
    pointer-events: none;
}

.upload-deco-tl {
    top: 40px;
    right: 120px;
    width: 64px;
    height: 64px;
    background: var(--quaternary);
    border: var(--border-w) solid var(--border-dark);
    border-radius: var(--radius-sm);
    transform: rotate(18deg);
    box-shadow: var(--shadow-pop);
    opacity: 0.75;
}

.upload-deco-br {
    bottom: 60px;
    left: 100px;
    width: 48px;
    height: 48px;
    background: var(--secondary);
    border: var(--border-w) solid var(--border-dark);
    border-radius: 50%;
    box-shadow: var(--shadow-pop);
    opacity: 0.75;
}

.upload-deco-mid {
    top: 50%;
    right: 60px;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 28px solid transparent;
    border-right: 28px solid transparent;
    border-bottom: 48px solid var(--accent);
    opacity: 0.6;
    filter: drop-shadow(3px 3px 0 var(--border-dark));
}

#drop-zone {
    width: 480px;
    padding: 56px 48px;
    background: var(--card);
    border: var(--border-w) solid var(--border-dark);
    border-radius: var(--radius-lg);
    text-align: center;
    cursor: pointer;
    box-shadow: var(--shadow-card-pink);
    transition: all 0.25s var(--ease-bounce);
    position: relative;
    z-index: 1;
}

#drop-zone:hover,
#drop-zone.drag-over {
    transform: translate(-2px, -2px);
    box-shadow: 10px 10px 0px 0px #F472B6;
    border-color: var(--accent);
}

#drop-zone.drag-over {
    background: #fdf4ff;
}

.drop-icon {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drop-icon-wrap {
    width: 80px;
    height: 80px;
    background: var(--accent);
    border: var(--border-w) solid var(--border-dark);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-pop);
    color: white;
    transform: rotate(-3deg);
    transition: transform 0.3s var(--ease-bounce);
}

#drop-zone:hover .drop-icon-wrap {
    transform: rotate(3deg) scale(1.08);
}

#drop-zone h2 {
    font-family: var(--font-heading);
    font-size: 26px;
    font-weight: 800;
    color: var(--foreground);
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

#drop-zone p {
    color: var(--muted-fg);
    font-size: 14px;
    font-weight: 500;
}

.drop-cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 24px;
    padding: 12px 28px;
    background: var(--accent);
    color: white;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 700;
    border: var(--border-w) solid var(--border-dark);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-pop);
    transition: all 0.2s var(--ease-bounce);
    pointer-events: none;
}

#drop-zone:hover .drop-cta {
    transform: translate(-2px, -2px);
    box-shadow: var(--shadow-pop-hover);
}

/* ── Editor Layout ─────────────────────────────────── */
#editor-screen {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ── Side Panel ────────────────────────────────────── */
#side-panel {
    width: 300px;
    background: var(--card);
    border-right: var(--border-w) solid var(--border-dark);
    overflow-y: auto;
    padding: 20px 18px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

#side-panel h3 {
    font-family: var(--font-heading);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--muted-fg);
    margin-bottom: 10px;
    margin-top: 22px;
    padding-bottom: 6px;
    border-bottom: var(--border-w) dashed var(--border);
}

#side-panel h3:first-child {
    margin-top: 0;
}

/* ── Property Grid ─────────────────────────────────── */
.prop-grid {
    display: grid;
    grid-template-columns: 60px 1fr;
    gap: 7px 10px;
    font-size: 12px;
    background: var(--bg-muted);
    border: var(--border-w) solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
}

.prop-grid label {
    color: var(--muted-fg);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
}

.prop-value {
    font-weight: 600;
    font-size: 12px;
    word-break: break-all;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--foreground);
}

.color-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: var(--border-w) solid var(--border-dark);
    flex-shrink: 0;
}

/* ── Edit Area ─────────────────────────────────────── */
.edit-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.edit-area label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--muted-fg);
}

.edit-area textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--card);
    border: var(--border-w) solid #CBD5E1;
    border-radius: var(--radius-sm);
    color: var(--foreground);
    font-size: 13px;
    font-family: var(--font-body);
    font-weight: 500;
    resize: vertical;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-shadow: 4px 4px 0px transparent;
}

.edit-area textarea:focus {
    border-color: var(--accent);
    box-shadow: 4px 4px 0px var(--accent);
}

.edit-area textarea[readonly] {
    background: var(--bg-muted);
    color: var(--muted-fg);
    cursor: default;
}

.edit-actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}

.edit-actions .btn {
    flex: 1;
    padding: 10px 12px;
    font-size: 13px;
}

/* ── Font Resolution Status ────────────────────────── */
.font-resolution {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    margin-top: 10px;
    border: var(--border-w) solid;
}

.font-resolution.res-system,
.font-resolution.res-downloaded,
.font-resolution.res-custom {
    background: rgba(52, 211, 153, 0.1);
    border-color: rgba(52, 211, 153, 0.4);
    color: #059669;
}

.font-resolution.res-embedded {
    background: rgba(139, 92, 246, 0.1);
    border-color: rgba(139, 92, 246, 0.35);
    color: var(--accent);
}

.font-resolution.res-fallback {
    background: rgba(251, 191, 36, 0.12);
    border-color: rgba(251, 191, 36, 0.4);
    color: #B45309;
}

.glyph-warning {
    padding: 8px 12px;
    background: rgba(244, 114, 182, 0.1);
    border: var(--border-w) solid rgba(244, 114, 182, 0.4);
    border-radius: var(--radius-sm);
    color: #be185d;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
}

/* ── Font Upload ───────────────────────────────────── */
.font-upload-area {
    margin-top: 4px;
}

.upload-hint {
    font-size: 12px;
    color: var(--muted-fg);
    margin-bottom: 10px;
    line-height: 1.5;
}

.btn-upload {
    display: block;
    text-align: center;
    cursor: pointer;
    width: 100%;
}

#custom-font-status {
    margin-top: 8px;
    font-size: 12px;
    font-weight: 600;
}

.custom-font-ok  { color: #059669; }
.custom-font-err { color: #be185d; }

/* ── Badges ────────────────────────────────────────── */
.badge {
    padding: 3px 8px;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1.5px solid;
}

.badge-embedded {
    background: rgba(52, 211, 153, 0.12);
    border-color: rgba(52, 211, 153, 0.5);
    color: #059669;
}

.badge-subset {
    background: rgba(251, 191, 36, 0.12);
    border-color: rgba(251, 191, 36, 0.5);
    color: #B45309;
}

.badge-fallback {
    background: rgba(244, 114, 182, 0.12);
    border-color: rgba(244, 114, 182, 0.5);
    color: #be185d;
}

/* ── No Selection Hint ─────────────────────────────── */
#no-selection {
    text-align: center;
    padding: 32px 16px;
    color: var(--muted-fg);
}

.hint-icon {
    margin-bottom: 12px;
    opacity: 0.5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hint-icon-wrap {
    width: 56px;
    height: 56px;
    background: var(--bg-muted);
    border: var(--border-w) solid var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#no-selection p {
    font-size: 13px;
    font-weight: 500;
    line-height: 1.6;
    color: var(--muted-fg);
}

#no-selection strong {
    color: var(--foreground);
    font-weight: 700;
}

/* ── Font Summary ──────────────────────────────────── */
#font-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.font-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 11px;
    background: var(--bg-muted);
    border: var(--border-w) solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    transition: border-color 0.15s;
}

.font-item:hover {
    border-color: var(--accent);
}

.font-item-name {
    font-weight: 700;
    font-size: 12px;
    color: var(--foreground);
    font-family: var(--font-heading);
}

.font-item-meta {
    color: var(--muted-fg);
    display: flex;
    gap: 6px;
    align-items: center;
    font-size: 11px;
    margin-top: 2px;
}

/* ── PDF Viewer ────────────────────────────────────── */
#viewer {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 32px;
    background: var(--bg-muted);
    background-image: radial-gradient(circle, #CBD5E1 1px, transparent 1px);
    background-size: 20px 20px;
}

#pdf-container {
    position: relative;
    border: var(--border-w) solid var(--border-dark);
    border-radius: var(--radius-sm);
    background: white;
    line-height: 0;
    box-shadow: 8px 8px 0px 0px var(--border-dark);
}

#pdf-canvas {
    display: block;
    border-radius: calc(var(--radius-sm) - 2px);
}

#text-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: text;
    border-radius: calc(var(--radius-sm) - 2px);
}

/* ── Text Span Overlays ────────────────────────────── */
.span-overlay {
    position: absolute;
    cursor: grab;
    border-radius: 3px;
    transition: background 0.1s ease, box-shadow 0.1s ease, outline 0.1s ease;
}

.span-overlay:hover {
    background: rgba(139, 92, 246, 0.12);
    outline: 2px solid rgba(139, 92, 246, 0.4);
    outline-offset: 1px;
}

.span-overlay.selected {
    background: rgba(139, 92, 246, 0.16);
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    box-shadow: 3px 3px 0px var(--accent);
}

.span-overlay.dragging {
    background: rgba(139, 92, 246, 0.22);
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    box-shadow: 4px 4px 0px var(--accent);
    z-index: 100;
    cursor: grabbing !important;
}

/* ── Loading Overlay ───────────────────────────────── */
#loading {
    position: fixed;
    inset: 0;
    background: rgba(255, 253, 245, 0.88);
    backdrop-filter: blur(2px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    gap: 20px;
}

.loading-card {
    background: var(--card);
    border: var(--border-w) solid var(--border-dark);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-pop);
    padding: 32px 40px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

#loading p {
    font-size: 14px;
    font-weight: 600;
    color: var(--muted-fg);
    font-family: var(--font-heading);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Scrollbar ─────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-full);
    border: 2px solid var(--bg-muted);
}
::-webkit-scrollbar-thumb:hover { background: var(--muted-fg); }

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 768px) {
    #side-panel { width: 260px; }
    #drop-zone { width: calc(100vw - 48px); padding: 40px 24px; }

    .btn-primary, .btn-secondary {
        box-shadow: 2px 2px 0px 0px #1E293B;
    }
    .btn-primary:hover:not(:disabled) { box-shadow: 3px 3px 0px 0px #1E293B; }

    .upload-deco-tl, .upload-deco-br, .upload-deco-mid { display: none; }
}

/* ── Toolbar Home Link ─────────────────────────────── */
.toolbar-home {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: var(--border-w) solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--muted-fg);
    text-decoration: none;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.toolbar-home:hover {
    border-color: var(--border-dark);
    color: var(--foreground);
    background: var(--bg-muted);
}

/* ── Privacy / Legal Modal ─────────────────────────── */
#privacy-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.privacy-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(255, 253, 245, 0.92);
    backdrop-filter: blur(3px);
}

.privacy-dialog {
    position: relative;
    z-index: 1;
    background: var(--card);
    border: var(--border-w) solid var(--border-dark);
    border-radius: var(--radius-lg);
    box-shadow: 10px 10px 0px 0px var(--border-dark);
    padding: 40px 40px 32px;
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
}

.privacy-dialog-icon {
    width: 56px;
    height: 56px;
    background: var(--accent);
    border: var(--border-w) solid var(--border-dark);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    margin-bottom: 20px;
    box-shadow: var(--shadow-pop);
}

.privacy-dialog-title {
    font-family: var(--font-heading);
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--foreground);
    margin-bottom: 6px;
}

.privacy-dialog-sub {
    font-size: 14px;
    font-weight: 500;
    color: var(--muted-fg);
    margin-bottom: 24px;
}

.privacy-dialog-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 28px;
    padding: 20px;
    background: var(--bg-muted);
    border: var(--border-w) solid var(--border);
    border-radius: var(--radius-sm);
}

.privacy-clause {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    font-size: 13px;
    line-height: 1.55;
    color: var(--foreground);
}

.privacy-clause strong {
    display: block;
    font-weight: 700;
    margin-bottom: 4px;
    font-size: 13px;
}

.privacy-clause p {
    color: var(--muted-fg);
    font-weight: 500;
}

.privacy-clause-icon {
    width: 22px;
    height: 22px;
    background: var(--accent);
    color: white;
    border: 1.5px solid var(--border-dark);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 1px;
}

.privacy-dialog-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.privacy-dialog-actions .btn {
    flex: 1;
    min-width: 160px;
    justify-content: center;
    padding: 13px 20px;
}

.privacy-dialog-footnote {
    margin-top: 16px;
    font-size: 11px;
    font-weight: 500;
    color: var(--muted-fg);
    text-align: center;
    line-height: 1.5;
}

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