/* From eooo.me labs (github.com/oopserian/oopserian.github.io), MIT License, Copyright (c) 2024 erian. See /lab/_kit/LICENSE. */
/* 舞台就是桌面：上面摆着一个对话窗口和三份打印出来的文件。.si 里按设计像素排，desk.js 整体缩放到舞台上。
   排法看根元素的 data-mode：wide（文件在左、对话在右）、tall（对话在上、文件在下）、compact（文件排成一列小图）。
   纸是实物，颜色不跟主题变（深色里整张压暗一点），角是直的；对话窗口和按钮用实验共用的颜色、圆角、阴影。 */
.paper-lab {
    --paper-dim: 1;   /* 深色主题里 desk.js 改成 0.9，跟着色器的曝光一样 */
    --ear: light-dark(#efeee9, #d8d7d2);
    /* 纸贴在桌上的影子，跟 WebGL 那张纸平放时的贴地影子对得上 */
    --paper-sh: drop-shadow(0 0.5px 0.6px light-dark(rgb(28 26 36 / 0.24), rgb(0 0 0 / 0.6))) drop-shadow(0 1.5px 2.5px light-dark(rgb(28 26 36 / 0.12), rgb(0 0 0 / 0.4)));
    --bubble: color-mix(in srgb, var(--lab-fg) 6%, var(--lab-surface));
    display: block;
    user-select: none;
    -webkit-user-select: none;
}
/* 桌面上一层很细的颗粒，看着是一张桌子的面，不是一块平涂的色 */
.paper-lab::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: var(--grain);
    background-size: 180px;
    opacity: 0.5;
    pointer-events: none;
}
.paper-lab .si { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.paper-lab .gl { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }
.paper-lab .flat { position: absolute; left: 0; top: 0; z-index: 20; transform-origin: 0 0; pointer-events: none; box-shadow: var(--lab-shadow-2); }

/* ───────── 三种排法 ───────── */
.paper-lab .chat, .paper-lab .desk { position: absolute; }
/* 宽的：文件和对话合起来不超过 840 宽，在舞台里居中，舞台再宽两边也只是多出桌面 */
.paper-lab[data-mode="wide"] { --side: max(24px, calc((100% - 840px) / 2)); --cw: clamp(300px, 42%, 380px); }
.paper-lab[data-mode="wide"] .chat { right: var(--side); top: 20px; bottom: 4px; width: var(--cw); }
.paper-lab[data-mode="wide"] .desk { left: var(--side); right: calc(var(--side) + var(--cw) + 24px); top: 20px; bottom: 4px; }
.paper-lab[data-mode="tall"] .chat { left: 16px; right: 16px; top: 16px; bottom: calc(var(--th) + 64px); }
.paper-lab[data-mode="tall"] .desk { left: 16px; right: 16px; bottom: 6px; height: calc(var(--th) + 46px); }
/* 又矮又窄（手机上的卡片），或者不够宽的那种排法（桌面上的半宽卡片）：文件一列在左、对话在右；舞台宽一点，文件那一列跟着宽，名字离对话框不挤 */
.paper-lab[data-mode="compact"] { --dw: clamp(138px, 30%, 184px); }
.paper-lab[data-mode="compact"] .chat { right: 12px; top: 12px; bottom: 2px; left: calc(var(--dw) + 22px); }
.paper-lab[data-mode="compact"] .desk { left: 10px; top: 12px; bottom: 2px; width: var(--dw); }

/* ───────── 滚动的字 ───────── */
.paper-lab .roll { display: inline-flex; flex: none; white-space: pre; vertical-align: top; }
.paper-lab .rc { position: relative; display: inline-block; flex: none; transition: width 0.45s var(--lab-ease); }
.paper-lab .rg { display: inline-block; transition: transform 0.42s var(--lab-ease), opacity 0.28s ease, filter 0.28s ease; }
.paper-lab .rg.old { position: absolute; left: 0; top: 0; opacity: 0; filter: blur(3px); transform: scale(0.92); }
.paper-lab .rg.new { opacity: 0; filter: blur(3px); transform: scale(0.92); transition: none; }
.paper-lab .rc.gone .rg { opacity: 0; filter: blur(3px); transform: scale(0.9); }
.paper-lab .rc.cl { clip-path: inset(-60% -1px -60% 0); }

/* ───────── 对话窗口 ───────── */
.paper-lab .chat {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: var(--lab-r-xl);
    background: var(--lab-surface);
    box-shadow: 0 0 0 1px var(--lab-line), var(--lab-shadow-2);
}
.paper-lab .ch-h { flex: none; height: 56px; display: flex; align-items: center; gap: 10px; padding: 0 16px; box-shadow: 0 1px 0 var(--lab-line); position: relative; z-index: 2; }
.paper-lab .av { flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--lab-sunken); color: var(--lab-fg-2); font-size: 11.5px; font-weight: 600; letter-spacing: 0.02em; }
.paper-lab .who { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.paper-lab .who b { font-size: 14px; font-weight: 600; line-height: 18px; }
.paper-lab .who span { font-size: 12px; line-height: 16px; color: var(--lab-fg-3); }
.paper-lab .call { margin-left: auto; color: var(--lab-fg-3); }

/* 对话贴着底；顶上只露整条的消息（desk.js 的 clip 把顶进上边留白的整条淡掉），遮罩只在挪动的那一下柔一柔切口 */
.paper-lab .thread {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 6px;
    padding: 12px 14px 6px;
    overflow: hidden;
    mask-image: linear-gradient(transparent, #000 12px);
}
.paper-lab .thread > * { flex-shrink: 0; transition: opacity 0.2s var(--lab-ease); }
.paper-lab .thread > .cut { opacity: 0; }
.paper-lab .day { align-self: center; margin-bottom: 4px; font-size: 11px; font-weight: 500; color: var(--lab-fg-3); font-variant-numeric: tabular-nums; }
.paper-lab .day:not(:first-child) { margin-top: 10px; }
.paper-lab .msg { max-width: 78%; padding: 8px 13px 9px; font-size: 14px; line-height: 20px; }
.paper-lab .msg.them { align-self: flex-start; background: var(--bubble); border-radius: var(--lab-r-lg) var(--lab-r-lg) var(--lab-r-lg) 4px; }
.paper-lab .msg.me { align-self: flex-end; background: var(--lab-fg); color: var(--lab-surface); border-radius: var(--lab-r-lg) var(--lab-r-lg) 4px var(--lab-r-lg); }
.paper-lab .sent { align-self: flex-end; display: flex; gap: 8px; align-items: flex-end; padding-top: 4px; }
.paper-lab .sent .pg { display: block; height: var(--pg); width: calc(var(--pg) / var(--ar)); filter: var(--paper-sh) brightness(var(--paper-dim)); }
.paper-lab .meta { align-self: flex-end; height: 14px; margin-top: -1px; font-size: 11px; font-weight: 500; line-height: 14px; color: var(--lab-fg-3); }
.paper-lab .typing { align-self: flex-start; display: flex; align-items: center; gap: 4px; height: 36px; padding: 0 13px; background: var(--bubble); border-radius: var(--lab-r-lg) var(--lab-r-lg) var(--lab-r-lg) 4px; }
.paper-lab .typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--lab-fg-3); animation: paper-blink 1.1s infinite ease-in-out; }
.paper-lab .typing i:nth-child(2) { animation-delay: 0.16s; }
.paper-lab .typing i:nth-child(3) { animation-delay: 0.32s; }
@keyframes paper-blink { 0%, 60%, 100% { opacity: 0.35; transform: none; } 30% { opacity: 1; transform: translateY(-2px); } }
.paper-lab .pop { animation: paper-pop 0.5s var(--lab-spring) both; }
@keyframes paper-pop { from { opacity: 0; transform: translateY(8px) scale(0.96); } }

