:root {
  color-scheme: light;
  --bg: #f5efe8;
  --bg-soft: #fff9f2;
  --panel: rgba(255, 255, 255, 0.76);
  --panel-strong: rgba(255, 255, 255, 0.94);
  --ink: #1e1814;
  --muted: #75665c;
  --accent: #b45d22;
  --accent-strong: #8a4417;
  --danger: #7b2b1c;
  --stroke: rgba(30, 24, 20, 0.13);
  --shadow: 0 28px 80px rgba(36, 21, 13, 0.15);
  --mono: "IBM Plex Mono", "SFMono-Regular", Menlo, monospace;
  --ui: "Manrope", "Segoe UI", sans-serif;
  --serif: "Newsreader", Georgia, serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--ui);
  color: var(--ink);
  background: radial-gradient(circle at 12% 2%, #fff8ef 0%, transparent 45%),
    radial-gradient(circle at 88% 0%, #f7e8dc 0%, transparent 40%),
    linear-gradient(130deg, var(--bg), #f2e8dc 45%, #f7efe5 100%);
  position: relative;
  overflow: hidden;
}

.bg-orb {
  position: fixed;
  pointer-events: none;
  filter: blur(28px);
  opacity: 0.55;
  z-index: 0;
}

.bg-orb--a {
  width: 300px;
  height: 300px;
  background: radial-gradient(circle at 40% 40%, rgba(239, 158, 100, 0.85), transparent 70%);
  top: -90px;
  right: 15vw;
}

.bg-orb--b {
  width: 360px;
  height: 360px;
  background: radial-gradient(circle at 30% 30%, rgba(114, 179, 194, 0.52), transparent 70%);
  bottom: -130px;
  left: -80px;
}

.app-shell {
  width: min(1600px, calc(100vw - 42px));
  margin: 20px auto;
  height: calc(100vh - 40px);
  max-height: calc(100vh - 40px);
  display: grid;
  grid-template-columns: 300px 1fr 250px;
  gap: 16px;
  position: relative;
  z-index: 2;
}

.panel,
.workspace {
  border-radius: 24px;
  border: 1px solid var(--stroke);
  background: var(--panel);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 20px 18px 14px;
  border-bottom: 1px solid var(--stroke);
}

.panel__header-actions {
  display: inline-flex;
  gap: 8px;
}

.panel__header--compact {
  justify-content: flex-start;
}

.panel__body {
  padding: 12px 12px 14px;
  overflow: auto;
}

.panel__hint {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  padding: 4px 8px 10px;
}

.panel__filter-wrap {
  padding: 0 8px 10px;
}

.panel__filter {
  width: 100%;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.88);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--ink);
  outline: none;
}

.panel__filter:focus {
  border-color: rgba(180, 93, 34, 0.52);
}

.kicker {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-family: var(--mono);
}

h1,
h2 {
  margin: 6px 0 0;
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 {
  font-size: clamp(24px, 2.6vw, 30px);
}

h2 {
  font-size: 24px;
}

.btn {
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  border-radius: 999px;
  height: 34px;
  padding: 0 14px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: 160ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: rgba(180, 93, 34, 0.55);
}

.btn.is-active {
  background: rgba(180, 93, 34, 0.14);
  border-color: rgba(180, 93, 34, 0.62);
  color: var(--accent-strong);
}

.btn-primary {
  border-color: transparent;
  color: #fff;
  background: linear-gradient(130deg, var(--accent), #c36a2f 65%, #d8893a);
}

.btn-primary:hover {
  border-color: transparent;
}

.btn-danger {
  color: var(--danger);
}

.btn-mobile {
  display: none;
}

.doc-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 7px;
}

.tree-block {
  display: grid;
  gap: 6px;
}

.tree-children {
  display: grid;
  gap: 6px;
}

.tree-row {
  border-radius: 14px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.6);
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  transition: 120ms ease;
}

.tree-row:hover {
  border-color: rgba(180, 93, 34, 0.45);
}

.tree-row.is-active {
  border-color: rgba(180, 93, 34, 0.68);
  background: rgba(255, 243, 231, 0.95);
}

.tree-row--folder {
  background: rgba(248, 242, 236, 0.78);
}

.tree-indent {
  flex: 0 0 auto;
  width: var(--indent, 0px);
}

.tree-toggle {
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 20px;
  height: 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 11px;
}

.tree-toggle:hover {
  background: rgba(180, 93, 34, 0.12);
}

.tree-label-btn {
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  flex: 1;
  text-align: left;
  padding: 0;
}

.tree-row__title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.32;
}

.tree-row__meta {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}

.tree-actions {
  display: inline-flex;
  gap: 4px;
}

