:root {
    --primary: #3b82f6;
    --primary-light: #93c5fd;
    --secondary: #64748b;
    --accent: #f97316;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #0ea5e9;
    --light: #f8fafc;
    --dark: #1e293b;
    --gray: #94a3b8;
    --light-gray: #e2e8f0;
    --border-radius: 6px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    /* 响应式间距与字体尺寸变量 */
    --space-1: clamp(6px, 0.6vw, 10px);
    --space-2: clamp(8px, 0.8vw, 14px);
    --space-3: clamp(12px, 1.2vw, 18px);
    --font-size-base: clamp(14px, 0.9vw + 12px, 17px);
    --font-size-xs: clamp(0.8rem, 0.84rem, 0.9rem);
    --font-size-sm: clamp(0.9rem, 0.96rem, 1.05rem);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: #f1f5f9;
    color: var(--dark);
    line-height: 1.5;
}

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    background-color: white;
    padding: 1rem 2rem;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-title {
    font-size: 1.5rem;
    color: var(--primary);
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sidebar {
    width: 300px;
    background-color: white;
    border-right: 1px solid var(--light-gray);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.right-sidebar {
    border-left: 1px solid var(--light-gray);
    border-right: none;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--light-gray);
}

.sidebar-title {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    color: var(--dark);
}

.search-box {
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 0.5rem 0.5rem 0.5rem 2rem;
    border: 1px solid var(--light-gray);
    border-radius: var(--border-radius);
    font-size: 0.9rem;
}

.search-box i {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray);
}

.deck-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.editor-area {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

.deck-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.deck-name-edit {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}


.hidden-checkbox {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--secondary);
    font-size: 0.9rem;
}

.deck-stats {
    color: var(--secondary);
    font-size: 0.9rem;
}

/* 保留 Tailwind 输入样式，避免旧ID选择器覆盖 */

.editor-toolbar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.divider {
    width: 1px;
    height: 24px;
    background-color: var(--light-gray);
    margin: 0 0.25rem;
}

.cards-editor {
    background-color: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    min-height: 200px;
}

.card-item {
    margin-bottom: 0.75rem;
}

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

.card-content {
    width: 100%;
    resize: vertical;
}

.card-item.active {
    border-color: var(--primary);
    background-color: rgba(59, 130, 246, 0.05);
}

.sidebar-section {
    padding: 1rem;
    border-bottom: 1px solid var(--light-gray);
}

.draw-controls {
    margin-bottom: 1rem;
}

.draw-result {
    min-height: 100px;
    background-color: var(--light);
    border-radius: var(--border-radius);
    padding: 1rem;
    border: 1px solid var(--light-gray);
}

.slide-in {
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateY(10px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.chart-container {
    height: 250px;
    position: relative;
}

/* JSON 预览优化：更小字体、自动换行、统一容器高度 */
#jsonPreviewContainer {
    font-size: 0.8125rem; /* 桌面略小字号 */
    min-height: 220px; /* 统一显示框基准高度 */
}
#jsonEditorContainer {
    min-height: 220px; /* 与预览容器保持一致 */
}
#jsonPreview {
    display: block;
    margin: 0;
    padding: 0.5rem 0.75rem;    /* 与 #jsonEditor 一致的内边距 */
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.875rem;        /* 明确覆盖容器 text-xs/sm 差异 */
    line-height: 1.5;
    white-space: pre-wrap;      /* 保留缩进同时自动换行 */
    word-break: break-word;     /* 打断长单词/键值避免横向滚动 */
    overflow-wrap: anywhere;    /* 进一步确保不出现水平滚动 */
    tab-size: 4;                /* 与编辑器统一制表宽度 */
}