/* ───────── 输入框 ───────── */
.paper-lab .cmp { flex: none; padding: 8px 12px 12px; }
.paper-lab .field {
    border-radius: var(--lab-r-xl);
    background: var(--lab-surface-2);
    box-shadow: inset 0 0 0 1px var(--lab-line);
    transition: box-shadow 0.25s var(--lab-ease), background-color 0.25s var(--lab-ease);
}
.paper-lab .field.hot { background: var(--lab-surface); box-shadow: inset 0 0 0 1.5px var(--lab-accent), 0 0 0 4px var(--lab-accent-soft); }
.paper-lab .atts { display: flex; align-items: flex-end; gap: 10px; height: 0; padding: 0 12px; overflow: visible; transition: height 0.45s var(--lab-ease); }
.paper-lab .att {
    all: unset;
    position: relative;
    flex: none;
    height: var(--att);
    width: calc(var(--att) / var(--ar));
    cursor: grab;
    touch-action: none;
    filter: var(--paper-sh) brightness(var(--paper-dim));
}
.paper-lab .att img { display: block; width: 100%; height: 100%; pointer-events: none; }
.paper-lab .att.pending, .paper-lab .att.away { visibility: hidden; }
.paper-lab .att .x {
    position: absolute;
    right: -7px;
    top: -7px;
    width: 18px;
    height: 18px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--lab-fg);
    color: var(--lab-surface);
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.18s var(--lab-ease), transform 0.25s var(--lab-spring);
    cursor: pointer;
}
.paper-lab .att:hover .x, .paper-lab .att:focus-visible .x { opacity: 1; transform: none; }
@media (hover: none) { .paper-lab .att .x { opacity: 1; transform: none; } }
.paper-lab .att:focus-visible { outline: 2px solid var(--lab-accent); outline-offset: 3px; }
.paper-lab .line { height: 40px; display: flex; align-items: center; justify-content: space-between; padding: 0 6px 0 15px; }
.paper-lab .ph { font-size: 14px; color: var(--lab-fg-3); transition: color 0.25s var(--lab-ease); }
.paper-lab .field.hot .ph { color: var(--lab-accent); }
.paper-lab .send {
    all: unset;
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--lab-line-strong);
    color: var(--lab-surface);
    transition: background-color 0.25s var(--lab-ease), transform 0.25s var(--lab-spring);
}
.paper-lab .send:not(:disabled) { background: var(--lab-fg); cursor: pointer; }
.paper-lab .send:not(:disabled):active { transform: scale(0.9); }
.paper-lab .send:focus-visible { outline: 2px solid var(--lab-accent); outline-offset: 2px; }