.tree-btn {
  border: 1px solid rgba(30, 24, 20, 0.14);
  background: rgba(255, 255, 255, 0.86);
  color: var(--muted);
  border-radius: 999px;
  font-size: 10px;
  height: 22px;
  padding: 0 8px;
  font-family: var(--mono);
  cursor: pointer;
}

.tree-btn:hover {
  color: var(--accent-strong);
  border-color: rgba(180, 93, 34, 0.42);
}

.doc-item {
  border-radius: 16px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.6);
  padding: 11px 12px;
  cursor: pointer;
  display: grid;
  gap: 5px;
  transition: 120ms ease;
}

.doc-item:hover {
  border-color: rgba(180, 93, 34, 0.45);
}

.doc-item.is-active {
  border-color: rgba(180, 93, 34, 0.68);
  background: rgba(255, 243, 231, 0.95);
}

.doc-item__title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

.doc-item__meta {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  overflow: hidden;
}

.workspace__header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--stroke);
  background: var(--panel-strong);
}

.title-wrap {
  flex: 1;
}

.doc-meta {
  margin-top: 8px;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.doc-meta__label {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.doc-meta__select {
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  padding: 7px 12px;
  min-width: 200px;
  outline: none;
}

.doc-meta__select:focus {
  border-color: rgba(180, 93, 34, 0.52);
}

#docTitle {
  width: 100%;
  border: 0;
  outline: none;
  padding: 0;
  font-family: var(--serif);
  color: var(--ink);
  background: transparent;
  font-size: clamp(28px, 3.5vw, 40px);
  line-height: 1.08;
  font-weight: 500;
}

#docTitle::placeholder {
  color: #a38e80;
}

.workspace__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.find-bar {
  border-bottom: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.85);
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.find-bar__input {
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.94);
  padding: 8px 10px;
  min-width: 150px;
  color: var(--ink);
  font-size: 13px;
  outline: none;
}

.find-bar__input:focus {
  border-color: rgba(180, 93, 34, 0.52);
}

.find-bar__toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}

.editor-grid {
  min-height: 0;
  height: 100%;
  padding: 14px 14px 0;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
  gap: 14px;
  align-items: stretch;
}

.surface {
  border: 1px solid var(--stroke);
  border-radius: 18px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.72);
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.surface.is-drop-target {
  border-color: rgba(180, 93, 34, 0.68);
  box-shadow: inset 0 0 0 1px rgba(180, 93, 34, 0.45);
}

.surface__title {
  height: 36px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--stroke);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-family: var(--mono);
  background: rgba(255, 255, 255, 0.85);
}

#editor {
  flex: 1;
  min-height: 0;
  width: 100%;
  resize: none;
  border: 0;
  outline: none;
  padding: 20px;
  color: var(--ink);
  background: transparent;
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.58;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  tab-size: 2;
}

.preview {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 24px 26px 42px;
  font-size: 19px;
  line-height: 1.62;
  font-family: var(--serif);
}

.preview h1,
.preview h2,
.preview h3,
.preview h4 {
  font-family: var(--serif);
  letter-spacing: -0.02em;
  margin: 1.4em 0 0.48em;
}

.preview p,
.preview li,
.preview td,
.preview th,
.preview blockquote {
  color: rgba(33, 27, 22, 0.95);
}

.preview a {
  color: #176280;
}

.preview code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: rgba(153, 138, 126, 0.14);
  padding: 0.1em 0.3em;
  border-radius: 5px;
}

.preview pre {
  background: #201a17;
  color: #f6f0ec;
  border-radius: 13px;
  padding: 14px;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.09);
}

.preview pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
}

.preview blockquote {
  margin: 1.2em 0;
  border-left: 3px solid rgba(180, 93, 34, 0.45);
  padding: 0.2em 0 0.2em 1em;
}

.preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
}

.preview th,
.preview td {
  border: 1px solid rgba(30, 24, 20, 0.17);
  padding: 8px 10px;
  text-align: left;
}

.preview hr {
  border: 0;
  border-top: 1px solid rgba(30, 24, 20, 0.15);
  margin: 1.6em 0;
}

.preview .mermaid {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(30, 24, 20, 0.13);
  border-radius: 12px;
  padding: 8px;
}

.preview img {
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(30, 24, 20, 0.14);
  box-shadow: 0 14px 36px rgba(24, 16, 11, 0.14);
}

.workspace__footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--stroke);
  background: var(--panel-strong);
}

.save-status {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.save-status.error {
  color: #9c3a25;
}

.stats {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.stats strong {
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
}

.outline-list {
  overflow: auto;
  padding: 10px 10px 14px;
  display: grid;
  gap: 6px;
}

.outline-link {
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 12px;
  padding: 8px 10px;
  text-align: left;
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
  line-height: 1.35;
}

.outline-link:hover {
  border-color: rgba(180, 93, 34, 0.48);
}

.outline-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 8px;
}

body.mode-focus .app-shell {
  grid-template-columns: 0 1fr 0;
}

body.mode-focus .files-panel,
body.mode-focus .outline-panel {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.99);
}

