/* 工作室界面样式（不影响导出的图片，图片样式在 pages.css） */

:root {
    --ui-bg: #f4f3f1;
    --ui-panel: #ffffff;
    --ui-sunken: #f7f6f4;
    --ui-line: #e6e3de;
    --ui-line-strong: #d6d2cb;
    --ui-text: #1f1d1a;
    --ui-muted: #85807a;
    --ui-brand: #ff2442;
    --ui-brand-ink: #ffffff;
    --ui-brand-soft: #fff0f2;
    --ui-focus: rgba(255, 36, 66, 0.28);
    --ui-shadow: 0 1px 2px rgba(30, 20, 10, 0.06), 0 8px 24px -12px rgba(30, 20, 10, 0.18);
    --ui-dots: rgba(0, 0, 0, 0.07);
    --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "WenQuanYi Zen Hei", sans-serif;
    --ui-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, "PingFang SC", "Microsoft YaHei", monospace;
    --topbar-h: 60px;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --ui-bg: #151514;
    --ui-panel: #1e1d1c;
    --ui-sunken: #191817;
    --ui-line: #2f2d2b;
    --ui-line-strong: #3d3a37;
    --ui-text: #ecebe8;
    --ui-muted: #9a958e;
    --ui-brand: #ff4d64;
    --ui-brand-soft: #3a1f24;
    --ui-focus: rgba(255, 77, 100, 0.35);
    --ui-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
    --ui-dots: rgba(255, 255, 255, 0.06);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
}

body {
    background: var(--ui-bg);
    color: var(--ui-text);
    font: 14px/1.5 var(--ui-font);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

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

button {
    cursor: pointer;
}

[hidden] {
    display: none !important;
}

.muted { color: var(--ui-muted); }
.small { font-size: 12px; }
.grow { flex: 1; }

.i {
    width: 18px;
    height: 18px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ------------------------------------------------------------------ 按钮 */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px;
    border-radius: 10px;
    border: 1px solid var(--ui-line);
    background: var(--ui-panel);
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn:hover { border-color: var(--ui-line-strong); background: var(--ui-sunken); }
.btn:active { transform: translateY(1px); }

.btn.ghost {
    border-color: transparent;
    background: transparent;
}

.btn.ghost:hover { background: var(--ui-sunken); }

.btn.icon {
    width: 36px;
    padding: 0;
}

.btn.primary {
    background: var(--ui-brand);
    border-color: var(--ui-brand);
    color: var(--ui-brand-ink);
    font-weight: 600;
}

.btn.primary:hover { filter: brightness(1.06); background: var(--ui-brand); }

.btn.small {
    height: 30px;
    padding: 0 10px;
    font-size: 13px;
    border-radius: 8px;
}

:focus-visible {
    outline: 3px solid var(--ui-focus);
    outline-offset: 1px;
}

/* 分段选择器 */
.seg {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    border-radius: 10px;
    background: var(--ui-sunken);
    border: 1px solid var(--ui-line);
}

.seg button {
    border: 0;
    background: transparent;
    border-radius: 7px;
    padding: 5px 12px;
    color: var(--ui-muted);
    white-space: nowrap;
}

.seg button.on {
    background: var(--ui-panel);
    color: var(--ui-text);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.seg.full {
    display: flex;
}

.seg.full button {
    flex: 1;
    padding: 6px 4px;
}

/* 下拉菜单 */
.dropdown {
    position: relative;
    display: inline-flex;
}

.menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 50;
    min-width: 220px;
    padding: 6px;
    border-radius: 12px;
    background: var(--ui-panel);
    border: 1px solid var(--ui-line);
    box-shadow: var(--ui-shadow);
    display: flex;
    flex-direction: column;
}

.menu.right { left: auto; right: 0; }

.menu > button,
.menu .item {
    display: flex;
    align-items: center;
    gap: 8px;
    text-align: left;
    border: 0;
    background: transparent;
    padding: 8px 10px;
    border-radius: 8px;
}

.menu > button:hover,
.menu .item:hover { background: var(--ui-sunken); }

.menu .item.on { background: var(--ui-brand-soft); }

.menu .item .t {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.menu .item .d { font-size: 12px; color: var(--ui-muted); }

.menu .item .x {
    border: 0;
    background: none;
    color: var(--ui-muted);
    padding: 2px 6px;
    border-radius: 6px;
}

.menu .item .x:hover { background: var(--ui-line); color: var(--ui-text); }

.menu hr {
    border: 0;
    border-top: 1px solid var(--ui-line);
    margin: 6px 4px;
}

.menu .label {
    padding: 4px 10px;
    font-size: 12px;
    color: var(--ui-muted);
}

/* ------------------------------------------------------------------ 顶栏 */

.app {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-h);
    flex: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    background: var(--ui-panel);
    border-bottom: 1px solid var(--ui-line);
    position: relative;
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-right: 6px;
}

.logo {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--ui-brand);
    position: relative;
    flex: none;
    box-shadow: 0 4px 12px -4px rgba(255, 36, 66, 0.6);
}

.logo::before {
    content: "";
    position: absolute;
    inset: 7px 9px;
    border-radius: 3px;
    background:
        linear-gradient(var(--ui-brand), var(--ui-brand)) 4px 5px / 9px 2.5px no-repeat,
        linear-gradient(#ffb3be, #ffb3be) 4px 10px / 9px 2px no-repeat,
        linear-gradient(#ffb3be, #ffb3be) 4px 14px / 6px 2px no-repeat,
        #fff;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-text b { font-size: 15px; }
.brand-text small { color: var(--ui-muted); font-size: 11px; }

#draftBtn {
    max-width: 260px;
}

#draftTitle {
    overflow: hidden;
    text-overflow: ellipsis;
}

.caret { width: 14px; height: 14px; }

.export-group .btn.primary:first-child {
    border-radius: 10px 0 0 10px;
}

.export-group .btn.more {
    border-radius: 0 10px 10px 0;
    width: 32px;
    padding: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.35);
}

#settingsToggle { display: none; }

/* ------------------------------------------------------------------ 三栏布局 */

.workspace {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(340px, 1fr) minmax(400px, 1.4fr) 320px;
}

.pane {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* 编辑区 */
.editor-pane {
    background: var(--ui-panel);
    border-right: 1px solid var(--ui-line);
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--ui-line);
}

.toolbar button {
    height: 32px;
    min-width: 32px;
    padding: 0 7px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ui-text);
    font-size: 13px;
    white-space: nowrap;
    flex: none;
}

