/* =============================================================
 * editor.css — 无限画布编辑器
 *
 *   ┌────────┬──────────────────────────────────────┐
 *   │ 工具条  │                                      │
 *   │ 面条态  │            画布（占据剩余全部）         │
 *   │ 58 / 218│                                      │
 *   └────────┴──────────────────────────────────────┘
 * ============================================================= */

body.editor {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: var(--surface-2);
}

/* 侧栏按钮：去掉移动端点击灰块闪烁，避免长按选中文字 */
.ed-tools button {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

/* =============================================================
 * 顶栏
 * ============================================================= */

.ed-topbar {
    gap: 12px;
    flex: none;
}

.ed-doc {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    gap: 1px;
}

.ed-doc-name {
    border: 0;
    background: transparent;
    font-size: 14px;
    font-weight: 680;
    letter-spacing: -.01em;
    padding: 1px 5px;
    border-radius: 5px;
    width: 190px;
    max-width: 100%;
    transition: background .15s var(--ease);
}

.ed-doc-name:hover {
    background: var(--surface-3);
}

.ed-doc-name:focus {
    outline: 0;
    background: var(--surface);
    box-shadow: 0 0 0 2px var(--brand-ring);
}

.ed-doc-meta {
    font-size: 11px;
    color: var(--ink-3);
    padding-left: 6px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.ed-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ed-actions .btn span {
    font-size: 12.8px;
}

/* =============================================================
 * 主体
 * ============================================================= */

.ed-main {
    flex: 1;
    min-height: 0;
    display: flex;
    position: relative;
    overflow: hidden;
}

.ed-viewport {
    flex: 1;
    min-width: 0;
    position: relative;
    overflow: hidden;
    background: #F1F2F5;
    touch-action: none;
}

#board {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

#board.is-panning {
    cursor: grabbing;
}

#board.is-pan-ready {
    cursor: grab;
}

/* HUD */
.ed-hud {
    position: absolute;
    bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.ed-hud-left {
    left: 14px;
}

.ed-hud-right {
    right: 14px;
}

.ed-zoom {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--sh-2);
}

.hud-btn {
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--ink-2);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background .14s var(--ease), color .14s var(--ease);
}

.hud-btn:hover {
    background: var(--surface-3);
    color: var(--ink);
}

.hud-btn-text {
    width: auto;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 600;
}

.hud-sep {
    width: 1px;
    height: 16px;
    background: var(--line-2);
    margin: 0 3px;
}

.ed-zoom-val {
    font-size: 11.8px;
    font-weight: 650;
    color: var(--ink-2);
    font-variant-numeric: tabular-nums;
    min-width: 42px;
    text-align: center;
}

.ed-hint {
    font-size: 11.5px;
    color: var(--ink-3);
    background: rgba(255, 255, 255, .85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 6px 11px;
    border-radius: 8px;
    border: 1px solid var(--line);
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =============================================================
 * 工具栏（面条 ⇄ 展开）
 * ============================================================= */

.ed-tools {
    flex: none;
    width: 58px;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--line);
    transition: width .24s var(--ease);
    position: relative;
    z-index: 20;
}

.ed-tools.is-open {
    width: 218px;
    box-shadow: 8px 0 26px rgba(20, 22, 26, .05);
}

/* 顶部展开开关 */
.tool-toggle {
    flex: none;
    height: 42px;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 0 16px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    color: var(--ink-2);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background .15s var(--ease);
}

.tool-toggle:hover {
    background: var(--surface-2);
}

/* 左侧栏：收起时箭头朝右（点开展开），展开时朝左（点收起） */
.tool-toggle-chev {
    flex: none;
    transition: transform .24s var(--ease);
    transform: rotate(0deg);
}

.ed-tools.is-open .tool-toggle-chev {
    transform: rotate(180deg);
}

.tool-toggle-label {
    display: none;
}

.ed-tools.is-open .tool-toggle-label {
    display: block;
}

/* 收起态：图标在 58px 里居中 */
.ed-tools:not(.is-open) .tool-toggle {
    padding: 0;
    justify-content: center;
}

/* 工具体：上（工具+参数）可滚，下（颜色）固定可见 */
.tool-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tool-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 7px 7px 5px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    scrollbar-width: thin;
}

.ed-tools.is-open .tool-scroll {
    padding: 8px 10px 5px;
}

.tool-section {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tool-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 26px;
    padding: 0 11px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--ink-2);
    cursor: pointer;
    font-size: 12.8px;
    font-weight: 550;
    white-space: nowrap;
    overflow: hidden;
    transition: background .14s var(--ease), color .14s var(--ease);
    text-align: left;
    flex: none;
}

.tool-item:hover {
    background: var(--surface-2);
    color: var(--ink);
}

/* 选中态：只改背景/文字色 + 左侧指示条，不动字重（改字重会触发文字重排，视觉上像整块闪一下） */
.tool-item.is-active {
    background: var(--brand-soft);
    color: var(--brand-hover);
}

