/* Native WebView consumes window insets in MainActivity. Older WebViews lack env(). */
:root { --dy-safe-top: 0px; --dy-safe-bottom: 0px; }
@supports (top: env(safe-area-inset-top, 0px)) {
  :root { --dy-safe-top: env(safe-area-inset-top, 0px); --dy-safe-bottom: env(safe-area-inset-bottom, 0px); }
}
html.is-android-app { --dy-safe-top: 0px; --dy-safe-bottom: 0px; }

/* ==========================================================================
   丁乙奇门 · Apple 级东方极简奢华手机 PWA 样式表（V3 像素级落地）
   双皮肤：宣纸白（默认日间）⇄ 玄黑鎏金（暗夜护眼）
   ========================================================================== */

@font-face {
  font-family: "WorkflowSerif";
  src: url("/m/workflow-serif.woff2") format("woff2");
  font-weight: 200 900;
  font-display: swap;
}

:root,
:root[data-theme="light"] {
  --bg: #FAF9F6;
  --bg-fade: rgba(250, 249, 246, 0);
  --bg-glass: rgba(250, 249, 246, 0.84);
  --surface: #FFFFFF;
  --surface-2: #F5F2EB;
  --subtle: #F2EFE9;
  --subtle-hover: #EAE5DC;
  --ink: #1C1A16;
  --ink-2: #3F3B33;
  --muted: #8C8578;
  --muted-2: #B0A99B;
  --hairline: rgba(120, 102, 72, 0.14);
  --hairline-strong: rgba(120, 102, 72, 0.26);
  --border: rgba(120, 102, 72, 0.20);
  --danger: #B83B3B;
  --accent: #9E382A;
  --accent-deep: #7F261A;
  --accent-soft: rgba(158, 56, 42, 0.09);
  --gold: #8D6A36;
  --gold-soft: rgba(141, 106, 54, 0.10);
  --jade: #386B55;
  --jade-soft: rgba(56, 107, 85, 0.10);
  --user-bg: #EFEBE1;
  --pill-bg: rgba(255, 254, 251, 0.66);
  --panel-glass: rgba(255, 254, 251, var(--chart-alpha, 0.96));
  --panel-cell: rgba(242, 239, 233, var(--chart-alpha, 0.96));
  --pill-shadow: 0 8px 28px rgba(34, 28, 18, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.65);
  --sheet-bg: #FAF9F6;
  --drawer-bg: #F6F4EE;
  --overlay: rgba(24, 21, 16, 0.38);
  --selection-bg: rgba(158, 56, 42, 0.16);
  --board-bg: #fffdfa;
  --board-grid: rgba(163, 58, 40, 0.56);
  --board-outline: rgba(163, 58, 40, 0.76);
  --board-house-fill: rgba(177, 65, 46, 0.04);
  --board-house-stroke: rgba(163, 58, 40, 0.56);
  --board-house-text: #8a582b;
  --board-branch-fill: rgba(60, 114, 78, 0.08);
  --board-branch-stroke: rgba(53, 104, 72, 0.58);
  --board-branch-text: #2d3326;
  --board-void-fill: rgba(197, 155, 99, 0.18);
  --board-void-stroke: #b08844;
  --board-void-badge: #a84232;
  --board-star-fill: #fff9f1;
  --board-star-stroke: #ae4b36;
  --board-star-text: #a13c2d;
  --board-bstar-fill: #f2e6ce;
  --board-bstar-stroke: #9c753b;
  --board-bstar-text: #795322;
  --board-god-text: #29271f;
  --board-label: #8a8272;
  --board-life-fill: #f2e7d0;
  --board-life-stroke: #9c753b;
  --board-house-hover: rgba(158, 56, 42, 0.13);
  --board-anchor-fill: rgba(158, 56, 42, 0.16);
  --board-anchor-stroke: #9E382A;
  --board-anchor-text: #8C281B;
  --board-anchor-branch-fill: rgba(158, 56, 42, 0.10);
  --serif: "WorkflowSerif", "Songti SC", "Noto Serif SC", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0A0B09;
  --bg-fade: rgba(10, 11, 9, 0);
  --bg-glass: rgba(10, 11, 9, 0.84);
  --surface: #171A15;
  --surface-2: #1E221B;
  --subtle: #1F231C;
  --subtle-hover: #282D24;
  --ink: #F7EFE0;
  --ink-2: #CFC6B2;
  --muted: #938A78;
  --muted-2: #686153;
  --hairline: rgba(225, 208, 166, 0.14);
  --hairline-strong: rgba(225, 208, 166, 0.26);
  --border: rgba(225, 208, 166, 0.20);
  --danger: #E06352;
  --accent: #C74938;
  --accent-deep: #9E3022;
  --accent-soft: rgba(199, 73, 56, 0.18);
  --gold: #D9A962;
  --gold-soft: rgba(217, 169, 98, 0.14);
  --jade: #5FA387;
  --jade-soft: rgba(95, 163, 135, 0.15);
  --user-bg: #1E211A;
  --pill-bg: rgba(22, 24, 19, 0.88);
  --panel-glass: rgba(16, 18, 14, var(--chart-alpha, 0.96));
  --panel-cell: rgba(28, 32, 25, var(--chart-alpha, 0.96));
  --pill-shadow: 0 12px 34px rgba(0, 0, 0, 0.50), inset 0 1px 0 rgba(255, 246, 224, 0.12);
  --sheet-bg: #151813;
  --drawer-bg: #121410;
  --overlay: rgba(0, 0, 0, 0.72);
  --selection-bg: rgba(217, 169, 98, 0.26);
  --board-bg: #101512;
  --board-grid: rgba(102, 93, 69, 0.72);
  --board-outline: rgba(128, 115, 84, 0.92);
  --board-house-fill: #181912;
  --board-house-stroke: #5c533d;
  --board-house-text: #ddbd83;
  --board-branch-fill: #1b2820;
  --board-branch-stroke: #52634e;
  --board-branch-text: #f0ead6;
  --board-void-fill: #30291d;
  --board-void-stroke: #c59b63;
  --board-void-badge: #b13b2d;
  --board-star-fill: #201b16;
  --board-star-stroke: #dc7763;
  --board-star-text: #f18b75;
  --board-bstar-fill: #252318;
  --board-bstar-stroke: #b79756;
  --board-bstar-text: #dfb86d;
  --board-god-text: #e5dcc4;
  --board-label: #b7aa8c;
  --board-life-fill: #302918;
  --board-life-stroke: #ad9158;
  --board-house-hover: rgba(217, 169, 98, 0.16);
  --board-anchor-fill: rgba(199, 73, 56, 0.28);
  --board-anchor-stroke: #D9A962;
  --board-anchor-text: #FFE4B5;
  --board-anchor-branch-fill: rgba(217, 169, 98, 0.18);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior-y: none;
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea {
  font-family: inherit;
  color: inherit;
  border: none;
  background: none;
  outline: none;
}

input, textarea {
  -webkit-user-select: text !important;
  user-select: text !important;
  font-size: 16px;
}

button { cursor: pointer; }

.hidden { display: none !important; }

/* Native Text Selection Luxury Highlight */
.selectable, .selectable * {
  -webkit-user-select: text !important;
  user-select: text !important;
  -webkit-touch-callout: default;
}
::selection {
  background: var(--selection-bg);
  color: var(--ink);
}

/* ==================== 1. LOCK SCREEN ==================== */
.lock-screen {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0; inset: 0;
  z-index: 90;
  background:
    radial-gradient(circle at 50% 18%, rgba(158, 56, 42, 0.08), transparent 420px),
    var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.lock-inner {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.brand-seal-lg {
  width: 62px;
  height: 62px;
  border-radius: 18px;
  background: linear-gradient(155deg, #B24030, #83271B);
  color: #FFF8EC;
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 14px 32px rgba(158, 56, 42, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.lock-title {
  font-family: var(--serif);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: 2px;
  margin-top: 20px;
  color: var(--ink);
}

.lock-sub {
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: 1px;
  margin-top: 8px;
}

.lock-form {
  width: 100%;
  margin-top: 34px;
}

.lock-input-pill {
  height: 54px;
  border-radius: 99px;
  background: var(--pill-bg);
  border: 1px solid var(--hairline-strong);
  box-shadow: var(--pill-shadow);
  padding: 6px 6px 6px 18px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.2s ease;
}

.lock-input-pill:focus-within {
  border-color: var(--accent);
}

.lock-input-pill.shake {
  animation: shake 0.36s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.lock-input-pill input {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  letter-spacing: 0.4px;
  color: var(--ink);
}

.lock-input-pill input::placeholder {
  color: var(--muted-2);
  letter-spacing: 0.2px;
}

.lock-eye {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.lock-enter {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.14s ease, opacity 0.2s ease;
}
.lock-enter:active { transform: scale(0.92); }
.lock-enter:disabled { opacity: 0.45; }

.lock-error {
  min-height: 22px;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--accent);
}

.lock-foot {
  margin-top: 42px;
  font-size: 11px;
  color: var(--muted-2);
  letter-spacing: 0.4px;
}

/* ==================== 2. MAIN APP SHELL (FULL-BLEED IMMERSIVE CANVAS) ==================== */
.app-shell {
  position: fixed;
  top: var(--vvt, 0px);
  bottom: 0;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: 100%;
  max-width: 560px;
  overflow: hidden;
  background: var(--bg);
}
body.kb-open .app-shell {
  bottom: auto;
  height: var(--vvh, 100%);
}
body.kb-open .app-header {
  padding-top: calc(var(--dy-safe-top) + 6px);
  padding-bottom: 10px;
}

/* Borderless Floating Top Controls — Zero opaque wall, zero divider lines; text glides seamlessly behind */
.app-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 26;
  padding: calc(var(--dy-safe-top) + 12px) 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: linear-gradient(to bottom, var(--bg) 62%, var(--bg-fade) 100%);
  pointer-events: none;
}
@media (display-mode: standalone) {
  .app-header {
    padding-top: calc(var(--dy-safe-top) + 18px);
  }
}
html.is-standalone .app-header {
  padding-top: calc(var(--dy-safe-top) + 18px);
}
.app-header > * { pointer-events: auto; }

.nav-circle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-2);
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.12s ease;
}
.nav-circle.glass-ctrl,
.nav-pill-back.glass-ctrl {
  background: var(--pill-bg);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border: 1px solid var(--hairline);
  box-shadow: 0 3px 12px rgba(24, 21, 16, 0.05);
}
.nav-circle:active,
.nav-pill-back:active { transform: scale(0.93); background: var(--subtle-hover); }

.nav-pill-back {
  height: 38px;
  padding: 0 11px 0 8px;
  border-radius: 99px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.12s ease;
}

/* Unified Top Floating Island Pill (Replaces BOTH bulky title header AND separate 2nd-row chart bar!) */
.top-island-pill {
  height: 38px;
  max-width: calc(100% - 122px);
  padding: 0 12px;
  border-radius: 99px;
  background: var(--pill-bg);
  backdrop-filter: blur(18px) saturate(1.45);
  -webkit-backdrop-filter: blur(18px) saturate(1.45);
  border: 1px solid var(--hairline-strong);
  box-shadow: 0 4px 16px rgba(24, 21, 16, 0.06);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  touch-action: none;
  transition: border-color 0.18s ease, transform 0.14s ease, background 0.14s ease, box-shadow 0.2s ease;
}
.top-island-pill:active { transform: scale(0.97); }
.top-island-pill.open { border-color: var(--gold); }
.top-island-pill.has-new-chart {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft), 0 4px 16px rgba(24, 21, 16, 0.08);
}

.tip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  animation: pulse 1.35s infinite ease-in-out;
}
.tip-badge {
  font-size: 9.5px;
  font-weight: 700;
  color: var(--gold);
  background: var(--gold-soft);
  padding: 1.5px 5.5px;
  border-radius: 99px;
  flex-shrink: 0;
  letter-spacing: 0.2px;
}
.tip-text {
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tip-caret {
  font-size: 10px;
  color: var(--muted);
  flex-shrink: 0;
  margin-left: -1px;
  display: inline-block;
  transition: transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}
.top-island-pill.open .tip-caret {
  transform: rotate(180deg);
}

.hdr-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 38px;
  gap: 6px;
  pointer-events: none;
}
.hdr-right > * { pointer-events: auto; }

/* ==================== 3. FULL-BLEED EDGE-TO-EDGE CHAT CANVAS ==================== */
.chat-canvas {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0; inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--dy-safe-top) + 64px) 18px calc(92px + var(--dy-safe-bottom));
  scroll-behavior: smooth;
}
html.is-standalone:not(.is-android-app) .chat-canvas {
  padding-top: calc(var(--dy-safe-top) + 68px);
  padding-bottom: calc(96px + var(--dy-safe-bottom));
}
html.is-android-app .chat-canvas {
  padding-top: calc(var(--dy-safe-top) + 64px);
  padding-bottom: 88px;
}

