:root {
    --bg: #faf6f9; --surface: #ffffff; --surface-2: #fdf2f8; --surface-3: #fce7f3;
    --border: #fbcfe8; --border-strong: #f9a8d4;
    --text: #1f2937; --text-dim: #4b5563; --text-faint: #9ca3af;
    --accent: #ec4899; --accent-hover: #db2777; --accent-soft: #fce7f3;
    --danger: #dc2626;
    --shadow: 0 1px 3px rgba(236,72,153,0.08);
    --shadow-lg: 0 8px 30px rgba(236,72,153,0.12);
    --peek: 40px; --gap: 20px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
    font-size: 14px; -webkit-font-smoothing: antialiased; }

.niri-app { height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.niri-header { flex-shrink: 0; display: flex; align-items: center; gap: 24px; padding: 12px 24px;
    background: var(--surface); border-bottom: 1px solid var(--border); z-index: 10; box-shadow: var(--shadow); }
.niri-brand { font-size: 0.95rem; font-weight: 700; color: var(--accent); letter-spacing: 0.5px; }
.niri-tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 10px; border: 1px solid var(--border); }
.niri-tab { padding: 6px 16px; border: none; background: transparent; color: var(--text-dim); border-radius: 7px;
    cursor: pointer; font-size: 0.82rem; font-family: inherit; transition: all 0.2s; white-space: nowrap; font-weight: 500; }
.niri-tab:hover { color: var(--accent); }
.niri-tab.active { background: var(--accent); color: #fff; box-shadow: 0 2px 6px rgba(236,72,153,0.3); }
.niri-viewport { flex: 1; position: relative; overflow: hidden; min-height: 0; }
.niri-track { display: flex; height: 100%; transition: transform 0.55s cubic-bezier(0.22, 1, 0.36, 1); will-change: transform; }
.niri-column { flex-shrink: 0; height: 100%; border-radius: 14px; background: var(--surface);
    border: 1px solid var(--border); overflow: hidden; transition: opacity 0.45s, filter 0.45s, border-color 0.45s, box-shadow 0.45s;
    opacity: 0.55; filter: saturate(0.4) brightness(0.97); cursor: pointer; }
.niri-column.active { opacity: 1; filter: none; border-color: var(--border-strong); box-shadow: var(--shadow-lg); cursor: auto; }
.niri-column-inner { height: 100%; overflow-y: auto; overflow-x: hidden; padding: 20px; }
.niri-column-inner::-webkit-scrollbar { width: 6px; }
.niri-column-inner::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.section-title { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-faint);
    margin: 0 0 10px 0; font-weight: 600; }
.field-label { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--text-faint); margin-bottom: 6px; font-weight: 600; }
.input, .select { width: 100%; padding: 8px 12px; background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text); font-size: 0.88rem; font-family: inherit;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s; outline: none; }
.input:focus, .select:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px rgba(236,72,153,0.12); }
.row { display: flex; gap: 12px; }
.col { flex: 1; min-width: 0; }
.btn { padding: 8px 16px; border-radius: 8px; border: 1px solid transparent; font-size: 0.85rem;
    font-family: inherit; cursor: pointer; transition: all 0.15s; white-space: nowrap; font-weight: 600; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: var(--surface); color: var(--text-dim); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--accent); border-color: var(--border-strong); }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.hint { font-size: 0.75rem; color: var(--text-faint); margin-top: 4px; }

.weapon-preview { display: flex; align-items: center; gap: 16px; padding: 12px; background: var(--surface-2);
    border-radius: 10px; border: 1px solid var(--border); }
.weapon-preview img { max-height: 72px; max-width: 120px; object-fit: contain; border-radius: 6px; background: #fff; padding: 4px; }
.weapon-preview .name { font-size: 1.05rem; font-weight: 600; margin-bottom: 4px; }
.weapon-preview .meta { font-size: 0.78rem; color: var(--text-dim); }

.stat-row { padding: 7px 10px; margin: 3px 0; border-radius: 6px; background: var(--surface-2);
    font-size: 0.85rem; line-height: 1.6; }
.stat-row:hover { background: var(--surface-3); }
.stat-row .value { font-family: "SF Mono", "Consolas", monospace; font-weight: 700;
    color: var(--accent); font-size: 0.85rem; white-space: nowrap; }
.stat-row.negative .value { color: var(--danger); }
.stat-row.incompatible { opacity: 0.45; }
.stat-row img, .stat-icon { height: 1.05em; width: auto; vertical-align: -0.18em; margin: 0 2px; display: inline-block; }

.roll-controls { display: flex; gap: 8px; margin-bottom: 16px; }
.roll-result { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
    padding: 14px; margin-bottom: 16px; }
.roll-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;
    padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.roll-badge { font-size: 0.72rem; padding: 3px 10px; border-radius: 5px; background: var(--accent-soft);
    color: var(--accent-hover); font-weight: 700; }
.roll-time { font-size: 0.7rem; color: var(--text-faint); font-family: monospace; }
.roll-history-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
    padding: 10px 12px; margin-bottom: 8px; font-size: 0.82rem; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-faint); font-size: 0.85rem; }

.count-btn-group { display: flex; gap: 6px; flex-wrap: wrap; }
.count-btn { padding: 7px 12px; background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 8px; cursor: pointer; font-size: 0.82rem; color: var(--text-dim);
    font-family: inherit; font-weight: 600; transition: all 0.15s; }