.toolbar button:hover { background: var(--ui-sunken); }

.toolbar .sep {
    width: 1px;
    height: 18px;
    background: var(--ui-line);
    margin: 0 4px;
}

.toolbar .mark-btn {
    background: linear-gradient(transparent 55%, rgba(255, 210, 0, 0.6) 55%) center / 70% 100% no-repeat;
}

.color-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: conic-gradient(#ff4757, #ffa502, #2ed573, #1e90ff, #a55eea, #ff4757);
}

.color-menu {
    min-width: 0;
    flex-direction: row;
    flex-wrap: wrap;
    width: 184px;
    gap: 6px;
    padding: 10px;
}

.color-menu button {
    width: 28px;
    height: 28px;
    min-width: 0;
    padding: 0;
    border-radius: 50%;
    border: 2px solid var(--ui-panel);
    box-shadow: 0 0 0 1px var(--ui-line);
}

.color-menu button:hover { transform: scale(1.1); background-color: inherit; }

.help-btn {
    font-weight: 700;
    border: 1px solid var(--ui-line) !important;
    border-radius: 50% !important;
    width: 28px;
    min-width: 28px !important;
    height: 28px !important;
}

#editor {
    flex: 1;
    min-height: 0;
    width: 100%;
    resize: none;
    border: 0;
    outline: none;
    padding: 20px 22px 40px;
    background: transparent;
    font: 15px/1.85 var(--ui-mono);
    tab-size: 2;
}

#editor::placeholder { color: var(--ui-muted); }

#editor.dragover {
    background: var(--ui-brand-soft);
    box-shadow: inset 0 0 0 2px var(--ui-brand);
}

.statusbar {
    flex: none;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 16px;
    font-size: 12px;
    border-top: 1px solid var(--ui-line);
    color: var(--ui-muted);
}

#stats .warn { color: #d9480f; }

/* 长文 / 自由排版 两种模式 */
body.mode-free .long-only,
body:not(.mode-free) .free-only { display: none !important; }

