/* Theme variables */
:root {
  --ink: #1c1914;
  --sand: #f7f3ee;
  --paper: #ffffff;
  --line: #e2d8cb;
  --accent: #c8924b;
  --shadow: rgba(44, 34, 22, 0.12);
  --danger-bg: #fbeaea;
  --danger-text: #8a2c2c;
  --danger-border: #e6b9b9;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --radius-1: 6px;
  --radius-2: 10px;
  --radius-3: 14px;
}

body[data-theme="parchment"] {
  --ink: #1c1914;
  --sand: #f7f3ee;
  --paper: #ffffff;
  --line: #e2d8cb;
  --accent: #c8924b;
  --shadow: rgba(44, 34, 22, 0.12);
}

body[data-theme="sage"] {
  --ink: #1f2b24;
  --sand: #eef3ef;
  --paper: #ffffff;
  --line: #cfdad3;
  --accent: #7aa089;
  --shadow: rgba(35, 56, 44, 0.12);
}

body[data-theme="slate"] {
  --ink: #1a2027;
  --sand: #f1f3f6;
  --paper: #ffffff;
  --line: #d5dbe3;
  --accent: #4e6b86;
  --shadow: rgba(26, 32, 39, 0.12);
}

body[data-theme="sunset"] {
  --ink: #2a1d1a;
  --sand: #f7efe9;
  --paper: #ffffff;
  --line: #e5d2c5;
  --accent: #d07a5b;
  --shadow: rgba(58, 34, 26, 0.12);
}

body[data-theme="memoria"] {
  --ink: #eef1f6;
  --sand: #191826;
  --paper: rgba(24, 22, 38, 0.88);
  --line: rgba(255, 215, 128, 0.25);
  --accent: #f7c948;
  --shadow: rgba(3, 8, 20, 0.55);
}

/* Base */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Palatino Linotype", "Book Antiqua", "Palatino", serif;
  background: radial-gradient(circle at top left, #fdfaf6 0%, var(--sand) 55%, #efe6db 100%);
  color: var(--ink);
}

body[data-theme="sage"] {
  background: radial-gradient(circle at top left, #f6faf7 0%, var(--sand) 55%, #e6efe9 100%);
}

body[data-theme="slate"] {
  background: radial-gradient(circle at top left, #f5f7fa 0%, var(--sand) 55%, #e7ecf2 100%);
}

body[data-theme="sunset"] {
  background: radial-gradient(circle at top left, #fff7f1 0%, var(--sand) 55%, #f1e3d9 100%);
}

body[data-theme="memoria"] {
  background: linear-gradient(135deg, #1a1a2e 0%, #2d1e4e 100%);
}

/* Overlays */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 20, 0.35);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 20;
}

.drop-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.drop-card {
  background: var(--paper);
  border: 2px dashed var(--accent);
  border-radius: 16px;
  padding: 24px 32px;
  box-shadow: 0 14px 30px var(--shadow);
  font-size: 18px;
  color: var(--ink);
}

/* Layout */
.main {
  max-width: none;
  margin: 12px auto;
  padding: 0 20px 24px;
  min-height: calc(100vh - 24px);
}

.layout {
  max-width: none;
}

/* Auth */
.auth-page .main {
  max-width: 520px;
  margin: 80px auto;
}

.auth-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 16px 40px var(--shadow);
}

.auth-card button {
  background: var(--accent);
  color: #1c1914;
  border: 1px solid transparent;
}

.auth-card button:hover {
  border-color: var(--accent);
  filter: brightness(0.98);
}

.guest-card {
  max-width: 540px;
  margin: 48px auto;
}

.guest-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}

.guest-actions .tool,
.guest-actions .ghost {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 900px) {
  .auth-page .main {
    max-width: none;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    width: 100%;
    display: flex;
  }

  .auth-card,
  .guest-card {
    border-radius: 0;
    min-height: 100vh;
    margin: 0;
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100%;
    max-width: none;
  }
}

.guest-actions .ghost {
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--paper);
}

.guest-actions .ghost:hover {
  background: #f3eadf;
}

.auth-logo {
  display: block;
  width: 100%;
  height: auto;
  margin-bottom: 16px;
}

.auth-logo-text {
  display: block;
  width: 100%;
  height: auto;
  margin-bottom: 16px;
}

.auth-header {
  margin-bottom: 16px;
}

.auth-header h1 {
  margin-bottom: 6px;
}

