/**
 * common.css - 全局公共样式
 *
 * 包含：CSS变量（主题色系）、基础重置、通用组件（按钮/徽章/模态框/输入框）、布局工具类。
 * 两个页面（刷题/整理）共享此文件，页面特有样式分别定义于 quiz.css / organize.css。
 */

/* ===================== 主题变量 ===================== */

:root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --success-bg: #dcfce7;
    --error: #ef4444;
    --error-bg: #fee2e2;
    --warning: #f59e0b;
    --warning-bg: #fffbeb;
    --info: #6366f1;
    --info-bg: #eef2ff;
    --bg: #f3f4f6;
    --card: #ffffff;
    --text: #1f2937;
    --text-sec: #6b7280;
    --border: #e5e7eb;
    --opt-bg: #f9fafb;
    --opt-hover: #eff6ff;
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* 护眼主题 - 低对比度暖色调 */
html[data-theme="eye-care"] {
    --bg: #f5f5dc;
    --card: #faf9de;
    --text: #5f4b32;
    --text-sec: #8c7b68;
    --border: #e6dcb1;
    --opt-bg: #fffdf0;
    --opt-hover: #ede8c4;
    --primary: #7048e8;
    --success-bg: #e6fcf5;
    --error-bg: #fff5f5;
}

/* 明亮主题 - 标准浅色 */
html[data-theme="light"] {
    --bg: #f3f4f6;
    --card: #ffffff;
    --text: #1f2937;
    --text-sec: #6b7280;
    --border: #e5e7eb;
    --opt-bg: #f9fafb;
    --opt-hover: #eff6ff;
}

/* 深色主题 - 高对比暗色 */
html[data-theme="dark"] {
    --bg: #0f172a;
    --card: #1e293b;
    --text: #f1f5f9;
    --text-sec: #94a3b8;
    --border: #334155;
    --opt-bg: #334155;
    --opt-hover: #475569;
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --warning-bg: #451a03;
}

/* ===================== 基础重置 ===================== */

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    transition: background 0.3s;
    overflow-x: hidden;
}

/* ===================== 通用布局 ===================== */

.content-wrapper {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    padding: 20px;
}

.card {
    background: var(--card);
    padding: 25px;
    border-radius: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    border: 1px solid var(--border);
    transition: 0.2s;
    position: relative;
}

.hidden {
    display: none !important;
}

/* ===================== 顶部导航栏 ===================== */

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    min-width: 0;
    flex-shrink: 0;
    z-index: 100;
    background: var(--bg);
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.top-bar > * {
    min-width: 0;
}

/* ===================== 按钮系统 ===================== */

button {
    border: none;
    padding: 10px 18px;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    font-size: 1rem;
}

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

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

.btn-primary:active {
    transform: scale(0.98);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-text {
    background: transparent;
    color: var(--text-sec);
    padding: 5px;
    font-size: 0.9em;
}

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

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

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

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

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

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: 0.2s;
    background: transparent;
    border: none;
    color: var(--text);
}

.btn-icon:hover {
    background: var(--opt-hover);
    color: var(--primary);
}

/* ===================== 徽章组件 ===================== */

.badge {
    padding: 4px 10px;
    border-radius: 6px;
    background: var(--border);
    color: var(--text);
    font-size: 0.85em;
    font-weight: 600;
    display: inline-block;
}

.badge-err {
    background: var(--error-bg);
    color: var(--error);
}

.badge-single {
    background: var(--info-bg);
    color: var(--info);
}

.badge-multiple {
    background: var(--warning-bg);
    color: var(--warning);
}

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

/* ===================== 模态框 ===================== */

.drag-over {
    border-color: var(--primary) !important;
    background: color-mix(in srgb, var(--primary) 8%, transparent) !important;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--card);
    padding: 25px;
    border-radius: 20px;
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

/* ===================== 表单控件 ===================== */

.edit-input {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95em;
}

.edit-input:focus {
    outline: none;
    border-color: var(--primary);
}

textarea.edit-input {
    resize: vertical;
    min-height: 80px;
}

select {
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9em;
}

/* ===================== 导航标签 ===================== */