.welcome-view {
  min-height: calc(100% - 16px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding-bottom: 36px;
}

.brand-seal-md {
  width: 52px;
  height: 52px;
  border-radius: 15px;
  background: linear-gradient(155deg, #B24030, #83271B);
  color: #FFF8EC;
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 28px rgba(158, 56, 42, 0.24);
}

.welcome-title {
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.6px;
  margin-top: 6px;
}

.welcome-desc {
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--muted);
  max-width: 286px;
}

.welcome-engines {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--gold);
  font-weight: 500;
  letter-spacing: 0.5px;
}
.sep-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--hairline-strong);
  display: inline-block;
}

.welcome-loc-hint {
  margin-top: 12px;
  font-size: 11px;
  color: var(--muted-2);
  max-width: 290px;
  line-height: 1.5;
}

/* Messages Stream */
.messages-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
  contain: layout style;
}

.msg-user-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.msg-user-bubble {
  max-width: 86%;
  background: var(--user-bg);
  border-radius: 20px 20px 6px 20px;
  padding: 11px 15px;
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--ink);
  word-break: break-word;
}

.msg-user-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.msg-user-thumb {
  width: 58px;
  height: 58px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--hairline-strong);
  cursor: zoom-in;
}

.msg-user-meta {
  font-size: 11px;
  color: var(--muted);
  padding: 0 4px;
}

