:root {
    /* 颜色系统 */
    --bg-primary: #09090b; /* 非常深的背景 */
    --bg-secondary: #18181b; /* 稍浅的面板背景 */
    --bg-tertiary: #27272a; /* 边框或输入框背景 */
    --bg-elevated: #202024; /* 悬浮卡片背景 */

    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-tertiary: #71717a;

    --accent-primary: #6366f1; /* Indigo 500 */
    --accent-hover: #4f46e5; /* Indigo 600 */
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); /* Indigo to Purple */
    
    --border-color: #3f3f46;
    --border-focus: #6366f1;

    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;

    /* 间距与尺寸 */
    --header-height: 60px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    /* 阴影 */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* 通用工具类 */
.page {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

/* 按钮样式重置与增强 */
button {
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    outline: none;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
    border-color: var(--text-secondary);
}

.btn-ai {
    background: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%); /* Pink to Purple */
    color: white;
    padding: 8px 20px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
}

.btn-ai::before {
    content: "\2728"; /* 简单的图标替代 */
    font-size: 1.1em;
}

.btn-ai:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: 0 0 15px rgba(236, 72, 153, 0.3);
}

/* ====================
   登录页面
   ==================== */
#login-page {
    background: radial-gradient(circle at 50% 50%, #1e1b4b 0%, var(--bg-primary) 70%);
    justify-content: center;
    align-items: center;
}

.login-container {
    background: rgba(24, 24, 27, 0.8);
    backdrop-filter: blur(12px);
    padding: 40px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    animation: fadeUp 0.5s ease-out;
}

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

.login-logo {
    text-align: center;
    margin-bottom: 24px;
}

.login-logo img {
    width: 64px;
    height: 64px;
    mix-blend-mode: screen;
    border-radius: 8px;
    filter: drop-shadow(0 0 8px rgba(255,255,255,0.2));
}

.login-container h1 {
    text-align: center;
    margin-bottom: 32px;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, #fff, #a1a1aa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

#login-form input {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 15px;
    transition: border-color 0.2s;
}

#login-form input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

#login-form button {
    width: 100%;
    padding: 12px;
    margin-top: 8px;
    background: var(--text-primary);
    color: var(--bg-primary);
    font-weight: 700;
    border-radius: var(--radius-md);
}

#login-form button:hover {
    background: #fff;
    box-shadow: 0 0 15px rgba(255,255,255,0.3);
}

.error {
    color: var(--danger-color);
    text-align: center;
    margin-top: 16px;
    font-size: 14px;
    min-height: 20px;
}

/* ====================
   页头 (Shared Header)
   ==================== */
header {
    height: var(--header-height);
    background: rgba(9, 9, 11, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-logo {
    width: 32px;
    height: 32px;
    mix-blend-mode: screen;
    border-radius: 4px;
}

header h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* ====================
   列表页面
   ==================== */
#list-page {
    background: var(--bg-primary);
}

.pens-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
    padding: 32px;
    overflow-y: auto;
    flex: 1;
    max-width: 1440px;
    margin: 0 auto;
    width: 100%;
}

/* 隐藏滚动条 */
.pens-grid::-webkit-scrollbar {
    width: 8px;
}
.pens-grid::-webkit-scrollbar-track {
    background: transparent;
}
.pens-grid::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.pen-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
}

.pen-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--text-secondary);
    z-index: 2;
}

.pen-preview {
    height: 180px;
    background: #000;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.pen-preview iframe {
    width: 200%; /* Scale down for better resolution simulation */
    height: 200%;
    border: none;
    transform: scale(0.5);
    transform-origin: top left;
    pointer-events: none;
    background: #fff; /* 预览背景默认为白，避免全黑 */
}

.pen-info {
    padding: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.pen-card h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pen-meta {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-bottom: 16px;
}

.pen-actions {
    margin-top: auto;
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 8px;
}

.pen-card button {
    padding: 6px 12px;
    font-size: 13px;
    border-radius: var(--radius-sm);
}

.btn-view {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.btn-view:hover { background: var(--bg-elevated); }

.btn-edit {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.btn-edit:hover { background: var(--bg-elevated); }

.btn-delete {
    background: transparent;
    color: var(--text-tertiary);
    padding: 6px 10px;
}
.btn-delete:hover {
    color: var(--danger-color);
    background: rgba(239, 68, 68, 0.1);
}

/* ====================
   编辑器页面
   ==================== */
#editor-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.pen-title-input {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    width: 300px;
    transition: all 0.2s;
}

.pen-title-input:hover {
    background: var(--bg-tertiary);
}

.pen-title-input:focus {
    background: var(--bg-primary);
    border-color: var(--accent-primary);
    outline: none;
}

.btn-share {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    padding: 8px 16px;
}
.btn-share:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
}

/* Editor Layout */
.editor-container {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr; /* HTML, CSS, JS */
    height: 45vh; /* Top half */
    border-bottom: 4px solid var(--bg-primary);
    background: var(--bg-primary);
    gap: 1px; /* Create gaps for borders */
}

.editor-panel {
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.panel-header {
    background: var(--bg-tertiary);
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.panel-header::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
}
.editor-panel:nth-child(1) .panel-header::before { background: #e34c26; } /* HTML Orange */
.editor-panel:nth-child(2) .panel-header::before { background: #264de4; } /* CSS Blue */
.editor-panel:nth-child(3) .panel-header::before { background: #f7df1e; } /* JS Yellow */

.code-editor {
    flex: 1;
    background: var(--bg-secondary);
    color: #d4d4d4;
    border: none;
    padding: 16px;
    font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
    font-size: 13px;
    line-height: 1.6;
    resize: none;
    outline: none;
    white-space: pre;
    overflow: auto;
}

/* Custom Scrollbar for Editor */
.code-editor::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
.code-editor::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}
.code-editor::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 5px;
    border: 2px solid var(--bg-secondary);
}
.code-editor::-webkit-scrollbar-thumb:hover {
    background: #52525b;
}

/* Preview Section */
.preview-container {
    flex: 1;
    background: #fff; /* 预览背景 */
    position: relative;
    display: flex;
    flex-direction: column;
}

.preview-container .panel-header {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

#preview-frame {
    flex: 1;
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
}

/* ====================
   AI Modal
   ==================== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 560px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    max-height: 85vh;
}

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

.modal-header h2 {
    font-size: 18px;
    background: linear-gradient(to right, #ec4899, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 700;
}

.modal-close {
    background: transparent;
    color: var(--text-tertiary);
    font-size: 24px;
    line-height: 1;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

.modal-body textarea {
    width: 100%;
    min-height: 120px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    color: var(--text-primary);
    font-size: 14px;
    resize: vertical;
    transition: border-color 0.2s;
    font-family: inherit;
}

.modal-body textarea:focus {
    border-color: var(--accent-primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background: var(--bg-secondary);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* AI Loading State */
.ai-loading {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: var(--radius-md);
    margin-top: 16px;
    color: var(--accent-primary);
    font-size: 14px;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(99, 102, 241, 0.3);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.ai-error {
    margin-top: 16px;
    padding: 12px 16px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--danger-color);
    border-radius: var(--radius-md);
    font-size: 14px;
}