.mode-seg button { padding: 5px 10px; }

/* 自由排版的素材栏 */
.free-panel {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 18px 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.free-panel h4 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 10px 0 0;
    font-size: 13px;
    color: var(--ui-muted);
    font-weight: 600;
}

.fp-title {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    color: var(--ui-muted);
}

.fp-title input {
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--ui-line);
    border-radius: 10px;
    background: var(--ui-sunken);
    color: var(--ui-text);
    font: inherit;
}

.fp-add {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.fp-add button,
.fp-lines button,
.fp-decos button {
    border: 1px solid var(--ui-line);
    background: var(--ui-panel);
    border-radius: 12px;
    color: var(--ui-text);
    transition: border-color 0.15s, transform 0.15s;
}

.fp-add button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 6px 10px;
    font-size: 13px;
}

.fp-add .i { width: 22px; height: 22px; }

.fp-lines {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
}

.fp-lines button { height: 38px; display: grid; place-items: center; }

.fp-add button:hover,
.fp-lines button:hover,
.fp-decos button:hover { border-color: var(--ui-brand); }

.fp-decos {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 6px;
}

.fp-decos button {
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    padding: 8px;
    background: var(--ui-sunken);
}

.fp-decos button:hover { transform: translateY(-1px) rotate(-2deg); }

/* 素材栏里的预览：借用页面里的贴纸样式，但不绝对定位 */
.fp-decos .stk.deco-prev {
    position: static;
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
}

.fp-decos .deco-prev .stk-in {
    width: 100%;
    height: auto;
    max-height: 48px;
    display: block;
    object-fit: contain;
    transform: none;
}

.fp-decos .deco-prev .sticky-note { width: 42px; }

.fp-decos .fp-pack {
    grid-column: 1 / -1;
    margin-top: 4px;
    font-size: 12px;
    color: var(--ui-muted);
}

.fp-pages {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.fp-page {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 6px 6px 10px;
    border: 1px solid var(--ui-line);
    border-radius: 10px;
    font-size: 12px;
    cursor: pointer;
}

.fp-page.on { border-color: var(--ui-brand); box-shadow: 0 0 0 2px var(--ui-focus); }
.fp-page b { width: 22px; font-size: 14px; }
.fp-page span { flex: 1; color: var(--ui-muted); }

.fp-page button {
    border: 0;
    background: transparent;
    color: var(--ui-muted);
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 12px;
}

.fp-page button:hover:not(:disabled) { background: var(--ui-sunken); color: var(--ui-text); }
.fp-page button:disabled { opacity: 0.3; }

.fp-tip {
    margin: 6px 0 0;
    font-size: 12px;
    line-height: 1.6;
    color: var(--ui-muted);
}

/* 画布缩略图：把真实页面缩小显示 */
.canvas-card .sw .pg {
    --pw: 540px;
    --ph: 360px;
    position: absolute;
    left: 0;
    top: 0;
    transform: scale(0.2);
    transform-origin: 0 0;
}

/* 预览区 */
.preview-pane {
    background-color: var(--ui-bg);
    background-image: radial-gradient(var(--ui-dots) 1px, transparent 1.2px);
    background-size: 18px 18px;
}

.preview-head {
    flex: none;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 20px;
    font-size: 13px;
}

#pageInfo { flex: 1; white-space: nowrap; }

.zoom {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--ui-muted);
}

.zoom input { width: 110px; }

.grid {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 6px 24px 40px;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    justify-content: center;
    gap: 28px 24px;
}

.thumb {
    position: relative;
    flex: none;
    cursor: pointer;
}

.thumb-frame {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 12px 30px -14px rgba(0, 0, 0, 0.35);
    transition: box-shadow 0.2s, transform 0.2s;
}

.thumb-frame > .pg {
    transform-origin: 0 0;
}

.thumb:hover .thumb-frame { transform: translateY(-2px); }

.thumb.sel .thumb-frame {
    box-shadow: 0 0 0 3px var(--ui-brand), 0 12px 30px -14px rgba(0, 0, 0, 0.35);
}

.thumb.caret-here::after {
    content: "";
    position: absolute;
    left: -12px;
    top: 12px;
    bottom: 12px;
    width: 4px;
    border-radius: 2px;
    background: var(--ui-brand);
    opacity: 0.8;
}

