/* WS-854 · line D shell. Dark deep-space look consistent with the host's
   visual family, but self-contained: no images, no three.js, no color-only
   meaning (学/立 markers differ by text AND shape). */

:root {
  --d-bg-0: #070b18;
  --d-bg-1: #0c1330;
  --d-bg-2: #121a3c;
  --d-line: rgba(148, 170, 255, 0.16);
  --d-text: #e8ecff;
  --d-text-dim: #9aa4cc;
  --d-accent: #7c93ff;
  --d-accent-soft: rgba(124, 147, 255, 0.14);
  --d-learn: #49c8b3;
  --d-project: #e0a34c;
  --d-danger: #e2737a;
}

#d-shell {
  position: fixed;
  inset: 0;
  z-index: 9990;
  display: grid;
  grid-template-rows: 56px 1fr;
  background:
    radial-gradient(1200px 800px at 78% -10%, rgba(60, 84, 200, 0.18), transparent 60%),
    radial-gradient(900px 700px at 12% 110%, rgba(30, 58, 160, 0.16), transparent 55%),
    var(--d-bg-0);
  color: var(--d-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
}

#d-shell[hidden] {
  display: none;
}

/* Top bar ---------------------------------------------------------------- */
.d-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  border-bottom: 1px solid var(--d-line);
  background: rgba(7, 11, 24, 0.9);
  backdrop-filter: blur(8px);
}