#jsonEditor {
    font-size: 0.875rem;        /* 与 #jsonPreview 明确一致 */
    line-height: 1.5;           /* 与 #jsonPreview 明确一致 */
    font-family: 'Consolas', 'Monaco', monospace;
    white-space: pre-wrap;      /* 与预览一致的换行策略 */
    word-break: break-word;     /* 尽量避免横向滚动 */
    overflow-wrap: anywhere;    /* 长键值也可断行 */
    overflow-x: hidden;         /* 禁止水平滚动 */
    overflow-y: hidden;         /* 由内层容器承担纵向滚动，避免双滚动条 */
    padding: 0.5rem 0.75rem;    /* 增加内边距，避免文本贴边 */
    tab-size: 4;                /* 与预览统一制表宽度 */
}

.json-container {
    background-color: #1e293b;
    color: #f8fafc;
    border-radius: var(--border-radius);
    overflow: hidden;
}

.json-toolbar {
    display: flex;
    justify-content: flex-end;
    padding: 0.5rem;
    background-color: #0f172a;
}

.json-preview {
    padding: 1rem;
    font-family: monospace;
    font-size: 0.85rem;
    white-space: pre;
    overflow: auto;
    max-height: 300px;
}

.json-editor textarea {
    width: 100%;
    height: 300px;
    background-color: transparent;
    border: none;
    color: inherit;
    font-family: monospace;
    font-size: 0.85rem;
    padding: 1rem;
    resize: none;
}

