/* style.css — 响应式设计 */

:root {
    --bg: #f5f5f5;
    --surface: #ffffff;
    --text: #1a1a1a;
    --text-secondary: #666666;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --error: #dc2626;
    --warning: #d97706;
    --border: #e5e7eb;
    --border-focus: #2563eb;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', 'Noto Sans JP', 'Noto Sans TC', 'Noto Sans SC', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* 头部 */
header {
    text-align: center;
    padding: 30px 0 12px;
}

header h1 {
    font-size: 1.8em;
    font-weight: 700;
    margin-bottom: 6px;
}

header p {
    color: var(--text-secondary);
    font-size: 0.95em;
}

/* 顶部工具栏：模式切换 + 语言切换（sticky） */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 200;
    background: rgba(245, 245, 245, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.top-bar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 800px;
    margin: 0 auto;
    padding: 8px 20px;
}

.mode-toggle {
    display: flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.mode-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    background: transparent;
    font-size: 0.88em;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.mode-toggle-btn:not(:last-child) {
    border-right: 1px solid var(--border);
}

.mode-toggle-btn:hover {
    color: var(--text);
    background: rgba(37, 99, 235, 0.04);
}

.mode-toggle-btn.active {
    color: var(--primary);
    background: rgba(37, 99, 235, 0.08);
    font-weight: 600;
}

/* 语言切换：文A 悬停展开 */
.lang-switcher {
    position: relative;
}

.lang-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    cursor: pointer;
    font-size: 0.95em;
    line-height: 1;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.lang-trigger:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.10);
}

.mode-toggle-btn:focus-visible,
.lang-trigger:focus-visible,
.lang-option:focus-visible,
.tab-btn:focus-visible,
.btn:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.lang-icon-zh {
    font-weight: 700;
    font-size: 1em;
    color: var(--text);
}

.lang-icon-en {
    font-weight: 600;
    font-size: 0.82em;
    color: var(--text-secondary);
    margin-left: 1px;
}

.lang-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 130px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    padding: 4px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.15s, visibility 0.15s, transform 0.15s;
    z-index: 100;
}

.lang-switcher:hover .lang-menu,
.lang-switcher:focus-within .lang-menu,
.lang-switcher.open .lang-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.lang-option {
    display: block;
    width: 100%;
    padding: 8px 14px;
    border: none;
    background: transparent;
    text-align: left;
    font-size: 0.88em;
    color: var(--text);
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s;
}

.lang-option:hover {
    background: rgba(37, 99, 235, 0.06);
}

.lang-option.active {
    color: var(--primary);
    font-weight: 600;
    background: rgba(37, 99, 235, 0.08);
}

/* 标签切换 */
.tabs {
    display: flex;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    overflow: hidden;
}

.tab-btn {
    flex: 1;
    padding: 14px 20px;
    border: none;
    background: transparent;
    font-size: 1em;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.tab-btn:hover {
    color: var(--text);
    background: rgba(37, 99, 235, 0.04);
}

.tab-btn.active {
    color: var(--primary);
    background: rgba(37, 99, 235, 0.08);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 10%;
    width: 80%;
    height: 3px;
    background: var(--primary);
    border-radius: 3px 3px 0 0;
}

/* 面板 */
.panel {
    display: none;
}

.panel.active {
    display: block;
}

/* 卡片 */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 16px;
}

.card h2 {
    font-size: 1.2em;
    margin-bottom: 16px;
    font-weight: 600;
}

.card h3 {
    font-size: 1.05em;
    margin-bottom: 12px;
    font-weight: 600;
}

/* 表单元素 */
label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    font-size: 0.9em;
}

input[type="text"],
input[type="number"],
input[type="password"],
textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95em;
    font-family: inherit;
    transition: border-color 0.2s;
    background: var(--surface);
    color: var(--text);
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

.form-group {
    margin-bottom: 16px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
}

