body {
  display: flex;
  flex-direction: column;
  margin: 0;
  height: 100vh;
  font-family: 'Helvetica Neue', sans-serif;
  background-color: #e8f0ff;
}

:root {
  --heading-flash-bg: #fff8b3;
  --heading-flash-ring: rgba(255, 248, 179, 0.6);
  --bg-accent-muted: rgba(140, 170, 220, 0.25);
  --text-accent: #003366;
  --text-muted: #5a6b85;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --heading-flash-bg: rgba(255, 225, 140, 0.4);
    --heading-flash-ring: rgba(255, 225, 140, 0.55);
    --bg-accent-muted: rgba(140, 170, 220, 0.35);
    --text-accent: #cde1ff;
    --text-muted: #9fb0c9;
  }
}

#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background-color: #cde1ff;
  position: relative;
  z-index: 300;
}

#app-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
  color: #003366;
}

#toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-left: auto;
}

.toolbar-button {
  background: #cde1ff;
  color: #003366;
  border: 1px solid #0055aa;
  padding: 0.4rem 0.9rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

#lang-label {
  font-weight: 500;
  color: #003366;
}

#lang-switch {
  padding: 0.35rem 0.6rem;
  border: 1px solid #aac8ff;
  border-radius: 4px;
  background: #ffffff;
  color: #003366;
  font-size: 0.9rem;
}

#lang-switch:focus-visible {
  outline: 2px solid #002d6c;
  outline-offset: 2px;
}

.toolbar-button:hover,
.toolbar-button:focus-visible {
  background: #b3d1ff;
}

/* Edit/Read button: keep filled style to stand out */
#toggle-mode {
  background: #0055aa;
  color: #ffffff;
  border: none;
}

#toggle-mode:hover,
#toggle-mode:focus-visible {
  background: #004488;
}

.toolbar-button:focus-visible {
  outline: 2px solid #002d6c;
  outline-offset: 2px;
}

#template-menu,
#open-menu,
#export-menu {
  position: relative;
}

#template-options {
  position: absolute;
  top: calc(100% + 0.25rem);
  right: 0;
  display: flex;
  flex-direction: column;
  padding: 0.25rem;
  background: #ffffff;
  border: 1px solid #aac8ff;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 240px;
  z-index: 1000;
}

#open-options {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  display: flex;
  flex-direction: column;
  padding: 0.25rem;
  background: #ffffff;
  border: 1px solid #aac8ff;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 180px;
  z-index: 1000;
}

#export-options {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  display: flex;
  flex-direction: column;
  padding: 0.25rem;
  background: #ffffff;
  border: 1px solid #aac8ff;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 220px;
  z-index: 1000;
}

#template-options[hidden],
#open-options[hidden],
#export-options[hidden] {
  display: none;
}

.open-option {
  background: transparent;
  border: none;
  text-align: left;
  color: #003366;
  font-size: 0.9rem;
  padding: 0.45rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  width: 100%;
  white-space: nowrap;
}

.open-option:hover,
.open-option:focus-visible {
  background: #e6f0ff;
  outline: none;
}

.template-option {
  background: transparent;
  border: none;
  text-align: left;
  color: #003366;
  font-size: 0.9rem;
  padding: 0.45rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  width: 100%;
  white-space: nowrap;
}

.template-option:hover,
.template-option:focus-visible {
  background: #e6f0ff;
  outline: none;
}

#formatting-menu {
  position: absolute;
  display: none;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.35rem;
  background: #ffffff;
  border: 1px solid #aac8ff;
  border-radius: 6px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
  min-width: 140px;
  z-index: 1500;
}

#formatting-menu.visible {
  display: flex;
}

.formatting-menu-button {
  background: transparent;
  border: none;
  color: #003366;
  font-size: 0.9rem;
  padding: 0.35rem 0.5rem;
  text-align: left;
  border-radius: 4px;
  cursor: pointer;
}

.formatting-menu-button:hover,
.formatting-menu-button:focus-visible {
  background: #e6f0ff;
  outline: none;
}

