/* style.css */
:root {
  --bg: #101417;
  --surface: #171d21;
  --editor: #11171b;
  --border: #2c373e;
  --text: #edf2ed;
  --muted: #9aa7a5;
  --accent: #8ed0af;
  --selection: #28483d;
  --danger: #e5877e;
  --shadow: rgba(0, 0, 0, 0.28);
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
}

body {
  min-width: 320px;
  overflow-x: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button,
input,
textarea,
select {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.app-shell {
  min-height: 100vh;
  background:
    radial-gradient(circle at 80% -30%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 34rem),
    var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.brand-button {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  text-align: left;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  color: var(--bg);
  background: var(--accent);
  border-radius: 11px;
  box-shadow: 0 5px 16px color-mix(in srgb, var(--accent) 25%, transparent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  font-weight: 900;
}

.brand-copy {
  display: grid;
  gap: 1px;
}

.brand-copy strong {
  font-size: 15px;
  letter-spacing: -0.025em;
}

.brand-copy small {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.04em;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
}

.top-actions::-webkit-scrollbar {
  display: none;
}

.button,
.icon-text-button,
.format-button,
.dialog-close {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 74%, transparent);
  font-size: 13px;
  font-weight: 700;
}

.button {
  padding: 0 13px;
  white-space: nowrap;
}

.button:hover,
.icon-text-button:hover,
.format-button:hover,
.dialog-close:hover {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--border));
  background: color-mix(in srgb, var(--accent) 11%, var(--surface));
}

.button-primary {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
}

.button-primary:hover {
  filter: brightness(1.07);
  background: var(--accent);
}

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

.button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.mini-button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

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

.library-panel {
  min-height: calc(100vh - 68px);
  display: flex;
  flex-direction: column;
  background: color-mix(in srgb, var(--surface) 94%, var(--bg));
  border-right: 1px solid var(--border);
}

.library-top {
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 17px 15px;
  border-bottom: 1px solid var(--border);
}

.section-kicker {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.13em;
}

.library-top strong,
.reader-header strong,
.outline-header strong {
  font-size: 14px;
  letter-spacing: -0.02em;
}

.file-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.file-row {
  width: 100%;
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  margin-bottom: 4px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 11px;
  text-align: left;
}

.file-row:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--text) 5%, transparent);
}

.file-row.active {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  border-color: color-mix(in srgb, var(--accent) 32%, var(--border));
}

.file-icon {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 11%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 24%, transparent);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  font-weight: 900;
}

.file-details {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.file-details strong,
.file-details small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-details strong {
  font-size: 13px;
  font-weight: 720;
}

.file-details small {
  color: var(--muted);
  font-size: 11px;
}

.library-bottom {
  padding: 13px;
  border-top: 1px solid var(--border);
}

.new-file-button {
  width: 100%;
}

.library-bottom p {
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.studio {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(340px, 1fr) 200px;
}

.editor-panel,
.reader-panel,
.outline-panel {
  min-width: 0;
  min-height: calc(100vh - 68px);
}

.editor-panel {
  display: flex;
  flex-direction: column;
  background: var(--editor);
  border-right: 1px solid var(--border);
}

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

.editor-header {
  min-height: 62px;
}

.document-name-wrap {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
}

.title-input {
  width: min(100%, 330px);
  min-height: 40px;
  padding: 0 8px;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.title-input:hover,
.title-input:focus {
  border-color: var(--border);
  background: color-mix(in srgb, var(--surface) 52%, transparent);
}

.saved-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 12%, transparent);
}

.saved-dot.pending {
  background: #e4b363;
  box-shadow: 0 0 0 4px color-mix(in srgb, #e4b363 12%, transparent);
}

.document-actions {
  display: flex;
  gap: 5px;
}

.icon-text-button {
  min-height: 34px;
  padding: 0 9px;
  background: transparent;
  font-size: 12px;
}

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

.format-toolbar {
  min-height: 47px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 13px;
  overflow-x: auto;
  background: color-mix(in srgb, var(--surface) 50%, var(--editor));
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}

.format-toolbar::-webkit-scrollbar {
  display: none;
}

.format-button {
  min-width: 34px;
  min-height: 32px;
  padding: 0 8px;
  border-radius: 7px;
  background: transparent;
  font-size: 12px;
}

.toolbar-divider {
  width: 1px;
  height: 22px;
  flex: 0 0 auto;
  margin: 0 4px;
  background: var(--border);
}

.wrap-note {
  min-width: max-content;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
}

.editor-wrap {
  position: relative;
  flex: 1;
  min-height: 390px;
  overflow: hidden;
}

#editor {
  width: 100%;
  height: 100%;
  min-height: 390px;
  display: block;
  resize: none;
  overflow: auto;
  padding: 28px clamp(20px, 4vw, 52px) 70px;
  color: var(--text);
  background: var(--editor);
  border: 0;
  outline: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.78;
  letter-spacing: 0;
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  caret-color: var(--accent);
}

#editor::selection {
  background: var(--selection);
}