.form-hint {
    font-size: 0.82em;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* 问题列表 */
.question-item {
    background: var(--bg);
    border-radius: 6px;
    padding: 16px;
    margin-bottom: 12px;
    position: relative;
}

.question-item .question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.question-item .question-number {
    font-weight: 600;
    color: var(--primary);
    font-size: 0.9em;
}

.btn-remove {
    background: none;
    border: none;
    color: var(--error);
    cursor: pointer;
    font-size: 0.85em;
    padding: 4px 8px;
    border-radius: 4px;
}

.btn-remove:hover {
    background: rgba(220, 38, 38, 0.1);
}

/* 多答案 */
.answers-group .answers-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.answers-group .answer-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.answers-group .answer-row input {
    flex: 1;
}

.btn-remove-answer {
    background: none;
    border: none;
    color: var(--error);
    cursor: pointer;
    font-size: 0.82em;
    padding: 4px 6px;
    border-radius: 4px;
    white-space: nowrap;
}

.btn-remove-answer:hover {
    background: rgba(220, 38, 38, 0.1);
}

.btn.btn-add-answer {
    margin-top: 6px;
    padding: 4px 12px;
    font-size: 0.82em;
}

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

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

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

.btn-primary:disabled {
    background: #93c5fd;
    cursor: not-allowed;
}

.btn-secondary {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: rgba(37, 99, 235, 0.04);
    border-color: var(--primary);
}

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

.btn-success:hover {
    background: #15803d;
}

.btn-block {
    width: 100%;
}

.btn-group {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: wrap;
}

/* 进度 */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin: 12px 0;
}

.progress-bar .fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s;
}

.progress-text {
    font-size: 0.85em;
    color: var(--text-secondary);
    text-align: center;
}

/* 结果区域 */
.result-box {
    padding: 16px;
    border-radius: 6px;
    margin-top: 16px;
}

.result-box.success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
}

.result-box.error {
    background: #fef2f2;
    border: 1px solid #fecaca;
}

.result-box.info {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
}

.result-box.warning {
    background: #fffbeb;
    border: 1px solid #fed7aa;
}

.result-box .result-label {
    font-size: 0.85em;
    font-weight: 600;
    margin-bottom: 8px;
}

.result-box.success .result-label {
    color: var(--success);
}

.result-box.error .result-label {
    color: var(--error);
}

.result-box.warning .result-label {
    color: var(--warning);
}

.result-box .result-value {
    font-size: 1.3em;
    font-weight: 700;
    word-break: break-all;
    padding: 12px;
    background: white;
    border-radius: 4px;
    text-align: center;
    user-select: all;
}

/* 链接输出 */
.share-link {
    width: 100%;
    padding: 10px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 0.82em;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    word-break: break-all;
    resize: none;
    min-height: 60px;
}

.shard-link-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.shard-link-item {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(37, 99, 235, 0.03);
}

.shard-link-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.shard-label {
    min-width: 64px;
    font-size: 0.84em;
    font-weight: 600;
    color: var(--primary);
}

.shard-url-output {
    flex: 1;
    min-width: 0;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 0.8em;
    background: var(--bg);
}

.shard-share-link {
    min-height: 72px;
}

/* 求解页面 */
.solve-load-desc {
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-size: 0.9em;
}

.solve-load-note {
    margin-bottom: 8px;
}

.paste-link-area {
    margin-top: 12px;
}

.paste-link-input {
    min-height: 50px;
}

.paste-link-submit {
    margin-top: 8px;
}

.challenge-info {
    background: var(--bg);
    padding: 14px;
    border-radius: 6px;
    margin-bottom: 16px;
}

.challenge-info .info-title {
    font-weight: 600;
    font-size: 1.1em;
    margin-bottom: 4px;
}

.challenge-info .info-desc {
    color: var(--text-secondary);
    font-size: 0.9em;
    margin-bottom: 8px;
}

.challenge-info .info-meta {
    font-size: 0.82em;
    color: var(--text-secondary);
}

.solve-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.solve-question {
    margin-bottom: 16px;
}

.solve-question label {
    font-weight: 500;
    margin-bottom: 2px;
}

.solve-question .hint {
    font-size: 0.82em;
    color: var(--warning);
    margin-bottom: 6px;
}

.shard-merge-topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
}

.shard-merge-meta {
    font-size: 0.84em;
    color: var(--text-secondary);
}

.shard-merge-input {
    margin-bottom: 12px;
}

.shard-merge-input label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.shard-merge-input textarea {
    min-height: 72px;
    font-size: 0.85em;
}

.input-note {
    font-size: 0.78em;
    color: var(--text-secondary);
    font-weight: 400;
}