/* ========== Move Up/Down Elastic Animations ========== */
@keyframes spring-up {
  0% { transform: translateY(0) scale(1); }
  20% { transform: translateY(-12px) scale(1.01); }
  60% { transform: translateY(4px) scale(0.998); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes spring-down {
  0% { transform: translateY(0) scale(1); }
  20% { transform: translateY(12px) scale(1.01); }
  60% { transform: translateY(-4px) scale(0.998); }
  100% { transform: translateY(0) scale(1); }
}

.anim-spring-up {
  animation: spring-up 420ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

.anim-spring-down {
  animation: spring-down 420ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

/* FLIP: 为牌堆列表过渡提供基础过渡曲线 */
.flip-animate {
  transition: transform 260ms cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}

@media (prefers-reduced-motion: reduce) {
  .anim-spring-up,
  .anim-spring-down,
  .flip-animate {
    animation: none !important;
    transition: none !important;
    transform: none !important;
  }
}

.json-editor textarea:focus {
    outline: none;
}

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

.modal-content {
    background-color: white;
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 1rem;
    border-bottom: 1px solid var(--light-gray);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 1rem;
    border-top: 1px solid var(--light-gray);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray);
}

.file-drop-area {
    cursor: pointer;
    transition: background-color 0.2s;
}

.file-drop-area:hover {
    background-color: var(--light);
}

/* 按钮样式 */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

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

.btn-primary:hover {
    background-color: #2563eb;
}

.bg-secondary {
    background-color: var(--secondary);
    color: white;
}

.bg-secondary:hover {
    background-color: #475569;
}

.bg-accent {
    background-color: var(--accent);
    color: white;
}

.bg-accent {
    background-color: rgba(249, 115, 22, 0.1);
}

.text-accent {
    color: var(--accent);
}

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

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

.bg-danger:hover {
    background-color: #dc2626;
}

/* 表单控件 */
.form-control {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--light-gray);
    border-radius: var(--border-radius);
    font-size: 0.9rem;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* 工具类 */
.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.w-full {
    width: 100%;
}

.mt-1 {
    margin-top: 0.25rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mr-1 {
    margin-right: 0.25rem;
}

/* 响应式设计 */
@media (max-width: 1200px) {
    .main-content {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        max-height: 300px;
    }
    
    .right-sidebar {
        order: -1;
    }
}

@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    .header-actions {
        width: 100%;
        flex-wrap: wrap;
    }
    
    .header-actions .btn {
        flex: 1;
        min-width: 120px;
    }
    
    .deck-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* 移动端悬浮操作按钮 */
.fab-container {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 10050; /* 高于全屏工具栏，低于通知 */
}

/* 仅在小屏幕显示 */
/* 桌面端隐藏（宽度>=1025px），平板和手机显示 */
@media (min-width: 1025px) {
    .fab-container { display: none; }
}

.fab-main {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: #fff;
    border: 1px solid var(--light-gray);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.fab-main .icon {
    display: block;
    width: 36px;
    height: 36px;
}

.fab-menu {
    display: flex;
    flex-direction: column;
    align-items: center; /* 保证子按钮与主按钮中心对齐 */
    gap: 8px;
    margin-bottom: 8px;
}

/* 关闭状态不占空间且不拦截点击 */
.fab-container:not(.open) .fab-menu {
    height: 0;
    margin-bottom: 0;
    pointer-events: none;
}

.fab-option {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-color: #fff;
    border: 1px solid var(--light-gray);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transform: translateY(10px) scale(0.92);
    pointer-events: none;
}

/* 颜色区分各操作按钮 */
#fabMediaBtn  { background-color: var(--primary); color: #fff; }
#fabImportBtn { background-color: var(--info); color: #fff; }
#fabExportBtn { background-color: var(--secondary); color: #fff; }
#fabSaveBtn   { background-color: var(--primary); color: #fff; }
#fabClearBtn  { background-color: var(--danger); color: #fff; }
#fabForumBtn  { background-color: var(--accent); color: #fff; }

#fabMediaBtn:hover  { filter: brightness(0.95); }
#fabImportBtn:hover { filter: brightness(0.95); }
#fabExportBtn:hover { filter: brightness(0.95); }
#fabSaveBtn:hover   { filter: brightness(0.95); }
#fabClearBtn:hover  { filter: brightness(0.95); }
#fabForumBtn:hover  { filter: brightness(0.95); }

.fab-container.open .fab-option {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    animation: fabPopIn 220ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* 轻微的阶梯动画效果 */
.fab-container.open #fabMediaBtn  { animation-delay: 0.00s; }
.fab-container.open #fabImportBtn { animation-delay: 0.02s; }
.fab-container.open #fabExportBtn { animation-delay: 0.05s; }
.fab-container.open #fabSaveBtn   { animation-delay: 0.08s; }
.fab-container.open #fabClearBtn  { animation-delay: 0.11s; }
.fab-container.open #fabForumBtn  { animation-delay: 0.14s; }

/* 收回动画（在 open + closing 状态下运行） */
.fab-container.open.closing .fab-option {
    animation: fabPopOut 160ms ease both;
}
.fab-container.open.closing #fabMediaBtn  { animation-delay: 0.00s; }
.fab-container.open.closing #fabImportBtn { animation-delay: 0.00s; }
.fab-container.open.closing #fabExportBtn { animation-delay: 0.02s; }
.fab-container.open.closing #fabSaveBtn   { animation-delay: 0.04s; }
.fab-container.open.closing #fabClearBtn  { animation-delay: 0.06s; }
.fab-container.open.closing #fabForumBtn  { animation-delay: 0.08s; }

@keyframes fabPopIn {
    0%   { opacity: 0; transform: translateY(10px) scale(0.86); }
    60%  { opacity: 1; transform: translateY(0)    scale(1.06); }
    100% { opacity: 1; transform: translateY(0)    scale(1.00); }
}

@keyframes fabPopOut {
    0%   { opacity: 1; transform: translateY(0)    scale(1.00); }
    100% { opacity: 0; transform: translateY(10px) scale(0.86); }
}

/* 手机和平板端隐藏头部的导入/导出/保存/清除按钮 div，避免重复显示 */
@media (max-width: 1024px) {
    #headerActions { display: none; }
}

/* ----------------------------- */
/* 移动端整体布局与排版优化       */
/* ----------------------------- */

/* 栅格容器：在任意分辨率下整齐排布 */
.grid {
    display: grid;
    grid-template-columns: 1fr; /* 移动端默认单列 */
    gap: 1rem; /* 等同于 gap-4 */
}

@media (min-width: 768px) {
    .grid {
        grid-template-columns: repeat(2, 1fr); /* 平板两列 */
    }
}

@media (min-width: 1025px) {
    .grid {
        grid-template-columns: repeat(3, 1fr); /* 桌面三列 */
    }
}

/* h2 标题在移动端的字号与间距优化 */
h2 {
    font-size: 1.125rem; /* 18px */
    line-height: 1.4;
    margin-bottom: 0.5rem;
}

@media (max-width: 640px) {
    h2 {
        font-size: 1rem; /* 16px，移动端更紧凑 */
        line-height: 1.4;
        margin-bottom: 0.5rem;
        word-break: break-word;
    }
}

@media (min-width: 1025px) {
    h2 {
        font-size: 1.25rem; /* 20px 桌面更清晰 */
    }
}

/* 输入框圆角矩形边框（移动端优先） */
@media (max-width: 1024px) {
    input[type="text"],
    input[type="number"],
    input[type="search"],
    select,
    textarea {
        border: 1px solid var(--light-gray);
        border-radius: 8px;
        padding: 0.5rem 0.75rem;
        box-sizing: border-box;
        background-color: #fff;
    }

    /* 覆盖牌堆名称输入在移动端的无边框样式 */
    #deckNameInput {
        border: 1px solid var(--light-gray);
        border-radius: 8px;
        background-color: #fff;
        padding: 0.5rem 0.75rem;
        width: 100%;
    }
}

/* 移动端代码编辑框最少显示7行 */
/* 移动端保持与桌面一致的换行策略，避免行数不一致 */
@media (max-width: 1024px) {
    #jsonEditor {
        min-height: calc(1.5em * 7);
        line-height: 1.5;
        font-size: 0.875rem;
        white-space: pre-wrap;
        overflow-x: hidden;
        min-width: auto;
    }
}

/* 预览区在移动端匹配编辑器的最小列宽 */
@media (max-width: 1024px) {
    #jsonPreview {
        min-width: auto;
        white-space: pre-wrap;
    }
}

/* 统一最小行数（7行），其余高度由容器控制 */
#jsonPreviewContainer,
#jsonEditorContainer {
    min-height: calc(1.5em * 7);
}

#jsonPreview {
    min-height: calc(1.5em * 7);
}

#jsonEditor {
    min-height: calc(1.5em * 7);
}