#editor::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

.editor-status {
  min-height: 35px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 16px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 52%, var(--editor));
  border-top: 1px solid var(--border);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.reader-panel {
  overflow-y: auto;
  background: var(--bg);
  border-right: 1px solid var(--border);
}

.reader-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: color-mix(in srgb, var(--bg) 93%, transparent);
  backdrop-filter: blur(10px);
}

.markdown-body {
  max-width: 790px;
  margin: 0 auto;
  padding: 38px clamp(22px, 5vw, 62px) 100px;
  color: var(--text);
  font-size: 16px;
  line-height: 1.8;
  overflow-wrap: anywhere;
}

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

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  color: var(--text);
  letter-spacing: -0.045em;
  line-height: 1.18;
  scroll-margin-top: 95px;
}

.markdown-body h1 {
  margin: 0 0 0.75em;
  font-size: clamp(31px, 4vw, 45px);
}

.markdown-body h2 {
  margin-top: 2.1em;
  font-size: 1.55em;
}

.markdown-body h3 {
  margin-top: 1.8em;
  font-size: 1.2em;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre {
  margin: 0 0 1.25em;
}

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

.markdown-body li + li {
  margin-top: 0.3em;
}

.markdown-body a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.markdown-body code {
  padding: 0.14em 0.35em;
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
}

.markdown-body pre {
  overflow-x: auto;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
  border: 0;
}

.markdown-body blockquote {
  padding: 3px 0 3px 18px;
  color: var(--muted);
  border-left: 3px solid var(--accent);
}

.markdown-body hr {
  margin: 2em 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.4em;
}

.markdown-body th,
.markdown-body td {
  padding: 9px;
  text-align: left;
  border: 1px solid var(--border);
}

.markdown-body th {
  background: var(--surface);
}

.markdown-body img {
  max-width: 100%;
  border-radius: 10px;
}

.outline-panel {
  padding: 22px 11px;
  overflow-y: auto;
  background: color-mix(in srgb, var(--surface) 90%, var(--bg));
}

.outline-header {
  padding: 0 8px 12px;
}

.outline-item {
  width: 100%;
  min-height: 36px;
  padding: 6px 8px;
  overflow: hidden;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 7px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.outline-item:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 11%, transparent);
}

.outline-item.level-2 {
  padding-left: 16px;
}

.outline-item.level-3 {
  padding-left: 24px;
}

.outline-empty {
  margin: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

body[data-layout="edit"] .reader-panel,
body[data-layout="edit"] .outline-panel {
  display: none;
}

body[data-layout="edit"] .studio {
  grid-template-columns: minmax(0, 1fr);
}

body[data-layout="read"] .editor-panel,
body[data-layout="read"] .outline-panel {
  display: none;
}

body[data-layout="read"] .studio {
  grid-template-columns: minmax(0, 1fr);
}

body.focus-mode .topbar,
body.focus-mode .library-panel,
body.focus-mode .outline-panel,
body.focus-mode .reader-header,
body.focus-mode .editor-header,
body.focus-mode .format-toolbar,
body.focus-mode .editor-status {
  display: none;
}

body.focus-mode .workspace,
body.focus-mode .studio {
  display: block;
}

body.focus-mode .reader-panel,
body.focus-mode .editor-panel {
  min-height: 100vh;
  border: 0;
}

body.focus-mode .editor-panel {
  display: none;
}

body.focus-mode[data-layout="edit"] .editor-panel {
  display: flex;
}

body.focus-mode[data-layout="edit"] #editor {
  min-height: 100vh;
  padding-top: 50px;
}