/* AI Editorial Message (Borderless Apple Luxury) */
.msg-ai-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chart-ribbon {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chart-bar-item {
  background: var(--subtle);
  border: 1px solid var(--hairline);
  border-radius: 13px;
  padding: 9px 13px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chart-bar-item.clickable {
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.12s ease;
}
.chart-bar-item.clickable:active {
  transform: scale(0.985);
  background: var(--subtle-hover);
  border-color: var(--gold);
}
.cb-detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.cb-jump {
  font-size: 10px;
  color: var(--gold);
  font-weight: 600;
  flex-shrink: 0;
  opacity: 0.88;
}

.cb-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cb-label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.4px;
}

.cb-gz {
  font-family: var(--serif);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.5px;
}

.cb-detail {
  font-size: 11px;
  color: var(--muted);
}

/* Luopan Output Gallery in Stream */
.lp-gallery {
  background: #121512;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--hairline-strong);
  position: relative;
  box-shadow: 0 10px 28px rgba(24, 21, 16, 0.14);
}

.lp-gallery-img {
  width: 100%;
  max-height: 340px;
  object-fit: contain;
  display: block;
  background: #101310;
  cursor: zoom-in;
}

.lp-glass-controls {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.lp-seg-bar {
  pointer-events: auto;
  background: rgba(18, 20, 18, 0.78);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(225, 208, 166, 0.22);
  border-radius: 99px;
  padding: 3px;
  display: flex;
  gap: 2px;
}

.lp-seg-btn {
  font-size: 10.5px;
  padding: 4px 10px;
  border-radius: 99px;
  color: rgba(247, 239, 224, 0.72);
  font-weight: 500;
}
.lp-seg-btn.active {
  background: rgba(247, 239, 224, 0.18);
  color: #F7EFE0;
  font-weight: 600;
}

.lp-ico-btns {
  pointer-events: auto;
  display: flex;
  gap: 6px;
}

.lp-ico-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(18, 20, 18, 0.80);
  border: 1px solid rgba(225, 208, 166, 0.25);
  color: #F7EFE0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

/* Pure Editorial Prose (100% Free Partial Text Selection) */
.ai-prose {
  font-size: 15px;
  line-height: 1.78;
  color: var(--ink-2);
  letter-spacing: 0.15px;
  word-break: break-word;
}

.ai-prose p { margin-bottom: 11px; }
.ai-prose p:last-child { margin-bottom: 0; }
.ai-prose strong { color: var(--ink); font-weight: 650; }
.ai-prose em { font-style: normal; color: var(--gold); font-weight: 600; }
.ai-prose h3, .ai-prose h4 {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  margin: 14px 0 6px;
}
.ai-prose ul, .ai-prose ol {
  padding-left: 18px;
  margin-bottom: 10px;
}
.ai-prose li { margin-bottom: 5px; }
.ai-prose blockquote {
  border-left: 2px solid var(--gold);
  padding: 2px 0 2px 12px;
  color: var(--ink);
  margin: 10px 0;
}

.ai-prose.is-error {
  color: var(--accent);
}
.ai-prose.is-aborted {
  color: var(--muted);
  font-size: 13.5px;
}

/* Ultra-Minimal Apple Action Row (Small Copy Icon Only, Zero Loud Button!) */
.ai-action-row {
  display: flex;
  align-items: center;
  gap: 18px;
  padding-top: 2px;
}

.action-mini {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  padding: 4px 2px;
  transition: color 0.15s ease, transform 0.12s ease;
}
.action-mini:active { transform: scale(0.92); }
.action-mini.copied { color: var(--jade); }
.action-mini.gold { color: var(--gold); }

/* Live Running Progress */
.running-indicator {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.running-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.running-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  align-self: flex-start;
  background: var(--subtle);
  border: 1px solid var(--hairline-strong);
  border-radius: 99px;
  padding: 8px 14px;
  font-size: 12.5px;
  color: var(--ink);
  font-weight: 500;
}

.running-stop-btn {
  padding: 6px 12px;
  border-radius: 99px;
  background: var(--accent-soft);
  border: 1px solid rgba(158, 56, 42, 0.28);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
  transition: transform 0.12s ease, background 0.14s ease;
}
.running-stop-btn:active { transform: scale(0.94); }

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.35s infinite ease-in-out;
}
@keyframes pulse {
  0%, 100% { transform: scale(0.85); opacity: 0.45; }
  50% { transform: scale(1.18); opacity: 1; }
}

.running-step {
  font-size: 11px;
  color: var(--gold);
  font-weight: 600;
}

.running-tip {
  font-size: 11.5px;
  color: var(--muted);
  padding-left: 4px;
}

/* ==================== 4. SLIM FLOATING LIQUID DOCK + IMMERSIVE AUTO-TUCK ==================== */
.dock-wrapper {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  padding: 14px 14px 10px;
  padding: 14px 14px max(10px, var(--dy-safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  background: linear-gradient(to top, var(--bg) 42%, var(--bg-fade) 100%);
  transition: opacity 0.22s ease, transform 0.24s cubic-bezier(0.2, 0.85, 0.3, 1);
}
html.is-android-app .dock-wrapper {
  padding-bottom: 8px;
}
body.kb-open .dock-wrapper {
  padding: 4px 12px 4px !important;
  background: transparent;
  transition: none;
}
body.kb-open .chat-canvas {
  padding-bottom: 66px !important;
}
body.reading-immersed .dock-wrapper {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}
body.reading-immersed .dock-wrapper > * {
  pointer-events: none !important;
}

.dock-wrapper > * { pointer-events: auto; }

@keyframes popUp {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Floating Jump-to-Bottom Pill when user scrolls away from bottom */
.jump-bottom-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(68px + var(--dy-safe-bottom));
  z-index: 28;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--pill-bg);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid var(--hairline-strong);
  box-shadow: 0 6px 18px rgba(24, 21, 16, 0.12);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.14s ease, opacity 0.18s ease;
}
.jump-bottom-btn:active { transform: translateX(-50%) scale(0.92); }
body.kb-open .jump-bottom-btn { bottom: 64px; }
body.reading-immersed .jump-bottom-btn { bottom: max(14px, var(--dy-safe-bottom)); }

/* Whisper-quiet Bottom-Right Compose Pill during Immersive Reading */
.immersed-compose-btn {
  position: absolute;
  right: 14px;
  bottom: max(12px, var(--dy-safe-bottom));
  z-index: 29;
  height: 38px;
  padding: 0 14px;
  border-radius: 99px;
  background: var(--pill-bg);
  backdrop-filter: blur(18px) saturate(1.45);
  -webkit-backdrop-filter: blur(18px) saturate(1.45);
  border: 1px solid var(--hairline-strong);
  box-shadow: 0 6px 20px rgba(24, 21, 16, 0.08);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  opacity: 0;
  transform: translateY(10px) scale(0.92);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.22s cubic-bezier(0.2, 0.85, 0.3, 1);
}
html.is-android-app .immersed-compose-btn { bottom: 10px; }
body.reading-immersed .immersed-compose-btn {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
body.kb-open .immersed-compose-btn {
  opacity: 0 !important;
  pointer-events: none !important;
}
.immersed-compose-btn:active { transform: scale(0.94); }

/* Pending Images Strip */
.pending-images {
  display: flex;
  gap: 8px;
  padding: 6px 4px 2px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.pending-images::-webkit-scrollbar { display: none; }

.pill-plus, .pill-action-btn, .pill-send {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.pend-item {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--hairline-strong);
  flex-shrink: 0;
  background: var(--surface);
}

.pend-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.pend-rm {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(20, 18, 15, 0.72);
  color: #FFF;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Smooth Attach Popover */
.attach-popover {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: 16px;
  padding: 6px;
  display: flex;
  gap: 4px;
  box-shadow: 0 14px 32px rgba(24, 21, 16, 0.14);
  animation: popUp 0.16s cubic-bezier(0.2, 0.85, 0.3, 1);
}

.ap-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 11px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
  transition: background 0.14s ease;
}
.ap-btn:active { background: var(--subtle); }

/* Slim Floating Input Pill */
.floating-pill {
  min-height: 46px;
  border-radius: 24px;
  background: var(--pill-bg);
  backdrop-filter: blur(18px) saturate(1.5);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  border: 1px solid var(--hairline);
  box-shadow: var(--pill-shadow);
  padding: 4px 5px 4px 6px;
  display: flex;
  align-items: flex-end;
  gap: 7px;
  transition: border-color 0.2s ease;
}
.floating-pill:focus-within { border-color: var(--gold); }

.sr-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

.pill-plus {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--subtle);
  color: var(--ink-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.14s ease, background 0.15s ease;
}
.pill-plus:active { transform: scale(0.92); background: var(--subtle-hover); }

#chat-input {
  flex: 1;
  min-width: 0;
  height: 36px;
  min-height: 36px;
  max-height: 120px;
  padding: 6px 2px;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  resize: none;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
/* The pill already indicates focus around the whole composer. */
#chat-input:focus {
  outline: none;
  max-height: calc(4.35em + 12px);
}
#chat-input::-webkit-scrollbar { display: none; }
#chat-input::placeholder { color: var(--muted); font-size: 13.5px; }

.pill-action-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.14s ease, opacity 0.18s ease, background 0.18s ease;
}
.pill-action-btn:active:not(:disabled) { transform: scale(0.92); }
.pill-action-btn:disabled {
  background: var(--subtle);
  color: var(--muted-2);
  opacity: 0.72;
  cursor: default;
}
.pill-action-btn.is-stop {
  background: var(--accent);
  color: #FFF8EC;
  opacity: 1;
}

.action-token-pill {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
  padding: 3px 6px;
  letter-spacing: 0.2px;
}


/* ==================== 5. LEFT CLIENT DRAWER & RIGHT SETTINGS DRAWER (NATIVE EDGE-SWIPE) ==================== */
.overlay {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0; inset: 0;
  z-index: 50;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, visibility 0s linear 0.22s;
}
.overlay.open {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.22s ease, visibility 0s;
}
.overlay.is-dragging {
  visibility: visible;
  pointer-events: auto;
  transition: none !important;
}
.overlay-right {
  justify-content: flex-end;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.left-drawer {
  width: 84%;
  max-width: 330px;
  height: 100%;
  background: var(--drawer-bg);
  border-right: 1px solid var(--hairline-strong);
  box-shadow: 12px 0 36px rgba(0, 0, 0, 0.24);
  padding: calc(var(--dy-safe-top) + 16px) 16px calc(var(--dy-safe-bottom) + 18px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  contain: layout style paint;
  transform: translate3d(-100%, 0, 0);
  transition: transform 0.22s cubic-bezier(0.2, 0.88, 0.32, 1);
}
.overlay.open .left-drawer,
.overlay.is-dragging .left-drawer {
  will-change: transform;
}
.overlay.open .left-drawer {
  transform: translate3d(0, 0, 0);
}
.overlay.is-dragging .left-drawer,
.overlay.is-dragging .right-drawer {
  transition: none !important;
}

.right-drawer {
  width: 82%;
  max-width: 310px;
  height: 100%;
  margin-left: auto;
  background: var(--drawer-bg);
  border-left: 1px solid var(--hairline-strong);
  box-shadow: -12px 0 36px rgba(0, 0, 0, 0.28);
  padding: calc(var(--dy-safe-top) + 16px) 16px calc(var(--dy-safe-bottom) + 18px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  contain: layout style paint;
  transform: translate3d(100%, 0, 0);
  transition: transform 0.22s cubic-bezier(0.2, 0.88, 0.32, 1);
}
.overlay.open .right-drawer,
.overlay.is-dragging .right-drawer {
  will-change: transform;
}
.overlay.open .right-drawer {
  transform: translate3d(0, 0, 0);
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.set-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.set-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.set-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.3px;
}
.set-val-text {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.set-sub-hint {
  font-size: 10.5px;
  color: var(--muted);
  line-height: 1.45;
}
.set-quota-line {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--gold);
  background: var(--gold-soft);
  padding: 5px 9px;
  border-radius: 9px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
.set-seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  background: var(--subtle);
  padding: 3px;
  border-radius: 10px;
}
.set-seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 36px;
  padding: 6px 4px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  transition: background 0.14s ease, color 0.14s ease;
}
.set-seg-btn.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.set-action-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--subtle);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  transition: background 0.14s ease;
}
.set-action-row.gold { color: var(--gold); }
.set-action-row:active { background: var(--subtle-hover); }
.set-chev { opacity: 0.7; font-size: 11px; }

.settings-foot {
  padding-top: 10px;
  border-top: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.set-gesture-tip {
  font-size: 10.5px;
  color: var(--muted-2);
  text-align: center;
  line-height: 1.4;
}
.set-logout-btn {
  width: 100%;
  height: 38px;
  border-radius: 11px;
  background: var(--subtle);
  border: 1px solid var(--hairline);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  transition: background 0.14s ease, color 0.14s ease;
}
.set-logout-btn:active { background: var(--subtle-hover); color: var(--accent); }

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.drawer-head-btns {
  display: flex;
  align-items: center;
  gap: 8px;
}
.drawer-brand { display: flex; align-items: center; gap: 9px; }
.brand-seal-xs {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(155deg, #B24030, #83271B);
  color: #FFF8EC; font-family: var(--serif); font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.drawer-brand-name {
  font-family: var(--serif); font-size: 18px; font-weight: 700; color: var(--ink); letter-spacing: 0.6px;
}
.drawer-new-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--subtle); border: 1px solid var(--hairline);
  color: var(--ink); display: flex; align-items: center; justify-content: center;
}

.drawer-search-wrap {
  height: 38px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--hairline);
  padding: 0 13px; display: flex; align-items: center; gap: 8px; color: var(--muted);
}
.drawer-search-wrap input { flex: 1; font-size: 13px; color: var(--ink); }

.drawer-account-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dac-row, .dac-loc-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.dac-label { font-size: 12.5px; font-weight: 600; color: var(--ink); white-space: nowrap; flex-shrink: 0; }
.dac-quota {
  font-size: 10.5px; font-weight: 600; color: var(--gold);
  background: var(--gold-soft); padding: 2px 8px; border-radius: 99px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dac-loc-text { font-size: 11px; color: var(--muted); }
.dac-gps-btn { font-size: 11px; font-weight: 600; color: var(--jade); }

.drawer-scope-bar {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  background: var(--subtle); padding: 3px; border-radius: 10px;
}
.scope-btn {
  padding: 5px; border-radius: 8px; font-size: 12px; color: var(--muted); font-weight: 500;
}
.scope-btn.active { background: var(--surface); color: var(--ink); font-weight: 600; }

.drawer-list-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.5px;
  padding: 2px 4px 0;
}

.drawer-sessions {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ds-item {
  padding: 10px 11px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: pointer;
  transition: background 0.14s ease;
}
.ds-item:active, .ds-item.active { background: var(--subtle); }
.ds-item.running {
  background: var(--gold-soft);
  border: 1px solid var(--hairline-strong);
}

.ds-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.ds-right { display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0; }
.ds-peek-btn,
.ds-rename-btn,
.ds-del-btn {
  width: 30px; height: 30px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); opacity: 0.72; transition: opacity 0.14s ease, background 0.14s ease, color 0.14s ease;
}
.ds-peek-btn:active { opacity: 1; background: var(--gold-soft); color: var(--gold); }
.ds-rename-btn:active { opacity: 1; background: var(--subtle-hover); color: var(--ink); }
.ds-del-btn:active { opacity: 1; background: var(--accent-soft); color: var(--danger); }

.floating-pill.is-readonly {
  opacity: 0.68;
}
.floating-pill.is-readonly .pill-plus {
  pointer-events: none;
  opacity: 0.4;
}
.welcome-client-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  padding: 4px 12px;
  border-radius: 99px;
  background: var(--gold-soft);
  color: var(--gold);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid rgba(154, 122, 68, 0.22);
}
.ds-title {
  font-size: 13.5px; font-weight: 600; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ds-sys { font-size: 10.5px; color: var(--gold); flex-shrink: 0; font-weight: 500; }
.ds-need-name {
  font-size: 10px;
  font-weight: 600;
  color: var(--gold);
  background: var(--gold-soft);
  border: 1px solid rgba(154, 122, 68, 0.28);
  padding: 1.5px 6.5px;
  border-radius: 99px;
  flex-shrink: 0;
  line-height: 1.35;
  transition: transform 0.12s ease, background 0.14s ease;
}
.ds-need-name:active { transform: scale(0.93); background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.ds-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

.drawer-foot {
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.drawer-foot-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.drawer-foot-link { font-size: 12.5px; color: var(--muted); font-weight: 500; padding: 4px 2px; }
.drawer-foot-link.gold { color: var(--gold); font-weight: 600; }

.drawer-ver-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 6px;
  border-top: 1px dashed var(--hairline);
}
.drawer-ver-label {
  font-size: 11px;
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
}
.drawer-ver-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-2);
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--subtle);
  transition: background 0.15s ease;
}
.drawer-ver-btn:active { background: var(--subtle-hover); }
.update-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Non-intrusive Apple-glass Update Banner */
.update-banner {
  position: absolute;
  top: calc(var(--dy-safe-top) + 52px);
  left: 14px;
  right: 14px;
  padding: 9px 12px 9px 14px;
  border-radius: 14px;
  background: var(--panel-glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--gold);
  box-shadow: 0 8px 24px rgba(24, 21, 16, 0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  color: var(--ink);
  z-index: 40;
  cursor: pointer;
  animation: popUp 0.2s cubic-bezier(0.2, 0.85, 0.3, 1);
}
@media (display-mode: standalone) {
  .update-banner {
    top: calc(var(--dy-safe-top) + 58px);
  }
}
html.is-standalone .update-banner {
  top: calc(var(--dy-safe-top) + 58px);
}
.ub-btn {
  padding: 5px 12px;
  border-radius: 99px;
  background: var(--ink);
  color: var(--bg);
  font-size: 11.5px;
  font-weight: 600;
  flex-shrink: 0;
}
.ub-btn:active { transform: scale(0.95); }

/* ==================== 6. BOTTOM SHEETS (PRO / FEEDBACK / KEYS) ==================== */
.sheet-overlay {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0; inset: 0;
  z-index: 60;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  animation: fadeIn 0.18s ease;
}
body.kb-open .sheet-overlay {
  top: var(--vvt, 0px);
  bottom: auto;
  height: var(--vvh, 100%);
}
body.kb-open .bottom-sheet {
  padding-bottom: 14px;
}

.bottom-sheet {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  max-height: 78vh; max-height: 78dvh;
  background: var(--sheet-bg);
  border-top: 1px solid var(--hairline-strong);
  border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(var(--dy-safe-bottom) + 22px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: slideUp 0.24s cubic-bezier(0.2, 0.85, 0.3, 1);
}
.bottom-sheet.sheet-tall { max-height: 88vh; max-height: 88dvh; }
.bottom-sheet.sheet-compact { max-height: 62vh; max-height: 62dvh; }

@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheet-grabber {
  width: 38px; height: 4px; border-radius: 99px;
  background: var(--hairline-strong); align-self: center; flex-shrink: 0;
}

.sheet-head {
  display: flex; justify-content: space-between; align-items: center;
  padding-bottom: 8px; border-bottom: 1px solid var(--hairline); flex-shrink: 0;
}

.sheet-title {
  font-family: var(--serif); font-size: 17px; font-weight: 700; color: var(--ink);
}
.sheet-head-actions { display: flex; align-items: center; gap: 8px; }
.sheet-ico-btn, .sheet-close-btn {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--subtle); color: var(--ink-2);
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 13.5px;
  line-height: 1.72;
  color: var(--ink-2);
}

.sheet-textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  resize: vertical;
  margin-bottom: 12px;
}

