/* ==========================================================================
   base.css —— 变量 / 重置 / 通用组件
   电脑端与手机端共用；端差异请写在 desktop.css / mobile.css
   ========================================================================== */

:root {
    --accent: #2563eb;
    --accent-2: #7c3aed;
    --radius: 14px;

    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e5e9f2;
    --text: #111827;
    --text-dim: #6b7280;
    --text-faint: #9ca3af;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, .06);
    --ok: #10b981;
    --warn: #f59e0b;
    --danger: #ef4444;
    --ring: 0 0 0 3px rgba(37, 99, 235, .18);
    --gap: 16px;
}

[data-theme="dark"] {
    --bg: #0f1420;
    --surface: #161c2b;
    --surface-2: #1d2436;
    --border: #2a3348;
    --text: #e7ecf5;
    --text-dim: #9aa6bf;
    --text-faint: #6b7994;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .3);
    --ring: 0 0 0 3px rgba(99, 153, 255, .25);
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
}

h1, h2, h3, p, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
a { color: var(--accent); text-decoration: none; }
img, canvas { display: block; max-width: 100%; }

button, input, select, textarea {
    font: inherit;
    color: inherit;
}

/* ---------- 布局容器 ---------- */
.wrap {
    width: 100%;
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 16px;
}

.app-header {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
    padding: 18px 0;
    box-shadow: var(--shadow-sm);
}

.app-header .wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-logo {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: rgba(255, 255, 255, .2);
    display: grid;
    place-items: center;
    flex: none;
}

.brand-logo svg { width: 20px; height: 20px; }

.brand-title {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: .5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-sub {
    font-size: 12px;
    opacity: .85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-footer {
    padding: 24px 0 32px;
    color: var(--text-faint);
    font-size: 12px;
    text-align: center;
}

/* ---------- 卡片 ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 16px;
}

.card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 12px;
}

.card-title .step {
    width: 22px;
    height: 22px;
    border-radius: 7px;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    display: grid;
    place-items: center;
    flex: none;
}

.card-title .hint {
    margin-left: auto;
    font-size: 12px;
    font-weight: 400;
    color: var(--text-faint);
}

/* ---------- 表单 ---------- */
.field { display: block; }

.field > .label {
    display: block;
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 5px;
}

.input,
.select,
.textarea {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 9px 11px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.input:focus,
.select:focus,
.textarea:focus {
    border-color: var(--accent);
    box-shadow: var(--ring);
}

.textarea {
    min-height: 92px;
    resize: vertical;
    line-height: 1.7;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
    font-size: 14px;
}

.select { appearance: none; padding-right: 28px;
    background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                      linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
    background-position: right 13px center, right 8px center;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}

.grid-fields {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-fields .span-2 { grid-column: 1 / -1; }

/* ---------- 位置标尺 ---------- */
.ruler-box {
    margin-top: 10px;
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 10px;
    background: var(--surface-2);
}

.ruler-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.ruler-head .num {
    width: 62px;
    padding: 5px 7px;
    text-align: center;
}

.ruler {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    max-height: 156px;
    overflow: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
}

.ruler-item {
    min-width: 22px;
    height: 46px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 3px 2px;
    font-size: 11px;
    color: var(--text-faint);
    cursor: pointer;
    user-select: none;
    transition: background .12s, color .12s, border-color .12s;
}

.ruler-item .ch {
    font-size: 13px;
    color: var(--text);
    line-height: 1.2;
    max-width: 26px;
    overflow: hidden;
}

.ruler-item:hover { border-color: var(--accent); }

.ruler-item.in-range {
    background: rgba(37, 99, 235, .1);
    border-color: var(--accent);
    color: var(--accent);
}

.ruler-item.edge {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.ruler-item.edge .ch { color: #fff; }

.ruler-tip {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-faint);
}

.ruler-tip b { color: var(--accent); }

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 10px;
    padding: 9px 14px;
    font-size: 14px;
    cursor: pointer;
    transition: transform .08s, background .15s, border-color .15s, opacity .15s;
    user-select: none;
    white-space: nowrap;
}

.btn:active { transform: scale(.97); }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border-color: transparent;
    color: #fff;
    font-weight: 600;
}

.btn-primary:hover { color: #fff; filter: brightness(1.05); }

.btn-ghost { background: transparent; }

.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }

.btn-icon {
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 10px;
    font-size: 16px;
}

.btn-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

/* ---------- 预览实例 ---------- */
.preview-list { display: grid; gap: 8px; }

.preview-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 13px;
}

.preview-item .no {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    display: grid;
    place-items: center;
    flex: none;
}

.preview-item .txt {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    word-break: break-all;
    min-width: 0;
}

.preview-item .mk { color: var(--accent); font-weight: 700; }

.preview-empty {
    padding: 14px;
    text-align: center;
    color: var(--text-faint);
    font-size: 13px;
    border: 1px dashed var(--border);
    border-radius: 10px;
}

/* ---------- 二维码舞台 ---------- */
.qr-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.qr-frame {
    position: relative;
    width: 320px;
    max-width: 100%;
    aspect-ratio: 1 / 1;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: grid;
    place-items: center;
    overflow: hidden;
    padding: 10px;
}

.qr-frame::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: var(--radius);
    pointer-events: none;
}

.qr-slot {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
}

.qr-slot canvas, .qr-slot img {
    width: 100% !important;
    height: 100% !important;
    image-rendering: pixelated;
}

.qr-placeholder {
    text-align: center;
    color: var(--text-faint);
    font-size: 13px;
    padding: 20px;
}

.qr-placeholder .ico { font-size: 34px; opacity: .35; margin-bottom: 6px; }

.qr-caption {
    text-align: center;
    width: 100%;
}

.qr-index {
    display: inline-block;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 12px;
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.qr-text {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px;
    color: var(--text-dim);
    word-break: break-all;
    max-height: 56px;
    overflow: auto;
}

.progress {
    width: 100%;
    height: 5px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    overflow: hidden;
}

.progress > i {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    transition: width .25s ease;
}

/* ---------- 播放器 ---------- */
.player {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.player .seg {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-dim);
}

.player .seg .input { width: 64px; text-align: center; padding: 6px 8px; }

.switch {
    position: relative;
    width: 44px;
    height: 25px;
    border-radius: 999px;
    background: var(--border);
    border: none;
    cursor: pointer;
    transition: background .18s;
    flex: none;
}

.switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 19px;
    height: 19px;
    border-radius: 50%;
    background: #fff;
    box-shadow: var(--shadow-sm);
    transition: transform .18s;
}

.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(19px); }