dialog {
  width: min(650px, calc(100% - 24px));
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 25px 80px var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(4px);
}

.dialog-card {
  padding: 22px;
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.dialog-header h2,
.small-dialog h2 {
  margin: 0;
  color: var(--text);
  font-size: 25px;
  letter-spacing: -0.04em;
}

.dialog-header p:not(.section-kicker) {
  max-width: 450px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.dialog-close {
  min-height: 36px;
  padding: 0 10px;
  background: transparent;
  font-size: 12px;
}

.appearance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.appearance-grid label,
.small-dialog label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
.small-dialog input {
  width: 100%;
  min-height: 44px;
  padding: 0 10px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
}

.theme-actions,
.transfer-actions,
.dialog-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.theme-actions {
  margin: 18px 0;
}

.transfer-actions {
  margin-top: 18px;
}

.color-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.color-control {
  min-height: 50px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 33px auto;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 11px;
}

.color-control > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-control input {
  width: 30px;
  height: 30px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 7px;
}

.color-control code {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
}

.small-dialog {
  width: min(430px, calc(100% - 24px));
}

.small-dialog h2 {
  margin-bottom: 20px;
}

.dialog-buttons {
  margin-top: 18px;
}

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

  .outline-panel {
    display: none;
  }
}

@media (max-width: 760px) {
  .topbar {
    min-height: 62px;
    padding: 8px 10px;
  }

  .brand-copy {
    display: none;
  }

  .workspace {
    min-height: calc(100vh - 62px);
    display: block;
  }

  .library-panel {
    position: fixed;
    top: 62px;
    bottom: 0;
    left: 0;
    z-index: 25;
    width: min(300px, 88vw);
    min-height: 0;
    transform: translateX(-105%);
    transition: transform 170ms ease;
    box-shadow: 16px 0 36px var(--shadow);
  }

  body.sidebar-open .library-panel {
    transform: translateX(0);
  }

  .studio {
    min-height: calc(100vh - 62px);
    display: block;
  }

  .editor-panel,
  .reader-panel {
    min-height: calc(100vh - 62px);
    border-right: 0;
  }

  body[data-layout="split"] .editor-panel {
    display: none;
  }

  body[data-layout="split"] .reader-panel {
    display: block;
  }

  .panel-header {
    padding: 9px 13px;
  }

  .editor-header {
    min-height: 58px;
  }

  .document-actions .icon-text-button:first-child {
    display: none;
  }

  .editor-wrap,
  #editor {
    min-height: calc(100vh - 202px);
  }

  #editor {
    padding: 22px 18px 56px;
    font-size: 14px;
  }

  .markdown-body {
    padding: 29px 20px 72px;
    font-size: 15.5px;
  }

  .editor-status {
    padding: 0 12px;
    font-size: 10px;
  }
}

@media (max-width: 510px) {
  .compact-action span:last-child {
    display: none;
  }

  .compact-action {
    min-width: 44px;
    padding: 0 10px;
  }

  #themeButton {
    font-size: 0;
    min-width: 44px;
    padding: 0;
  }

  #themeButton::after {
    content: "Theme";
    font-size: 11px;
  }

  .button-primary {
    padding: 0 11px;
  }

  .appearance-grid,
  .color-controls {
    grid-template-columns: 1fr;
  }

  .dialog-card {
    padding: 18px;
  }

  .dialog-header h2,
  .small-dialog h2 {
    font-size: 22px;
  }
}

@media (prefers-color-scheme: light) {
  :root {
    --shadow: rgba(45, 39, 28, 0.16);
  }
}