.formatting-menu-button:disabled {
  cursor: default;
  opacity: 0.6;
  background: transparent;
  color: #7a7a7a;
}

.formatting-menu-button:disabled:hover,
.formatting-menu-button:disabled:focus-visible {
  background: transparent;
}

main {
  display: flex;
  flex: 1;
  overflow: hidden;
  background-color: #ffffff;
}

#editor-pane {
  display: flex;
  flex: none;
  width: 40%;
  height: 100%;
  background-color: #ffffff;
  box-sizing: border-box;
}

#editor-content-container {
  position: relative;
  flex: 1;
  box-sizing: border-box;
  background-color: #ffffff;
  font-family: monospace;
  font-size: 1rem;
  line-height: 1.5;
  color: #003366;
  --editor-text-color: #003366;
  --editor-padding-top: 1rem;
  --editor-padding-right: 1rem;
  --editor-padding-bottom: 1rem;
  --editor-padding-left: 1rem;
  --editor-scrollbar-width: 0px;
  --editor-scrollbar-height: 0px;
}

#editor-pane textarea {
  flex: 1;
  width: 100%;
  height: 100%;
  padding: var(--editor-padding-top, 1rem)
    var(--editor-padding-right, 1rem)
    var(--editor-padding-bottom, 1rem)
    var(--editor-padding-left, 1rem);
  box-sizing: border-box;
  border: none;
  resize: none;
  font: inherit;
  line-height: inherit;
  outline: none;
  background-color: #ffffff;
  color: inherit;
  position: relative;
  z-index: 2;
}

#editor-content-container.editor-highlight-enabled textarea {
  background-color: transparent;
  color: transparent;
  caret-color: var(--editor-text-color, #003366);
}

#editor-highlight {
  position: absolute;
  top: 0;
  left: 0;
  right: var(--editor-scrollbar-width, 0px);
  bottom: var(--editor-scrollbar-height, 0px);
  display: none;
  padding: var(--editor-padding-top, 1rem)
    var(--editor-padding-right, 1rem)
    var(--editor-padding-bottom, 1rem)
    var(--editor-padding-left, 1rem);
  box-sizing: border-box;
  pointer-events: none;
  background-color: inherit;
  color: inherit;
  font: inherit;
  line-height: inherit;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  overflow: hidden;
  z-index: 1;
}

#editor-content-container.editor-highlight-enabled #editor-highlight {
  display: block;
}

#editor-highlight .editor-highlight-content {
  min-height: 100%;
  transform: translate(0, 0);
  will-change: transform;
  white-space: inherit;
}

#editor-highlight .editor-heading-flash {
  background-color: var(--heading-flash-bg, #fff8b3);
  box-shadow: 0 0 0 2px var(--heading-flash-ring, rgba(255, 248, 179, 0.6));
}

#editor-highlight .editor-heading-flash.editor-heading-fade-out {
  animation: editor-heading-fade-out var(--heading-flash-fade-duration, 600ms)
    ease-out forwards;
}

@keyframes editor-heading-fade-out {
  0% {
    background-color: var(--heading-flash-bg, #fff8b3);
    box-shadow: 0 0 0 2px var(--heading-flash-ring, rgba(255, 248, 179, 0.6));
  }

  100% {
    background-color: transparent;
    box-shadow: 0 0 0 0 rgba(255, 248, 179, 0);
  }
}

#editor-highlight .external-link-text {
  color: #6d7cff;
}

#line-number-gutter {
  display: none;
  padding: 0.75rem 0.375rem 0.75rem 0.5rem;
  background-color: #eef4ff;
  color: #4d6faa;
  font-family: monospace;
  font-size: 1rem;
  font-weight: 300;
  line-height: 1.5;
  text-align: center;
  user-select: none;
  min-width: 2ch;
  box-sizing: border-box;
  border-right: 1px solid #d6e4ff;
  overflow: hidden;
}

#line-number-gutter.line-numbers-visible {
  display: block;
}

#line-number-gutter .line-number {
  display: block;
}

#line-number-gutter .line-number-continuation {
  display: block;
}