.d-close {
  border: 1px solid var(--d-line);
  background: var(--d-bg-2);
  color: var(--d-text);
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.d-close:hover {
  border-color: var(--d-accent);
}

.d-target-badge {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.d-target-symbol {
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 15px;
}

.d-target-id {
  color: var(--d-text-dim);
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
}

.d-progress {
  margin-inline: auto;
  color: var(--d-text);
  background: var(--d-accent-soft);
  border: 1px solid var(--d-line);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}

.d-notice {
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--d-line);
  white-space: nowrap;
}

.d-notice-queue {
  color: var(--d-project);
  border-color: rgba(224, 163, 76, 0.4);
}

.d-notice-auth,
.d-notice-net {
  color: var(--d-danger);
  border-color: rgba(226, 115, 122, 0.4);
}

.d-notice-ok {
  color: var(--d-learn);
  border-color: rgba(73, 200, 179, 0.4);
}

/* 学习|立项 segmented switch (top bar, left side) ------------------------- */
.d-kind-switch {
  display: inline-flex;
  border: 1px solid var(--d-line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--d-bg-2);
  flex: 0 0 auto;
}

.d-kind-switch-btn {
  border: 0;
  background: transparent;
  color: var(--d-text-dim);
  padding: 7px 14px;
  cursor: pointer;
  font-size: 13px;
}

.d-kind-switch-btn + .d-kind-switch-btn {
  border-left: 1px solid var(--d-line);
}

.d-kind-switch-btn:hover {
  color: var(--d-text);
}

.d-kind-switch-active {
  background: var(--d-accent-soft);
  color: var(--d-text);
}

/* Theme button (top bar, right side). Deep = moon, light = sun. ----------- */
.d-theme-btn {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 1px solid var(--d-line);
  border-radius: 50%;
  background: var(--d-bg-2);
  color: var(--d-project);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.d-theme-btn:hover {
  border-color: var(--d-accent);
  color: var(--d-accent);
}

.d-theme-btn svg {
  width: 15px;
  height: 15px;
}

/* Body grid -------------------------------------------------------------- */
.d-body {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr) 340px;
  min-height: 0;
}

/* Collapsing a rail takes its column to zero: the conversation column then
   runs to the far edge. No leftover 1px sliver, no collapsed stub. */
.d-left-collapsed .d-body {
  grid-template-columns: minmax(0, 1fr) 340px;
}

.d-right-collapsed .d-body {
  grid-template-columns: 224px minmax(0, 1fr);
}

.d-left-collapsed.d-right-collapsed .d-body {
  grid-template-columns: minmax(0, 1fr);
}

.d-left-collapsed .d-left,
.d-right-collapsed .d-right {
  display: none;
}

.d-left,
.d-mid,
.d-right {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.d-left {
  border-right: 1px solid var(--d-line);
  overflow-y: auto;
  background: rgba(12, 19, 48, 0.55);
}

.d-right {
  border-left: 1px solid var(--d-line);
  background: rgba(12, 19, 48, 0.35);
}

.d-left-head {
  padding: 14px 14px 8px;
  color: var(--d-text-dim);
  font-size: 12px;
  letter-spacing: 0.06em;
}

.d-left-empty {
  padding: 0 14px;
  color: var(--d-text-dim);
  font-size: 12.5px;
  line-height: 1.6;
}

.d-group {
  padding: 6px 0 12px;
}

.d-group-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 14px;
}

.d-group-symbol {
  font-weight: 700;
}

.d-group-id {
  color: var(--d-text-dim);
  font-size: 10.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.d-session {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--d-text);
  padding: 8px 14px;
  cursor: pointer;
  text-align: left;
}

.d-session:hover {
  background: var(--d-accent-soft);
}

.d-session-active {
  background: var(--d-accent-soft);
  box-shadow: inset 2px 0 0 var(--d-accent);
}

/* 学 / 立 markers: text and shape together, never color alone. */
.d-kind {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  font-size: 12px;
  font-weight: 700;
  flex: 0 0 auto;
}

.d-kind-learn {
  border-radius: 50%;
  border: 1.5px solid var(--d-learn);
  color: var(--d-learn);
  background: rgba(73, 200, 179, 0.12);
}

.d-kind-project {
  border-radius: 3px;
  border: 1.5px dashed var(--d-project);
  color: var(--d-project);
  background: rgba(224, 163, 76, 0.1);
}

.d-session-meta {
  color: var(--d-text-dim);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Middle column ---------------------------------------------------------- */
.d-mid {
  display: flex;
  flex-direction: row;
  min-width: 0;
  min-height: 0;
}

.d-mid-scroll {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 16px clamp(16px, 4vw, 40px) 12px;
}

/* The two rail collapse buttons sit on the conversation column's own edges,
   not inside the rails they control. The strips don't scroll, so the buttons
   stay reachable in any scroll position and even when the rail is at 0. */
.d-mid-edge {
  flex: 0 0 26px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.d-edge-btn {
  width: 20px;
  height: 42px;
  border: 1px solid var(--d-line);
  background: var(--d-bg-2);
  color: var(--d-text-dim);
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  line-height: 1;
}

.d-edge-btn:hover {
  border-color: var(--d-accent);
  color: var(--d-accent);
}

.d-edge-btn[aria-expanded="false"] {
  border-color: var(--d-accent);
  color: var(--d-accent);
  background: var(--d-accent-soft);
}

.d-status {
  color: var(--d-text-dim);
  padding: 18px 0;
  font-size: 13.5px;
}

.d-message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 14px;
  max-width: 86%;
}

.d-message-user {
  align-self: flex-end;
  align-items: flex-end;
}

.d-message-assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.d-message-role {
  font-size: 10.5px;
  color: var(--d-text-dim);
}

.d-message-body {
  background: var(--d-bg-2);
  border: 1px solid var(--d-line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.d-message-user .d-message-body {
  background: var(--d-accent-soft);
  border-color: rgba(124, 147, 255, 0.35);
}

.d-block {
  margin: 18px 0;
  padding: 14px;
  border: 1px solid var(--d-line);
  border-radius: 12px;
  background: rgba(18, 26, 60, 0.5);
}

.d-block-title,
.d-version-title,
.d-worth-title,
.d-preview-title,
.d-pane-fallback-title {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--d-text-dim);
  text-transform: uppercase;
  margin: 0 0 10px;
}

.d-question {
  padding: 10px 0;
  border-top: 1px solid var(--d-line);
}

.d-question:first-of-type {
  border-top: 0;
}

.d-question-text {
  font-size: 14px;
  line-height: 1.65;
  margin-bottom: 8px;
}

.d-mark-row {
  display: flex;
  gap: 8px;
}

.d-mark,
.d-option,
.d-dispose-btn,
.d-export-btn,
.d-gate-submit,
.d-send,
.d-pane-tab {
  border: 1px solid var(--d-line);
  background: var(--d-bg-2);
  color: var(--d-text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}

.d-mark {
  padding: 5px 12px;
}

.d-mark-selected {
  border-color: var(--d-learn);
  color: var(--d-learn);
  background: rgba(73, 200, 179, 0.12);
}

.d-blindspots ul,
.d-coverage ul {
  margin: 4px 0 0;
  padding-left: 20px;
  color: var(--d-text);
  line-height: 1.7;
}

.d-card-blindspot-line {
  margin-top: 8px;
  color: var(--d-learn);
  font-size: 13px;
}

/* Composer --------------------------------------------------------------- */
.d-composer {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(7, 11, 24, 0), rgba(7, 11, 24, 0.96) 30%);
  padding-top: 14px;
}

.d-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.d-options-label {
  color: var(--d-text-dim);
  font-size: 12.5px;
}

.d-option {
  padding: 6px 12px;
}

.d-option:hover {
  border-color: var(--d-accent);
}

.d-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.d-input,
.d-gate-input {
  flex: 1;
  resize: vertical;
  border: 1px solid var(--d-line);
  background: var(--d-bg-2);
  color: var(--d-text);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
}

.d-input:focus,
.d-gate-input:focus {
  outline: none;
  border-color: var(--d-accent);
}

.d-send {
  padding: 10px 18px;
  background: var(--d-accent);
  border-color: var(--d-accent);
  color: #0b1026;
  font-weight: 600;
}

.d-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Project slot ----------------------------------------------------------- */
.d-gate-hint {
  color: var(--d-text-dim);
  font-size: 12.5px;
  margin: 0 0 10px;
}

.d-gate-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 10px;
}

.d-gate-submit {
  padding: 8px 16px;
}

.d-gate-submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.d-versions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.d-version {
  border: 1px solid var(--d-line);
  border-radius: 12px;
  background: rgba(18, 26, 60, 0.5);
  padding: 14px;
  min-width: 0;
}

.d-version-user {
  border-color: rgba(224, 163, 76, 0.35);
}

.d-version-ai {
  border-color: rgba(124, 147, 255, 0.35);
}

.d-version-empty {
  color: var(--d-text-dim);
  font-size: 13px;
}

.d-worth {
  margin-bottom: 12px;
}

.d-worth-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 6px 0;
  border-top: 1px dashed var(--d-line);
  font-size: 12.5px;
}

.d-worth-label {
  flex: 0 0 auto;
  color: var(--d-text);
  font-weight: 600;
}

.d-worth-text {
  color: var(--d-text);
}

.d-worth-empty {
  color: var(--d-text-dim);
  border: 1px dashed var(--d-line);
  border-radius: 5px;
  padding: 1px 7px;
}

.d-dispose-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.d-dispose-btn {
  padding: 8px 14px;
}

.d-dispose-selected {
  border-color: var(--d-learn);
  color: var(--d-learn);
  background: rgba(73, 200, 179, 0.12);
}

.d-export-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.d-export-btn {
  padding: 7px 12px;
}

.d-export-copy {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--d-line);
  border-radius: 8px;
  padding: 3px 4px 3px 8px;
}

