:root {
    --primary: #4F6EF7;
    --primary-hover: #3A54D4;
    --bg: #F8FAFC;
    --surface: #FFFFFF;
    --text: #1E293B;
    --text-secondary: #64748B;
    --border: #E2E8F0;
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
    --radius: 14px;
    --radius-sm: 10px;
    --transition: 0.2s ease;
}

* { margin:0; padding:0; box-sizing:border-box; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    padding: 1rem;
    display: flex;
    justify-content: center;
}

.app-container {
    width: 100%;
    max-width: 820px;
    display: flex;
    flex-direction: column;
    gap: 1.8rem;
}

/* Header */
.app-header { text-align: center; }
.logo { display: flex; align-items: center; justify-content: center; gap: 0.5rem; margin-bottom: 0.25rem; }
.logo h1 {
    font-size: clamp(1.5rem, 5vw, 2rem);
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), #8B5CF6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.header-subtitle { color: var(--text-secondary); font-size: 0.9rem; }

/* Tabs */
.tool-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    padding: 0.5rem;
    background: var(--surface);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.tool-tab {
    flex: 0 0 auto;
    padding: 0.65rem 1.1rem;
    border: none;
    background: transparent;
    border-radius: 50px;
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.tool-tab:hover { background: #F1F5F9; }
.tool-tab.active { background: var(--primary); color: white; box-shadow: 0 2px 8px rgba(79,110,247,0.3); }

/* Upload */
.drop-zone {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem 1rem;
    text-align: center;
    background: var(--surface);
    transition: all var(--transition);
    cursor: pointer;
}
.drop-zone.drag-over { border-color: var(--primary); background: #EEF2FF; transform: scale(1.01); }
.upload-icon { margin-bottom: 0.75rem; }
.drop-zone-title { font-weight: 600; font-size: 1rem; margin-bottom: 0.2rem; }
.drop-zone-subtitle { color: var(--text-secondary); font-size: 0.85rem; }
.drop-zone-hint { color: var(--text-secondary); font-size: 0.75rem; opacity: 0.8; margin-top: 0.25rem; }
.file-input-hidden { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload-actions { display: flex; align-items: center; gap: 1rem; justify-content: center; margin-top: 0.5rem; }
.file-info { font-size: 0.85rem; color: var(--text-secondary); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.7rem 1.4rem;
    border-radius: 50px;
    font-weight: 500;
    font-size: 0.9rem;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.btn:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }
.btn-outline:hover { background: #F8FAFC; color: var(--text); border-color: var(--primary); }
.btn-sm { padding: 0.5rem 1rem; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-download { padding: 0.8rem 2rem; font-size: 1rem; }

/* Loading & Error */
.loading-overlay {
    display: none; position: fixed; inset:0; background: rgba(255,255,255,0.9); z-index: 100;
    flex-direction: column; align-items: center; justify-content: center; gap: 1rem;
}
.spinner {
    width: 40px; height: 40px; border: 4px solid var(--border);
    border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-message {
    display: none; background: #FEF2F2; color: #DC2626; padding: 0.8rem 1rem;
    border-radius: var(--radius-sm); text-align: center; font-weight: 500; font-size: 0.9rem;
    border: 1px solid #FECACA; animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity:0; transform: translateY(-5px); } to { opacity:1; transform: translateY(0); } }

/* Extra controls */
.tool-extra-controls {
    background: var(--surface); padding: 1rem; border-radius: var(--radius-sm);
    box-shadow: var(--shadow); display: flex; flex-wrap: wrap; gap: 0.8rem; align-items: center;
}
.tool-extra-controls label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; }
.tool-extra-controls input[type="text"],
.tool-extra-controls input[type="number"] {
    width: 80px; padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 8px; font-size: 0.9rem;
}

/* Editor Tools */
.editor-tools {
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 1.2rem; border: 1px solid var(--border); animation: fadeIn 0.3s ease;
}
.editor-panel { display: flex; flex-direction: column; gap: 1rem; }
.editor-panel-section h3 { font-size: 1rem; margin-bottom: 0.3rem; }
.editor-input-row { display: flex; gap: 0.5rem; }
.text-input {
    flex:1; padding: 0.55rem 0.8rem; border: 1px solid var(--border); border-radius: 8px;
    font-size: 0.9rem; outline: none;
}
.text-input:focus { border-color: var(--primary); }
.editor-hint { color: var(--text-secondary); font-size: 0.8rem; margin-top: 0.25rem; }
.signature-wrapper {
    border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden;
    background: white; touch-action: none;
}
.signature-canvas { display: block; width: 100%; height: auto; cursor: crosshair; background: white; }
.signature-actions { display: flex; gap: 0.5rem; margin-top: 0.3rem; }
.page-nav { display: flex; align-items: center; gap: 0.75rem; }
.page-indicator { font-weight: 500; min-width: 90px; text-align: center; font-size: 0.9rem; }
.editor-mod-list { border-top: 1px solid var(--border); padding-top: 0.5rem; }
.editor-mod-list h4 { font-weight: 500; margin-bottom: 0.2rem; }
#modListItems { list-style: none; font-size: 0.85rem; color: var(--text-secondary); }

/* Preview */
.preview-section { animation: fadeIn 0.3s ease; }
.preview-title { margin-bottom: 0.5rem; font-size: 1.2rem; }
.preview-container {
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 1rem; overflow-x: auto; display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center;
}
.preview-container canvas,
.preview-container img {
    max-width: 100%; height: auto; border-radius: var(--radius-sm);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05); border: 1px solid var(--border);
}
.preview-container pre {
    white-space: pre-wrap; word-wrap: break-word; font-family: monospace; background: #F8FAFC;
    padding: 1rem; border-radius: var(--radius-sm); width: 100%; max-height: 300px; overflow-y: auto;
    font-size: 0.8rem;
}
.preview-actions { margin-top: 1rem; text-align: center; }

/* Live users */
.live-users {
    display: flex; align-items: center; justify-content: center; gap: 0.5rem;
    font-size: 0.9rem; color: var(--text-secondary);
}
.live-dot {
    width: 10px; height: 10px; border-radius: 50%; background: #22C55E;
    box-shadow: 0 0 0 3px rgba(34,197,94,0.2); animation: pulse 2s infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(34,197,94,0.4); }
    70% { box-shadow: 0 0 0 6px rgba(34,197,94,0); }
    100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

/* Footer */
.app-footer { text-align: center; font-size: 0.8rem; color: var(--text-secondary); }

/* Mobile */
@media (max-width: 600px) {
    body { padding: 0.5rem; }
    .app-container { gap: 1.2rem; }
    .tool-tab { padding: 0.5rem 0.9rem; font-size: 0.78rem; }
    .drop-zone { padding: 1.5rem 0.8rem; }
    .btn { padding: 0.6rem 1rem; font-size: 0.85rem; }
    .editor-panel { gap: 0.8rem; }
    .tool-extra-controls { flex-direction: column; align-items: flex-start; }
    .tool-extra-controls input { width: 100%; }
}