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

:root {
    --primary-color: #4a90e2;
    --secondary-color: #7b68ee;
    --success-color: #2ecc71;
    --info-color: #3498db;
    --danger-color: #e74c3c;
    --dark-bg: #2c3e50;
    --light-bg: #ecf0f1;
    --border-color: #bdc3c7;
    --text-color: #2c3e50;
    --shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 10px 25px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.18);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: var(--text-color);
}

.container {
    max-width: 1600px;
    margin: 0 auto;
}

header {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    text-align: center;
    margin-bottom: 20px;
}

header h1 {
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 2.5em;
}

header p {
    color: #7f8c8d;
    font-size: 1.1em;
}

.section {
    background: white;
    border-radius: 10px;
    padding: 30px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.hidden {
    display: none !important;
}

/* Upload Section */
.upload-area {
    border: 3px dashed var(--border-color);
    border-radius: 10px;
    padding: 60px 40px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
}

.upload-area:hover,
.upload-area.drag-over {
    border-color: var(--primary-color);
    background: #f8f9fa;
    transform: scale(1.02);
}

.upload-area svg {
    color: var(--primary-color);
    margin-bottom: 20px;
}

.upload-area h3 {
    color: var(--text-color);
    margin-bottom: 10px;
}

.upload-area p {
    color: #95a5a6;
    margin: 10px 0;
}

.file-info {
    font-size: 0.9em;
    color: #7f8c8d;
    margin-top: 20px;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-block;
    text-decoration: none;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: #357abd;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: #27ae60;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-info {
    background: var(--info-color);
    color: white;
}

.btn-info:hover {
    background: #2980b9;
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.2em;
    transition: all 0.3s ease;
}

.btn-icon:hover {
    background: var(--light-bg);
}

.btn-group {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

/* Toolbar */
.toolbar {
    background: linear-gradient(180deg, #2f3e52 0%, #253649 100%);
    padding: 15px 20px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    box-shadow: var(--shadow-md);
}

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

/* Editor Layout */
.editor-layout {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 20px;
    min-height: 600px;
}

/* Control Panel */
.control-panel {
    background: #f8f9fb;
    border-radius: 16px;
    position: sticky;
    top: 10px;
    max-height: calc(100vh - 160px);
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    padding: 20px;
}

/* Fullscreen editor overrides */
#editorSection .control-panel {
    position: relative;
    top: auto;
    max-height: none;
    height: 100vh;
    padding: 16px;
}

.panel-header {
    background: var(--dark-bg);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 12px;
}

.panel-header h3 {
    margin: 0;
    font-size: 1.2em;
}

.tool-section {
    padding: 20px;
    background: white;
    border-radius: 14px;
    box-shadow: var(--shadow);
    margin-top: 18px;
}

.tool-section h4 {
    margin-bottom: 10px;
    color: var(--primary-color);
}

.hint {
    font-size: 0.9em;
    color: #7f8c8d;
    font-style: italic;
    margin-bottom: 10px;
}

.tool-list {
    list-style: none;
    padding-left: 0;
    margin-top: 10px;
}

.tool-list li {
    padding: 6px 0;
    color: var(--text-color);
    border-bottom: 1px solid rgba(189, 195, 199, 0.3);
}

.tool-list li:last-child {
    border-bottom: none;
}

.tool-panel {
    background: #f4f6fb;
    border-radius: 10px;
    padding: 16px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.panel-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.panel-actions .btn {
    flex-shrink: 0;
}

.file-hint {
    font-size: 0.9em;
    color: #52606d;
    display: block;
    margin-top: 8px;
}

.insert-hint {
    color: #e74c3c;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 12px 0;
}

.file-list {
    background: #f4f6fb;
    border-radius: 10px;
    padding: 12px;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid rgba(189, 195, 199, 0.4);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

#textEditArea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: inherit;
    font-size: 1em;
    margin-top: 10px;
    resize: vertical;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: var(--text-color);
}

input[type="text"],
input[type="email"],
input[type="password"] {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1em;
    margin-top: 5px;
}

input[type="number"] {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1em;
    margin-top: 5px;
}

/* Video Options */
.video-options {
    margin: 15px 0;
    padding: 15px;
    background: white;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.video-options label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-weight: normal;
}

.video-options input[type="radio"] {
    width: auto;
    margin: 0;
}

.video-options input[type="text"] {
    margin-top: 10px;
}

/* Preview Panel */
.preview-panel {
    background: #f8f9fa;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
}

.preview-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.page-select {
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 1em;
    cursor: pointer;
}

.preview-container {
    flex: 1;
    background: #eef2f7;
    border: 2px solid var(--border-color);
    margin: 10px;
    border-radius: 8px;
    overflow: auto;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

#previewFrame {
    width: 100%;
    height: 100%;
    border: none;
    min-height: 600px;
}

.preview-viewport {
    width: 1200px;
    /* default desktop */
    margin: 0 auto;
    background: white;
    border-radius: 6px;
    box-shadow: var(--shadow-lg);
    border: 1px solid #dde3ea;
}

/* Segmented device controls */
.segmented {
    display: inline-flex;
    background: #e5e7eb;
    border-radius: 8px;
    padding: 2px;
}

.segmented .seg-btn {
    border: none;
    background: transparent;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
}

.segmented .seg-btn.active {
    background: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
}

/* Smooth custom scrollbars */
*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 8px;
}

*::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

*::-webkit-scrollbar-track {
    background: #f1f5f9;
}

/* File List */
#fileList {
    background: white;
    border-radius: 6px;
    padding: 10px;
    max-height: 200px;
    overflow-y: auto;
}

.file-item {
    padding: 8px 12px;
    margin-bottom: 5px;
    background: var(--light-bg);
    border-radius: 4px;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-item::before {
    content: "📄";
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 10px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-header {
    background: var(--dark-bg);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
}

.btn-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 2em;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.btn-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.modal-body {
    padding: 30px;
}

.modal-footer {
    padding: 20px 30px;
    background: var(--light-bg);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.form-group {
    margin-bottom: 20px;
}

.field-list {
    background: var(--light-bg);
    border-radius: 6px;
    padding: 15px;
    margin-top: 10px;
}

.field-item {
    padding: 10px;
    background: white;
    border-radius: 4px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.field-item:last-child {
    margin-bottom: 0;
}

/* Preview editing highlights */
.editing-highlight {
    outline: 2px dashed var(--primary-color) !important;
    cursor: pointer !important;
}

.editing-highlight:hover {
    outline-color: var(--secondary-color) !important;
    background: rgba(74, 144, 226, 0.1) !important;
}

/* Insert mode highlights */
.insert-mode-active {
    cursor: crosshair !important;
}

.insert-mode-active * {
    cursor: crosshair !important;
}

.insert-hover {
    outline: 3px dashed var(--success-color) !important;
    outline-offset: 3px;
    background: rgba(46, 204, 113, 0.15) !important;
    box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.2),
        0 0 20px rgba(46, 204, 113, 0.3) !important;
    animation: insertPulse 2s infinite;
}

@keyframes insertPulse {

    0%,
    100% {
        box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.2),
            0 0 20px rgba(46, 204, 113, 0.3);
    }

    50% {
        box-shadow: 0 0 0 5px rgba(46, 204, 113, 0.3),
            0 0 30px rgba(46, 204, 113, 0.5);
    }
}

/* Responsive */
@media (max-width: 1200px) {
    .editor-layout {
        grid-template-columns: 1fr;
    }

    .control-panel {
        order: 2;
    }

    .preview-panel {
        order: 1;
        min-height: 500px;
    }
}

@media (max-width: 768px) {
    header h1 {
        font-size: 1.8em;
    }

    .toolbar {
        flex-direction: column;
        gap: 10px;
    }

    .toolbar-right {
        width: 100%;
    }

    .btn {
        width: 100%;
    }
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

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

/* Success message */
.success-message {
    background: var(--success-color);
    color: white;
    padding: 15px 20px;
    border-radius: 6px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

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

/* Pulse animation for insertion marker */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.7);
    }

    50% {
        opacity: 0.8;
        box-shadow: 0 0 15px 5px rgba(46, 204, 113, 0.3);
    }
}

/* Floating style popup for text editing */
.style-popup {
    position: absolute;
    z-index: 2000;
    width: 360px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    padding: 12px 12px 16px;
}

.style-popup.hidden {
    display: none !important;
}

.style-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.style-popup-header .btn-icon {
    border: none;
    font-size: 16px;
}

.style-popup-body label {
    margin: 6px 0 2px;
}

.style-popup-body select,
.style-popup-body input[type="number"],
.style-popup-body input[type="color"] {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #fff;
}

.style-popup-body textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #fff;
    resize: vertical;
}

.style-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-top: 8px;
}