@import url("https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Inter:wght@400;500;600&family=Newsreader:opsz,wght@6..72,400;6..72,600&display=swap");

:root {
  color-scheme: light;
  --canvas: #f7f5f0;
  --paper: #fffefa;
  --ink: #252724;
  --muted: #777a72;
  --line: #deddd6;
  --line-soft: #ebe9e2;
  --accent: #e85d3f;
  --accent-dark: #c8462d;
  --green: #6a9b79;
  font-family: "Inter", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--canvas);
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.topbar {
  position: relative;
  z-index: 10;
  height: 68px;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 480px) minmax(260px, 1fr);
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 245, 240, 0.94);
  backdrop-filter: blur(14px);
}

.brand {
  width: max-content;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fffdf8;
  background: var(--ink);
  font: 500 14px/1 "DM Mono", monospace;
  letter-spacing: -0.08em;
}

.title-wrap {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.document-title {
  width: min(270px, 60%);
  border: 0;
  border-bottom: 1px solid transparent;
  padding: 6px 3px;
  outline: none;
  color: var(--ink);
  background: transparent;
  text-align: right;
  font-size: 13px;
  font-weight: 500;
  text-overflow: ellipsis;
}

.document-title:hover,
.document-title:focus {
  border-bottom-color: var(--line);
}

.save-state {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
}

.connection-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #b7b8b3;
  box-shadow: 0 0 0 3px rgba(183, 184, 179, 0.13);
}

.connection-dot[data-connected="true"] {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(106, 155, 121, 0.14);
}

.actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.view-switcher {
  height: 34px;
  display: flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 254, 250, 0.65);
}

.view-switcher button {
  width: 30px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  padding: 0;
  cursor: pointer;
  background: transparent;
}

.view-switcher button:hover {
  background: #eeece6;
}

.view-switcher button[aria-pressed="true"] {
  background: var(--paper);
  box-shadow: 0 1px 3px rgba(36, 38, 35, 0.12);
}

svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.45;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.share-button {
  height: 36px;
  min-width: 89px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--ink);
  border-radius: 9px;
  padding: 0 13px;
  cursor: pointer;
  color: #fff;
  background: var(--ink);
  font-size: 12px;
  font-weight: 500;
  transition: transform 120ms ease, background 120ms ease;
}

.share-button:hover {
  background: #3a3c38;
  transform: translateY(-1px);
}

.share-button[data-copied="true"] {
  border-color: var(--green);
  background: var(--green);
}

.workspace {
  height: calc(100vh - 68px);
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.pane {
  min-width: 0;
  position: relative;
}

.editor-pane {
  border-right: 1px solid var(--line);
  background-color: var(--canvas);
  background-image:
    linear-gradient(rgba(222, 221, 214, 0.25) 1px, transparent 1px),
    linear-gradient(90deg, rgba(222, 221, 214, 0.25) 1px, transparent 1px);
  background-size: 24px 24px;
}

.preview-pane {
  overflow-y: auto;
  background: var(--paper);
}

.pane-label {
  position: absolute;
  top: 18px;
  left: 24px;
  z-index: 2;
  color: #999b94;
  font: 500 9px/1 "DM Mono", monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  user-select: none;
}

#editor {
  width: 100%;
  height: 100%;
  resize: none;
  border: 0;
  outline: 0;
  padding: 58px clamp(28px, 5vw, 78px) 68px;
  color: #343632;
  caret-color: var(--accent);
  background: rgba(247, 245, 240, 0.88);
  font: 400 14px/1.8 "DM Mono", monospace;
  tab-size: 2;
}

#editor::selection {
  background: rgba(232, 93, 63, 0.16);
}

.editor-footer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-top: 1px solid rgba(222, 221, 214, 0.75);
  color: #999b94;
  background: rgba(247, 245, 240, 0.94);
  font: 400 9px/1 "DM Mono", monospace;
  letter-spacing: 0.03em;
}

.markdown-body {
  width: min(680px, calc(100% - 64px));
  margin: 0 auto;
  padding: 74px 0 100px;
  color: #333530;
  font: 400 17px/1.76 "Newsreader", serif;
}

