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

body {
    background: rgb(226, 242, 240);
    color: #000;
    font-family: 'DM Sans', sans-serif;
    font-weight: 300;
    font-size: 17px;
    line-height: 1.6;
    letter-spacing: -0.01em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* ---- The page canvas ---- */

.page-canvas {
    position: relative;
    width: 100%;
    min-height: 100vh;
}

.page-canvas.hidden {
    display: none;
}

/* ---- Editable elements (absolute positioned) ---- */

.el {
    position: absolute;
    cursor: default;
    user-select: none;
}

.el.text-el {
    white-space: nowrap;
}

.el.text-el.editing {
    outline: 2px solid #0af;
    cursor: text;
    user-select: text;
    white-space: nowrap;
}

.el.img-el {
    line-height: 0;
}

.el.img-el img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: opacity 0.2s ease, filter 0.4s ease;
}

.el.embed-el {
    line-height: 0;
    overflow: hidden;
    background: #000;
}

.el.embed-el iframe,
.el.embed-el video {
    display: block;
    width: 100%;
    height: 100%;
}

/* In editor mode, allow dragging over iframes */
.editor-mode .el.embed-el iframe {
    pointer-events: none;
}

/* ---- Blur: can be on whole element OR on inline spans inside text ---- */

/* Whole-element blur (for images) */
.el.blurred {
    filter: blur(var(--blur-amount, 5px));
    -webkit-filter: blur(var(--blur-amount, 5px));
    user-select: none;
    transition: filter 0.6s ease;
}

.el.blurred:hover {
    filter: blur(0px);
    -webkit-filter: blur(0px);
}

/* Inline character-level blur (for partial text) */
.blur-span {
    filter: blur(var(--blur-amount, 5px));
    -webkit-filter: blur(var(--blur-amount, 5px));
    transition: filter 0.6s ease;
    display: inline;
}

.blur-span:hover {
    filter: blur(0px);
    -webkit-filter: blur(0px);
}

/* ---- Nav hover menu on "Lu Meng" ---- */

.nav-trigger {
    position: absolute;
    z-index: 10;
}

.nav-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    padding-top: 6px;
    flex-direction: column;
    gap: 2px;
    white-space: nowrap;
}

.nav-trigger:hover .nav-menu {
    display: flex;
}

.nav-item {
    display: block;
    font-size: 14px;
    opacity: 0.45;
    cursor: pointer;
    padding: 2px 0;
    transition: opacity 0.2s ease;
}

.nav-item:hover {
    opacity: 1;
}

/* ---- Inline link spans ---- */

.link-span {
    cursor: pointer;
    display: inline;
    text-decoration: none;
    border-bottom: 1px dotted rgba(0,0,0,0.3);
}

.link-span:hover {
    opacity: 0.6;
}

/* ---- Linked elements (whole element) ---- */

.el[data-link] {
    cursor: pointer;
}

.el[data-link]:hover {
    opacity: 0.6;
}

/* External link indicator in editor mode */
.editor-mode .el[data-link^="ext:"]::after {
    content: '↗';
    position: absolute;
    top: -8px;
    right: -8px;
    font-size: 10px;
    color: #0af;
    opacity: 0.5;
}

/* ---- Image lightbox ---- */

/* Blur page content when lightbox is open */
body.lightbox-active .page-canvas {
    filter: blur(40px) !important;
    transition: filter 0.3s ease;
}

.lightbox-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 6000;
    align-items: center;
    justify-content: center;
}

.lightbox-overlay.active {
    display: flex;
}

/* Heavy grain overlay on lightbox background — controlled by CSS vars */
.lightbox-overlay::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    opacity: var(--lb-grain-opacity, 0.5);
    background-image: var(--lb-grain-svg);
    background-repeat: repeat;
    background-size: 200px 200px;
    pointer-events: none;
    z-index: 0;
}

.lightbox-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    display: block;
    position: relative;
    z-index: 1;
}

.lightbox-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 28px;
    color: rgba(0, 0, 0, 0.3);
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
    cursor: pointer;
    padding: 20px;
    user-select: none;
    transition: color 0.3s ease;
    z-index: 6001;
}

.lightbox-arrow:hover {
    color: rgba(0, 0, 0, 0.6);
}

.lightbox-arrow.left {
    left: 10px;
}

.lightbox-arrow.right {
    right: 10px;
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 20px;
    font-size: 20px;
    color: rgba(0, 0, 0, 0.3);
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
    cursor: pointer;
    padding: 10px;
    z-index: 6001;
    transition: color 0.3s ease;
}

.lightbox-close:hover {
    color: rgba(0, 0, 0, 0.6);
}

/* ---- Image popover (hover preview) ---- */