.d-export-copy-label {
  color: var(--d-text-dim);
  font-size: 12px;
}

.d-preview {
  border: 1px solid var(--d-line);
  border-radius: 10px;
  padding: 12px;
  background: rgba(7, 11, 24, 0.6);
}

/* GitHub-like preview ---------------------------------------------------- */
.d-md {
  font-size: 13.5px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.d-md h1,
.d-md h2,
.d-md h3,
.d-md h4,
.d-md h5,
.d-md h6 {
  margin: 0.8em 0 0.4em;
  line-height: 1.3;
  border-bottom: 1px solid var(--d-line);
  padding-bottom: 0.2em;
}

.d-md p {
  margin: 0.45em 0;
}

.d-md ul,
.d-md ol {
  margin: 0.45em 0;
  padding-left: 1.7em;
}

.d-md blockquote {
  margin: 0.5em 0;
  padding: 2px 12px;
  border-left: 3px solid var(--d-accent);
  color: var(--d-text-dim);
}

.d-md pre {
  background: #05070f;
  border: 1px solid var(--d-line);
  border-radius: 8px;
  padding: 10px;
  overflow-x: auto;
}

.d-md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: rgba(124, 147, 255, 0.14);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

.d-md pre code {
  background: transparent;
  padding: 0;
}

.d-md a {
  color: var(--d-accent);
}

.d-md hr {
  border: 0;
  border-top: 1px solid var(--d-line);
  margin: 1em 0;
}

/* Right pane ------------------------------------------------------------- */
.d-right-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid var(--d-line);
}