.auth-footer {
  margin-top: 16px;
  font-size: 14px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0;
  height: 60px;
}

.pwa-install {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
}

.pwa-install.show {
  display: grid;
}

.pwa-text {
  display: grid;
  gap: 4px;
  font-size: 14px;
  color: var(--ink);
}

.pwa-actions {
  display: inline-flex;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 100%;
}

.brand-logos {
  display: flex;
  flex-direction: row;
  justify-content: center;
  gap: 10px;
  height: 100%;
}

.logo {
  height: 100%;
  width: auto;
  display: block;
}

.logo-text {
  height: 100%;
  width: auto;
  display: block;
}
.hamburger {
  display: none;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 10px;
  padding: 6px 10px;
  width: 40px;
  height: 38px;
  cursor: pointer;
  color: var(--ink);
}

.hamburger svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.user-menu {
  position: relative;
}

.user-button {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}

.user-button svg {
  width: 18px;
  height: 18px;
}

.user-status {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
  box-shadow: 0 0 0 2px var(--paper);
}

.user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  min-width: 200px;
  box-shadow: 0 10px 24px var(--shadow);
  display: grid;
  gap: 8px;
  z-index: 30;
}

.user-dropdown[hidden] {
  display: none !important;
}

.user-backdrop {
  display: none;
}

.user-email {
  font-size: 13px;
  color: var(--muted);
}

.user-link {
  text-decoration: none;
  color: var(--ink);
  font-size: 14px;
}

.user-link.disabled {
  opacity: 0.6;
  pointer-events: none;
}

.user-logout button {
  width: 100%;
  margin-top: 0;
}

@media (max-width: 900px) {
  .user-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 20;
  }

  .user-backdrop.visible {
    display: block;
  }

  .user-dropdown {
    position: fixed;
    inset: auto 12px 12px 12px;
    top: 50%;
    transform: translateY(-50%);
    max-width: 360px;
    margin: 0 auto;
    z-index: 30;
  }

  .user-menu.open .user-dropdown {
    display: grid;
  }
}

.icon-button {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

h1 {
  font-size: 28px;
  margin: 0 0 12px;
}

h2 {
  font-size: 20px;
  margin: 0 0 8px;
}

p {
  line-height: 1.6;
}

.muted {
  color: #6b5e53;
  margin-bottom: 18px;
}

body[data-theme="memoria"] .muted,
body[data-theme="memoria"] .tree-hint {
  color: #b3b7c7;
}

label {
  display: block;
  margin: var(--space-3) 0 var(--space-1);
  font-weight: 600;
}

input[type="email"],
input[type="password"],
input[type="text"],
select {
  width: 100%;
  padding: 10px var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-1);
  font-size: 15px;
  background: var(--paper);
}

textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 10px var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-1);
  font-size: 14px;
  font-family: "Courier New", Courier, monospace;
  min-height: 60vh;
  background: var(--paper);
  resize: vertical;
  flex: 1;
}

textarea.drop-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(200, 146, 75, 0.2);
}