.thumb-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 12px;
    color: var(--ui-muted);
}

.thumb-bar button {
    border: 0;
    background: transparent;
    color: var(--ui-muted);
    padding: 2px 6px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.15s;
}

.thumb:hover .thumb-bar button,
.thumb.sel .thumb-bar button { opacity: 1; }
.thumb-bar button:hover { background: var(--ui-panel); color: var(--ui-text); }
.thumb-bar .i { width: 14px; height: 14px; }

/* 贴纸菜单 */
.sticker-menu {
    width: 340px;
    max-width: calc(100vw - 24px);
}

.emoji-tabs {
    display: flex;
    gap: 2px;
    padding: 2px 2px 6px;
    border-bottom: 1px solid var(--ui-line);
    overflow-x: auto;
    scrollbar-width: none;
}

.emoji-tabs button {
    flex: 1 0 auto;
    border: 0;
    background: transparent;
    font-size: 17px;
    line-height: 1;
    padding: 6px 4px;
    border-radius: 8px;
    opacity: 0.5;
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

.emoji-tabs button.on { opacity: 1; background: var(--ui-sunken); }

.emoji-grid {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    overscroll-behavior: contain;
    scroll-snap-type: x proximity;
    padding: 6px 4px 8px;
    scrollbar-width: thin;
}

.emoji-cat {
    flex: none;
    scroll-snap-align: start;
}

.cat-name {
    font-size: 11px;
    color: var(--ui-muted);
    padding: 0 4px 4px;
    position: sticky;
    left: 0;
}

.cat-grid {
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: repeat(4, 38px);
    grid-auto-columns: 38px;
}

.cat-grid button {
    border: 0;
    background: transparent;
    font-size: 24px;
    line-height: 1;
    padding: 0;
    border-radius: 8px;
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
    transition: transform 0.1s;
}

.cat-grid button:hover { background: var(--ui-sunken); transform: scale(1.18); }

.sticker-menu .check {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px 6px;
    font-size: 12px;
    color: var(--ui-muted);
}

.line-menu { width: 220px; }
.line-menu .tip { font-size: 12px; line-height: 1.5; white-space: normal; }

.sticker-menu .tip {
    font-size: 12px;
    line-height: 1.5;
    white-space: normal;
}

/* 预览里可以直接拖动的贴纸和图片 */
#grid .stk {
    pointer-events: auto;
    cursor: move;
    touch-action: none;
}

#grid .fig { position: relative; }
#grid .fig img { cursor: pointer; }

#grid .sel-obj {
    outline: calc(2px * var(--inv, 3)) dashed var(--ui-brand);
    outline-offset: calc(3px * var(--inv, 3));
}

.obj-h {
    position: absolute;
    width: calc(16px * var(--inv, 3));
    height: calc(16px * var(--inv, 3));
    border-radius: 50%;
    background: #fff;
    border: calc(2px * var(--inv, 3)) solid var(--ui-brand);
    box-shadow: 0 0 0 calc(1px * var(--inv, 3)) rgba(0, 0, 0, 0.15);
    pointer-events: auto;
    touch-action: none;
    z-index: 2;
}

.obj-h.h-size {
    right: 0;
    bottom: 0;
    transform: translate(50%, 50%);
    cursor: nwse-resize;
}

.obj-h.h-rot {
    left: 50%;
    top: calc(-30px * var(--inv, 3));
    transform: translateX(-50%);
    cursor: grab;
}

.obj-h.h-rot::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 100%;
    width: calc(2px * var(--inv, 3));
    height: calc(12px * var(--inv, 3));
    background: var(--ui-brand);
    transform: translateX(-50%);
}

.obj-h.h-end {
    top: 50%;
    cursor: crosshair;
}

.obj-h.h-end.e0 { left: 0; transform: translate(-50%, -50%); }
.obj-h.h-end.e1 { right: 0; transform: translate(50%, -50%); }

#grid .stk.editing,
#grid .stk.editing * {
    cursor: text;
    user-select: text;
    -webkit-user-select: text;
}

#grid .stk.editing [contenteditable] {
    outline: none;
    caret-color: var(--ui-brand);
}