#divider,
#toc-divider {
  width: 8px;
  background-color: transparent;
  cursor: col-resize;
  flex-shrink: 0;
  position: relative;
}

#divider::after,
#toc-divider::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background-color: transparent;
  transform: translateX(-50%);
  transition: background-color 0.15s ease, width 0.15s ease;
}

#divider:hover::after,
#toc-divider:hover::after {
  width: 3px;
  background-color: #8fb8ff;
}

/* #preview-pane wraps the tab bar + #preview so the two share the space
   previously occupied by #preview alone (Issue #181 / MEW-012 Lv2-8). */
#preview-pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  height: 100%;
  min-width: 0;
  box-sizing: border-box;
}

#tab-bar {
  display: flex;
  flex-wrap: wrap;
  flex-shrink: 0;
  gap: 0.25rem;
  padding: 0.4rem 0.6rem 0;
  background-color: #ffffff;
  border-bottom: 1px solid #aac8ff;
  box-sizing: border-box;
}

#tab-bar:empty {
  display: none;
}

.tab-bar-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid #aac8ff;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  background-color: #e6f0ff;
  color: #003366;
  font-size: 0.85rem;
  cursor: pointer;
  max-width: 200px;
}

.tab-bar-item.active {
  background-color: #ffffff;
  font-weight: 600;
}

.tab-bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-bar-close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: inherit;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0 0.1rem;
  border-radius: 3px;
  flex-shrink: 0;
}

.tab-bar-close:hover {
  background: rgba(0, 51, 102, 0.12);
}

.tab-bar-add-btn {
  border: none;
  background: transparent;
  color: #3d7bd6;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
  align-self: center;
}

.tab-bar-add-btn:hover {
  background-color: rgba(140, 170, 220, 0.12);
}

/* Shell constraints for #preview (layout/overflow); document appearance is in preview.css.
   flex:1/height:100% now live on the #preview-pane wrapper above; #preview itself
   only needs flex:1 + min-height:0 to fill the remaining column space below #tab-bar. */
#preview {
  flex: 1;
  min-height: 0;
  overflow: auto;
  /* Firefox */
  scrollbar-width: thin;
  scrollbar-color: rgba(140, 170, 220, 0.35) transparent;
}

/* Chrome / Edge */
#preview::-webkit-scrollbar {
  width: 6px;
}

#preview::-webkit-scrollbar-track {
  background: transparent;
}

#preview::-webkit-scrollbar-thumb {
  background-color: rgba(140, 170, 220, 0.35);
  border-radius: 6px;
}

#preview::-webkit-scrollbar-thumb:hover {
  background-color: rgba(140, 170, 220, 0.42);
}

#toc {
  width: 360px;
  padding: 1rem;
  overflow-y: auto;
  background-color: #ffffff;
  color: #88b4ff;
  font-size: 0.95rem;
  position: sticky;
  top: var(--header-offset, 0);
  height: calc(100vh - var(--header-offset, 0));
  flex-shrink: 0;
  align-self: flex-start;
  box-sizing: border-box;
}

/* Firefox */
#toc {
  scrollbar-width: thin;
  scrollbar-color: rgba(140, 170, 220, 0.22) transparent;
}

/* Chrome / Edge */
#toc::-webkit-scrollbar {
  width: 6px;
}

#toc::-webkit-scrollbar-track {
  background: transparent;
}

#toc::-webkit-scrollbar-thumb {
  background-color: rgba(140, 170, 220, 0.22);
  border-radius: 6px;
}

#toc::-webkit-scrollbar-thumb:hover {
  background-color: rgba(140, 170, 220, 0.3);
}

#toc-headings ul {
  list-style: none;
  padding-left: 1rem;
  margin: 0;
  pointer-events: none;
}

#toc-headings .toc-item {
  cursor: default;
  margin: 0.2rem 0;
  pointer-events: none;
}

#toc-headings .toc-label {
  cursor: pointer;
  pointer-events: auto;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 4px;
  transition: background-color 0.15s ease;
}

#toc-headings .toc-label:hover {
  background-color: rgba(140, 170, 220, 0.12);
}