/* ---------- 二级菜单网格 ---------- */
.grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

.grid-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: var(--shadow-sm);
}

.grid-item .thumb {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    display: grid;
    place-items: center;
    overflow: hidden;
    padding: 6px;
}

.grid-item .thumb canvas, .grid-item .thumb img {
    width: 100% !important;
    height: 100% !important;
    image-rendering: pixelated;
}

.grid-item .meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    font-size: 12px;
    color: var(--text-dim);
}

.grid-item .meta .no {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1px 6px;
    flex: none;
}

.grid-item .txt {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    color: var(--text-dim);
    word-break: break-all;
    max-height: 34px;
    overflow: hidden;
}

.grid-item .acts { display: flex; gap: 6px; }
.grid-item .acts .btn { flex: 1; padding: 5px 6px; font-size: 12px; }

.skeleton {
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
    background-size: 400% 100%;
    animation: sk 1.2s ease infinite;
    width: 100%;
    height: 100%;
    border-radius: 8px;
}

@keyframes sk {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* ---------- 提示条 ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translate(-50%, 20px);
    background: rgba(17, 24, 39, .93);
    color: #fff;
    padding: 9px 16px;
    border-radius: 999px;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    z-index: 99;
    max-width: 86vw;
    text-align: center;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-faint);
}

.empty-state .ico { font-size: 40px; opacity: .4; }
.empty-state h3 { font-size: 16px; margin: 10px 0 6px; color: var(--text-dim); }
.empty-state p { font-size: 13px; margin-bottom: 14px; }

.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 12px;
}

.toolbar .spacer { margin-left: auto; }

.badge {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 12px;
}

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.hide { display: none !important; }

/* ---------- 重复内容提示 ---------- */
.dup-tip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 12px;
    padding: 8px 12px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--warn) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
    color: var(--text);
    font-size: 13px;
}

.dup-tip b { color: var(--warn); }

/* ---------- 历史记录 ---------- */
.hist-date {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 4px 6px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.hist-item {
    display: grid;
    grid-template-columns: 22px 62px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
    margin-bottom: 8px;
    box-shadow: var(--shadow-sm);
}

.hist-item .thumb {
    width: 62px;
    height: 62px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    display: grid;
    place-items: center;
    overflow: hidden;
    padding: 3px;
}

.hist-item .thumb canvas, .hist-item .thumb img {
    width: 100% !important;
    height: 100% !important;
    image-rendering: pixelated;
}

.hist-item .txt { min-width: 0; font-size: 13px; }
.hist-item .txt .mono { word-break: break-all; }
.hist-item .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.hist-check { width: 17px; height: 17px; accent-color: var(--accent); }

/* ---------- A4 打印排版 ---------- */
#print-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10mm;
    padding: 4mm 0 14mm;
}

.page {
    width: calc(210mm - 2 * var(--p-margin, 12mm));
    min-height: calc(297mm - 2 * var(--p-margin, 12mm));
    background: #fff;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: grid;
    grid-template-columns: repeat(var(--p-cols, 4), 1fr);
    align-content: start;
}

.sticker {
    height: calc((297mm - 2 * var(--p-margin, 12mm)) / var(--p-rows, 8));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1mm;
    padding: 1mm;
    border: 1px dashed #d8dde8;
    overflow: hidden;
    box-sizing: border-box;
}

.sticker .thumb {
    width: var(--p-qr, 38mm);
    height: var(--p-qr, 38mm);
    display: grid;
    place-items: center;
    overflow: hidden;
}

.sticker .thumb canvas, .sticker .thumb img {
    width: 100% !important;
    height: 100% !important;
    image-rendering: pixelated;
}

.sticker .label {
    font-size: var(--p-font, 9pt);
    line-height: 1.2;
    text-align: center;
    word-break: break-all;
    max-height: 2.4em;
    overflow: hidden;
    color: #111827;
}

@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
    #print-stage { display: block; padding: 0; gap: 0; }
    .page { border: none; box-shadow: none; page-break-after: always; break-after: page; }
    @page { size: A4; margin: var(--p-margin, 12mm); }
}

/* ---------- 无障碍与降级 ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