.obj-h.h-img {
    transform: translate(-50%, -50%);
    cursor: nwse-resize;
}

.obj-h.h-img.left { cursor: nesw-resize; }

body.dragging,
body.dragging * {
    user-select: none;
    cursor: grabbing !important;
}

/* 选中对象时的浮动工具条 */
.objbar {
    position: fixed;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px;
    border-radius: 12px;
    background: var(--ui-panel);
    border: 1px solid var(--ui-line);
    box-shadow: var(--ui-shadow);
    font-size: 12px;
    white-space: nowrap;
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 4px;
    max-width: min(600px, calc(100vw - 16px));
}

.objbar button,
.objbar select {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    height: 30px;
    padding: 0 8px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ui-text);
    font-size: 12px;
}

.objbar select { border: 1px solid var(--ui-line); background: var(--ui-panel); }
.objbar button:hover:not(:disabled) { background: var(--ui-sunken); }
.objbar button.on { background: var(--ui-brand-soft); color: var(--ui-brand); }
.objbar button:disabled { opacity: 0.35; cursor: default; }
.objbar .i { width: 16px; height: 16px; }
.objbar .sep { width: 1px; height: 18px; background: var(--ui-line); margin: 0 3px; }
.objbar .pct { min-width: 40px; text-align: center; color: var(--ui-muted); font-variant-numeric: tabular-nums; }
.objbar .cut-range input { width: 80px; vertical-align: middle; }
.objbar .colors { display: inline-flex; align-items: center; gap: 3px; padding: 0 2px; }
.objbar button.dot {
    width: 20px;
    height: 20px;
    padding: 0;
    border-radius: 50%;
    background: var(--c);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
    justify-content: center;
    font-size: 0;
}
.objbar button.dot:first-child { width: auto; padding: 0 7px; border-radius: 10px; font-size: 11px; color: #fff; }
.objbar button.dot:hover:not(:disabled) { background: var(--c); filter: brightness(1.08); }
.objbar button.dot.on { box-shadow: 0 0 0 2px var(--ui-panel), 0 0 0 4px var(--ui-brand); }

/* 设置区 */
.settings-pane {
    background: var(--ui-panel);
    border-left: 1px solid var(--ui-line);
    overflow-y: auto;
    padding: 4px 18px 40px;
}

.settings-close {
    display: none;
}

.group {
    padding: 16px 0;
    border-bottom: 1px solid var(--ui-line);
}

.group:last-child { border-bottom: 0; }

.group h3 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 12px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--ui-muted);
}

.row output {
    float: right;
    color: var(--ui-text);
    font-variant-numeric: tabular-nums;
}

.row.inline {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.row input[type="text"],
.row textarea,
.row select {
    width: 100%;
    padding: 8px 10px;
    border-radius: 9px;
    border: 1px solid var(--ui-line);
    background: var(--ui-sunken);
    color: var(--ui-text);
    outline: none;
}

.row.inline select { width: 170px; }

.row textarea {
    resize: vertical;
    min-height: 58px;
    line-height: 1.5;
}

.row input:focus,
.row textarea:focus,
.row select:focus {
    border-color: var(--ui-brand);
    box-shadow: 0 0 0 3px var(--ui-focus);
}

input[type="range"] {
    width: 100%;
    accent-color: var(--ui-brand);
}

/* 开关 */
.switch input {
    appearance: none;
    -webkit-appearance: none;
    width: 38px;
    height: 22px;
    border-radius: 11px;
    background: var(--ui-line-strong);
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
    margin: 0;
    flex: none;
}

.switch input::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s;
}

.switch input:checked { background: var(--ui-brand); }
.switch input:checked::after { transform: translateX(16px); }