.check-row {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 12.5px; color: var(--ink-2); margin-bottom: 14px;
}

.sheet-primary-btn {
  width: 100%; height: 44px; border-radius: 13px;
  background: var(--ink); color: var(--bg);
  font-size: 14px; font-weight: 600; letter-spacing: 0.4px;
}

/* Client Archive Profile Form inside Bottom Sheet */
.prof-form {
  display: flex;
  flex-direction: column;
  gap: 11px;
}
.prof-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.prof-field span {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
}
.prof-input {
  width: 100%;
  height: 40px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  padding: 0 12px;
  font-size: 14px;
  color: var(--ink);
  transition: border-color 0.15s ease;
}
.prof-input:focus {
  border-color: var(--gold);
}
.prof-hint {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
  margin: 0;
}

/* Member keys and usage */
input[type="checkbox"] { accent-color: var(--gold); width: 15px; height: 15px; }

#keys-overlay .bottom-sheet { gap: 8px; }
#keys-overlay .sheet-head { gap: 12px; padding-bottom: 8px; }
#keys-title { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 1.125rem; }
#keys-title:focus { outline: none; }
#keys-overlay button { min-height: 44px; }
#keys-overlay button:disabled { opacity: .6; }
#keys-overlay button:active { opacity: .75; }
#keys-overlay button:focus-visible, #keys-overlay input:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
#keys-overlay .sheet-close-btn { width: 44px; height: 44px; flex: none; }
#keys-back { color: var(--gold); padding: 0 4px; font-size: .875rem; }
#keys-body { min-height: 0; overscroll-behavior: contain; }
.kc-tools, .kc-head, .kc-usage-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.kc-tools { margin-bottom: 10px; color: var(--ink-2); font-size: .8125rem; }
#keys-new { color: var(--gold); font-size: .875rem; font-weight: 650; padding: 0 10px; }
#keys-list { display: grid; gap: 12px; }
.key-card { min-width: 0; border: 1px solid var(--hairline-strong); border-radius: 14px; padding: 8px 16px 14px; background: var(--surface); }
.kc-identity { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.kc-identity h4 { color: var(--ink); font-family: var(--serif); font-size: 1.0625rem; overflow-wrap: anywhere; }
.kc-state { padding: 1px 7px; border-radius: 5px; font-size: .75rem; background: var(--subtle); color: var(--ink-2); }
.kc-state.on { background: var(--jade-soft); color: var(--jade); }
.kc-state.admin { background: var(--gold-soft); color: var(--gold); }
.kc-more { min-width: 44px; margin-right: -8px; display: grid; place-content: center; color: var(--ink-2); }
.kc-more span { font: 700 21px/24px var(--sans); width: 32px; background: var(--subtle); border-radius: 8px; }
.kc-facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 3px 14px; font-size: .8125rem; }
.kc-facts b { color: var(--ink); font-weight: 500; overflow-wrap: anywhere; }
.kc-suffix, .kc-usage { font-variant-numeric: tabular-nums; }
.kc-usage-head { border-top: 1px solid var(--hairline); margin-top: 10px; padding: 9px 0 6px; font-size: .75rem; }
.kc-usage { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; }
.kc-usage dt, .kc-usage small { font-size: .75rem; color: var(--ink-2); }
.kc-usage dd { margin: 0; overflow-wrap: anywhere; }
.kc-usage strong, .kc-usage small { display: block; }
.kc-usage strong { color: var(--ink); font-size: 1.0625rem; line-height: 1.5; }
.kc-option { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 11px 6px; gap: 12px; text-align: left; font-size: .9375rem; color: var(--ink); border-bottom: 1px solid var(--hairline); }
.kc-option:last-child { border-bottom: 0; }
.kc-option span { font-size: 1.25rem; color: var(--ink-2); }
.kc-option.danger, #keys-error { color: var(--danger); }
.kc-form { display: grid; gap: 14px; padding: 5px 0; font-size: .9375rem; }
.kc-member { font-size: .8125rem; overflow-wrap: anywhere; }
.kc-member strong { color: var(--ink); margin-left: 5px; }
.kc-form .confirm-actions { margin-top: 8px; }
.kc-secret { user-select: all; -webkit-user-select: all; overflow-wrap: anywhere; background: var(--subtle); border-radius: 8px; padding: 12px; color: var(--ink); }
.kc-fields { display: grid; gap: 5px; min-width: 0; margin: 0; padding: 0; border: 0; }
.kc-fields legend, .kc-field { font-weight: 600; color: var(--ink); }
.kc-fields p, .kc-hint { font-size: .8125rem; color: var(--ink-2); }
.kc-field { display: grid; gap: 5px; }
.kc-limit-field { display: grid; grid-template-columns: 3em minmax(0, 1fr); align-items: center; gap: 12px; }
.kc-field input, .kc-limit-field input { width: 100%; min-width: 0; height: 44px; padding: 0 12px; background: var(--surface); color: var(--ink); border: 1px solid var(--hairline-strong); border-radius: 9px; font: 400 1rem var(--sans); }
.kc-choice { min-height: 44px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--hairline); }
.kc-choice input { flex: none; width: 18px; height: 18px; accent-color: var(--gold); }
#keys-error { padding: 8px 2px; font-size: .875rem; }
@media (prefers-reduced-motion: reduce) {
  #keys-overlay, #keys-overlay .bottom-sheet { animation: none; }
}

/* ==================== 7. FLOATING COLLAPSIBLE CHART OVERLAY (DIRECTLY UNDER TOP ISLAND) ==================== */
.chart-backdrop {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0; inset: 0;
  z-index: 24;
  background: rgba(16, 14, 10, 0.16);
}
:root[data-theme="dark"] .chart-backdrop {
  background: rgba(0, 0, 0, 0.36);
}
.chart-drawer-dock {
  position: absolute;
  top: calc(var(--dy-safe-top) + 58px);
  left: 0;
  right: 0;
  z-index: 25;
  pointer-events: none;
}
html.is-standalone .chart-drawer-dock {
  top: calc(var(--dy-safe-top) + 64px);
}