.markdown-body > *:first-child {
  margin-top: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  color: #242622;
  font-family: "Inter", sans-serif;
  letter-spacing: -0.035em;
}

.markdown-body h1 {
  margin: 0 0 29px;
  font-size: clamp(34px, 4vw, 47px);
  line-height: 1.08;
  font-weight: 600;
}

.markdown-body h2 {
  margin: 2.1em 0 0.65em;
  padding-top: 0.45em;
  border-top: 1px solid var(--line-soft);
  font-size: 24px;
  line-height: 1.25;
  font-weight: 600;
}

.markdown-body h3 {
  margin: 1.8em 0 0.5em;
  font-size: 19px;
  font-weight: 600;
}

.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 1.7em 0 0.5em;
  font-size: 16px;
  font-weight: 600;
}

.markdown-body p {
  margin: 0 0 1.25em;
}

.markdown-body strong {
  font-weight: 600;
}

.markdown-body a {
  color: var(--accent-dark);
  text-decoration-color: rgba(200, 70, 45, 0.35);
  text-underline-offset: 3px;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0.7em 0 1.4em;
  padding-left: 1.3em;
}

.markdown-body li {
  margin: 0.28em 0;
  padding-left: 0.25em;
}

.markdown-body li::marker {
  color: var(--accent);
}

.markdown-body .task {
  list-style: none;
  margin-left: -1.5em;
}

.markdown-body .task input {
  margin-right: 10px;
  accent-color: var(--accent);
}

.markdown-body code {
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  padding: 0.12em 0.32em;
  background: #f4f1eb;
  font: 400 0.78em/1.4 "DM Mono", monospace;
}

.markdown-body pre {
  overflow-x: auto;
  margin: 1.6em 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px 22px;
  background: #292b28;
  box-shadow: 0 8px 24px rgba(36, 38, 34, 0.08);
}

.markdown-body pre code {
  border: 0;
  padding: 0;
  color: #ecebe5;
  background: transparent;
  font-size: 12px;
  line-height: 1.75;
}

.markdown-body blockquote {
  margin: 1.6em 0;
  border-left: 3px solid var(--accent);
  padding: 0.2em 0 0.2em 1.25em;
  color: #666861;
  font-style: italic;
}

.markdown-body hr {
  width: 22%;
  margin: 3em auto;
  border: 0;
  border-top: 1px solid var(--line);
}

.empty-state {
  margin: 15vh auto 0;
  text-align: center;
}

.empty-state > span {
  color: var(--accent);
  font: 500 12px/1 "DM Mono", monospace;
  letter-spacing: 0.1em;
}

.empty-state h2 {
  margin: 14px 0 7px;
}

.empty-state p {
  color: var(--muted);
}

.empty-state a {
  display: inline-block;
  margin-top: 14px;
  border-radius: 8px;
  padding: 9px 14px;
  color: white;
  background: var(--ink);
  font: 500 12px/1 "Inter", sans-serif;
  text-decoration: none;
}

body[data-view="write"] .workspace,
body[data-view="preview"] .workspace {
  grid-template-columns: 1fr;
}

body[data-view="write"] .preview-pane,
body[data-view="preview"] .editor-pane {
  display: none;
}

body[data-view="write"] #editor {
  padding-right: max(calc((100vw - 820px) / 2), 40px);
  padding-left: max(calc((100vw - 820px) / 2), 40px);
}

@media (max-width: 760px) {
  .topbar {
    height: 62px;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    padding: 0 14px;
  }

  .brand > span:last-child,
  .save-state {
    display: none;
  }

  .title-wrap {
    justify-content: flex-start;
  }

  .document-title {
    width: 100%;
    text-align: left;
  }

  .view-switcher button[data-view="split"] {
    display: none;
  }

  .share-button {
    width: 38px;
    min-width: 38px;
    padding: 0;
  }

  .share-button span {
    display: none;
  }

  .workspace {
    height: calc(100vh - 62px);
    grid-template-columns: 1fr;
  }

  .editor-pane {
    display: none;
  }

  .preview-pane {
    display: block;
  }

  body[data-view="write"] .editor-pane {
    display: block;
  }

  body[data-view="write"] .preview-pane {
    display: none;
  }

  .markdown-body {
    width: calc(100% - 44px);
    padding-top: 64px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