/* 主题卡片 */
.themes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.theme-card {
    border: 1px solid var(--ui-line);
    border-radius: 12px;
    background: var(--ui-panel);
    padding: 6px 6px 7px;
    text-align: center;
    font-size: 12px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.theme-card:hover { border-color: var(--ui-line-strong); }

.theme-card.on {
    border-color: var(--ui-brand);
    box-shadow: 0 0 0 2px var(--ui-focus);
    font-weight: 600;
}

.theme-card .sw {
    display: block;
    height: 64px;
    border-radius: 8px;
    margin-bottom: 6px;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.theme-card .sw i {
    position: absolute;
    left: 10px;
    height: 5px;
    border-radius: 3px;
}

.theme-card .sw i:nth-child(1) { top: 12px; width: 44%; height: 8px; }
.theme-card .sw i:nth-child(2) { top: 28px; width: 70%; opacity: 0.35; }
.theme-card .sw i:nth-child(3) { top: 38px; width: 58%; opacity: 0.35; }
.theme-card .sw i:nth-child(4) { top: 48px; width: 64%; opacity: 0.35; }

/* 色块 */
.swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.swatches button,
.swatches label {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid var(--ui-panel);
    box-shadow: 0 0 0 1px var(--ui-line);
    padding: 0;
    position: relative;
}

.swatches .on {
    box-shadow: 0 0 0 2px var(--ui-text);
}

.swatches label {
    background: conic-gradient(#ff4757, #ffa502, #2ed573, #1e90ff, #a55eea, #ff4757);
    cursor: pointer;
    overflow: hidden;
}

.swatches label input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

/* 小标签 */
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: -4px 0 12px;
}

.row .chips { margin: 0; }

.chips button {
    border: 1px solid var(--ui-line);
    background: var(--ui-sunken);
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 12px;
    color: var(--ui-text);
}

.chips button.on {
    border-color: var(--ui-brand);
    background: var(--ui-brand-soft);
}

.chips.emoji button {
    font-size: 16px;
    padding: 2px 8px;
}

#coverFields.off {
    opacity: 0.45;
    pointer-events: none;
}

.reset {
    margin-top: 14px;
    width: 100%;
}

/* ------------------------------------------------------------------ 手机预览 */

.phone-view {
    flex: 1;
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px 16px 40px;
    gap: 14px;
}

.phone-tip {
    margin: 0;
    font-size: 12px;
    color: var(--ui-muted);
}

.phone {
    width: 384px;
    height: 800px;
    flex: none;
    border-radius: 56px;
    padding: 12px;
    background: #111;
    box-shadow: 0 0 0 2px #333, 0 30px 60px -20px rgba(0, 0, 0, 0.5);
}

.phone-screen {
    width: 360px;
    height: 776px;
    border-radius: 44px;
    overflow: hidden;
    background: #fff;
    color: #222;
    display: flex;
    flex-direction: column;
    font: 14px/1.5 var(--ui-font);
    position: relative;
}

.phone-screen .i,
.phone-screen svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ph-status {
    flex: none;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 30px 0;
    font-size: 15px;
}

.ph-sig {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 12px;
}

.ph-sig i {
    width: 3px;
    background: #222;
    border-radius: 1px;
}

.ph-sig i:nth-child(1) { height: 4px; }
.ph-sig i:nth-child(2) { height: 6px; }
.ph-sig i:nth-child(3) { height: 9px; }
.ph-sig i:nth-child(4) { height: 12px; }

.ph-nav {
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px 8px;
}

.ph-ic { display: inline-flex; color: #333; }

.ph-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffd1dc, #ffb199);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex: none;
}

.ph-avatar.sm { width: 26px; height: 26px; font-size: 11px; }
.ph-avatar.xs { width: 18px; height: 18px; font-size: 9px; }

.ph-name {
    flex: 1;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ph-follow {
    border: 1px solid #ff2442;
    color: #ff2442;
    border-radius: 999px;
    padding: 2px 14px;
    font-size: 13px;
}

.ph-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: none;
}

.ph-scroll::-webkit-scrollbar { display: none; }

.ph-carousel {
    position: relative;
    background: #f3f3f3;
}

.ph-track {
    display: flex;
    height: 100%;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
}

.ph-track::-webkit-scrollbar { display: none; }

.ph-track .ph-page {
    scroll-snap-align: start;
    flex: none;
}

.ph-page {
    overflow: hidden;
    position: relative;
}

.ph-count {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
}

.ph-dots {
    display: flex;
    justify-content: center;
    gap: 5px;
    padding: 10px 0 2px;
}

.ph-dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #d9d9d9;
}