.popover {
    position: fixed;
    display: none;
    z-index: 5500;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.popover.active {
    display: block;
}

.popover img {
    display: block;
    max-width: 400px;
    max-height: 500px;
    object-fit: contain;
    border-radius: 2px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* ---- Drag alignment guides ---- */

.align-guide {
    position: absolute;
    z-index: 5003;
    pointer-events: none;
}

.align-guide.vertical {
    width: 1px;
    top: 0;
    bottom: 0;
    border-left: 1px dashed rgba(0, 170, 255, 0.4);
}

.align-guide.horizontal {
    height: 1px;
    left: 0;
    right: 0;
    border-top: 1px dashed rgba(0, 170, 255, 0.4);
}

.align-guide.center {
    border-color: rgba(255, 100, 100, 0.3);
}

/* ---- EDITOR UI ---- */

/* Placement cursor */
body.placing-text,
body.placing-text .page-canvas {
    cursor: text !important;
}

body.placing-img,
body.placing-img .page-canvas {
    cursor: crosshair !important;
}

.editor-mode .el {
    cursor: move;
}

.editor-mode .el.editing {
    cursor: text;
}

.editor-mode .el:hover {
    outline: 1px dashed rgba(0,200,0,0.5);
}

.editor-mode .el.selected {
    outline: 2px solid #0f0;
}

.editor-mode .el.editing {
    outline: 2px solid #0af !important;
}

/* Drag-and-drop overlay */
.drag-over .page-canvas:not(.hidden) {
    outline: 3px dashed #0af;
    outline-offset: -3px;
    background: rgba(0, 170, 255, 0.03);
}

/* Marquee selection rectangle */
.marquee-rect {
    position: absolute;
    border: 1px dashed rgba(0, 170, 255, 0.8);
    background: rgba(0, 170, 255, 0.08);
    z-index: 5003;
    pointer-events: none;
}

/* Resize handles */
.resize-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #0f0;
    border: 1px solid #000;
    z-index: 5002;
    pointer-events: auto;
}

.resize-handle.nw { top: -4px; left: -4px; cursor: nw-resize; }
.resize-handle.n  { top: -4px; left: 50%; margin-left: -4px; cursor: n-resize; }
.resize-handle.ne { top: -4px; right: -4px; cursor: ne-resize; }
.resize-handle.w  { top: 50%; margin-top: -4px; left: -4px; cursor: w-resize; }
.resize-handle.e  { top: 50%; margin-top: -4px; right: -4px; cursor: e-resize; }
.resize-handle.sw { bottom: -4px; left: -4px; cursor: sw-resize; }
.resize-handle.s  { bottom: -4px; left: 50%; margin-left: -4px; cursor: s-resize; }
.resize-handle.se { bottom: -4px; right: -4px; cursor: se-resize; }

/* Toolbar */
#toolbar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    background: #111;
    z-index: 5000;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 4px;
    font-family: -apple-system, system-ui, sans-serif;
    font-size: 12px;
    color: #fff;
    box-shadow: 0 2px 20px rgba(0,0,0,0.3);
}

#toolbar.hidden {
    display: none !important;
}

#toolbar button, #toolbar select, #toolbar input {
    font-family: -apple-system, system-ui, sans-serif;
    font-size: 12px;
    border: none;
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
    background: #333;
    color: #fff;
}

#toolbar button:hover {
    background: #555;
}

#toolbar .sep {
    width: 1px;
    height: 24px;
    background: #444;
    margin: 0 6px;
}

#toolbar select {
    max-width: 120px;
}

#toolbar input[type="color"] {
    width: 28px;
    height: 28px;
    padding: 2px;
    border-radius: 4px;
    cursor: pointer;
}

#toolbar input[type="number"] {
    width: 50px;
    text-align: center;
}

#toolbar .active {
    background: #0a0 !important;
    color: #000;
}

/* Layout toggle buttons */
#tb-layout-toggle .layout-btn {
    border-radius: 0;
    border: 1px solid #555;
    padding: 6px 12px;
    font-size: 11px;
}
#tb-layout-toggle .layout-btn:first-child { border-radius: 4px 0 0 4px; }
#tb-layout-toggle .layout-btn:last-child { border-radius: 0 4px 4px 0; margin-left: -1px; }
#tb-layout-toggle .layout-btn.active { background: #0af !important; color: #000; }

/* Mobile edit mode */
body.editor-mode.mobile-edit .page-canvas:not(.hidden) {
    width: 390px !important;
    margin: 0 auto;
    outline: 2px dashed #0af;
    outline-offset: 4px;
}

/* Mobile-hidden elements: ghosted in editor so you can click to unhide */
body.editor-mode.mobile-edit .el[data-m-hidden] {
    display: block !important;
    opacity: 0.15 !important;
    outline: 1px dashed rgba(255, 0, 0, 0.4) !important;
    pointer-events: auto;
}

body.editor-mode.mobile-edit::after {
    content: 'MOBILE 390px';
    position: fixed;
    top: 56px;
    left: 50%;
    transform: translateX(-50%);
    background: #0af;
    color: #000;
    font-size: 11px;
    font-weight: 500;
    padding: 2px 12px;
    border-radius: 0 0 4px 4px;
    z-index: 5010;
    font-family: -apple-system, system-ui, sans-serif;
}