/* Compact Floating Glass Overlay — iOS Control-Center grade 60/120fps GPU spring sheet! */
.cd-panel {
  position: relative;
  margin: 0 10px;
  pointer-events: auto;
  max-height: 60vh; max-height: min(60dvh, 496px);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--panel-glass);
  backdrop-filter: blur(20px) saturate(1.45);
  -webkit-backdrop-filter: blur(20px) saturate(1.45);
  border: 1px solid var(--hairline-strong);
  border-radius: 16px;
  padding: 8px 10px 6px;
  box-shadow: 0 14px 36px rgba(15, 13, 10, 0.16);
  display: flex;
  flex-direction: column;
  gap: 6px;
  transform-origin: 50% 0%;
  will-change: transform, opacity;
  transform: translate3d(0, 0, 0) scale(1);
  opacity: 1;
  visibility: visible;
  transition:
    transform 0.38s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.24s ease,
    visibility 0s linear 0s;
}
.chart-drawer-dock.is-closed .cd-panel {
  pointer-events: none;
  transform: translate3d(0, calc(-100% - 76px), 0) scale(0.95);
  opacity: 0;
  visibility: hidden;
  transition:
    transform 0.30s cubic-bezier(0.32, 0.72, 0, 1),
    opacity 0.20s ease,
    visibility 0s linear 0.30s;
}
.chart-drawer-dock.is-open .cd-panel {
  pointer-events: auto;
  transform: translate3d(0, 0, 0) scale(1);
  opacity: 1;
  visibility: visible;
}
.chart-drawer-dock.is-dragging .cd-panel {
  transition: none !important;
  visibility: visible !important;
  pointer-events: auto;
}
.cd-grabber-wrap {
  position: sticky;
  bottom: -6px;
  margin: -1px -10px -6px;
  padding: 6px 0 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  background: linear-gradient(to bottom, transparent, var(--panel-glass) 48%);
  border-radius: 0 0 15px 15px;
  z-index: 4;
}
.cd-grabber {
  width: 36px;
  height: 4px;
  border-radius: 99px;
  background: var(--hairline-strong);
  opacity: 0.9;
  transition: transform 0.16s ease, opacity 0.16s ease, background 0.16s ease;
}
.cd-grabber-wrap:active .cd-grabber,
.chart-drawer-dock.is-dragging .cd-grabber {
  transform: scaleX(1.18);
  background: var(--gold);
  opacity: 1;
}
.cd-panel > * { flex-shrink: 0; }
.cd-panel .cd-meta-strip,
.cd-panel .bz-col:not(.is-day),
.cd-panel .dy-card:not(.selected),
.cd-panel .qm-fp-cell,
.cd-panel .qm-cell:not(.is-life):not(.is-center) {
  background: var(--panel-cell);
}

.cd-tabs {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--subtle);
  padding: 2.5px;
  border-radius: 9px;
}
.cd-tab {
  flex: 1;
  min-width: 0;
  padding: 4.5px 4px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.14s ease, color 0.14s ease;
}
.cd-tab.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

/* Spacetime Qimen Multi-Chart Horizontal History Strip (shown when N >= 2) */
.qm-hist-strip {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 1px 0 3px;
  touch-action: pan-x;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.qm-hist-strip::-webkit-scrollbar { display: none; }
.qm-hist-pill {
  flex: 0 0 auto;
  height: 26px;
  padding: 0 9px;
  border-radius: 99px;
  background: var(--panel-cell);
  border: 1px solid var(--hairline);
  color: var(--ink-2);
  font-size: 10.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  transition: border-color 0.14s ease, background 0.14s ease, color 0.14s ease;
}
.qm-hist-pill b {
  color: var(--gold);
  font-weight: 700;
}
.qm-hist-pill .qm-hist-date {
  color: var(--muted);
  font-size: 9.5px;
  font-variant-numeric: tabular-nums;
}
.qm-hist-pill.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
  font-weight: 600;
}
.qm-hist-pill.active b { color: var(--accent); }

/* Customer Archive Tab inside Floating Panel */
.arc-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.arc-card {
  background: var(--panel-cell);
  border: 1px solid var(--hairline);
  border-radius: 11px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.arc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.arc-name-wrap {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  flex-wrap: wrap;
}
.arc-name {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}
.arc-name.is-empty {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
}
.arc-nick {
  font-size: 11px;
  color: var(--gold);
  background: var(--gold-soft);
  padding: 1px 7px;
  border-radius: 99px;
  font-weight: 600;
}
.arc-notes {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-2);
}
.arc-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.arc-stat-pill {
  font-size: 10px;
  color: var(--muted);
  background: var(--subtle);
  border: 1px solid var(--hairline);
  padding: 1.5px 7px;
  border-radius: 99px;
}
.arc-btn-row {
  display: flex;
  gap: 6px;
  padding-top: 2px;
}
.arc-btn {
  flex: 1;
  min-height: 36px;
  border-radius: 9px;
  background: var(--subtle);
  border: 1px solid var(--hairline-strong);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.arc-btn.primary {
  background: var(--gold-soft);
  border-color: var(--gold);
  color: var(--gold);
}
.arc-btn.danger {
  background: var(--accent-soft);
  border-color: rgba(184, 59, 59, 0.35);
  color: var(--danger);
}
.arc-btn:active { transform: scale(0.97); }
.arc-fb-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
  padding: 0 2px;
}
.arc-fb-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.arc-fb-item {
  background: var(--panel-cell);
  border: 1px solid var(--hairline);
  border-left: 2.5px solid var(--gold);
  border-radius: 9px;
  padding: 6px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.arc-fb-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.arc-fb-time {
  color: var(--ink-2);
  font-weight: 600;
}
.arc-fb-del {
  margin-left: auto;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  min-width: 34px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
}
.arc-fb-del:active { background: var(--accent-soft); color: var(--danger); }
.arc-group {
  background: var(--panel-cell);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 7px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.arc-group-hd {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}
.arc-group-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.arc-group-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}
.arc-group-seq {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent, #9e3124);
  background: var(--gold-soft);
  padding: 0.5px 5px;
  border-radius: 5px;
}
.arc-group-sub {
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.arc-group-acts {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.arc-mini-btn {
  min-height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--hairline-strong);
  background: var(--subtle);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 600;
}
.arc-mini-btn.danger {
  color: var(--danger);
  border-color: rgba(184, 59, 59, 0.34);
}
.arc-mini-btn:active { transform: scale(0.95); }
.arc-group-empty {
  font-size: 10.5px;
  color: var(--muted);
  padding: 2px 2px;
}
.fb-chart-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}
.fb-chart-lbl {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.fb-chart-select {
  width: 100%;
  height: 36px;
  border-radius: 9px;
  border: 1px solid var(--hairline-strong);
  background: var(--subtle);
  color: var(--ink);
  font-size: 12.5px;
  padding: 0 10px;
}
.arc-fb-ref {
  color: var(--gold);
  font-weight: 600;
}
.arc-fb-text {
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink);
  word-break: break-word;
}
.arc-empty {
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
  padding: 10px 8px;
  background: var(--panel-cell);
  border: 1px dashed var(--hairline);
  border-radius: 9px;
}
.arc-tip {
  font-size: 10.5px;
  color: var(--muted);
  line-height: 1.45;
  padding: 0 2px;
}

.cd-meta-strip {
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--muted);
  background: var(--subtle);
  border-radius: 9px;
  padding: 5px 9px;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 8px;
}
.cd-meta-strip strong { color: var(--ink-2); font-weight: 600; }