/* 保证代码内容列对齐（制表符宽度） */
.json-editor-content {
    tab-size: 4;
}
    
/* 移除强制固定13行高度，改由黑色内层容器max-height + auto滚动控制 */
    
/* 全局流式字体与行高 */
html { font-size: var(--font-size-base); }
body { line-height: 1.6; }

/* 在常用小字号场景下提升可读性 */
.text-xs { font-size: var(--font-size-xs); }
.text-sm { font-size: var(--font-size-sm); }

/* 统一按钮与表单控件的最小触达高度（不覆盖具体内边距） */
button.rounded-md,
input.rounded-md,
select.rounded-md,
textarea.rounded-md {
  min-height: clamp(36px, 4.5vh, 44px);
}

/* JSON 编辑/预览的等宽字体与字号在不同分辨率下更舒适 */
.json-editor-content,
#jsonPreview {
  font-size: clamp(0.85rem, 0.92rem, 0.98rem);
  line-height: 1.6;
}
    
/* 拖动排序视觉提示（移动端） */
.card-item.dragging {
    background-color: rgba(59, 130, 246, 0.06);
}
.card-item.drop-before {
    border-top: 2px dashed var(--primary);
}
.card-item.drop-after {
    border-bottom: 2px dashed var(--primary);
}

/* 牌堆列表拖动提示（使用内阴影避免影响布局） */
#deckList [data-deck].dragging {
    box-shadow: inset 0 0 0 2px rgba(59, 130, 246, 0.3);
}
#deckList [data-deck].drop-before {
    box-shadow: inset 0 2px 0 var(--primary);
}
#deckList [data-deck].drop-after {
    box-shadow: inset 0 -2px 0 var(--primary);
}
    
/* 提升媒体库弹窗层级，避免被悬浮菜单覆盖 */
#mediaModal { z-index: 10100; }
    