.tool-item.is-active::before {
    content: "";
    position: absolute;
    left: -4px;
    top: 50%;
    width: 2.5px;
    height: 13px;
    margin-top: -6.5px;
    border-radius: 0 2px 2px 0;
    background: var(--brand);
}

.tool-icon {
    flex: none;
    width: 18px;
    height: 18px;
    display: grid;
    place-items: center;
}

.tool-emoji {
    font-size: 14px;
    line-height: 1;
}

.tool-label {
    display: none;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ed-tools.is-open .tool-label {
    display: block;
}

.tool-sep {
    height: 1px;
    background: var(--line);
    margin: 6px 6px;
}

/* 工具参数（固定，不参与滚动） */
.tool-params {
    display: none;
    flex: none;
    gap: 3px;
    padding: 6px 8px 5px;
    border-top: 1px solid var(--line);
    background: var(--surface);
}

.ed-tools.is-open .tool-params {
    display: flex;
}

.tp-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--ink-2);
}

.tp-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tp-input {
    width: 54px;
    height: 28px;
    border: 1px solid var(--line-2);
    border-radius: 7px;
    text-align: center;
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
    padding: 0 3px;
}

.tp-color {
    width: 30px;
    height: 26px;
}

.tp-flip {
    display: flex;
    gap: 4px;
}

.mini-btn {
    width: 26px;
    height: 26px;
    border: 1px solid var(--line-2);
    border-radius: 7px;
    background: var(--surface);
    color: var(--ink-2);
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    display: grid;
    place-items: center;
    transition: background .14s var(--ease), border-color .14s var(--ease);
}

.mini-btn:hover {
    background: var(--surface-2);
    border-color: var(--line-3);
    color: var(--ink);
}

/* 颜色面板 */
.tool-colors {
    display: none;
    flex: none;
    gap: 7px;
    padding: 9px 8px 10px;
    border-top: 1px solid var(--line);
    background: var(--surface);
    max-height: 38%;
    overflow: hidden;
}

.ed-tools.is-open .tool-colors {
    display: flex;
}

.tc-current {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tc-swatch {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid var(--line-2);
    background: #fff;
    flex: none;
}

.tc-info {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
    min-width: 0;
}

.tc-info b {
    font-size: 12.5px;
    font-weight: 700;
}

.tc-info span {
    font-size: 10.5px;
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
}

.tc-search {
    height: 28px;
    border: 1px solid var(--line-2);
    border-radius: 7px;
    padding: 0 9px;
    font-size: 12px;
    width: 100%;
    background: var(--surface);
}

.tc-search:focus {
    outline: 0;
    border-color: var(--brand);
    box-shadow: 0 0 0 2px var(--brand-ring);
}

.tc-series {
    display: flex;
    flex-wrap: nowrap;
    gap: 3px;
    overflow-x: auto;
    scrollbar-width: none;
    flex: none;
}

.tc-series::-webkit-scrollbar {
    display: none;
}

.tc-series button {
    flex: none;
}

.tc-series button {
    border: 0;
    background: var(--surface-3);
    color: var(--ink-2);
    font-size: 10.5px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 5px;
    cursor: pointer;
    transition: background .14s var(--ease), color .14s var(--ease);
}

.tc-series button.is-active {
    background: var(--brand);
    color: #fff;
}

.tc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(20px, 1fr));
    gap: 3px;
    max-height: min(78px, 11vh);
    overflow-y: auto;
    padding-right: 2px;
}

.tc-cell {
    aspect-ratio: 1;
    border-radius: 5px;
    border: 1px solid rgba(0, 0, 0, .1);
    cursor: pointer;
    position: relative;
    transition: transform .1s var(--ease), box-shadow .1s var(--ease);
    padding: 0;
}

.tc-cell:hover {
    transform: scale(1.14);
    z-index: 2;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .22);
}

.tc-cell.is-active {
    box-shadow: 0 0 0 2px var(--brand), 0 0 0 3.5px #fff;
    z-index: 3;
}

/* 底部撤销/重做 */
.tool-foot {
    flex: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px;
    border-top: 1px solid var(--line);
}

.ed-tools.is-open .tool-foot {
    flex-direction: row;
    padding: 8px 10px;
}

/* 收起态只放图标，展开态才出现文字和更大的点击区 */
.undo-btn span {
    display: none;
}

.ed-tools.is-open .undo-btn {
    flex: 1;
    height: 34px;
}

.ed-tools.is-open .undo-btn span {
    display: inline;
}

.undo-btn {
    flex: none;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--ink-2);
    cursor: pointer;
    font-size: 12.3px;
    font-weight: 560;
    transition: background .14s var(--ease), color .14s var(--ease);
}

.undo-btn:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--ink);
}

.undo-btn:disabled {
    opacity: .32;
    cursor: not-allowed;
}

.undo-btn span {
    display: none;
}

.ed-tools.is-open .undo-btn span {
    display: block;
}

