:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: rgba(255, 255, 255, 0.84);
  --panel-strong: #fff;
  --line: rgba(15, 23, 42, 0.09);
  --line-strong: rgba(15, 23, 42, 0.16);
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0f766e;
  --accent-soft: rgba(15, 118, 110, 0.1);
  --danger: #b91c1c;
  --shadow: 0 24px 70px rgba(15, 23, 42, 0.08);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --topbar-h: 68px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.08), transparent 24%),
    radial-gradient(circle at bottom right, rgba(148, 163, 184, 0.12), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  background: none;
  color: inherit;
}

#app {
  min-height: 100dvh;
}

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(244, 247, 251, 0.82);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}

.brand {
  width: 44px;
  height: 44px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.16), rgba(15, 23, 42, 0.05));
  border: 1px solid rgba(15, 118, 110, 0.18);
  color: var(--accent);
  font-weight: 800;
  flex: 0 0 auto;
}

.crumb {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}

.crumb strong {
  font-size: 14px;
  letter-spacing: -0.01em;
}

.crumb span {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.btn,
.icon-btn,
.chip,
.danger {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.btn,
.chip,
.danger {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), #115e59);
  border-color: transparent;
  color: white;
}

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

.btn:hover,
.icon-btn:hover,
.chip:hover,
.danger:hover {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.92);
}

.btn.primary:hover {
  background: linear-gradient(135deg, #0f766e, #0f5e59);
}

.btn:active,
.icon-btn:active,
.chip:active,
.danger:active {
  transform: translateY(1px) scale(0.99);
}

.icon-btn {
  padding: 0 14px;
  min-width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 320px;
  gap: 14px;
  padding: 14px;
  width: 100%;
  max-width: 1920px;
  margin: 0 auto;
}

.panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--panel);
  backdrop-filter: blur(22px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.panel-head strong {
  font-size: 14px;
}

.panel-head span {
  font-size: 12px;
  color: var(--muted);
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}

.search {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.search input,
.folder-input,
.name-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 13px;
  outline: none;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
}

.search input:focus,
.folder-input:focus,
.name-input:focus {
  border-color: rgba(15, 118, 110, 0.32);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.09);
}

.tree,
.folder-list,
.file-list {
  min-height: 0;
  overflow: auto;
}

.tree {
  padding: 10px;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border-radius: 14px;
  border: 1px solid transparent;
  text-align: left;
}

.tree-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 0;
  text-align: left;
}

.tree-row:hover {
  background: rgba(255, 255, 255, 0.7);
  border-color: var(--line);
}

.tree-row.active {
  background: var(--accent-soft);
  border-color: rgba(15, 118, 110, 0.16);
}

.tree-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
}

.tree-meta {
  font-size: 11px;
  color: var(--muted);
  flex: 0 0 auto;
}

.tree-toggle {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
}

.tree-children {
  display: grid;
}