body.mode-focus .preview-surface {
  display: none;
}

body.mode-focus .editor-grid {
  grid-template-columns: 1fr;
}

body.mode-focus .editor-surface {
  position: relative;
}

body.mode-focus .editor-surface::before,
body.mode-focus .editor-surface::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 5;
}

body.mode-focus .editor-surface::before {
  top: 36px;
  height: calc(50% - 18px);
  background: linear-gradient(180deg, rgba(255, 247, 237, 0.82), rgba(255, 247, 237, 0));
}

body.mode-focus .editor-surface::after {
  bottom: 0;
  height: calc(50% - 18px);
  background: linear-gradient(180deg, rgba(255, 247, 237, 0), rgba(255, 247, 237, 0.82));
}

body.mode-typewriter #editor {
  scroll-behavior: smooth;
}

body.mode-typewriter .editor-surface {
  position: relative;
}

body.mode-typewriter .editor-surface::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  margin-top: -21px;
  height: 42px;
  background: linear-gradient(180deg, rgba(255, 241, 223, 0), rgba(255, 241, 223, 0.5), rgba(255, 241, 223, 0));
  pointer-events: none;
}

.command-palette {
  position: fixed;
  inset: 0;
  background: rgba(18, 13, 10, 0.34);
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
}

.command-palette__card {
  width: min(620px, calc(100vw - 30px));
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--stroke);
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(13, 10, 8, 0.28);
  overflow: hidden;
}

.command-palette__input {
  width: 100%;
  border: 0;
  outline: none;
  padding: 16px 18px;
  border-bottom: 1px solid var(--stroke);
  font-size: 15px;
  font-family: var(--ui);
  background: #fff;
}

.command-palette__list {
  max-height: min(52vh, 410px);
  overflow: auto;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.command-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  display: grid;
  gap: 4px;
}

.command-item:hover,
.command-item.is-active {
  border-color: rgba(180, 93, 34, 0.58);
  background: rgba(255, 243, 231, 0.92);
}

.command-item__title {
  font-weight: 700;
  font-size: 14px;
}

.command-item__hint {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}

.history-panel {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(16, 12, 10, 0.36);
  display: grid;
  place-items: center;
  padding: 20px;
}

.history-panel__card {
  width: min(760px, calc(100vw - 30px));
  max-height: min(78vh, 760px);
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--stroke);
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(13, 10, 8, 0.28);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}

.history-panel__header {
  border-bottom: 1px solid var(--stroke);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.history-panel__header h3 {
  margin: 0;
  font-size: 24px;
  font-family: var(--serif);
  font-weight: 600;
}

.history-list {
  overflow: auto;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.history-item {
  border: 1px solid var(--stroke);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.86);
  padding: 10px 11px;
  display: grid;
  gap: 7px;
}

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

.history-item__title {
  font-size: 14px;
  font-weight: 700;
}

.history-item__meta {
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
}

.history-item__reason {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

@media (max-width: 1260px) {
  .app-shell {
    grid-template-columns: 280px 1fr;
  }

  .outline-panel {
    position: fixed;
    top: 20px;
    right: 20px;
    width: min(320px, calc(100vw - 40px));
    max-height: calc(100vh - 40px);
    transform: translateX(120%);
    opacity: 0;
    pointer-events: none;
    transition: 180ms ease;
    z-index: 15;
  }

  body.show-outline .outline-panel {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }

  .btn-mobile {
    display: inline-flex;
    align-items: center;
  }
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app-shell {
    margin: 12px auto;
    width: calc(100vw - 18px);
    height: calc(100vh - 24px);
    max-height: calc(100vh - 24px);
    grid-template-columns: 1fr;
  }

  .files-panel {
    position: fixed;
    left: 9px;
    top: 12px;
    width: min(360px, calc(100vw - 18px));
    max-height: calc(100vh - 24px);
    transform: translateX(-120%);
    opacity: 0;
    pointer-events: none;
    transition: 180ms ease;
    z-index: 14;
  }

  body.show-files .files-panel {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }

  .workspace__header {
    flex-direction: column;
    align-items: stretch;
  }

  .workspace__actions {
    justify-content: flex-start;
  }

  .doc-meta__select {
    min-width: 150px;
  }

  .find-bar__input {
    min-width: 120px;
    flex: 1;
  }

  .editor-grid {
    grid-template-columns: 1fr;
    padding: 10px 10px 0;
    gap: 10px;
  }

  .preview {
    font-size: 18px;
  }

  .workspace__footer {
    flex-direction: column;
    align-items: flex-start;
  }
}