/* =============================================================
 * 抽屉 / 弹层
 * ============================================================= */

.ed-scrim {
    position: absolute;
    inset: 0;
    background: rgba(20, 22, 26, .28);
    z-index: 50;
    animation: fade-in .18s var(--ease);
}

.ed-scrim[hidden] {
    display: none;
}

@keyframes fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.ed-drawer {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(370px, 92vw);
    background: var(--surface);
    border-left: 1px solid var(--line);
    box-shadow: -18px 0 50px rgba(20, 22, 26, .14);
    z-index: 60;
    display: flex;
    flex-direction: column;
    animation: drawer-in .26s var(--ease-out);
}

.ed-drawer[hidden] {
    display: none;
}

@keyframes drawer-in {
    from {
        transform: translateX(24px);
        opacity: 0;
    }

    to {
        transform: none;
        opacity: 1;
    }
}

.dr-head {
    flex: none;
    height: 52px;
    padding: 0 16px 0 19px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--line);
}

.dr-head h2 {
    font-size: 14.5px;
    font-weight: 700;
    letter-spacing: -.01em;
}

.dr-close {
    margin-left: auto;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--ink-3);
    cursor: pointer;
    font-size: 13px;
    display: grid;
    place-items: center;
    transition: background .14s var(--ease), color .14s var(--ease);
}

.dr-close:hover {
    background: var(--surface-3);
    color: var(--ink);
}

.dr-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 19px 22px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.dr-group {
    display: flex;
    flex-direction: column;
    gap: 11px;
}

.dr-group-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--ink-4);
}

.dr-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12.5px;
    color: var(--ink-2);
}

.dr-row > span:first-child {
    font-weight: 560;
}

.dr-row-tight {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.dr-row-tight .range {
    width: 130px;
}

.dr-inline {
    display: flex;
    align-items: center;
    gap: 6px;
}

.dr-inline em {
    font-style: normal;
    font-size: 11.5px;
    color: var(--ink-4);
}

.dr-inline .range {
    flex: 1;
    width: auto;
}

.dr-num {
    width: 58px;
    height: 30px;
    text-align: center;
    padding: 0 4px;
}

.dr-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    color: var(--ink-2);
    cursor: pointer;
}

.dr-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--brand);
    cursor: pointer;
    flex: none;
}

.dr-check > span {
    flex: 1;
}

.dr-mini-color {
    width: 30px;
    height: 26px;
    flex: none;
}

.dr-foot {
    flex: none;
    display: flex;
    gap: 8px;
    padding: 13px 19px;
    border-top: 1px solid var(--line);
}

.dr-foot .btn {
    flex: 1;
}

/* 操作历史 / 成品预览（居中弹层） */
.ed-sheet {
    position: absolute;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    width: min(420px, 92vw);
    max-height: 80vh;
    background: var(--surface);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-4);
    z-index: 70;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: sheet-in .22s var(--ease-out);
}

.ed-sheet[hidden] {
    display: none;
}

.ed-sheet-wide {
    width: min(720px, 94vw);
}

@keyframes sheet-in {
    from {
        opacity: 0;
        transform: translate(-50%, -48%) scale(.98);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.hist-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.hist-list li {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 9px;
    border-radius: 7px;
    font-size: 12.8px;
    color: var(--ink-2);
}

.hist-list li.is-current {
    background: var(--brand-soft);
    color: var(--brand-hover);
    font-weight: 600;
}

.hist-idx {
    width: 20px;
    font-size: 11px;
    color: var(--ink-4);
    font-variant-numeric: tabular-nums;
    flex: none;
}

.hist-list li.is-current .hist-idx {
    color: var(--brand);
}

.hist-empty {
    color: var(--ink-3);
    font-size: 13px;
    text-align: center;
    padding: 26px 0;
}

.iron-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 20px;
    display: grid;
    place-items: center;
    background: var(--surface-2);
}

.iron-body img,
.iron-body canvas {
    max-width: 100%;
    max-height: 62vh;
    border-radius: 6px;
    box-shadow: var(--sh-3);
    image-rendering: auto;
}

.iron-caption {
    margin-top: 12px;
    font-size: 11.5px;
    color: var(--ink-3);
    text-align: center;
}

/* =============================================================
 * 响应式
 * ============================================================= */

/* 矮屏：色板压到两行，保证 15 个工具全部可见 */
@media (max-height: 880px) {
    .tc-grid {
        max-height: 42px;
    }

    .tool-params {
        padding: 5px 8px 4px;
    }

}

@media (max-width: 1100px) {
    .ed-actions .btn span {
        display: none;
    }

    .ed-actions .btn {
        width: 34px;
        padding: 0;
    }

    .ed-doc-name {
        width: 130px;
    }
}

@media (max-width: 760px) {
    .ed-doc {
        display: none;
    }

    .ed-hud-right {
        display: none;
    }

    .ed-tools {
        width: 52px;
    }

    .ed-tools.is-open {
        width: 200px;
    }
}