#toc-headings .toc-item.active > .toc-label {
  color: #0055aa;
}

#toc-headings .toc-item[data-level="3"] > ul {
  display: none;
}

#toc-headings .toc-item[data-level="3"].expanded > ul {
  display: block;
}

#toc-headings .toc-item.active-ancestor > .toc-label {
  color: #3d7bd6;
  font-weight: 500;
}

#toc-headings .toc-item[data-level="3"]:has(> ul) > .toc-label {
  position: relative;
  padding-right: 1.2em;
}

#toc-headings .toc-item[data-level="3"]:has(> ul) > .toc-label::after {
  content: '›';
  position: absolute;
  right: 0.2em;
  top: 50%;
  transform: translateY(-50%);
  transition: transform 0.15s ease;
  color: #88b4ff;
}

#toc-headings .toc-item[data-level="3"].expanded > .toc-label::after {
  transform: translateY(-50%) rotate(90deg);
}

#toc-headings {
  width: 360px;
  padding: 1rem;
  overflow-y: auto;
  background-color: #ffffff;
  color: #88b4ff;
  font-size: 0.95rem;
  position: sticky;
  top: var(--header-offset, 0);
  height: calc(100vh - var(--header-offset, 0));
  flex-shrink: 0;
  align-self: flex-start;
  box-sizing: border-box;
}

#toc-headings.hidden {
  display: none;
}

#toc-headings {
  scrollbar-width: thin;
  scrollbar-color: rgba(140, 170, 220, 0.22) transparent;
}

#toc-headings::-webkit-scrollbar {
  width: 6px;
}

#toc-headings::-webkit-scrollbar-track {
  background: transparent;
}

#toc-headings::-webkit-scrollbar-thumb {
  background-color: rgba(140, 170, 220, 0.22);
  border-radius: 6px;
}

#toc-headings::-webkit-scrollbar-thumb:hover {
  background-color: rgba(140, 170, 220, 0.3);
}

#preview-toolbar {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

#preview-toolbar #tab-bar {
  flex: 1;
  min-width: 0;
}

#toggle-toc-panel {
  flex-shrink: 0;
  margin: 0.4rem 0.6rem 0 0;
  padding: 4px;
  border: none;
  background: transparent;
  color: #88b4ff;
  cursor: pointer;
  border-radius: 4px;
}

#toggle-toc-panel:hover {
  background-color: rgba(140, 170, 220, 0.12);
}

#toggle-toc-panel.hidden {
  display: none;
}

#file-tree {
  position: relative;
  margin: -1rem -1rem 0;
  padding: 0.75rem 1rem;
}

#file-tree.hidden {
  display: none;
}

#file-tree .file-tree-list {
  list-style: none;
  padding-left: 1rem;
  margin: 0;
}

#file-tree > .file-tree-list {
  padding-left: 0;
}

#file-tree .file-tree-item {
  margin: 0.1rem 0;
}

#file-tree .file-tree-row {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.15rem;
  /* Base transparent outline + transition so the copy indicator (below) can
     fade smoothly on removal instead of vanishing instantly -- outline
     itself doesn't animate, but outline-color does. */
  outline: 1px dashed transparent;
  outline-offset: -1px;
  border-radius: 4px;
  transition: outline-color 0.6s ease;
}

#file-tree .file-tree-label {
  cursor: pointer;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 4px;
  padding: 0.1rem 0.3rem;
  transition: background-color 0.15s ease;
  pointer-events: auto;
}

#file-tree .file-tree-label:hover {
  background-color: rgba(140, 170, 220, 0.12);
}

#file-tree .file-tree-row.file-tree-drop-target {
  outline: 2px dashed #3d7bd6;
  outline-offset: -2px;
  border-radius: 4px;
}

#file-tree.file-tree-drop-target {
  outline: 2px dashed #3d7bd6;
  outline-offset: -2px;
}

#file-tree .file-tree-folder > .file-tree-row > .file-tree-label {
  color: #3d7bd6;
  text-shadow: 0 0 1px rgba(0, 0, 0, 0.12);
}