.nav-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.nav-tab {
    padding: 8px 16px;
    border-radius: 8px;
    background: var(--opt-bg);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    transition: 0.15s;
    color: var(--text);
}

.nav-tab:hover {
    border-color: var(--primary);
}

.nav-tab.active {
    border-color: var(--primary);
    background: var(--opt-hover);
    color: var(--primary);
}

/* ===================== 工具类 ===================== */

.section-title {
    font-size: 0.9em;
    font-weight: 600;
    color: var(--text-sec);
    margin-bottom: 8px;
}

.empty-msg {
    text-align: center;
    padding: 40px;
    color: var(--text-sec);
}

/* 正误判断题编辑器 - 双按钮选择 */
.tf-editor {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 15px;
}

.tf-btn {
    padding: 12px 24px;
    border-radius: 10px;
    border: 2px solid var(--border);
    background: var(--opt-bg);
    color: var(--text);
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: 0.15s;
}

.tf-btn:hover {
    border-color: var(--primary);
}

.tf-btn.selected-t {
    border-color: var(--success);
    background: var(--success-bg);
    color: #064e3b;
}

.tf-btn.selected-f {
    border-color: var(--error);
    background: var(--error-bg);
    color: #7f1d1d;
}

/* 选项行 - 编辑弹窗内单行选项 */
.opt-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.opt-row input[type="text"] {
    flex: 1;
}

.opt-row input[type="radio"],
.opt-row input[type="checkbox"] {
    accent-color: var(--primary);
}

.opt-row .btn-danger {
    padding: 6px 10px;
}

/* 统计行 - 编辑弹窗内统计字段 */
.stat-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.stat-row label {
    font-size: 0.85em;
    color: var(--text-sec);
}

.stat-row input {
    width: 80px;
}

/* ===================== 自定义弹窗组件 ===================== */

.select-item {
    padding: 12px 16px;
    border-radius: 10px;
    cursor: pointer;
    transition: 0.15s;
    margin-bottom: 6px;
    border: 1px solid var(--border);
    background: var(--opt-bg);
    font-weight: 500;
}

.select-item:hover {
    border-color: var(--primary);
    background: var(--opt-hover);
}

.select-item.select-active {
    border-color: var(--primary);
    background: var(--opt-hover);
    color: var(--primary);
    font-weight: 700;
}

.select-item.select-active::before {
    content: "✓ ";
}

/* ===================== 拖拽排序 ===================== */

.drag-handle {
    cursor: grab;
    color: var(--text-sec);
    font-size: 1.1em;
    padding: 4px 6px;
    user-select: none;
    -webkit-user-select: none;
    opacity: 0.4;
    transition: opacity 0.15s;
    touch-action: none;
}

.drag-handle:hover {
    opacity: 1;
}

.drag-handle:active {
    cursor: grabbing;
    opacity: 1;
}

@media (max-width: 768px) {
    .drag-handle {
        opacity: 0.7;
        padding: 8px 10px;
        margin: -8px -4px;
    }
}

.q-list-item.dragging {
    opacity: 0.4;
    border-style: dashed;
}

.q-list-item.drag-over-item {
    border-top: 3px solid var(--primary);
}

/* ===================== AI 徽章 ===================== */

.ai-title-wrap {
    flex: 1;
    display: flex;
    justify-content: center;
    overflow: visible;
}

.ai-badge {
    position: absolute;
    right: -32px;
    bottom: -15px;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 1px 8px;
    border-radius: 20px;
    background: linear-gradient(135deg, #60a5fa, #3b82f6, #38bdf8);
    color: #fff;
    font-size: 0.55em;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 8px rgba(59,130,246,0.35);
    transition: 0.2s;
    user-select: none;
    line-height: 1.6;
    z-index: 10;
}

.ai-badge:hover {
    background: linear-gradient(135deg, #3b82f6, #2563eb, #60a5fa);
    box-shadow: 0 4px 14px rgba(59,130,246,0.5);
    transform: translateY(-1px);
}

/* ===================== AI 提示词弹窗 ===================== */

.ai-modal {
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 28px;
    border-radius: 20px;
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(59,130,246,0.08), 0 0 0 1px rgba(59,130,246,0.06);
    border: 1px solid rgba(59,130,246,0.08);
    color: #1e293b;
}

.ai-modal h3 {
    color: #3b82f6;
}

.ai-intro-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.ai-intro-text {
    flex: 1;
    font-size: 0.88em;
    color: #64748b;
    line-height: 1.5;
}

.ai-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(59,130,246,0.12), transparent);
    margin-bottom: 16px;
}