/* Five-Element Subtle Luxury Colors */
.el-木 { color: #2D7A56; }
.el-火 { color: #B43B2B; }
.el-土 { color: #966F2D; }
.el-金 { color: #6B6860; }
.el-水 { color: #2C5D8C; }
:root[data-theme="dark"] .el-木 { color: #67C096; }
:root[data-theme="dark"] .el-火 { color: #EA7562; }
:root[data-theme="dark"] .el-土 { color: #DFB062; }
:root[data-theme="dark"] .el-金 { color: #D4CFC3; }
:root[data-theme="dark"] .el-水 { color: #74AAE0; }

/* Compact BaZi 4-Pillar Master Table (Traditional Vertical: Stem Top / Branch Bottom, Stem Ten-God Only, No NaYin) */
.bz-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}
.bz-col {
  background: var(--subtle);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 6px 3px 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
}
.bz-col.is-day {
  border-color: var(--gold);
  background: var(--gold-soft);
}
.bz-head-line {
  font-size: 9.5px;
  color: var(--muted);
  white-space: nowrap;
}
.bz-head-line b { color: var(--gold); font-weight: 700; margin-left: 2px; }
.bz-gz-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin: 1px 0 2px;
}
.bz-char {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 800;
  line-height: 1.08;
}
.bz-hid {
  padding-top: 3px;
  border-top: 1px dashed var(--hairline);
  width: 100%;
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 4px;
  font-family: var(--serif);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
}
.bz-sub-row {
  font-size: 9px;
  color: var(--muted);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Collapsible Accordion Header for DaYun & LiuNian inside Chart Panel */
.cd-fold-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 9px;
  background: var(--panel-cell);
  border: 1px solid var(--hairline);
  text-align: left;
  transition: background 0.14s ease, border-color 0.14s ease;
}
.cd-fold-btn:active { background: var(--subtle-hover); }
.cd-fold-btn.open { border-color: var(--hairline-strong); }
.cd-fold-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}
.cd-fold-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.3px;
  flex-shrink: 0;
}
.cd-fold-meta {
  font-size: 10px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cd-fold-arrow {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
}

.cd-sec-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.3px;
}
.cd-sec-sub {
  font-weight: 500;
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cd-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.cd-tag {
  font-size: 10px;
  padding: 1.5px 6px;
  border-radius: 5px;
  background: var(--subtle);
  border: 1px solid var(--hairline);
  color: var(--ink-2);
}
.cd-tag.accent {
  border-color: var(--gold);
  color: var(--gold);
  background: var(--gold-soft);
}

/* Interactive DaYun & Linked 10-Year LiuNian Strips */
.dy-strip {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 3px;
  touch-action: pan-x;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.dy-strip::-webkit-scrollbar { display: none; }
.dy-card {
  flex: 0 0 54px;
  border-radius: 9px;
  padding: 4.5px 3px;
  background: var(--subtle);
  border: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.14s ease, background 0.14s ease, transform 0.1s ease;
}
.dy-card:active { transform: scale(0.95); }
.dy-card.current {
  border-color: var(--gold);
  background: var(--gold-soft);
}
.dy-card.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 2px 8px rgba(158, 56, 42, 0.16);
}
.dy-yr { font-size: 9px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dy-gz { font-family: var(--serif); font-size: 14px; font-weight: 800; letter-spacing: 0.4px; line-height: 1.15; }
.dy-tg { font-size: 9px; color: var(--ink-2); }
.dy-age { font-size: 8.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dy-now { font-size: 8.5px; font-weight: 700; color: var(--accent); }

/* Authentic 1:1 Taigong Qimen Square Board (Ported from Original GanZhi App TaigongQimenBoard) */
.qm-five-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}
.qm-fp-cell {
  background: var(--panel-cell);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 4px 2px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.qm-fp-val {
  font-family: var(--serif);
  font-size: 14.5px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.qm-fp-sub {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.25;
}

.qm-board-wrap {
  width: 100%;
  max-width: 294px;
  margin: 0 auto;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--hairline);
}
.cd-panel:has(.qm-hist-strip) .qm-board-wrap {
  max-width: 282px;
}
.cd-panel:has(.qm-transfer-bar) .qm-board-wrap {
  max-width: 266px;
}
.cd-panel:has(.qm-hist-strip):has(.qm-transfer-bar) .qm-board-wrap {
  max-width: 252px;
}
.qimen-board { display: block; width: 100%; height: auto; aspect-ratio: 1; }
.qimen-board text { user-select: none; pointer-events: none; }
.qimen-board .qb-bg { fill: var(--board-bg); }
.qimen-board .qb-grid { fill: none; stroke: var(--board-grid); stroke-width: 2px; }
.qimen-board .qb-outline { stroke: var(--board-outline); stroke-width: 2.5px; }
.qimen-board .qb-house { fill: var(--board-house-fill); stroke: var(--board-house-stroke); stroke-width: 1.8px; transition: fill 0.15s ease, stroke 0.15s ease; }
.qimen-board .qb-house-text { fill: var(--board-house-text); font-family: var(--serif); font-size: 46px; font-weight: 700; transition: fill 0.15s ease; }
.qimen-board .qb-house-slot,
.qimen-board .qb-branch-slot { cursor: pointer; outline: none; -webkit-tap-highlight-color: transparent; }
.qimen-board .qb-house-slot:hover .qb-house,
.qimen-board .qb-house-slot:active .qb-house { fill: var(--board-house-hover); }
.qimen-board .qb-house-slot.is-anchor .qb-house {
  fill: var(--board-anchor-fill);
  stroke: var(--board-anchor-stroke);
  stroke-width: 4.5px;
}
.qimen-board .qb-house-slot.is-anchor .qb-house-text { fill: var(--board-anchor-text); }
.qimen-board .qb-anchor-dot { fill: var(--board-anchor-stroke); pointer-events: none; }
.qimen-board .qb-branch { fill: var(--board-branch-fill); stroke: var(--board-branch-stroke); stroke-width: 1.8px; transition: fill 0.15s ease, stroke 0.15s ease; }
.qimen-board .qb-branch-slot:hover .qb-branch,
.qimen-board .qb-branch-slot:active .qb-branch { fill: var(--board-house-hover); }
.qimen-board .qb-branch.is-anchor {
  fill: var(--board-anchor-branch-fill);
  stroke: var(--board-anchor-stroke);
  stroke-width: 3.4px;
}
.qimen-board .qb-branch-text { fill: var(--board-branch-text); font-family: var(--serif); font-size: 52px; font-weight: 700; }

/* Interactive Taigong Qimen Palace Transfer Bar (立极转宫控制栏) */
.qm-transfer-hint {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.2px;
  margin: -1px 0 5px;
  user-select: none;
}
.qm-transfer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin: 0;
  padding: 3px 6px 3px 8px;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid var(--hairline-strong);
}
.qm-transfer-crumb {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 3px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.qm-transfer-crumb::-webkit-scrollbar { display: none; }
.qm-tc-btn {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 500;
  padding: 2px 5px;
  border-radius: 6px;
  white-space: nowrap;
  cursor: pointer;
}
.qm-tc-btn:active { background: var(--subtle-hover); }
.qm-tc-btn.active {
  color: var(--accent);
  font-weight: 700;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.qm-tc-btn em {
  font-style: normal;
  font-size: 9.5px;
  margin-left: 3px;
  padding: 0 3px;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.qm-tc-sep {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--muted);
  user-select: none;
}
.qm-transfer-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
}
.qm-ta-btn {
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 99px;
  white-space: nowrap;
  cursor: pointer;
}
.qm-ta-btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
.qm-ta-btn:active { opacity: 0.8; }
.qimen-board .qb-branch.is-void { fill: var(--board-void-fill); stroke: var(--board-void-stroke); stroke-dasharray: 6 4; }
.qimen-board .qb-void-mark rect { fill: var(--board-void-badge); }
.qimen-board .qb-void-mark text { fill: #fff6e6; font-family: var(--sans); font-size: 30px; font-weight: 700; }
.qimen-board .qb-star { fill: var(--board-star-fill); stroke: var(--board-star-stroke); stroke-width: 2.6px; }
.qimen-board .qb-star-num { fill: var(--board-star-text); font-family: var(--sans); font-size: 36px; font-weight: 700; }
.qimen-board .qb-bstar { fill: var(--board-bstar-fill); stroke: var(--board-bstar-stroke); stroke-width: 2.4px; }
.qimen-board .qb-bstar-num { fill: var(--board-bstar-text); font-family: var(--sans); font-size: 34px; font-weight: 700; }
.qimen-board .qb-god { fill: var(--board-god-text); font-family: var(--serif); font-size: 36px; font-weight: 700; }
.qimen-board .qb-life rect { fill: var(--board-life-fill); stroke: var(--board-life-stroke); stroke-width: 2px; }
.qimen-board .qb-life text { fill: var(--gold); font-family: var(--sans); font-size: 24px; font-weight: 700; }
.qimen-board .qb-birth-center rect { fill: var(--board-bg); stroke: var(--board-bstar-stroke); stroke-width: 2px; }
.qimen-board .qb-bp-label { fill: var(--board-label); font-family: var(--sans); font-size: 24px; font-weight: 600; }
.qimen-board .qb-bp-text { fill: var(--board-branch-text); font-family: var(--serif); font-size: 46px; font-weight: 700; }

/* Enhanced Master-Compact Prose Readability */
.ai-prose h4 {
  font-family: var(--serif);
  font-size: 15.5px;
  font-weight: 700;
  color: var(--ink);
  margin: 16px 0 7px;
  padding-left: 9px;
  border-left: 2.5px solid var(--gold);
  letter-spacing: 0.3px;
}
.ai-prose h4:first-child { margin-top: 2px; }

/* ==================== 8. LIGHTBOX & TOAST ==================== */
.lightbox {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; inset: 0; z-index: 80;
  background: rgba(5, 6, 5, 0.96);
  display: flex; flex-direction: column;
}
.lb-top {
  padding: calc(var(--dy-safe-top) + 12px) 16px 12px;
  display: flex; justify-content: space-between; align-items: center;
  color: #F7EFE0;
}
.lb-caption { font-size: 13.5px; font-weight: 600; }
.lb-actions { display: flex; gap: 8px; }
.lb-btn {
  padding: 6px 12px; border-radius: 99px;
  background: rgba(255, 255, 255, 0.14); color: #F7EFE0;
  font-size: 12px; font-weight: 500; text-decoration: none;
}
.lb-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 12px;
  touch-action: none;
  position: relative;
}
.lb-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: default;
}
.lb-zoom-hint {
  padding: 8px 16px calc(var(--dy-safe-bottom) + 12px);
  text-align: center;
  font-size: 11px;
  color: rgba(247, 239, 224, 0.56);
  letter-spacing: 0.3px;
}

.toast {
  position: fixed;
  top: calc(var(--dy-safe-top) + 62px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 99;
  background: var(--ink);
  color: var(--bg);
  padding: 9px 18px;
  border-radius: 99px;
  font-size: 12.5px;
  font-weight: 500;
  max-width: calc(100vw - 36px);
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
  pointer-events: none;
}
:root[data-theme="dark"] .toast {
  background: #242820;
  color: #F7EFE0;
  border: 1px solid rgba(217, 169, 98, 0.38);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.56);
}

/* ==================== INSTALL TO HOME SCREEN (ANDROID / iOS) ==================== */
.lock-install-btn {
  margin-top: 24px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.14s ease, background 0.14s ease;
}
.lock-install-btn:active {
  transform: scale(0.97);
  background: var(--subtle-hover);
}
.install-guide-body {
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.install-tip-card {
  padding: 11px 13px;
  border-radius: 14px;
  background: var(--surface-2, var(--surface));
  border: 1px solid var(--border);
}
.install-tip-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}
.install-tip-card p {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.65;
}
.install-tip-card strong {
  color: var(--ink);
}
.install-sheet-actions {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sheet-secondary-btn {
  width: 100%;
  padding: 11px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.sheet-secondary-btn:active {
  background: var(--subtle-hover);
}


/* ==================== ANDROID PERFORMANCE MODE ====================
   Android WebView/Chrome re-rasterizes backdrop-filter & large blur box-shadows on every frame,
   causing severe jank on long conversations. Use crisp opaque/hairline layers & CSS containment. */
html.is-android {
  --pill-bg: rgba(255, 254, 251, 0.985);
}
html.is-android[data-theme="dark"] {
  --pill-bg: rgba(22, 24, 19, 0.985);
}
html.is-android .nav-circle.glass-ctrl,
html.is-android .nav-pill-back.glass-ctrl,
html.is-android .top-island-pill,
html.is-android .floating-pill,
html.is-android .jump-bottom-btn,
html.is-android .immersed-compose-btn,
html.is-android .update-banner,
html.is-android .cd-panel,
html.is-android .lp-seg-bar,
html.is-android .bg-task-pill,
html.is-android .bg-task-expanded,
html.is-android .live-agent-card,
html.is-android .overlay,
html.is-android .sheet-overlay,
html.is-android .chart-backdrop {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
html.is-android .left-drawer,
html.is-android .right-drawer {
  box-shadow: none !important;
  transition: transform 0.18s cubic-bezier(0.2, 0.9, 0.3, 1);
}
html.is-android .overlay {
  transition: opacity 0.15s linear, visibility 0s linear 0.15s;
}
html.is-android .overlay.open {
  transition: opacity 0.15s linear, visibility 0s;
}
html.is-android .cd-panel {
  box-shadow: 0 4px 12px rgba(15, 13, 10, 0.14);
  contain: layout style paint;
  will-change: auto;
}
html.is-android .chart-drawer-dock.is-dragging .cd-panel,
html.is-android .chart-drawer-dock.is-open .cd-panel {
  will-change: transform, opacity;
}
html.is-android .top-island-pill,
html.is-android .floating-pill,
html.is-android .nav-circle.glass-ctrl,
html.is-android .nav-pill-back.glass-ctrl,
html.is-android .jump-bottom-btn,
html.is-android .immersed-compose-btn,
html.is-android .update-banner {
  box-shadow: 0 2px 6px rgba(24, 21, 16, 0.08);
}
html.is-android[data-theme="dark"] .top-island-pill,
html.is-android[data-theme="dark"] .floating-pill,
html.is-android[data-theme="dark"] .nav-circle.glass-ctrl,
html.is-android[data-theme="dark"] .nav-pill-back.glass-ctrl,
html.is-android[data-theme="dark"] .cd-panel {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.32);
}
html.is-android .chat-canvas {
  scroll-behavior: auto;
  contain: layout style;
}
html.is-android .drawer-sessions,
html.is-android .settings-body {
  contain: layout style;
}
.session-loading-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 56px 16px;
  color: var(--muted);
  font-size: 13px;
}

/* Settings Range Slider (Chart Panel Opacity) */
.set-range-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 2px 0;
}
.set-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  background: transparent;
  cursor: pointer;
  touch-action: pan-x;
}
.set-range::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 99px;
  background: var(--hairline-strong);
}
.set-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
  margin-top: -7.5px;
}
.set-range-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--muted);
  padding: 0 2px;
}

/* Smart Hub Top Chart Panel Hint Bar */
.cd-hub-hint-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 10px;
  background: var(--gold-soft);
  border: 1px solid var(--hairline);
  font-size: 11.5px;
}
.cd-hub-hint-label {
  color: var(--gold);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cd-hub-hint-acts {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.cd-hub-btn {
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--hairline-strong);
}
.cd-hub-btn.primary {
  background: var(--gold);
  color: #fff;
  border-color: var(--gold);
}
.cd-hub-btn.dismiss {
  color: var(--muted);
  background: transparent;
}
.cd-hub-btn:active { opacity: 0.72; }

.cd-loading-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 26px 14px;
  font-size: 12.5px;
  color: var(--muted);
}

/* Per-Client History Tab inside Floating Dossier Panel */
.hist-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 2px 0 4px;
}
.hist-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  padding: 0 2px;
}
.hist-item {
  border-radius: 11px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hist-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 10.5px;
  color: var(--muted);
}
.hist-meta-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.hist-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--gold);
  background: var(--gold-soft);
  padding: 1px 6px;
  border-radius: 99px;
  white-space: nowrap;
}
.hist-q {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  background: var(--bg-soft, rgba(138, 108, 62, 0.06));
  border-radius: 8px;
  padding: 6px 8px;
  line-height: 1.48;
  word-break: break-word;
}
.hist-a {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink);
  word-break: break-word;
}
.hist-a h4 {
  font-size: 13px;
  margin: 8px 0 4px;
}
.hist-a p {
  margin: 4px 0;
}
.hist-a ul, .hist-a ol {
  margin: 4px 0 4px 16px;
}
.hist-a.is-clamped {
  max-height: 168px;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(180deg, #000 68%, transparent 100%);
  mask-image: linear-gradient(180deg, #000 68%, transparent 100%);
}
.hist-acts {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 2px;
}
.hist-act-btn {
  font-size: 11px;
  font-weight: 600;
  color: var(--gold);
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--gold-soft);
}
.hist-act-btn.muted {
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--hairline);
}
.hist-empty {
  text-align: center;
  padding: 22px 10px;
  font-size: 12px;
  color: var(--muted);
}

