/* F62：共享排版与房间工作区，适配 Windows 桌面及 Android 触屏。 */
:root {
  --shadow: 0 12px 32px rgba(0, 0, 0, .22);
  --shadow-sm: 0 4px 16px rgba(0, 0, 0, .18);
  --text-glow: none;
  --text-glow-2: none;
  --tap: 44px;
}
body { line-height: 1.6; }
body::before, body::after { opacity: .12; pointer-events: none; }
.ambient { opacity: .3; }
.topbar { min-height: 66px; gap: 16px; padding-inline: clamp(16px, 3vw, 40px); box-shadow: none; }
.topbar .logo { font-size: 15px; letter-spacing: .03em; filter: none; }
.topbar .nav-link { min-height: 38px; display: inline-flex; align-items: center; box-shadow: none; }
.topbar .sub { max-width: 220px; }
.page { width: min(1180px, calc(100% - 64px)); padding: 34px 0 56px; }
.page-wide { width: min(1440px, calc(100% - 64px)); }
.btn, .chip { touch-action: manipulation; text-shadow: none; }
.btn-primary { box-shadow: none; }
.btn:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.glass, .side-card, .room-card { box-shadow: none; background: rgba(19, 23, 38, .88); }
.section-title { letter-spacing: .02em; }
.modal-mask { padding: 24px; }
.modal { width: min(100%, 720px); max-height: calc(100dvh - 48px); overflow-y: auto; }
.modal h3 { line-height: 1.4; }
input, select, textarea { min-width: 0; }
pre, .doc-hero, .book-grid, .book-card { min-width: 0; }
pre { overflow-x: auto; max-width: 100%; }
.book-grid { gap: 20px; }
.doc-hero { margin-bottom: 28px; }
.doc-hero h1 { font-size: clamp(24px, 3vw, 34px); }
.doc-hero > p { max-width: 760px; color: var(--text-2); line-height: 1.85; }