.shard-merge-intro {
    margin-top: 8px;
    font-size: 0.84em;
    color: var(--text-secondary);
}

.shard-success-glow {
    background: linear-gradient(135deg, #f0fdf4, #ecfeff);
    border: 1px solid #a7f3d0;
}

/* 加载文件按钮 */
.file-input-wrapper {
    position: relative;
    display: inline-block;
}

.file-input-wrapper input[type="file"] {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

/* 隐藏区域 */
.hidden {
    display: none !important;
}

/* Footer */
footer {
    text-align: center;
    padding: 30px 0;
    color: var(--text-secondary);
    font-size: 0.82em;
}

footer a {
    color: var(--primary);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* 响应式 */
@media (max-width: 600px) {
    .container {
        padding: 12px;
    }

    .top-bar-inner {
        padding: 6px 12px;
        flex-wrap: wrap;
        gap: 6px;
    }

    header {
        padding: 20px 0 8px;
    }

    header h1 {
        font-size: 1.4em;
    }

    .card {
        padding: 16px;
    }

    /* 防止 iOS Safari 输入框聚焦自动缩放 */
    input[type="text"],
    input[type="number"],
    input[type="password"],
    textarea,
    select {
        font-size: 16px;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .btn-group {
        flex-direction: column;
    }

    /* 顶栏模式切换 */
    .mode-toggle {
        border-radius: 8px;
    }

    .mode-toggle-btn {
        padding: 8px 10px;
        font-size: 0.82em;
    }

    /* 增大触摸目标 */
    .tab-btn {
        padding: 14px 10px;
        font-size: 0.9em;
    }

    .btn {
        min-height: 44px;
    }

    .btn-remove {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .btn-remove-answer {
        min-width: 40px;
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .lang-trigger {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .lang-option {
        padding: 12px 14px;
    }

    /* 分片链接区域 */
    .shard-link-item,
    .shard-merge-topbar,
    .shard-link-head {
        flex-direction: column;
        align-items: stretch;
    }

    .share-link,
    .shard-url-output {
        font-size: 0.88em;
    }

    .shard-share-link {
        min-height: 60px;
    }

    /* 分片合并标签 */
    .shard-merge-input label {
        flex-wrap: wrap;
    }

    /* 问题项间距 */
    .question-item {
        padding: 14px;
    }

    /* 结果区 */
    .result-box .result-value {
        font-size: 1.1em;
        padding: 10px;
    }
}

/* 暗色模式 */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #18181b;
        --surface: #27272a;
        --text: #e4e4e7;
        --text-secondary: #a1a1aa;
        --primary: #60a5fa;
        --primary-hover: #3b82f6;
        --success: #4ade80;
        --error: #f87171;
        --warning: #fbbf24;
        --border: #3f3f46;
        --border-focus: #60a5fa;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.4);
    }

    .top-bar {
        background: rgba(24, 24, 27, 0.85);
    }

    .question-item {
        background: #1f1f23;
    }

    .result-box.success {
        background: #052e16;
        border-color: #166534;
    }

    .result-box.error {
        background: #450a0a;
        border-color: #991b1b;
    }

    .result-box.info {
        background: #172554;
        border-color: #1e40af;
    }

    .result-box.warning {
        background: #451a03;
        border-color: #92400e;
    }

    .result-box .result-value {
        background: #18181b;
    }

    .btn-primary:disabled {
        background: #1e3a5f;
        color: #94a3b8;
    }

    .shard-success-glow {
        background: linear-gradient(135deg, #052e16, #042f2e);
        border-color: #166534;
    }

    .shard-link-item {
        background: rgba(96, 165, 250, 0.05);
    }

    .share-link,
    .shard-url-output {
        background: #1f1f23;
    }

    .challenge-info {
        background: #1f1f23;
    }
}

/* 极窄屏幕 (≤380px) */
@media (max-width: 380px) {
    .container {
        padding: 8px;
    }

    header h1 {
        font-size: 1.2em;
    }

    .card {
        padding: 12px;
    }

    .mode-toggle-btn {
        padding: 6px 8px;
        font-size: 0.78em;
    }

    .mode-toggle-btn span[aria-hidden] {
        display: none;
    }

    .tab-btn {
        font-size: 0.85em;
    }
}