.ds-focus-pill {
  font-size: 9.5px;
  font-weight: 700;
  color: var(--gold);
  background: var(--gold-soft);
  padding: 1px 5px;
  border-radius: 99px;
  margin-left: 4px;
  flex-shrink: 0;
}

/* ==================== NON-BLOCKING BACKGROUND SPECIALIST TASK TRAY ==================== */
.bg-tasks-tray {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 6px;
  width: 100%;
  pointer-events: auto;
}
.bg-tasks-tray.hidden {
  display: none !important;
}
.bg-task-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 1px 2px;
}
.bg-task-strip::-webkit-scrollbar { display: none; }
.bg-task-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 8px 5px 7px;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  color: var(--ink);
  font-size: 11.5px;
  line-height: 1.2;
  flex-shrink: 0;
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease;
}
.bg-task-pill.expanded {
  border-color: var(--gold);
  background: var(--gold-soft);
}
.bg-task-spin {
  width: 15px;
  height: 15px;
  color: var(--gold);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.bg-task-spin svg {
  animation: laSpinOuter 6s linear infinite;
}
.bg-task-role {
  font-weight: 700;
  color: var(--gold);
  white-space: nowrap;
}
.bg-task-who {
  color: var(--ink);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}
.bg-task-time {
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.bg-task-caret {
  font-size: 10px;
  color: var(--muted);
}
.bg-task-stop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  margin-left: 1px;
}
.bg-task-stop:active {
  background: rgba(180, 50, 40, 0.14);
  color: #b53228;
}

.bg-task-detail {
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  animation: fadeUpQuick 0.16s ease;
}
@keyframes fadeUpQuick {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.bg-td-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.bg-td-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
  min-width: 0;
}
.bg-td-sub {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.4;
}
.bg-td-acts {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.bg-td-btn {
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--hairline-strong);
  background: transparent;
}
.bg-td-btn.danger {
  color: #b53228;
  border-color: rgba(181, 50, 40, 0.35);
}
.bg-task-stream-prose {
  max-height: 190px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 12.5px;
  line-height: 1.58;
  padding-top: 6px;
  border-top: 1px solid var(--hairline);
}

/* Specialist author badge & sleek compact dispatch-ack bubble */
.msg-specialist-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
  background: var(--gold-soft);
  border: 1px solid rgba(162, 122, 62, 0.24);
  white-space: nowrap;
}
.msg-ai-wrap.is-dispatch-ack .ai-prose {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--muted);
  background: var(--gold-soft);
  border: 1px solid var(--hairline);
  border-radius: 13px;
  padding: 9px 12px;
}
.msg-ai-wrap.is-dispatch-ack .ai-prose p {
  margin: 0;
}
.msg-ai-wrap.is-dispatch-ack .ai-prose strong {
  color: var(--ink);
}

/* The install guide can be opened from the signed-out lock screen (layer 90). */
#install-overlay { z-index: 94; }

#boot-recovery:not([hidden]) { position: fixed; z-index: 100; bottom: 0; left: 0; right: 0; background: #faf9f6; color: #221e1a; padding: 14px; font-size: 15px; }
#boot-retry { padding: 6px 12px; }

/* Explicit geometry for legacy WebViews that do not implement modern CSS viewport and inset functions. */
html.legacy-webview .app-header { padding: 12px 14px 18px; }
html.legacy-webview.is-standalone .app-header { padding-top: 18px; }
html.legacy-webview .chart-drawer-dock, html.legacy-webview .update-banner { top: 52px; }
html.legacy-webview.is-standalone .chart-drawer-dock, html.legacy-webview.is-standalone .update-banner { top: 58px; }
html.legacy-webview #chat-canvas { padding: 64px 18px 84px; }

/* Instant zero-flash boot for already-authenticated users (cleared immediately if session expired) */
html.boot-authed #lock-screen {
  display: none !important;
}
html.boot-authed #app-shell.hidden {
  display: block !important;
}

/* ==================== v5.0 MASTER ASSISTANT HUB & REAL-TIME AGENT STREAMING ==================== */
.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  max-width: 320px;
}
.welcome-chip {
  padding: 7px 12px;
  border-radius: 99px;
  background: var(--subtle);
  border: 1px solid var(--hairline-strong);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  transition: transform 0.12s ease, border-color 0.14s ease, background 0.14s ease;
}
.welcome-chip:active {
  transform: scale(0.96);
  border-color: var(--gold);
  background: var(--gold-soft);
  color: var(--ink);
}