.ai-prompt-text {
    background: rgba(59,130,246,0.03);
    border: 1px solid rgba(59,130,246,0.08);
    border-radius: 12px;
    padding: 16px;
    font-size: 0.92em;
    line-height: 2.2;
    color: #334155;
    margin-bottom: 16px;
    min-height: 60px;
}

.ai-seg {
    display: inline;
    background: rgba(59,130,246,0.07);
    border-radius: 4px;
    padding: 2px 6px;
}

.ai-seg-code {
    font-family: 'SF Mono', 'Consolas', 'Menlo', monospace;
    font-size: 0.88em;
    background: rgba(59,130,246,0.1);
    color: #1d4ed8;
}

.ai-seg-select {
    display: inline-block;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding: 2px 22px 2px 8px;
    border: none;
    border-radius: 4px;
    background-color: rgba(59,130,246,0.1);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='10' viewBox='0 0 8 10'%3E%3Cpath d='M1 3l3-2 3 2' fill='none' stroke='%233b82f6' stroke-width='1.3' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M1 7l3 2 3-2' fill='none' stroke='%233b82f6' stroke-width='1.3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    color: #1d4ed8;
    font-size: inherit;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-align: center;
    text-align-last: center;
    transition: 0.15s;
}

.ai-seg-select:hover {
    background-color: rgba(59,130,246,0.16);
}

.ai-seg-select:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

.ai-seg-select option {
    background: #fff;
    color: #334155;
    padding: 8px 16px;
    font-size: 0.92em;
    font-weight: 500;
    text-align: center;
}

.ai-toggles {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.ai-toggle-wrap {
    position: relative;
}

.ai-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 10px;
    border: 1px solid rgba(59,130,246,0.12);
    background: rgba(59,130,246,0.03);
    color: #2563eb;
    font-size: 0.88em;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}

.ai-toggle-btn:hover {
    border-color: rgba(59,130,246,0.3);
    background: rgba(59,130,246,0.07);
}

.ai-toggle-btn.active {
    border-color: rgba(34,197,94,0.35);
    background: rgba(34,197,94,0.05);
    color: #16a34a;
}

.ai-toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    font-size: 0.75em;
    font-weight: 700;
    transition: 0.2s;
}

.ai-toggle-btn.active .ai-toggle-icon {
    border-color: #22c55e;
    background: #22c55e;
    color: #fff;
}

.ai-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    width: 280px;
    background: rgba(255,255,255,0.97);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(59,130,246,0.1);
    border-radius: 14px;
    padding: 16px;
    box-shadow: 0 12px 32px rgba(59,130,246,0.08), 0 0 0 1px rgba(59,130,246,0.04);
    opacity: 0;
    visibility: hidden;
    transition: 0.2s;
    pointer-events: none;
    z-index: 10;
}

.ai-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: rgba(255,255,255,0.97);
}

.ai-toggle-wrap:hover .ai-tooltip {
    opacity: 1;
    visibility: visible;
}

.ai-tooltip-title {
    font-weight: 700;
    font-size: 0.88em;
    color: #2563eb;
    margin-bottom: 8px;
}

.ai-tooltip-body {
    font-size: 0.82em;
    color: #475569;
    line-height: 1.6;
}

.ai-tooltip-body code {
    background: rgba(59,130,246,0.06);
    color: #2563eb;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'SF Mono', 'Consolas', monospace;
}

.ai-copy-btn {
    padding: 7px 18px;
    border-radius: 8px;
    border: none;
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
    color: #fff;
    font-weight: 700;
    font-size: 0.85em;
    cursor: pointer;
    transition: 0.2s;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(59,130,246,0.2);
}

.ai-copy-btn:hover {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    box-shadow: 0 4px 14px rgba(59,130,246,0.3);
}

.ai-copy-btn:active {
    transform: scale(0.97);
}