/* Properties panel */
#props-panel {
    display: none;
    position: fixed;
    top: 60px;
    right: 16px;
    width: 240px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    background: #111;
    border-radius: 8px;
    z-index: 5001;
    font-family: -apple-system, system-ui, sans-serif;
    font-size: 12px;
    color: #fff;
    padding: 16px;
    box-shadow: 0 4px 30px rgba(0,0,0,0.4);
}

#props-panel label {
    display: block;
    margin-bottom: 8px;
}

#props-panel select, #props-panel input {
    font-size: 12px;
    border: none;
    border-radius: 3px;
    padding: 4px 6px;
    background: #333;
    color: #fff;
    width: 100%;
    margin-top: 2px;
}

#props-panel button {
    font-size: 12px;
    border: none;
    border-radius: 3px;
    padding: 5px 10px;
    cursor: pointer;
    background: #333;
    color: #fff;
    margin-top: 4px;
    margin-right: 4px;
}

#props-panel button:hover {
    background: #555;
}

#props-panel button.danger {
    background: #c00;
}

#props-panel button.primary {
    background: #0a0;
    color: #000;
}

#props-panel .section-title {
    font-weight: 600;
    color: #0f0;
    margin-bottom: 10px;
    font-size: 13px;
}

/* Page tabs in editor */
#page-tabs {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 36px;
    background: #111;
    z-index: 5000;
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 2px;
    font-family: -apple-system, system-ui, sans-serif;
    font-size: 11px;
    color: #fff;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

#page-tabs.hidden {
    display: none !important;
}

#page-tabs .tab {
    padding: 6px 14px;
    background: #333;
    border-radius: 4px 4px 0 0;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

#page-tabs .tab.active {
    background: #fff;
    color: #000;
}

#page-tabs .tab:hover {
    background: #555;
}

#page-tabs .tab.active:hover {
    background: #eee;
}

#page-tabs .add-page {
    padding: 6px 10px;
    background: none;
    border: 1px dashed #555;
    border-radius: 4px;
    cursor: pointer;
    color: #888;
    flex-shrink: 0;
}

#page-tabs .add-page:hover {
    border-color: #aaa;
    color: #fff;
}

/* Editor active adjustments */
body.editor-mode .page-canvas {
    padding-top: 60px;
}

/* Status bar for placement mode */
#status-bar {
    display: none;
    position: fixed;
    bottom: 44px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.85);
    color: #0f0;
    font-family: -apple-system, system-ui, sans-serif;
    font-size: 13px;
    padding: 8px 20px;
    border-radius: 6px;
    z-index: 5010;
    white-space: nowrap;
}

/* ---- Canvas overlay effects ---- */

.canvas-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 0;
    mix-blend-mode: normal;
}

/* Noise grain via pseudo-element */
.canvas-overlay::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: var(--noise-opacity, 0);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.4'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 200px 200px;
    pointer-events: none;
}

.canvas-glass {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 0;
}

/* Ensure .el elements sit above overlays */
.page-canvas .el {
    z-index: 1;
}

/* ---- Canvas style panel ---- */

#canvas-panel {
    display: none;
    position: fixed;
    top: 60px;
    left: 16px;
    width: 240px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    background: #111;
    border-radius: 8px;
    z-index: 5001;
    font-family: -apple-system, system-ui, sans-serif;
    font-size: 12px;
    color: #fff;
    padding: 16px;
    box-shadow: 0 4px 30px rgba(0,0,0,0.4);
}

#canvas-panel label {
    display: block;
    margin-bottom: 8px;
}

#canvas-panel select, #canvas-panel input {
    font-size: 12px;
    border: none;
    border-radius: 3px;
    padding: 4px 6px;
    background: #333;
    color: #fff;
    width: 100%;
    margin-top: 2px;
}

#canvas-panel input[type="color"] {
    width: 32px;
    height: 24px;
    padding: 1px;
    cursor: pointer;
}

#canvas-panel input[type="range"] {
    width: 100%;
    margin-top: 4px;
}

#canvas-panel button {
    font-size: 11px;
    border: none;
    border-radius: 3px;
    padding: 5px 8px;
    cursor: pointer;
    background: #333;
    color: #fff;
}

#canvas-panel button:hover {
    background: #555;
}

#canvas-panel button.primary {
    background: #0a0;
    color: #000;
}

#canvas-panel .preset-btn {
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.15s;
}

#canvas-panel .preset-btn:hover {
    background: #0af;
    color: #000;
}

#canvas-panel .section-title {
    font-weight: 600;
    color: #0f0;
    margin-bottom: 10px;
    font-size: 13px;
}

/* ---- Responsive ---- */

@media (max-width: 768px) {
    body {
        font-size: 15px;
    }
}
