@font-face {
    font-family: 'YouSheBiaoTiHei';
    src: url('../font/yousheh.ttf') format('truetype');
}

:root {
    /* 主题色彩变量 - 更新为深邃神秘色系 */
    --primary: #4caeb7;
    --primary-hover: #3d8c93;
    --background: #0f172a;
    --panel-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    /* Retained from original, as it's used and not clearly replaced */
    --secondary: #64748b;
    /* Retained from original */
    --secondary-hover: #475569;
    /* Retained from original */
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #10b981;
    --danger: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    /* 移除了外部字体，使用现代系统默认 UI 字体 */
    font-family: system-ui, -apple-system, "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--background);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-image:
        radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.15), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.15), transparent 25%);
    background-attachment: fixed;
    overflow-x: hidden;
    /* 锁定总高度防止页面滚动，除非子元素溢出 */
    height: 100vh;
}


.container {
    flex: 1;
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 1rem;
    padding: 1rem;
    max-width: 100%;
    margin: 0 auto;
    width: 100%;
    /* 让主体内容占据剩余高度而且不溢出 */
    min-height: 0;
    height: 100vh;
}

.panel {
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    /* 限制面板高度不超过容器 */
    min-height: 0;
    height: 100%;
}

.controls {
    overflow-y: auto;
}

/* 全局滚动条样式 - 纤细、深色风格 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* 针对特定容器的滚动条兼容性优化 */
.controls,
#assets-modal-body,
#layers-modal-body,
#layout-list-body {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.upload-area {
    border: 2px dashed var(--glass-border);
    border-radius: 12px;
    padding: 1.5rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.05);
}

/* 顶部链接按钮 */
.header-link-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 34px;
    padding: 0 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.header-link-btn:hover {
    background: rgba(76, 174, 183, 0.1);
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.header-link-btn svg {
    color: var(--primary);
    transition: transform 0.3s ease;
}

.header-link-btn:hover svg {
    transform: scale(1.1);
}

.clear-btn {
    display: none;
    position: absolute;
    right: -8px;
    top: -8px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white !important;
    border: 2px solid rgba(255, 255, 255, 0.8);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.clear-btn:hover {
    transform: rotate(90deg) scale(1.15);
    background: linear-gradient(135deg, #f87171, #ef4444);
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.6);
    border-color: #fff;
}

.clear-btn:active {
    transform: scale(0.92);
}

.file-inputs {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* 排版画板：禁止拖拽元素产生文本选区蓝色高亮 */
#layout-canvas-container,
#layout-canvas-container .draggable,
#layout-canvas-container img {
    user-select: none;
    -webkit-user-select: none;
}

/* text-elem 聚焦进入编辑状态时，才允许选中文字 */
#layout-canvas-container .text-elem:focus {
    user-select: text;
    -webkit-user-select: text;
}

.text-elem {
    padding: 4px;
    border: 1px solid transparent;
    width: max-content;
    min-width: 20px;
}

/* 键盘微调时的选中状态 */
.draggable.selected-nudge {
    outline: 2px dashed var(--primary);
    outline-offset: 4px;
}

.text-elem:focus {
    outline: none;
    border-color: rgba(59, 130, 246, 0.8);
    background: rgba(255, 255, 255, 0.1);
}

/* --- Reference Map Border Replication (CSS representation for Live Preview) --- */
/* Removed procedural border CSS as per instruction */

.input-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
}