#file-tree .file-tree-file.active > .file-tree-row > .file-tree-label {
  color: #0055aa;
  background-color: rgba(140, 170, 220, 0.16);
}

#file-tree .file-tree-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.25rem;
}

#file-tree .file-tree-add-btn {
  pointer-events: auto;
  border: none;
  background: transparent;
  color: #3d7bd6;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
}

#file-tree .file-tree-add-btn:hover {
  background-color: rgba(140, 170, 220, 0.12);
}

#file-tree .file-tree-row > .file-tree-label {
  flex: 1;
  min-width: 0;
}

#file-tree .file-tree-icon {
  flex: none;
  color: #88b4ff; /* Default: file. */
  vertical-align: middle; /* Fixes baseline-default misalignment against the label. */
}

/* SVG-based folder open/closed toggle indicator (Issue #223 follow-up),
   replacing a text-glyph (▸) + translateY tuning that never fully
   converged -- an explicit viewBox has no glyph-vs-box center mismatch to
   correct for. */
#file-tree .file-tree-toggle-icon {
  flex: none;
  color: #3d7bd6; /* Matches the existing folder icon/label color. */
  vertical-align: middle;
  transition: transform 0.15s ease;
}

#file-tree .file-tree-folder.open > .file-tree-row > .file-tree-toggle-icon {
  transform: rotate(90deg);
}

#file-tree .file-tree-folder > .file-tree-row .file-tree-icon {
  color: #3d7bd6; /* Folder: matches the existing toggle-arrow color. */
}

/* Cut/copy clipboard feedback (Issue #221 / MEW-041 Lv3-2). Only the icon is
   dimmed on cut, matching OS file-explorer conventions (Windows Explorer /
   macOS Finder): the label text stays full-strength, since it is already a
   light color (#88b4ff-family) and would become unreadable if dimmed too. */
#file-tree .file-tree-item-cut > .file-tree-row > .file-tree-icon {
  opacity: 0.4;
}

/* Copy indicator (Issue #221 / MEW-041 Lv3-2 follow-up): fades out via
   outline-color after COPY_INDICATOR_DURATION (filetree.js), independent of
   the clipboard contents -- Ctrl+V keeps working after it fades. Only sets
   outline-color, leaving the outline-style/width/transition declared on the
   base .file-tree-row rule above so removing this class animates smoothly
   instead of vanishing instantly. */
#file-tree .file-tree-item-copy > .file-tree-row {
  outline-color: #3d7bd6;
}

#file-tree .file-tree-create-input,
#file-tree .file-tree-rename-input {
  pointer-events: auto;
  flex: 1;
  min-width: 0;
  font: inherit;
  border: 1px solid #3d7bd6;
  border-radius: 4px;
  padding: 0.1rem 0.3rem;
}

/* Appended to <body> (see filetree.js openMenuFor()), not scoped under
   #file-tree, so it escapes #toc's sticky-positioning stacking context and
   always draws above siblings like #toc-divider regardless of z-index. */
.app-context-menu {
  pointer-events: auto;
  position: fixed;
  z-index: 20;
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
  background: #fff;
  border: 1px solid #aac8ff;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  min-width: 8rem;
}

.app-context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  font: inherit;
}

.app-context-menu button:hover {
  background-color: rgba(140, 170, 220, 0.12);
}

#help-window {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  width: 320px;
  max-height: 70vh;
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid #aac8ff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  padding: 0.5rem;
  font-size: 0.9rem;
  z-index: 1000;
}

#help-window.hidden {
  display: none;
}

#help-window pre {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  white-space: pre-wrap;
}

#help-close {
  float: right;
  background: none;
  border: none;
  cursor: pointer;
}

#shortcuts-window {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  width: 320px;
  max-height: 70vh;
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid #aac8ff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  padding: 0.5rem;
  font-size: 0.9rem;
  z-index: 1000;
}

#shortcuts-window.hidden {
  display: none;
}

#shortcuts-window table {
  width: 100%;
  border-collapse: collapse;
}

#shortcuts-window td {
  padding: 0.35rem 0.25rem;
  border-bottom: 1px solid rgba(140, 170, 220, 0.3);
}