.d-pane-switch {
  display: flex;
  gap: 4px;
  flex: 1;
}

.d-pane-tab {
  flex: 1;
  padding: 6px 8px;
  font-size: 12.5px;
}

.d-pane-tab-active {
  border-color: var(--d-accent);
  background: var(--d-accent-soft);
  color: var(--d-text);
}

.d-pane {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.d-pane-fallback {
  padding: 14px;
  overflow-y: auto;
  height: 100%;
  box-sizing: border-box;
}

.d-pane-fallback-empty {
  color: var(--d-text-dim);
  font-size: 13px;
  line-height: 1.7;
}

.d-passage-para {
  font-size: 13.5px;
  line-height: 1.8;
  color: var(--d-text);
  padding: 8px 10px;
  border-left: 2px solid transparent;
  border-radius: 0 8px 8px 0;
}

.d-passage-para.highlighted {
  background: var(--d-accent-soft);
  border-left-color: var(--d-accent);
}

/* Light theme: the second (and last) D-shell chrome theme ------------------ */
/* 淡蓝 = 太阳。深蓝 = 月亮（默认，见 :root）。只有这两套壳铬；这不是蓝图
   §5.6 的六套星图背景，不碰线 A 的星场，也不发明第三套。 */
#d-shell.d-theme-light {
  --d-bg-0: #eaf1ff;
  --d-bg-1: #dfe9ff;
  --d-bg-2: #f5f9ff;
  --d-line: rgba(37, 68, 150, 0.18);
  --d-text: #17224a;
  --d-text-dim: #5b6b96;
  --d-accent: #3f6df6;
  --d-accent-soft: rgba(63, 109, 246, 0.1);
  --d-learn: #0f9d86;
  --d-project: #b5781f;
  --d-danger: #c14a55;
  background:
    radial-gradient(1200px 800px at 78% -10%, rgba(120, 160, 255, 0.3), transparent 60%),
    radial-gradient(900px 700px at 12% 110%, rgba(90, 140, 255, 0.22), transparent 55%),
    var(--d-bg-0);
}

#d-shell.d-theme-light .d-topbar {
  background: rgba(234, 241, 255, 0.92);
}

#d-shell.d-theme-light .d-left {
  background: rgba(223, 233, 255, 0.55);
}

#d-shell.d-theme-light .d-right {
  background: rgba(223, 233, 255, 0.35);
}

#d-shell.d-theme-light .d-block,
#d-shell.d-theme-light .d-version {
  background: rgba(245, 249, 255, 0.72);
}

#d-shell.d-theme-light .d-message-body {
  background: var(--d-bg-2);
}

#d-shell.d-theme-light .d-composer {
  background: linear-gradient(180deg, rgba(234, 241, 255, 0), rgba(234, 241, 255, 0.96) 30%);
}

#d-shell.d-theme-light .d-preview {
  background: rgba(255, 255, 255, 0.55);
}

#d-shell.d-theme-light .d-md pre {
  background: #e3ebfb;
}

#d-shell.d-theme-light .d-send {
  color: #ffffff;
}

#d-shell.d-theme-light .d-message-user .d-message-body {
  background: var(--d-accent-soft);
  border-color: rgba(63, 109, 246, 0.35);
}

@media (max-width: 860px) {
  .d-body,
  .d-left-collapsed .d-body,
  .d-right-collapsed .d-body,
  .d-left-collapsed.d-right-collapsed .d-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .d-left,
  .d-right {
    border: 0;
    border-top: 1px solid var(--d-line);
    max-height: 40vh;
  }

  .d-progress {
    display: none;
  }
}