.input-row {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.input-row input[type="number"] {
    flex: 1;
}

.link-btn {
    background: transparent;
    border: none;
    color: var(--primary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    outline: none;
}

.link-btn:hover {
    opacity: 0.7;
    transform: scale(1.05);
}

input[type="number"] {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: white;
    padding: 0.4rem 0.6rem;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
    width: 100%;
    /* 隐藏 Chrome/Safari/Edge/Opera 的微调按钮 */
    appearance: textfield;
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"]:focus {
    border-color: var(--primary);
}

input[type="checkbox"] {
    accent-color: var(--primary);
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

input[type="range"] {
    accent-color: #4caeb7;
    cursor: pointer;
}

/* 统一调色盘尺寸与圆角风格 */
input[type="color"] {
    width: 32px;
    height: 24px;
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    padding: 0;
    cursor: pointer;
    background: transparent;
    outline: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    vertical-align: middle;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 5px;
}

input[type="color"]:hover {
    border-color: var(--primary);
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(76, 174, 183, 0.4);
}

select {
    appearance: none;
    -webkit-appearance: none;
    background-color: rgba(15, 23, 42, 0.5);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%234caeb7' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: #fff;
    padding: 0 32px 0 12px;
    height: 32px;
    font-size: 0.82rem;
    outline: none;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.05);
}

select:hover {
    border-color: var(--primary);
    background-color: rgba(30, 41, 59, 0.7);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

select:focus {
    border-color: var(--primary);
    background-color: rgba(30, 41, 59, 0.8);
    box-shadow: 0 0 0 3px rgba(76, 174, 183, 0.25), 0 8px 16px rgba(0, 0, 0, 0.4);
}

optgroup {
    background-color: #1e293b;
    color: var(--primary);
    font-weight: 700;
    padding: 10px 0;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

option {
    background-color: #1e293b;
    color: #f8fafc;
    padding: 10px 12px;
    font-size: 0.9rem;
}

button.btn-primary,
button.btn-secondary {
    color: white;
    border: none;
    padding: 1rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

button.btn-primary {
    background: var(--primary);
}

button.btn-secondary {
    background: var(--secondary);
}

button.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(59, 130, 246, 0.4);
}

button.btn-secondary:hover:not(:disabled) {
    background: var(--secondary-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(100, 116, 139, 0.4);
}

button:disabled {
    background: #334155;
    color: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.action-buttons {
    display: flex;
    gap: 0.75rem;
    margin-top: auto;
    flex-shrink: 0;
    padding-top: 1rem;
}

.action-buttons button {
    flex: 1;
}

#save-btn {
    flex: 2;
}

.preview-container {
    position: relative;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: 1px solid var(--glass-border);
    /* 使其完美填充满右侧面板 */
    flex: 1;
    min-height: 0;
}

.image-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#cropper-image {
    display: block;
    /* 限制地图的最大宽高不超过容器 */
    max-width: 100%;
    max-height: 100%;
}

.empty-state {
    position: absolute;
    color: var(--text-muted);
    text-align: center;
    pointer-events: auto;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    height: 80%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#preview-empty:hover {
    border-color: var(--primary) !important;
    background: rgba(76, 174, 183, 0.08) !important;
}

#preview-empty:hover svg {
    opacity: 0.8;
    color: var(--primary);
    transform: scale(1.1);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 1rem;
    opacity: 0.5;
    transition: all 0.3s ease;
}

.info-card {
    background: rgba(15, 23, 42, 0.4);
    border-radius: 8px;
    padding: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-shrink: 0;
}

.info-card strong {
    color: var(--text-main);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

.status-badge.success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-badge.pending {
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-muted);
    border: 1px solid rgba(148, 163, 184, 0.2);
}

/* Responsive */
@media (max-width: 1024px) {
    body {
        height: auto;
        overflow-x: hidden;
    }

    .container {
        grid-template-columns: 1fr;
        height: auto;
        display: flex;
        flex-direction: column;
    }

    .preview-container {
        min-height: 500px;
    }

    .panel {
        height: auto;
    }
}

#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#loading-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

/* Customizing Cropper.js UI */
.cropper-line,
.cropper-point {
    background-color: var(--primary);
}

.cropper-view-box {
    outline: 2px solid var(--primary);
    outline-color: var(--primary);
}

/* 当允许扩展时，虚线框也可以跑出地图边缘以外 */
.cropper-modal {
    opacity: 0.6;
}

/* 适配手机端 */
@media screen and (max-width: 768px) {
    body {
        height: auto;
        overflow-y: auto;
    }

    .container {
        grid-template-columns: 1fr;
        grid-template-rows: auto 60vh;
        gap: 0.5rem;
        padding: 0.5rem;
        height: auto;
        min-height: 100vh;
    }

    .panel {
        height: auto;
        min-height: unset;
    }

    .controls {
        overflow-y: visible;
    }

    .panel.preview {
        height: 60vh;
    }

    /* 缩小弹窗提示字体和间距 */
    #jgw-preview {
        width: 90%;
        left: 5%;
        transform: translateX(0);
        font-size: 0.75rem;
        padding: 4px 10px;
        flex-direction: column;
        align-items: flex-start;
        bottom: 8px;
    }

    #bg-color-picker {
        top: 0.5rem;
        right: 0.5rem;
    }

    /* 头部排版变垂直 */
    header {
        flex-direction: column !important;
        align-items: flex-start !important;
        padding: 0.5rem !important;
    }

    header>div:first-child {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.25rem !important;
    }

    #drop-zone {
        width: 100% !important;
        min-width: unset !important;
        justify-content: flex-start !important;
    }
}

/* Micro-adjustment cursor indicators */
span[id$="-stroke-val"],
span[id$="-px-val"],
.custom-text-px-val,
.custom-text-stroke-val {
    cursor: ns-resize;
    user-select: none;
}

#layout-canvas-container .text-elem {
    /* Transforms webkit-text-stroke from center-stroke to outer-stroke */
    paint-order: stroke fill;
    stroke-linejoin: round;
    stroke-linecap: round;
}
.header-link-btn:disabled {
    background: transparent !important;
    opacity: 0.4 !important;
    cursor: not-allowed !important;
}
.header-link-btn:disabled:hover {
    background: transparent !important;
    color: var(--text-muted) !important;
}