#shortcuts-window kbd {
  display: inline-block;
  padding: 0.05rem 0.35rem;
  border: 1px solid #aac8ff;
  border-radius: 3px;
  background: rgba(140, 170, 220, 0.16);
  font-family: inherit;
  font-size: 0.85em;
}

#shortcuts-close {
  float: right;
  background: none;
  border: none;
  cursor: pointer;
}

/* Quick switcher (Issue #191 / MEW-013) */
#quickswitcher {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  z-index: 1100;
}

#quickswitcher.hidden {
  display: none;
}

#quickswitcher-panel {
  width: 480px;
  max-width: 90vw;
  max-height: 60vh;
  background: #ffffff;
  border: 1px solid #aac8ff;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#quickswitcher-input {
  border: none;
  border-bottom: 1px solid #aac8ff;
  padding: 0.75rem;
  font-size: 1rem;
  outline: none;
  box-sizing: border-box;
}

#quickswitcher-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
}

.quickswitcher-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid rgba(140, 170, 220, 0.16);
}

.quickswitcher-item-icon {
  flex: none;
}

.quickswitcher-item-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quickswitcher-item.selected,
.quickswitcher-item:hover {
  background: var(--bg-accent-muted);
  color: var(--text-accent);
  border-radius: var(--radius);
}

.quickswitcher-footer {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid rgba(140, 170, 220, 0.16);
}

#crosssearch {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  z-index: 1100;
}

#crosssearch.hidden {
  display: none;
}

#crosssearch-panel {
  width: 560px;
  max-width: 90vw;
  max-height: 60vh;
  background: #ffffff;
  border: 1px solid #aac8ff;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#crosssearch-input {
  border: none;
  border-bottom: 1px solid #aac8ff;
  padding: 0.75rem;
  font-size: 1rem;
  outline: none;
  box-sizing: border-box;
}

#crosssearch-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
}

.crosssearch-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid rgba(140, 170, 220, 0.16);
}

.crosssearch-item-path {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.crosssearch-item-snippet {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.crosssearch-item-snippet mark {
  background: var(--bg-accent-muted);
  color: var(--text-accent);
}

.crosssearch-item.selected,
.crosssearch-item:hover {
  background: var(--bg-accent-muted);
  color: var(--text-accent);
  border-radius: var(--radius);
}

.crosssearch-footer {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid rgba(140, 170, 220, 0.16);
}

/* Mode-based layout */
body[data-mode="read"] #editor-pane,
body[data-mode="read"] #divider,
body[data-mode="edit"] #divider {
  display: none;
}

/* Floating panel (edit mode) */
body[data-mode="edit"] #editor-pane {
  position: fixed;
  z-index: 200;
  border: 1px solid #aac8ff;
  box-shadow: 0 4px 20px rgba(0, 85, 170, 0.25);
  border-radius: 6px;
  overflow: hidden;
  resize: both;
  min-width: 200px;
  min-height: 150px;
  max-width: 90vw;
  max-height: 85vh;
  box-sizing: border-box;
  padding-top: 28px;
}

#editor-drag-handle {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 28px;
  background: #cde1ff;
  border-bottom: 1px solid #aac8ff;
  cursor: grab;
  user-select: none;
  align-items: center;
  padding: 0 0.5rem;
  font-size: 0.8rem;
  color: #003366;
  font-weight: 500;
  z-index: 1;
}

body[data-mode="edit"] #editor-drag-handle {
  display: flex;
}

#editor-drag-handle:active {
  cursor: grabbing;
}

#editor-close-btn {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: #003366;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

#editor-close-btn:hover {
  background: rgba(0, 51, 102, 0.12);
}

body[data-mode="edit"] #editor-close-btn {
  display: flex;
  align-items: center;
}