.ph-dots i.on { background: #ff2442; }

.ph-content { padding: 6px 16px 10px; }

.ph-content h3 {
    margin: 4px 0 6px;
    font-size: 17px;
    line-height: 1.4;
}

.ph-content p {
    margin: 0 0 6px;
    font-size: 14px;
    line-height: 1.6;
    color: #333;
}

.ph-tags { color: #13386c !important; }
.ph-date { color: #999 !important; font-size: 12px !important; }

.ph-comments {
    border-top: 1px solid #f0f0f0;
    margin: 0 16px;
    padding: 12px 0 30px;
    font-size: 13px;
    color: #666;
}

.ph-comments p { margin: 0 0 10px; }

.ph-cbox {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #aaa;
}

.ph-bottom {
    flex: none;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px 26px;
    border-top: 1px solid #f0f0f0;
    background: #fff;
}

.ph-input {
    flex: 1;
    background: #f5f5f5;
    border-radius: 999px;
    padding: 7px 14px;
    color: #999;
    font-size: 13px;
}

.ph-act {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 12px;
    color: #333;
}

.ph-act b { font-weight: 400; }

.ph-feedtop {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 26px;
    padding: 6px 16px 10px;
    color: #999;
    font-size: 15px;
    position: relative;
}

.ph-feedtop b {
    color: #222;
    font-size: 16px;
    border-bottom: 2px solid #ff2442;
    padding-bottom: 2px;
}

.ph-feedtop .ph-ic {
    position: absolute;
    right: 16px;
}

.ph-feed {
    display: flex;
    align-items: flex-start;
    gap: 5px;
    padding: 4px 5px 20px;
    background: #f5f5f5;
}

.ph-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.ph-card {
    flex: none;
    background: #fff;
    border-radius: 6px;
    overflow: hidden;
}

.ph-mine {
    overflow: hidden;
    position: relative;
}

/* 用红框标出「你的笔记」 */
.ph-mine::after {
    content: "";
    position: absolute;
    inset: 0;
    border: 2px solid #ff2442;
    border-radius: 6px 6px 0 0;
    pointer-events: none;
}

.ph-ct {
    margin: 6px 8px 4px;
    font-size: 13px;
    line-height: 1.4;
    font-weight: 600;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ph-cm {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px 8px;
    font-size: 11px;
    color: #888;
}

.ph-cn {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ph-like {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.phone-screen .ph-like svg {
    width: 13px;
    height: 13px;
}

/* ------------------------------------------------------------------ 其它 */

/* 测量台和导出台：放在屏幕外面，用户看不到 */
.measure-stage,
.export-stage {
    position: fixed;
    left: -40000px;
    top: 0;
    pointer-events: none;
    z-index: -1;
}

.measure-stage { visibility: hidden; }

.toast {
    position: fixed;
    left: 50%;
    bottom: 32px;
    transform: translate(-50%, 20px);
    opacity: 0;
    background: #1f1d1a;
    color: #fff;
    padding: 10px 18px;
    border-radius: 12px;
    font-size: 14px;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    z-index: 100;
    max-width: calc(100vw - 32px);
}

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

.dialog {
    border: 0;
    border-radius: 18px;
    padding: 24px;
    max-width: min(560px, calc(100vw - 32px));
    background: var(--ui-panel);
    color: var(--ui-text);
    box-shadow: var(--ui-shadow);
}

.dialog::backdrop { background: rgba(0, 0, 0, 0.4); }

.dialog h2 { margin: 0 0 14px; font-size: 18px; }

.cheats {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: 18px;
}

.cheats td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--ui-line);
    vertical-align: top;
}

.cheats code {
    font-family: var(--ui-mono);
    background: var(--ui-sunken);
    padding: 1px 5px;
    border-radius: 5px;
    white-space: nowrap;
}

.cheats mark { background: rgba(255, 210, 0, 0.55); color: inherit; }

.dialog .btn { width: 100%; }

/* 裁剪框 */
.crop-dialog { width: min(640px, calc(100vw - 32px)); }
.crop-dialog .btn { width: auto; }
.crop-tip { margin: -6px 0 14px; font-size: 13px; color: var(--ui-muted); line-height: 1.6; }
.crop-tip b { color: var(--ui-text); font-weight: 600; }

.crop-wrap {
    display: flex;
    justify-content: center;
    padding: 10px;
    border-radius: 12px;
    background-color: var(--ui-sunken);
    background-image: conic-gradient(var(--ui-line) 25%, transparent 0 50%, var(--ui-line) 0 75%, transparent 0);
    background-size: 16px 16px;
}

.crop-stage {
    position: relative;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    cursor: crosshair;
    line-height: 0;
}

.crop-stage img {
    display: block;
    max-width: 100%;
    max-height: 56vh;
    pointer-events: none;
}

.crop-box {
    position: absolute;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    outline: 2px solid #fff;
    cursor: move;
}

.crop-box i {
    position: absolute;
    width: 18px;
    height: 18px;
    background: #fff;
    border: 2px solid var(--ui-brand);
    border-radius: 50%;
    margin: -1px;
}

/* 手柄放在框的四个角内侧，框贴着图片边缘时也不会被裁掉 */
.crop-box i[data-c="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.crop-box i[data-c="ne"] { right: 0; top: 0; cursor: nesw-resize; }
.crop-box i[data-c="sw"] { left: 0; bottom: 0; cursor: nesw-resize; }
.crop-box i[data-c="se"] { right: 0; bottom: 0; cursor: nwse-resize; }

.crop-cut {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 14px 0 16px;
    font-size: 13px;
}

.crop-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.crop-actions .grow { flex: 1; }

.scrim {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 29;
}

.mobile-tabs { display: none; }

/* ------------------------------------------------------------------ 响应式 */

/* 中等屏幕：设置面板改为从右侧滑出 */
@media (max-width: 1240px) {
    .workspace { grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.3fr); }

    #settingsToggle { display: inline-flex; }

    .settings-pane {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: min(340px, 92vw);
        z-index: 30;
        transform: translateX(105%);
        transition: transform 0.25s ease;
        box-shadow: var(--ui-shadow);
    }

    .app.settings-open .settings-pane { transform: none; }

    .settings-close {
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: sticky;
        top: 0;
        background: var(--ui-panel);
        padding: 12px 0;
        z-index: 1;
        border-bottom: 1px solid var(--ui-line);
    }
}

/* 手机：一次只显示一个面板，底部标签切换 */
@media (max-width: 820px) {
    :root { --topbar-h: 54px; }

    .topbar { padding: 0 10px; gap: 6px; }
    .brand-text, #draftBtn .i:first-child { display: none; }
    .brand { margin-right: 0; }
    #draftBtn { max-width: 120px; padding: 0 8px; }
    .mode-seg button { padding: 5px 8px; }
    .zoom input { width: 80px; }
    #settingsToggle { display: none; }
    .export-group .btn.primary:first-child span { display: none; }
    .export-group .btn.primary:first-child { padding: 0 10px; }

    .workspace { display: block; position: relative; }

    .pane {
        position: absolute;
        inset: 0;
        display: none;
    }

    .app[data-pane="editor"] .editor-pane,
    .app[data-pane="preview"] .preview-pane { display: flex; }

    .app[data-pane="settings"] .settings-pane {
        display: block;
        position: absolute;
        width: auto;
        transform: none;
        box-shadow: none;
        z-index: 1;
    }

    .settings-close { display: none; }
    .editor-pane { border-right: 0; }
    .toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
    .toolbar::-webkit-scrollbar { display: none; }
    .toolbar .grow { display: none; }
    #editor { font-size: 16px; padding: 16px; }

    .preview-head { padding: 10px 16px; gap: 8px; }
    /* 手机上预览区顶部放不下文字，只留图标 */
    #stickerBtn, #textBtn, #lineBtn { font-size: 0; gap: 0; padding: 0 9px; }
    #pageInfo, .preview-head .zoom { display: none; }
    .grid { padding: 6px 16px 30px; gap: 20px 16px; }

    .phone-view .phone-switch { order: -1; }

    .mobile-tabs {
        flex: none;
        display: flex;
        border-top: 1px solid var(--ui-line);
        background: var(--ui-panel);
        padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
        gap: 6px;
    }

    .mobile-tabs button {
        flex: 1;
        border: 0;
        background: transparent;
        padding: 8px 0;
        border-radius: 10px;
        color: var(--ui-muted);
        font-weight: 600;
    }

    .mobile-tabs button.on {
        background: var(--ui-brand-soft);
        color: var(--ui-brand);
    }

    .phone { transform: scale(0.86); transform-origin: top center; margin-bottom: -110px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}