.sidebar-foot {
  display: flex;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

.main {
  display: grid;
  grid-template-rows: auto 1fr;
  align-self: start;
  width: 100%;
}

.main-head {
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.main-title {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.main-title strong {
  font-size: 16px;
  letter-spacing: -0.02em;
}

.main-title span {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.body {
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.preview {
  width: 100%;
  min-width: 0;
  min-height: 0;
  padding: clamp(28px, 4vw, 64px);
}

.md {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  overflow-wrap: anywhere;
}

.md h1,
.md h2,
.md h3,
.md h4 {
  margin: 1.2em 0 0.55em;
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.md > :first-child {
  margin-top: 0;
}

.md h1 {
  font-size: clamp(34px, 4vw, 48px);
}

.md h2 {
  font-size: clamp(26px, 3vw, 34px);
}

.md h3 {
  font-size: clamp(21px, 2.2vw, 26px);
}

.md p,
.md li,
.md blockquote,
.md table {
  line-height: 1.8;
  font-size: 16px;
}

.md p {
  margin: 0 0 1em;
}

.md ul,
.md ol {
  margin: 0 0 1em;
  padding-left: 1.2em;
}

.md a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(15, 118, 110, 0.24);
}

.md blockquote {
  margin: 1em 0;
  padding: 12px 14px;
  border-left: 4px solid rgba(15, 118, 110, 0.35);
  background: rgba(15, 118, 110, 0.06);
  border-radius: 0 14px 14px 0;
}

.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: rgba(15, 23, 42, 0.06);
  padding: 0.12em 0.38em;
  border-radius: 8px;
}

.md pre {
  overflow: auto;
  padding: 14px;
  border-radius: 18px;
  background: #0f172a;
  color: #e2e8f0;
  margin: 1em 0;
}

.md pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

.md table {
  width: 100%;
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
  margin: 1em 0;
}

.md th,
.md td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.md img {
  max-width: 100%;
  height: auto;
  border-radius: 16px;
}

.folder-bar {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.folder-bar span {
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-list {
  padding: 10px;
  display: grid;
  gap: 8px;
}

.item {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.74);
  padding: 12px;
  display: grid;
  gap: 10px;
}

.item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.item-title {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.item-title strong {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-title span {
  font-size: 11px;
  color: var(--muted);
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.item-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 11px;
}

.pill {
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.04);
}

.status {
  min-height: 24px;
  padding: 0 14px 12px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.32);
  backdrop-filter: blur(6px);
  z-index: 35;
}

.drawer {
  position: fixed;
  inset: auto 10px 10px;
  max-height: 84dvh;
  z-index: 40;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  display: grid;
  overflow: hidden;
}

.drawer .panel {
  border: 0;
  box-shadow: none;
  background: transparent;
  backdrop-filter: none;
}

.drawer-head {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.drawer-body {
  min-height: 0;
  overflow: auto;
}

.hide {
  display: none !important;
}

@media (max-width: 1439px) {
  .workspace {
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .right-panel {
    display: none;
  }
}

@media (max-width: 1119px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .left-panel {
    display: none;
  }

}

@media (max-width: 767px) {
  .topbar {
    padding: 8px max(10px, env(safe-area-inset-left));
    height: 60px;
    min-height: 60px;
    align-items: center;
    gap: 8px;
  }

  .brand {
    width: 40px;
    height: 40px;
    border-radius: 13px;
  }

  .actions {
    gap: 4px;
    flex-wrap: nowrap;
  }

  .actions .icon-btn,
  .actions .btn {
    min-width: 0;
    height: 38px;
    padding: 0 10px;
    font-size: 12px;
  }

  .workspace {
    padding: 0;
  }

  .main {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: none;
    backdrop-filter: none;
  }

  .main-head {
    padding: 14px 18px;
  }

  .main-title {
    gap: 0;
  }

  .main-title strong {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .main-title span {
    display: none;
  }

  .preview {
    padding: 26px 18px max(48px, env(safe-area-inset-bottom));
  }

  .md h1 {
    font-size: 30px;
    line-height: 1.15;
  }

  .md h2 {
    font-size: 24px;
    line-height: 1.25;
  }

  .md h3 {
    font-size: 20px;
    line-height: 1.3;
  }

  .md p,
  .md li,
  .md blockquote,
  .md table {
    font-size: 16px;
    line-height: 1.75;
  }

  .md ul,
  .md ol {
    padding-left: 1.35em;
  }

  .md pre {
    margin-inline: -4px;
    border-radius: 14px;
  }

  .drawer {
    inset: auto 8px max(8px, env(safe-area-inset-bottom));
    max-height: calc(100dvh - 76px);
    border-radius: 22px;
  }
}

@media (max-width: 420px) {
  .crumb span {
    display: none;
  }

  .actions .icon-btn,
  .actions .btn {
    padding-inline: 9px;
  }
}