/* Pinned Master Assistant Entry in Left Drawer */
.drawer-hub-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  text-align: left;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.12s ease;
}
.drawer-hub-btn.active {
  background: var(--gold-soft);
  border-color: var(--gold);
}
.drawer-hub-btn:active {
  transform: scale(0.985);
}
.dhub-icon {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: linear-gradient(145deg, rgba(168, 128, 60, 0.20), rgba(158, 56, 42, 0.14));
  color: var(--gold);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.drawer-hub-btn.active .dhub-icon {
  background: linear-gradient(155deg, #B24030, #83271B);
  color: #FFF8EC;
}
.dhub-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dhub-title {
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.3px;
}
.dhub-sub {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dhub-tag {
  font-size: 10px;
  font-weight: 600;
  color: var(--gold);
  background: var(--gold-soft);
  padding: 2px 7px;
  border-radius: 99px;
  flex-shrink: 0;
}
/* Oriental Astrolabe & Real-Chart Focus Progress Card */
.live-agent-card {
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: 15px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: padding 0.18s ease;
}
.live-agent-card.is-streaming {
  padding: 7px 11px;
  gap: 0;
  border-color: var(--hairline);
  background: var(--subtle);
}
.live-agent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.live-agent-status {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex: 1;
}
.live-astrolabe {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--gold);
  flex-shrink: 0;
}
.live-astrolabe .la-ring-outer {
  transform-origin: 14px 14px;
  animation: astrolabeSpin 14s linear infinite;
}
.live-astrolabe .la-core {
  color: var(--accent);
  animation: liveSoftPulse 1.8s ease-in-out infinite;
}
@keyframes astrolabeSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.live-stage-wrap {
  display: flex;
  flex-direction: column;
  gap: 1.5px;
  min-width: 0;
  flex: 1;
}
.live-shimmer-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: liveSoftPulse 2.2s ease-in-out infinite;
}
.live-sub-text {
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.live-agent-card.is-streaming .live-sub-text,
.live-agent-card.is-streaming .live-focus-strip {
  display: none !important;
}
@keyframes liveSoftPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.58; }
}
.live-agent-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.live-elapsed {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.live-focus-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding-top: 7px;
  border-top: 1px dashed var(--hairline);
}
.live-focus-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2.5px 8px;
  border-radius: 99px;
  font-size: 11px;
  line-height: 1.35;
  border: 1px solid var(--hairline);
  background: var(--subtle);
  color: var(--muted);
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}
.live-focus-chip.is-done {
  color: var(--ink-2);
  border-color: var(--hairline);
  background: var(--subtle);
}
.live-focus-chip.is-done .lfc-ico {
  color: var(--jade);
  font-weight: 700;
}
.live-focus-chip.is-active {
  color: var(--gold);
  font-weight: 600;
  border-color: var(--gold);
  background: var(--gold-soft);
}
.live-focus-chip.is-active .lfc-ico {
  color: var(--accent);
  animation: liveSoftPulse 1.5s ease-in-out infinite;
}
.lfc-ico {
  font-size: 9.5px;
  line-height: 1;
}

/* Real-Time Streaming Markdown Box */
.live-stream-prose {
  padding-top: 2px;
}
.live-stream-prose::after {
  content: '▍';
  display: inline-block;
  margin-left: 2px;
  color: var(--gold);
  animation: streamCaret 0.9s steps(2, start) infinite;
}
@keyframes streamCaret {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Completed Message Meta Strip: Collapsed Activity Trail + Client Archive Jump Chip */
.msg-meta-bar {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 7px;
}
.msg-client-ref-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3.5px 9px;
  border-radius: 99px;
  background: var(--gold-soft);
  border: 1px solid rgba(154, 122, 68, 0.28);
  color: var(--gold);
  font-size: 11px;
  font-weight: 600;
  transition: transform 0.12s ease, background 0.14s ease;
}
.msg-client-ref-chip:active {
  transform: scale(0.95);
  background: var(--accent-soft);
  color: var(--accent);
}
.msg-activity-details {
  max-width: 100%;
}
.msg-activity-summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3.5px 9px;
  border-radius: 99px;
  background: var(--subtle);
  border: 1px solid var(--hairline);
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}
.msg-activity-summary::-webkit-details-marker {
  display: none;
}
.msg-activity-summary .mas-star {
  color: var(--gold);
  font-size: 10px;
}
.msg-activity-steps {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--subtle);
  border: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11.5px;
  color: var(--muted);
}
.msg-activity-step-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.msg-activity-step-line b {
  color: var(--jade);
  font-weight: 700;
}

/* ==================== v5.0.1 SILKY INSTANT IMAGE ATTACHMENT STRIP ==================== */
.pending-images {
  -webkit-overflow-scrolling: touch;
}
.pend-item {
  width: 60px;
  height: 60px;
  border-radius: 13px;
  animation: pendPop 0.16s cubic-bezier(0.2, 0.85, 0.3, 1);
}
@keyframes pendPop {
  from { opacity: 0; transform: scale(0.84); }
  to { opacity: 1; transform: scale(1); }
}
.pend-item img {
  transition: opacity 0.18s ease;
}
.pend-item.is-uploading img {
  opacity: 0.52;
}
.pend-item.is-error img {
  opacity: 0.36;
}
.pend-loading {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0; inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 15, 13, 0.22);
  pointer-events: none;
}
.pend-spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.32);
  border-top-color: #FFF8EC;
  animation: pendSpin 0.72s linear infinite;
}
@keyframes pendSpin {
  to { transform: rotate(360deg); }
}
.pend-retry {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0; inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(130, 32, 24, 0.74);
  color: #FFF8EC;
  font-size: 11px;
  font-weight: 600;
}
.pend-rm {
  z-index: 2;
  width: 24px;
  height: 24px;
  font-size: 13px;
  background: rgba(20, 18, 15, 0.80);
}
.pend-rm::after {
  content: '';
  position: absolute;
  inset: -8px;
}
.pend-rm:active {
  transform: scale(0.9);
}

/* 3-Tier Divination Reasoning Depth Control */
.set-seg.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}
.set-tier-badge {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--gold);
  background: var(--gold-soft);
  padding: 2px 8px;
  border-radius: 999px;
}

/* WeChat Bot One-Click QR Bridge */
.wx-status-badge {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--muted);
  background: var(--subtle);
  padding: 2px 8px;
  border-radius: 999px;
}
.wx-status-badge.connected {
  color: var(--jade);
  background: var(--jade-soft);
}
.wx-status-badge.expired {
  color: var(--danger);
  background: var(--accent-soft);
}
.wx-entry-btn {
  color: var(--jade);
  font-weight: 600;
}
.wx-sheet-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.wx-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.wx-conn-card {
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wx-conn-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.wx-dot-live {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--jade);
  box-shadow: 0 0 0 3px var(--jade-soft);
  flex: none;
}
.wx-conn-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}
.wx-conn-meta {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
.wx-conn-desc {
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.6;
}
.wx-sync-row {
  margin: 0;
}
.wx-alert-banner {
  background: var(--accent-soft);
  color: var(--danger);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 12.5px;
  line-height: 1.5;
}
.wx-qr-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 224px;
  padding: 14px;
  border-radius: 16px;
  background: #FFFFFF;
  border: 1px solid var(--hairline-strong);
}
.wx-qr-loading {
  font-size: 13px;
  color: #6B6559;
  text-align: center;
  padding: 20px 10px;
}
.wx-qr-img {
  width: 210px;
  height: 210px;
  display: block;
  border-radius: 8px;
  object-fit: contain;
  image-rendering: pixelated;
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}
.wx-qr-status {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
  line-height: 1.5;
}
.wx-qr-status.scaned {
  color: var(--jade);
}
.wx-qr-status.warn {
  color: var(--danger);
}
.wx-verify-box {
  background: var(--surface);
  border: 1px solid var(--gold);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wx-verify-lbl {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--gold);
}
.wx-verify-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.wx-verify-input {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  letter-spacing: 2px;
  text-align: center;
}
.wx-verify-btn {
  width: auto;
  padding: 0 18px;
  flex: none;
}
.wx-btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.wx-qr-tip {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.55;
  text-align: center;
}
#btn-hdr-settings,
#btn-open-settings {
  position: relative;
}
.wx-expired-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--surface);
  pointer-events: none;
}
.msg-wx-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  color: var(--jade);
  background: var(--jade-soft);
  padding: 1px 6px;
  border-radius: 999px;
  margin-right: 4px;
  vertical-align: middle;
}

/* Markdown Tables (Horizontal Scroll Container) */
.md-table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 12px 0;
  border-radius: 11px;
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  scrollbar-width: none;
}
.md-table-wrap::-webkit-scrollbar { display: none; }
.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.5;
}
.md-table th,
.md-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--hairline);
  border-right: 1px solid var(--hairline);
  text-align: left;
  vertical-align: top;
  word-break: normal;
  overflow-wrap: break-word;
}
.md-table td:first-child {
  white-space: nowrap;
}
.md-table th:last-child,
.md-table td:last-child { border-right: none; }
.md-table tr:last-child td { border-bottom: none; }
.md-table th {
  background: var(--subtle);
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
}
.md-table tr:nth-child(even) td {
  background: rgba(120, 102, 72, 0.035);
}

/* Custom Confirm Sheet */
.confirm-msg {
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink);
  margin-bottom: 18px;
}
.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.sheet-primary-btn.danger {
  background: var(--danger);
  color: #FFF8EC;
}
.msg-optimistic {
  opacity: 0.82;
}
.older-msgs-wrap {
  display: flex;
  justify-content: center;
  padding: 4px 0 12px;
}
.older-msgs-btn {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--subtle);
  border: 1px solid var(--hairline);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.older-msgs-btn:active {
  background: var(--subtle-hover);
  color: var(--ink);
}
.msg-ai-wrap,
.msg-user-wrap {
  contain: layout style;
}
@supports (content-visibility: auto) {
  .messages-list > .msg-ai-wrap:not(:nth-last-child(-n+6)) {
    content-visibility: auto;
    contain-intrinsic-size: auto 180px;
  }
  .messages-list > .msg-user-wrap:not(:nth-last-child(-n+6)) {
    content-visibility: auto;
    contain-intrinsic-size: auto 56px;
  }
}

:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.sheet-overlay:focus, .overlay:focus, .lightbox:focus { outline: none; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