/* ───────── 桌上的文件 ───────── */
.paper-lab .desk { display: grid; place-items: center; }
.paper-lab .files { display: flex; align-items: flex-end; justify-content: center; gap: 28px; }
.paper-lab[data-mode="tall"] .files { width: 100%; justify-content: space-around; gap: 0; }
.paper-lab .file { all: unset; display: flex; flex-direction: column; align-items: center; gap: 9px; cursor: grab; touch-action: none; }
.paper-lab .file[aria-pressed="true"] { cursor: pointer; }
.paper-lab .file:focus-visible { outline: none; }
.paper-lab .th { position: relative; height: var(--th); width: calc(var(--th) / var(--ar)); filter: var(--paper-sh) brightness(var(--paper-dim)); }
/* 焦点框画在小图外面一圈（按钮本身的框会把名字也框进去） */
.paper-lab .th::after { content: ""; position: absolute; inset: -6px; border-radius: var(--lab-r-sm); box-shadow: 0 0 0 2px var(--lab-accent); opacity: 0; pointer-events: none; }
.paper-lab .file:focus-visible .th::after { opacity: 1; }
.paper-lab .th img { display: block; width: 100%; height: 100%; pointer-events: none; }
/* 右上角一个折角：图裁掉一角，补上折过来的那一块和它投下的一道影子 */
.paper-lab .th.ear { --f: calc(var(--th) / var(--ar) * 0.2); }
.paper-lab .th.ear img { clip-path: polygon(0 0, calc(100% - var(--f)) 0, 100% var(--f), 100% 100%, 0 100%); }
.paper-lab .th .ea { position: absolute; right: 0; top: 0; width: var(--f); height: var(--f); background: linear-gradient(225deg, #e8e7e2, var(--ear) 60%); clip-path: polygon(0 0, 0 100%, 100% 100%); }
.paper-lab .th .es { position: absolute; right: 0; top: var(--f); width: var(--f); height: 4px; background: linear-gradient(rgb(30 28 36 / 0.13), rgb(30 28 36 / 0)); pointer-events: none; }
/* 拿走以后桌上留一个浅浅的印子 */
.paper-lab .file.lifted .th { filter: none; }
.paper-lab .file.lifted .th > * { visibility: hidden; }
.paper-lab .th .dent {
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, var(--lab-fg) 3.5%, transparent);
    box-shadow: inset 0 0 0 1px var(--lab-line), inset 0 1px 2px var(--lab-line);
    opacity: 0;
    transition: opacity 0.4s ease 0.1s;
    visibility: visible !important;
}
.paper-lab .file.lifted .dent { opacity: 1; }
.paper-lab .nm { display: flex; flex-direction: column; align-items: center; gap: 1px; transition: opacity 0.3s ease; }
.paper-lab .nm b { font-size: 12px; font-weight: 500; line-height: 16px; white-space: nowrap; }
.paper-lab .nm span { font-size: 11px; line-height: 14px; color: var(--lab-fg-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.paper-lab .file.lifted .nm { opacity: 0.45; }

/* 又矮又窄：对话窗口紧一点，文件排成一列，名字在小图右边 */
.paper-lab[data-mode="compact"] .ch-h { height: 44px; padding: 0 12px; gap: 8px; }
.paper-lab[data-mode="compact"] .av { width: 26px; height: 26px; font-size: 10px; }
.paper-lab[data-mode="compact"] .who b { font-size: 13px; line-height: 16px; }
.paper-lab[data-mode="compact"] .who span { font-size: 11px; line-height: 14px; }
.paper-lab[data-mode="compact"] .thread { padding: 8px 10px 4px; gap: 5px; }
.paper-lab[data-mode="compact"] .msg { font-size: 13px; line-height: 18px; padding: 7px 11px 8px; max-width: 86%; }
.paper-lab[data-mode="compact"] .cmp { padding: 6px 8px 8px; }
.paper-lab[data-mode="compact"] .line { height: 36px; padding-left: 13px; }
.paper-lab[data-mode="compact"] .ph { font-size: 13px; }
.paper-lab[data-mode="compact"] .files { flex-direction: column; align-items: stretch; gap: 12px; }
.paper-lab[data-mode="compact"] .file { flex-direction: row; gap: 10px; }
/* 小图竖着排时放进一样宽的格子（A4 那么宽），比例不同的照片居中，三个文件名左边对齐 */
.paper-lab[data-mode="compact"] .th { margin-inline: calc((var(--th) / 1.4142 - var(--th) / var(--ar)) / 2); }
.paper-lab[data-mode="compact"] .nm { align-items: flex-start; min-width: 0; }
.paper-lab[data-mode="compact"] .nm span { display: none; }