button {
  margin-top: 10px;
  padding: 10px var(--space-4);
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: var(--radius-1);
  cursor: pointer;
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

a {
  color: var(--accent);
}

.notice {
  padding: 10px 12px;
  background: #f5ede2;
  border: 1px solid var(--line);
  margin-bottom: 16px;
}

/* Sidebar + shell */
.app-shell {
  display: grid !important;
  grid-template-columns: 280px minmax(0, 1fr) !important;
  grid-auto-rows: minmax(0, auto);
  align-items: start;
  gap: 24px;
  margin: 18px 0 12px;
  width: 100%;
  overflow-x: hidden;
}

.sidebar {
  grid-column: 1;
  grid-row: 1;
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 16px;
  border-radius: 14px;
  box-shadow: 0 12px 30px var(--shadow);
  align-self: stretch;
  height: auto;
  overflow: auto;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
}

.tree-search {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.tree-search input,
.tree-secret input {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.tree-secret {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.tree-secret label {
  font-size: 12px;
  color: #6b5e53;
}

.tree-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.tree-actions {
  display: flex;
  gap: 6px;
}

.tree-actions .tool {
  margin-top: 0;
  padding: 4px 8px;
  font-size: 12px;
}

.tree-new-folder {
  display: none !important;
  margin-top: 12px;
}

.tree-new-folder.open {
  display: grid !important;
}

.tree-new-folder button {
  background: var(--accent);
  color: #1c1914;
  border: 1px solid transparent;
}

.tree-new-folder button:hover {
  border-color: var(--accent);
  filter: brightness(0.98);
}

.tree-hint {
  font-size: 12px;
  color: #6b5e53;
}

.prefs-button {
  margin-top: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 10px;
  padding: 8px 12px;
  color: var(--ink);
  cursor: pointer;
  width: 100%;
  justify-content: center;
}

.prefs-button:hover {
  border-color: var(--accent);
}

.sidebar-backdrop {
  display: none;
}

.sidebar-links {
  margin: 12px 0 6px;
}

.stack {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.inline {
  display: inline-block;
  margin-left: 10px;
}

.main-panel {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  gap: 16px;
  min-width: 0;
  width: 100%;
}

/* Editor + preview */
.editor-shell {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
  gap: 16px;
  min-width: 0;
  width: 100%;
}

.editor {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 12px 30px var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 220px);
  min-width: 0;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1px 6px;
  padding: 6px 0 6px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}

.tool {
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
}

.tool strong,
.tool em {
  font-weight: 700;
}

.tool svg {
  width: 18px;
  height: 18px;
}

.tool .icon {
  font-size: 12px;
  font-weight: 700;
}

.save-button {
  margin-left: auto;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  border: none;
}

.save-button .save-icon {
  margin-left: 6px;
  display: none;
}

.save-button.saving {
  background: var(--accent);
}

.save-button.saved .save-icon {
  display: inline;
}

.upload-status {
  font-size: 13px;
  color: #6b5e53;
  min-height: 18px;
}

/* Panels + dialogs */
.note-panel,
.link-panel,
.table-panel,
.image-panel {
  display: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fdf8f2;
  margin-bottom: 10px;
}

.note-panel.open,
.link-panel.open,
.table-panel.open,
.image-panel.open {
  display: block;
}

.link-panel-row,
.table-panel-row {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

.table-panel-checks {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 13px;
  color: #6b5e53;
}

.note-panel-search {
  margin-bottom: 10px;
}

.note-panel-list {
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
}

.note-item {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  display: block;
  padding: 6px 10px;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
}

.image-panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.help-modal,
.prefs-modal,
.media-modal {
  position: fixed;
  inset: 0;
  background: rgba(32, 24, 18, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 40;
}

.help-modal.open,
.prefs-modal.open,
.media-modal.open {
  display: flex;
}

.help-dialog,
.prefs-dialog,
.media-dialog {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  width: 100%;
  max-height: 80vh;
  overflow: auto;
  padding: 18px 20px 24px;
  box-shadow: 0 18px 50px var(--shadow);
  position: relative;
}

.help-dialog {
  max-width: 960px;
}

.prefs-dialog {
  max-width: 520px;
}

.media-dialog {
  max-width: 820px;
}

.help-close,
.prefs-close,
.media-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: none;
  background: var(--paper);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
}

.media-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.media-size strong {
  display: inline-block;
  margin-left: 6px;
}

.media-list {
  display: grid;
  gap: 12px;
}

.media-row {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.media-preview {
  width: 88px;
  height: 64px;
  border-radius: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.media-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-file-icon {
  font-size: 12px;
  color: var(--muted);
}

.media-info {
  display: grid;
  gap: 4px;
}

.media-name {
  font-weight: 600;
  font-size: 14px;
  word-break: break-word;
}

.media-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 12px;
  color: var(--muted);
}

.media-actions .tool.danger {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-color: var(--danger-border);
}

@media (max-width: 720px) {
  .media-row {
    grid-template-columns: 1fr;
  }
  .media-actions {
    justify-self: start;
  }
  .media-preview {
    width: 100%;
    height: 140px;
  }
}

.help-grid {
  display: grid;
  gap: 16px;
  margin-top: 12px;
}

.help-item h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.help-columns {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.help-code {
  background: #f1e9dd;
  padding: 10px 12px;
  border-radius: 8px;
  white-space: pre-wrap;
}

.help-preview {
  background: #fffaf4;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

body[data-theme="memoria"] .help-code,
body[data-theme="memoria"] .help-preview,
body[data-theme="memoria"] .preview pre,
body[data-theme="memoria"] .preview mark,
body[data-theme="memoria"] .preview th,
body[data-theme="memoria"] .preview tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--line);
  color: var(--ink);
}

body[data-theme="memoria"] .preview code,
body[data-theme="memoria"] .help-code {
  border: none;
}

body[data-theme="memoria"] .sidebar,
body[data-theme="memoria"] .topbar,
body[data-theme="memoria"] .preview,
body[data-theme="memoria"] .editor,
body[data-theme="memoria"] .tree-gadget,
body[data-theme="memoria"] .note-panel,
body[data-theme="memoria"] .link-panel,
body[data-theme="memoria"] .table-panel,
body[data-theme="memoria"] .image-panel,
body[data-theme="memoria"] .prefs-dialog,
body[data-theme="memoria"] .help-dialog {
  background: rgba(24, 22, 38, 0.92);
  border-color: var(--line);
}

body[data-theme="memoria"] .topbar {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

body[data-theme="memoria"] input,
body[data-theme="memoria"] textarea,
body[data-theme="memoria"] select {
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  border-color: var(--line);
}

body[data-theme="memoria"] .tool,
body[data-theme="memoria"] .ghost,
body[data-theme="memoria"] .prefs-button {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  border-color: var(--line);
}

body[data-theme="memoria"] .tool:hover,
body[data-theme="memoria"] .ghost:hover,
body[data-theme="memoria"] .prefs-button:hover {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.12);
}

body[data-theme="memoria"] .user-pill {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  border-color: var(--line);
}

body[data-theme="memoria"] .preview a,
body[data-theme="memoria"] .preview .wikilink {
  color: var(--accent);
}


.prefs-section h3 {
  margin: 12px 0 8px;
}

.prefs-themes {
  display: grid;
  gap: 8px;
}

.prefs-theme {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--paper);
}

.prefs-theme input {
  accent-color: var(--accent);
}

.help-preview img {
  max-width: 100%;
  height: auto;
  display: block;
}

.image-url {
  display: flex;
  gap: 8px;
  align-items: center;
  flex: 1;
}

.image-url input {
  flex: 1;
}

.image-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
}

.image-thumb {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  background: var(--paper);
  cursor: pointer;
}

.image-thumb img {
  width: 100%;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
}

.editor-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(140px, 200px);
  gap: 12px;
  margin-bottom: 12px;
}

.editor-meta input,
.editor-meta select {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

select option {
  background: var(--paper);
  color: var(--ink);
}

.tree {
  list-style: none;
  padding-left: 0;
  margin: 12px 0;
}

.tree li {
  margin-bottom: 8px;
}

.tree ul {
  list-style: none;
  padding-left: 16px;
  margin: 8px 0 0;
}

.tree-name {
  font-weight: 600;
}

.tree-gadget {
  display: grid;
  gap: 10px;
}

.tree-node {
  margin-bottom: 6px;
}

.tree-node summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.tree-node summary.drop-target {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(200, 146, 75, 0.18);
}

.tree-node summary:hover {
  background: rgba(0, 0, 0, 0.03);
}

.tree-node[open] summary {
  background: rgba(0, 0, 0, 0.02);
  border-color: var(--line);
}

.tree-toggle {
  margin-right: 6px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid var(--accent);
  transition: border-color 0.2s ease, transform 0.2s ease;
  display: inline-block;
}

.tree-node[open] .tree-toggle {
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid var(--accent);
  border-bottom: 0;
}

.tree-node[open] > summary .tree-toggle {
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid var(--accent);
  border-bottom: 0;
}


.tree-node.active summary {
  border-color: var(--accent);
  box-shadow: 0 6px 14px var(--shadow);
}

.tree-folder-link {
  color: var(--ink);
  text-decoration: none;
  flex: 1;
  font-weight: 600;
}

.tree-node summary::-webkit-details-marker {
  display: none;
}

.tree-count {
  font-size: 12px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 8px;
  border-radius: 999px;
}

.tree-notes {
  list-style: none;
  padding-left: 18px;
  margin: 8px 0 6px;
}

.tree-node.tree-root > .tree-notes {
  padding-left: 12px;
}

.tree-node.tree-root > .tree-node {
  margin-left: 12px;
}

.tree-note {
  margin-bottom: 6px;
}

.tree-note a {
  text-decoration: none;
  color: var(--ink);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--paper);
  border: 1px solid transparent;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.tree-note.active a {
  color: var(--accent);
  font-weight: 700;
  border-color: var(--accent);
  background: rgba(0, 0, 0, 0.04);
}

.preview {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  padding: 16px;
  box-shadow: 0 12px 30px var(--shadow);
  min-height: 60vh;
  min-width: 0;
}

.preview-toc {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  padding: 10px;
  margin-bottom: 12px;
}

.preview-content {
  display: block;
}

.toc-toggle {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
}

.toc-body {
  display: none;
  margin-top: 10px;
  max-height: 220px;
  overflow: auto;
}

.preview-toc.open .toc-body {
  display: block;
}

.preview-toc.empty .toc-toggle {
  opacity: 0.7;
}

.toc-list {
  display: grid;
  gap: 6px;
}

.toc-link {
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  padding-left: calc(var(--toc-indent, 0) * 14px);
}

.toc-link:hover {
  text-decoration: underline;
}

.preview h1,
.preview h2,
.preview h3,
.preview h4,
.preview h5,
.preview h6 {
  margin: 16px 0 8px;
}

.preview ul {
  padding-left: 18px;
}

.preview code {
  background: transparent;
  padding: 0;
  border-radius: 0;
}

.preview mark {
  background: #fff2a8;
  padding: 0 2px;
}

.preview del {
  color: #6b5e53;
}

.preview .wikilink {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.preview .wikilink:hover {
  text-decoration: underline;
}

.preview pre {
  background: #f1e9dd;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
}

.preview blockquote {
  border-left: 3px solid var(--accent);
  margin: 12px 0;
  padding: 6px 12px;
  background: #fbf3e8;
  border-radius: 8px;
}

.preview hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 16px 0;
}

.preview kbd {
  background: #f4eadf;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  font-family: "Courier New", monospace;
}

.preview .footnotes {
  margin-top: 16px;
  font-size: 13px;
  color: #6b5e53;
}

.preview .footnotes ol {
  padding-left: 18px;
}

.preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 14px;
}

.preview th,
.preview td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}

.preview th {
  background: #f6efe7;
}

.preview tbody tr:nth-child(even) {
  background: #faf6f1;
}

.preview .md-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.preview .md-checkbox input {
  accent-color: var(--accent);
}
.code-block {
  position: relative;
  margin: 12px 0;
}

.code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 28px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.code-copy svg {
  width: 16px;
  height: 16px;
}

.code-copy .icon-check {
  display: none;
  color: var(--accent);
}

.code-copy.copied {
  border-color: var(--accent);
  transform: scale(1.06);
}

.code-copy.copied .icon-copy {
  display: none;
}

.code-copy.copied .icon-check {
  display: block;
}

.preview img {
  max-width: 520px;
  width: 100%;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 8px 18px var(--shadow);
  cursor: zoom-in;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.preview img:hover {
  transform: scale(1.01);
}

.secret-block {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff6ea;
  color: #6b5e53;
  margin: 10px 0;
}

.secret-block.inline {
  display: inline-flex;
  align-items: center;
  margin: 0 6px;
  padding: 4px 8px;
  font-size: 12px;
}

.secret-block.inline p,
.secret-block.inline ul,
.secret-block.inline ol,
.secret-block.inline blockquote,
.secret-block.inline pre,
.secret-block.inline table,
.secret-block.inline div {
  display: inline;
  margin: 0;
  padding: 0;
}

.secret-block.inline ul,
.secret-block.inline ol {
  list-style: none;
}

.secret-block.inline li::before {
  content: '• ';
}

.secret-block.error {
  border-color: #d9a7a7;
  background: #fdeeee;
  color: #8a2f2f;
}

.secret-status {
  font-size: 13px;
}

.secret-content {
  color: var(--ink);
}

.secret-block.inline .secret-content {
  display: inline;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(14, 12, 9, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 30;
}

.lightbox.visible {
  opacity: 1;
  pointer-events: auto;
}

.lightbox img {
  max-width: 92vw;
  max-height: 90vh;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

/* Responsive */
@media (max-width: 1000px) {
  .editor-shell {
    grid-template-columns: 1fr;
  }

  .main-panel {
    width: 100%;
  }
}

@media (max-width: 900px) {
  .hamburger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-auto-flow: row;
  }

  .sidebar {
    grid-column: 1;
    grid-row: auto;
  }

  .main-panel {
    grid-column: 1 !important;
    grid-row: auto;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 85vw;
    max-width: 320px;
    transform: translateX(-110%);
    transition: transform 0.2s ease;
    z-index: 40;
    max-height: none;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(14, 12, 9, 0.4);
    z-index: 35;
    display: none;
  }

  .sidebar-backdrop.visible {
    display: block;
  }
  .app-shell {
    display: block !important;
  }

  .main-panel {
    width: 100%;
  }
}