/* 大厅把“加入房间”和“继续存档”分成独立视图，剧本作为筛选侧栏。 */
.lobby-layout { grid-template-columns: 270px minmax(0, 1fr); gap: 28px; }
.lobby-heading { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; gap: 16px; }
.lobby-heading h1 { margin: 0; font-size: 28px; }
.lobby-heading p { margin: 5px 0 0; color: var(--text-2); font-size: 13px; }
.lobby-tabs { display: flex; gap: 6px; padding: 5px; background: var(--paper-2); border: 1px solid var(--border); border-radius: 12px; }
.lobby-tabs button { border: 0; background: transparent; color: var(--text-2); padding: 10px 20px; border-radius: 8px; white-space: nowrap; }
.lobby-tabs button.active { background: var(--accent-soft); color: var(--accent); }
.right-col { min-width: 0; }
.wb-panel { padding: 18px; }
.wb-list { max-height: 52vh; }
.room-grid { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.room-card { padding: 20px; min-height: 178px; }
.filter-row { flex-wrap: wrap; gap: 12px; }
.saves-panel { margin-top: 0; }
.saves-item { padding: 18px; gap: 16px; }
.s-i-actions { flex-wrap: wrap; }
.save-versions { white-space: nowrap; }
.create-fab { display: none; }
.admin-btn { position: static; margin: 0 32px 24px auto; display: block; width: max-content; }
.page-rooms .topbar .user-chip { max-width: 140px; overflow: hidden; }
.mobile-filter { display: none; }

/* 房间主体只有聊天滚动；工具折叠，角色/剧情/管理各自成页。 */
.page-room { height: var(--room-height, 100dvh); }
.page-room > .topbar { flex: 0 0 auto; min-height: 62px; }
.page-room .room-shell { grid-template-columns: minmax(0, 1fr) 360px; }
.room-toolbar { display: flex; align-items: center; justify-content: space-between; flex: 0 0 auto; border-bottom: 1px solid var(--border); padding: 4px 22px; gap: 12px; min-height: 52px; }
.room-toolbar .channel-tabs { padding: 0; border: 0; background: transparent; }
.channel-tab { min-height: 40px; box-shadow: none !important; }
.room-quick-actions { display: flex; align-items: center; gap: 8px; }
.connection-state { color: var(--text-3); font-size: 11px; white-space: nowrap; }
.connection-state.connected::before { content: ''; display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 100%; background: var(--success); }
.chat-feed { padding: 24px clamp(20px, 4vw, 70px); scroll-padding-bottom: 18px; overscroll-behavior: contain; }
.chat-feed .msg { max-width: min(100%, 880px); }
.msg.gm .gm-card { box-shadow: none; padding: 22px 26px; }
.msg.gm .gm-text { line-height: 1.95; font-size: 15px; }
.composer { flex: 0 0 auto; padding: 12px 24px 18px; background: var(--paper); box-shadow: 0 -4px 20px rgba(0,0,0,.12); }
.composer-tools { margin-bottom: 8px; }
.composer-tools > summary { list-style: none; cursor: pointer; color: var(--text-2); font-size: 12px; padding: 4px 0; min-height: 28px; }
.composer-tools > summary::before { content: '＋'; margin-right: 6px; color: var(--accent); }
.composer-tools[open] > summary::before { content: '−'; }
.composer-tools > summary span { color: var(--text-3); margin-left: 12px; }
.composer-tools .dice-chips { margin-top: 10px; display: flex; flex-wrap: wrap; }
.composer .input-row { align-items: flex-end; gap: 10px; }
.composer textarea { min-height: 54px; max-height: 130px; resize: vertical; line-height: 1.6; }
.composer .input-row .btn { min-height: 54px; white-space: nowrap; }
.gm-thinking { font-size: 12px; }
.sidebar { padding: 0 18px 24px; background: var(--paper-2); }
.sidebar-tabs { position: sticky; top: 0; z-index: 2; display: flex; gap: 4px; padding: 12px 0; margin-bottom: 14px; background: var(--paper-2); border-bottom: 1px solid var(--border); }
.sidebar-tabs [role=tab] { flex: 1; min-height: 40px; border: 0; border-radius: 8px; background: transparent; color: var(--text-2); }
.sidebar-tabs [role=tab].active { color: var(--accent); background: var(--accent-soft); }
.sidebar .side-section[hidden] { display: none !important; }
.side-section { margin-bottom: 24px; }
.side-title { margin: 0 0 10px; font-size: 12px; }
.side-card { padding: 14px; border-color: rgba(160,180,215,.13); }
.sidebar .archive-actions { display: grid; grid-template-columns: 1fr; gap: 9px; }
.sidebar-close, .sidebar-scrim, .workspace-nav { display: none; }
.char-art-box img { max-height: 280px; object-fit: contain; }

/* 原生对话框支持焦点约束与 Escape；预览、画廊和任务各有清晰标题。 */
.workspace-dialog { color: var(--text-1); background: var(--paper-2); border: 1px solid var(--border); border-radius: 18px; padding: 26px; width: min(920px, calc(100vw - 64px)); max-height: min(88dvh, 1000px); overflow: auto; box-shadow: 0 28px 100px #0008; }
.workspace-dialog::backdrop { background: #040812c9; backdrop-filter: blur(5px); }
.workspace-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.workspace-heading small { font-size: 11px; color: var(--accent); letter-spacing: .08em; }
.workspace-heading h2 { margin: 3px 0 0; font-size: 24px; }
.workspace-heading [data-close] { font-size: 25px; min-width: 44px; }
.workspace-note { font-size: 13px; line-height: 1.7; color: var(--text-2); }
.workspace-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 16px 0; flex-wrap: wrap; }
.workspace-list { display: grid; gap: 12px; }
.workspace-empty { grid-column: 1 / -1; padding: 44px 18px; text-align: center; color: var(--text-2); }
.workspace-empty > span { font-size: 38px; color: var(--accent); }
.workspace-empty h3 { font-size: 17px; font-weight: 500; color: var(--text-1); margin-bottom: 8px; }
.workspace-empty p { font-size: 13px; }
.task-card, .version-card { padding: 18px; background: var(--paper); border: 1px solid rgba(160,180,215,.14); border-radius: 12px; }
.task-title, .version-card { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.task-title strong { font-size: 15px; }
.task-status { padding: 3px 9px; border-radius: 20px; font-size: 11px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.task-status.failed, .task-status.partial, .task-status.interrupted { background: var(--warning-soft); color: var(--warning); }
.task-status.completed { background: var(--success-soft); color: var(--success); }
.task-card p { font-size: 13px; margin: 8px 0; overflow-wrap: anywhere; }
.task-meta, .version-card small, .version-card p { color: var(--text-3); font-size: 12px; }
.task-meta { display: block; }
.task-error { color: var(--warning); }
.task-shots { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.task-shots span { padding: 4px 8px; background: var(--paper-3); border-radius: 6px; font-size: 12px; }
.task-shots .saved { color: var(--success); }
.task-draft { margin: 12px 0; font-size: 13px; }
.task-draft div { white-space: pre-wrap; max-height: 220px; overflow: auto; padding-top: 10px; }
.task-card progress { width: 100%; height: 6px; accent-color: var(--accent); }
.task-count:not(:empty) { padding: 1px 5px; color: var(--accent); font-size: 10px; }
.gallery-filters { display: grid; grid-template-columns: minmax(140px, 1fr) 145px 145px; gap: 10px; }
.gallery-filters input, .gallery-filters select { width: 100%; min-height: 42px; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(185px, 1fr)); gap: 16px; }
.gallery-item { overflow: hidden; border-radius: 12px; border: 1px solid var(--border); background: var(--paper); }
.gallery-image { display: block; padding: 0; width: 100%; border: 0; background: var(--paper-3); cursor: zoom-in; }
.gallery-image img { display: block; width: 100%; aspect-ratio: 4/3; object-fit: cover; }
.gallery-item > div { padding: 12px; }
.gallery-item strong, .gallery-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gallery-item strong { font-size: 13px; }
.gallery-item small { font-size: 11px; margin-top: 5px; color: var(--text-3); }
.gallery-original { display: block; width: 100%; max-height: 60dvh; object-fit: contain; border-radius: 10px; background: var(--paper); }

@media (min-width: 1440px) {
  .page-room .room-shell { grid-template-columns: minmax(0, 1fr) 400px; }
}
@media (max-width: 1100px) {
  .page-rooms .topbar { gap: 8px; flex-wrap: wrap; }
  .page-rooms .topbar .sub { display: none; }
  .lobby-layout { grid-template-columns: 235px minmax(0, 1fr); gap: 18px; }
}
@media (max-width: 900px) {
  .topbar { padding: 10px 14px; min-height: 58px; gap: 10px; }
  .topbar .nav { gap: 4px; }
  .topbar .nav-link { padding: 7px 10px; }
  .page, .page-wide { width: calc(100% - 32px); padding: 22px 0 32px; }
  .page-rooms .topbar .logo { margin-right: auto; }
  .page-rooms .topbar .spacer, .page-rooms .topbar .sub { display: none; }
  .page-rooms .topbar .nav { order: 10; width: 100%; }
  .page-rooms .topbar .nav a { flex: 1; justify-content: center; }
  .page-rooms #templates-btn { font-size: 0; width: 40px; padding: 0; }
  .page-rooms #templates-btn::before { content: '📁'; font-size: 17px; }
  .page-rooms #online-toggle { font-size: 0; width: 40px; padding: 0; }
  .page-rooms #online-toggle::before { content: '👥'; font-size: 17px; }
  .page-rooms .user-chip { max-width: 85px !important; }
  .page-rooms .user-chip > span:last-child { display: none; }
  .lobby-layout { display: flex; flex-direction: column; gap: 16px; }
  .lobby-layout .right-col { order: -1; }
  .lobby-heading { align-items: stretch; flex-direction: column; gap: 16px; }
  .lobby-heading h1 { font-size: 25px; }
  .lobby-tabs button { flex: 1; padding-inline: 12px; }
  .lobby-layout .side-panel { display: none; }
  .lobby-layout.filters-open .side-panel { display: block; order: -2; }
  .mobile-filter { display: inline-flex; }
  .room-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
  .room-card { min-height: 155px; }
  .filter-row .toggle { font-size: 12px; }
  .saves-item { flex-direction: column; align-items: stretch; }
  .s-i-actions .btn { min-height: 40px; }
  .admin-btn { margin: 0 16px 24px auto; }
  .page-room > .topbar { min-height: 56px; padding: 8px 12px; flex-wrap: nowrap; }
  .page-room > .topbar .logo, .page-room > .topbar .nav { display: none; }
  .page-room > .topbar .topbar-title { flex: 1; }
  .page-room > .topbar .spacer { display: none; }
  .page-room > .topbar .sub { max-width: 65vw; }
  .page-room > .topbar .sidebar-toggle { display: none; }
  .page-room .room-shell { grid-template-columns: minmax(0, 1fr); }
  .room-toolbar { padding: 3px 12px; min-height: 44px; }
  .room-quick-actions > button { display: none; }
  .channel-tab { min-height: 38px; font-size: 12px; }
  .chat-feed { padding: 14px 12px; }
  .chat-feed .msg { max-width: 100%; }
  .msg.gm .gm-card { padding: 16px; }
  .msg.gm .gm-text { font-size: 15px; line-height: 1.85; }
  .composer { padding: 6px 12px 10px; }
  .composer .input-row { display: grid; grid-template-columns: minmax(0, 1fr) 68px; gap: 8px; }
  .composer textarea { grid-column: 1 / -1; width: 100%; min-height: 44px; max-height: 100px; height: 44px; font-size: 16px; resize: none; }
  .composer .input-row .btn { height: 38px; min-height: 38px; padding-block: 5px; }
  #gm-btn { justify-self: start; padding-inline: 10px; font-size: 12px; }
  .composer-tools > summary { min-height: 32px; padding: 4px 0; }
  .composer-tools > summary span { font-size: 10px; }
  .composer-tools[open] { max-height: 185px; overflow-y: auto; }
  .composer .custom-dice { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
  .composer .custom-dice input { font-size: 14px; }
  .composer .chip { min-height: 38px; }
  .workspace-nav { display: flex; flex: 0 0 auto; justify-content: space-around; border-top: 1px solid var(--border); padding: 4px 4px max(4px, env(safe-area-inset-bottom)); background: var(--paper-2); }
  .workspace-nav button { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-height: 48px; font-size: 10px; border: 0; border-radius: 8px; background: transparent; color: var(--text-3); }
  .workspace-nav button > span { font-size: 19px; line-height: 1.2; }
  .workspace-nav button.active { color: var(--accent); background: var(--accent-soft); }
  .workspace-nav .task-count { position: absolute; top: 1px; right: 24%; }
  .sidebar { width: min(420px, 94vw); z-index: 61; padding: 0 16px 30px; background: var(--paper-2); }
  .sidebar-close { display: block; min-width: 40px; border: 0; background: transparent; color: var(--text-2); font-size: 24px; }
  .sidebar-scrim { position: fixed; inset: 0; background: #0008; z-index: 60; border: 0; }
  .sidebar-open .sidebar-scrim { display: block; }
  .modal-mask { padding: 12px; }
  .modal { max-height: calc(100dvh - 24px); padding: 20px 16px; }
  .workspace-dialog { width: calc(100vw - 24px); max-height: calc(var(--room-height, 100dvh) - 24px); border-radius: 14px; padding: 18px; }
  .workspace-heading { margin-bottom: 16px; }
  .workspace-heading h2 { font-size: 22px; }
  .gallery-filters { grid-template-columns: 1fr 1fr; gap: 8px; }
  .gallery-filters input { grid-column: 1 / -1; }
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .gallery-item > div { padding: 10px; }
  .workspace-actions .btn { flex: 1; }
  .task-card, .version-card { padding: 14px; }
  .version-card .btn { min-height: 44px; }
  .char-fields, .char-tab-pane.attrs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 380px) {
  .page-rooms .topbar { gap: 4px; }
  .page-rooms .topbar .logo { font-size: 13px; }
  .page-rooms #logout { padding-inline: 8px; }
  .room-toolbar { padding-inline: 8px; gap: 5px; }
  .connection-state { font-size: 10px; }
  .composer-tools > summary span { display: none; }
}
@media (max-height: 500px) and (max-width: 900px) {
  .page-room .workspace-nav { display: none; }
  .composer-tools { display: none; }
  .page-room > .topbar { min-height: 42px; padding-block: 4px; }
  .room-toolbar { min-height: 36px; }
  .composer .input-row { grid-template-columns: minmax(0, 1fr) auto auto; }
  .composer textarea { grid-column: auto; }
  .composer { padding-block: 6px; }
}

[hidden] { display: none !important; }
.lobby-tabs { margin-bottom: 22px; }

body { background-image: radial-gradient(ellipse at 15% 0%, rgba(var(--accent-rgb), .055), transparent 50%); }
body.page-room { --text-glow: none; --text-glow-2: none; --shadow-sm: 0 3px 14px #0003; }
body.page-room .ambient { display: none; }
@media (max-height: 500px) and (max-width: 900px) {
  .page-room > .topbar .sidebar-toggle { display: inline-flex; }
  .room-quick-actions > button { display: inline-flex; min-height: 32px; }
  .room-quick-actions .connection-state { display: none; }
}

.workspace-dialog { margin: auto; }

.library-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin: 28px 0 20px; }
.library-toolbar input { flex: 1; min-width: 200px; min-height: 44px; }
.library-toolbar select { min-height: 44px; }
.library-toolbar > span { font-size: 12px; color: var(--text-3); }
.library-card { padding: 24px; border-radius: 14px; align-self: start; min-width: 0; }
.library-card h2 { font-size: 18px; line-height: 1.5; margin: 0; }
.library-card > p { margin: 12px 0; font-size: 13px; color: var(--text-2); line-height: 1.85; }
.library-card > small { color: var(--text-3); font-size: 11px; }
.library-card .b-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.library-details { margin-top: 18px; border-top: 1px solid var(--border); }
.library-details > summary { cursor: pointer; min-height: 44px; padding-top: 13px; font-size: 13px; color: var(--accent); }
.library-content { padding-top: 16px; min-width: 0; }
.library-content .book-card { padding: 0; border: 0; background: transparent; box-shadow: none; }
.library-content section { margin-bottom: 20px; }
.library-content h3 { margin-bottom: 8px; font-size: 14px; }
.library-content .e-content { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }
@media (max-width: 900px) { .library-card { padding: 18px; } .library-toolbar > span { display: none; } }

.library-content .book-card > .b-head, .library-content .book-card > .b-desc { display: none; }