.count-btn:hover { border-color: var(--accent); color: var(--accent); }
.count-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.chip-pool { display: flex; flex-wrap: wrap; gap: 5px; padding: 8px;
    background: var(--surface-2); border-radius: 8px; border: 1px solid var(--border);
    max-height: 260px; overflow-y: auto; }
.chip { padding: 4px 10px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; cursor: pointer; font-size: 0.78rem; color: var(--text); transition: all 0.15s; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.selected { background: var(--accent); color: #fff; border-color: var(--accent); }

.progress-bar { width: 100%; height: 6px; background: var(--surface-2); border-radius: 3px;
    overflow: hidden; margin-top: 10px; display: none; }
.progress-bar-fill { height: 100%; background: var(--accent); transition: width 0.1s; width: 0%; }

.sim-card { padding: 14px; background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 10px; margin-bottom: 12px; }
.sim-stat { display: flex; justify-content: space-between; padding: 3px 0; font-size: 0.82rem; }
.sim-stat .label { color: var(--text-dim); }
.sim-stat .value { font-weight: 600; font-family: monospace; }
.sim-note { padding: 10px 12px; background: var(--accent-soft); border-radius: 8px;
    font-size: 0.82rem; margin-top: 10px; }

#loading-overlay { position: fixed; inset: 0; background: var(--bg); display: flex;
    flex-direction: column; align-items: center; justify-content: center; z-index: 1000; gap: 16px; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   移动端适配
   ============================================================ */
@media (max-width: 700px) {
    html, body { font-size: 13px; }

    /* 头部 */
    .niri-header {
        padding: 8px 10px;
        gap: 8px;
    }
    .niri-brand { font-size: 0.8rem; flex-shrink: 0; }
    .niri-tabs { flex: 1; padding: 2px; gap: 1px; }
    .niri-tab {
        padding: 6px 4px;
        font-size: 0.72rem;
        flex: 1;
        text-align: center;
        letter-spacing: -0.3px;
    }

    /* 列（去掉圆角，全宽） */
    .niri-column {
        border-radius: 0 !important;
        border-left: none;
        border-right: none;
    }
    .niri-column-inner {
        padding: 14px 12px 60px;
    }

    /* 表单 */
    .section-title { font-size: 0.68rem; margin-bottom: 8px; letter-spacing: 0.5px; }
    .field-label { font-size: 0.68rem; margin-bottom: 4px; letter-spacing: 0.3px; }
    .input, .select {
        font-size: 16px;             /* 防止 iOS 自动缩放 */
        padding: 9px 10px;
        border-radius: 8px;
    }
    .hint { font-size: 0.68rem; }

    /* 表单行改为纵向堆叠 */
    .row { flex-direction: column; gap: 10px; }
    .col { width: 100%; }

    /* 武器预览改为竖向 */
    .weapon-preview {
        flex-direction: column;
        text-align: center;
        gap: 8px;
        padding: 10px;
    }
    .weapon-preview img { max-height: 56px; max-width: 100px; }
    .weapon-preview .name { font-size: 0.95rem; margin-bottom: 2px; }
    .weapon-preview .meta { font-size: 0.72rem; }

    /* 词条列表 */
    .stat-row {
        padding: 6px 8px;
        font-size: 0.78rem;
        margin: 2px 0;
        line-height: 1.5;
    }
    .stat-row .value { font-size: 0.78rem; }
    .stat-row img, .stat-icon { height: 1em; }

    /* 按钮 */
    .btn { font-size: 0.8rem; padding: 9px 12px; }
    .roll-controls { gap: 6px; flex-wrap: wrap; }
    .roll-controls .btn { flex: 1; min-width: 0; }
    .roll-controls .btn-primary { flex: 2; }

    /* 抽取结果 */
    .roll-result { padding: 10px; margin-bottom: 12px; }
    .roll-header { margin-bottom: 8px; padding-bottom: 6px; }
    .roll-badge { font-size: 0.68rem; padding: 2px 8px; }
    .roll-time { font-size: 0.65rem; }
    .roll-history-item { padding: 8px 10px; margin-bottom: 6px; }

    /* 目标数量按钮：2x2 网格 */
    .count-btn-group {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    .count-btn {
        padding: 9px 4px;
        text-align: center;
        font-size: 0.76rem;
    }

    /* Chip 池 */
    .chip-pool { padding: 6px; gap: 4px; max-height: 200px; }
    .chip {
        padding: 5px 9px;
        font-size: 0.72rem;
        border-radius: 10px;
    }

    /* 模拟结果 */
    .sim-card { padding: 10px; margin-bottom: 8px; border-radius: 8px; }
    .sim-stat { font-size: 0.76rem; padding: 2px 0; }
    .sim-stat .label { font-size: 0.72rem; }
    .sim-stat .value { font-size: 0.76rem; }
    .sim-note { padding: 8px 10px; font-size: 0.74rem; line-height: 1.5; border-radius: 6px; }

    /* 进度条 */
    .progress-bar { height: 5px; }

    /* 分隔 */
    .divider { margin: 12px 0; }
    .empty-state { padding: 28px 16px; font-size: 0.8rem; }
}

/* 超窄手机（iPhone SE 等） */
@media (max-width: 380px) {
    .niri-brand { font-size: 0.72rem; }
    .niri-tab { font-size: 0.68rem; padding: 5px 2px; }
    .niri-column-inner { padding: 12px 10px 60px; }
    .stat-row { font-size: 0.74rem; }
    .stat-row .value { font-size: 0.74rem; }
}