/* Resize indicator: visual hint at bottom-right corner */
body[data-mode="edit"] #editor-pane::after {
  content: '';
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 10px;
  height: 10px;
  background:
    linear-gradient(135deg, transparent 30%, #aac8ff 30%, #aac8ff 45%, transparent 45%),
    linear-gradient(135deg, transparent 55%, #aac8ff 55%, #aac8ff 70%, transparent 70%),
    linear-gradient(135deg, transparent 80%, #aac8ff 80%);
  pointer-events: none;
  border-radius: 0 0 4px 0;
}

body[data-mode="edit"] #editor-pane.panel-dragging {
  opacity: 0.9;
  box-shadow: 0 8px 32px rgba(0, 85, 170, 0.35);
}

body[data-mode="read"] [data-mode-visible="edit"] {
  display: none !important;
}

body[data-mode="edit"] [data-mode-visible="read"] {
  display: none !important;
}

/* Document Picture-in-Picture mode: hide floating panel chrome */
body.pip-mode #editor-close-btn {
  display: none !important;
}

body.pip-mode #editor-drag-handle {
  display: flex;
  cursor: default;
  background: #202124;
  border-bottom: none;
}

body.pip-mode #editor-drag-handle #editor-drag-label {
  display: none;
}

#editor-copy-btn {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

#editor-copy-btn:hover {
  background: rgba(0, 51, 102, 0.12);
}

body.pip-mode #editor-copy-btn {
  display: inline-flex;
  align-items: center;
  color: #b0b0b0;
}

body.pip-mode #editor-copy-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

body.pip-mode #editor-copy-btn.copy-success {
  color: #6fcf6f;
}

body.pip-mode #editor-pane::after {
  display: none !important;
}

/* Document Picture-in-Picture mode: dark theme */
body.pip-mode {
  background-color: #202124;
}

body.pip-mode #editor-pane,
body.pip-mode #editor-content-container,
body[data-mode="edit"] #editor-pane,
body[data-mode="edit"] #editor-content-container {
  background-color: transparent;
}

body.pip-mode #editor-pane textarea,
body[data-mode="edit"] #editor-pane textarea {
  background-color: transparent;
}

body.pip-mode #line-number-gutter,
body[data-mode="edit"] #line-number-gutter {
  background-color: #202124;
  color: #b0b0b0;
  border-right: none;
}

body[data-mode="edit"] #editor-pane {
  background-color: #202124;
}

body[data-mode="edit"] #editor-drag-handle {
  background: #202124;
  border-bottom: none;
}

/* Dark scrollbar for floating panel textarea */
body[data-mode="edit"] #editor-pane textarea {
  scrollbar-width: auto;
  scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

body[data-mode="edit"] #editor-pane textarea::-webkit-scrollbar-track {
  background: transparent;
}

body[data-mode="edit"] #editor-pane textarea::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: content-box;
}

body[data-mode="edit"] #editor-pane textarea::-webkit-scrollbar-thumb:hover {
  background-color: rgba(255, 255, 255, 0.4);
}

/* Syntax highlight colors for floating panel and PiP window */
body[data-mode="edit"] #editor-pane #editor-content-container,
body.pip-mode #editor-content-container {
  --editor-text-color: #ffffff;
  color: #ffffff;
}

body[data-mode="edit"] .editor-heading-text,
body.pip-mode .editor-heading-text {
  color: #5b9dff;
}

body[data-mode="edit"] .editor-heading-flash,
body.pip-mode .editor-heading-flash {
  color: #5b9dff;
}

body[data-mode="edit"] .editor-comment-text,
body.pip-mode .editor-comment-text {
  color: #6fcf6f;
}

body[data-mode="edit"] .editor-bold-text,
body.pip-mode .editor-bold-text {
  color: #5b9dff;
}

body[data-mode="edit"] .editor-inline-code-text,
body.pip-mode .editor-inline-code-text {
  color: #ffcc80;
}

/* Dark scrollbar for PiP window textarea */
body.pip-mode #editor-pane textarea {
  scrollbar-width: auto;
  scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

body.pip-mode #editor-pane textarea::-webkit-scrollbar-track {
  background: transparent;
}

body.pip-mode #editor-pane textarea::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: content-box;
}

body.pip-mode #editor-pane textarea::-webkit-scrollbar-thumb:hover {
  background-color: rgba(255, 255, 255, 0.4);
}
