:root {
  --bg: #07090d;
  --sidebar-bg: #07090d;
  --surface: #0b0e14;
  --panel: #0f131b;
  --panel-hover: #161b25;
  --border: #1b202a;
  --separator: #141922;
  --text: #f4f7ff;
  --muted: #8f98aa;
  --accent: #d8adb8;
  --accent-soft: #2a1d24;
  --logo: #e5bac6;
  --editor-text: #f9fbff;
  --status-bg: #090b10;
  --font-family: 'Manrope', 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-family);
}

body {
  overflow: hidden;
}

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

label {
  font-size: 13px;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  transition: grid-template-columns 180ms ease;
}

.app[data-sidebar='collapsed'] {
  grid-template-columns: 76px 1fr;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--separator);
  min-width: 0;
  min-height: 0;
}

.brand-block {
  height: 112px;
  border-bottom: 1px solid var(--separator);
  padding: 20px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  color: var(--logo);
  flex: 0 0 auto;
}

.brand-mark svg {
  width: 100%;
  height: 100%;
}

.brand-text-wrap {
  min-width: 0;
}

.brand-text {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0.02em;
  line-height: 1;
  color: var(--logo);
  white-space: nowrap;
}

.sidebar-actions {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  padding: 18px;
  border-bottom: 1px solid var(--separator);
}

.sidebar-actions .icon-btn {
  aspect-ratio: 1 / 1;
  height: auto;
  border-radius: 8px;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  height: 36px;
  width: 100%;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.icon-btn:hover {
  background: var(--panel-hover);
}

.mobile-nav-btn,
.mobile-format-btn,
.mobile-actions-btn {
  display: none;
}

.mobile-format-btn {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.mobile-actions-menu {
  position: fixed;
  top: calc(52px + env(safe-area-inset-top));
  right: 10px;
  width: min(240px, calc(100vw - 20px));
  max-height: min(70vh, 460px);
  overflow: auto;
  z-index: 72;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.46);
  padding: 6px;
}

.mobile-actions-menu button {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  border-radius: 8px;
  min-height: 36px;
  padding: 0 10px;
  cursor: pointer;
}

.mobile-actions-menu button:hover {
  background: var(--panel-hover);
}

.mobile-actions-separator {
  height: 1px;
  background: var(--separator);
  margin: 6px 0;
}

.icon-btn:focus-visible,
.tool-btn:focus-visible,
.action-btn:focus-visible,
.mode-btn:focus-visible,
.file-main-btn:focus-visible,
.favorites-toggle-btn:focus-visible,
.font-select:focus-visible,
.danger-btn:focus-visible,
.title-input:focus-visible,
.export-format-select:focus-visible,
.custom-color-input:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

.icon-btn svg,
.tool-btn svg,
.action-btn svg,
.file-icon {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.file-list-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.file-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 8px 18px;
}

.file-list-title {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.favorites-toggle-btn {
  border: 1px solid transparent;
  background: transparent;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.favorites-toggle-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.favorites-toggle-btn:hover {
  background: var(--panel-hover);
  color: var(--text);
}

.favorites-toggle-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.favorites-toggle-btn.active svg {
  fill: currentColor;
}

.file-list {
  list-style: none;
  margin: 0;
  padding: 0 0 12px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.file-list::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.file-list-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 12px 18px;
}

.file-item {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border-left: 2px solid transparent;
}

.file-main-btn {
  min-width: 0;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  padding: 12px 12px 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.file-main-btn:hover,
.file-item:hover .file-main-btn {
  background: rgba(255, 255, 255, 0.03);
}

.file-item.active {
  border-left-color: var(--accent);
  background: linear-gradient(90deg, var(--accent-soft), transparent 68%);
}

.file-item .doc-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  flex: 0 0 auto;
}

.file-item .doc-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.file-actions {
  position: relative;
  padding-right: 8px;
}

.file-menu-trigger {
  border: none;
  background: transparent;
  color: var(--muted);
  width: 26px;
  height: 26px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 120ms ease;
}

.file-item:hover .file-menu-trigger,
.file-menu-trigger[data-open='true'] {
  opacity: 1;
}

.file-menu-trigger:hover {
  background: var(--panel-hover);
  color: var(--text);
}

.file-menu-trigger svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.file-menu {
  position: absolute;
  right: 0;
  top: 30px;
  min-width: 118px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 4px;
  display: none;
  z-index: 40;
}

.file-menu[data-open='true'] {
  display: block;
}

.file-menu button {
  width: 100%;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 7px;
  text-align: left;
  padding: 0 8px;
  cursor: pointer;
}

.file-menu button:hover {
  background: var(--panel-hover);
}

.app[data-sidebar='collapsed'] .brand-text-wrap,
.app[data-sidebar='collapsed'] .file-list-header,
.app[data-sidebar='collapsed'] .file-list {
  display: none;
}

.app[data-sidebar='collapsed'] .sidebar-actions {
  grid-template-columns: 1fr;
  justify-items: center;
  padding: 12px;
  gap: 8px;
}

.app[data-sidebar='collapsed'] .sidebar-actions .icon-btn {
  width: 40px;
}

.app[data-sidebar='collapsed'] .brand-block {
  padding: 20px 0;
  justify-content: center;
}

.main {
  display: grid;
  grid-template-rows: auto 1fr 44px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
}

.topbar {
  border-bottom: 1px solid var(--separator);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.current-file-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.file-icon {
  color: var(--accent);
  flex: 0 0 auto;
}

.title-input {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 23px;
  font-weight: 600;
  min-width: 180px;
  width: min(360px, 38vw);
  border-radius: 8px;
  padding: 4px 8px;
}

.title-input:hover {
  border-color: var(--border);
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.tool-group {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 12px;
  padding: 4px;
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.tool-btn {
  border: none;
  background: transparent;
  color: var(--text);
  height: 32px;
  min-width: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 700;
}

.tool-btn em {
  font-style: italic;
  font-weight: 700;
}

.tool-btn:hover,
.mode-btn:hover {
  background: var(--panel-hover);
}

.size-control {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  height: 32px;
  overflow: hidden;
}

.size-control .tool-btn {
  width: 26px;
  min-width: 26px;
  border-radius: 0;
}

.font-size-value {
  min-width: 34px;
  text-align: center;
  font-size: 12px;
  color: var(--text);
}

.action-btn {
  border: 1px solid var(--border);
  border-radius: 12px;
  height: 40px;
  padding: 0 14px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.action-btn.accent {
  border-color: var(--accent);
  color: var(--accent);
}

.action-btn:hover {
  background: var(--panel-hover);
}

.export-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.export-format-select {
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 0 10px;
  text-transform: lowercase;
}

.mode-toggle {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 12px;
  padding: 4px;
  display: inline-flex;
  gap: 4px;
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  min-width: 74px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.mode-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.editor-area {
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.editor-content,
.preview {
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  background: var(--surface);
  color: var(--editor-text);
  font-family: var(--font-family);
  font-size: 16px;
  line-height: 1.7;
  padding: 24px 28px 32px;
}

.editor-content {
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) var(--panel);
  white-space: pre-wrap;
  word-break: break-word;
  caret-color: var(--editor-text);
}

.editor-content:focus {
  outline: none;
}

.editor-content::selection,
.preview ::selection {
  background: var(--accent-soft);
}

.preview {
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) var(--panel);
  white-space: pre-wrap;
  word-break: break-word;
}

.editor-content::-webkit-scrollbar,
.preview::-webkit-scrollbar {
  width: 12px;
}

.editor-content::-webkit-scrollbar-track,
.preview::-webkit-scrollbar-track {
  background: var(--panel);
}

.editor-content::-webkit-scrollbar-thumb,
.preview::-webkit-scrollbar-thumb {
  background: var(--accent);
  border: 3px solid var(--panel);
  border-radius: 999px;
}

.editor-content::-webkit-scrollbar-thumb:hover,
.preview::-webkit-scrollbar-thumb:hover {
  filter: brightness(1.08);
}

.preview a {
  color: var(--accent);
  text-decoration: underline;
}

.status-bar {
  border-top: 1px solid var(--separator);
  background: var(--status-bg);
  color: var(--muted);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 20px;
  font-size: 13px;
  padding: 0 20px;
}

#saveState {
  margin-right: auto;
}

.status-bar strong {
  color: var(--text);
  font-weight: 600;
}

.mobile-sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 8, 0.68);
  z-index: 55;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 8, 0.76);
}

.search-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 8, 0.76);
  z-index: 69;
}

.modal-backdrop[hidden],
.modal[hidden],
.search-backdrop[hidden],
.search-modal[hidden] {
  display: none !important;
}

.search-modal {
  position: fixed;
  top: 12vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(700px, calc(100vw - 30px));
  max-height: 72vh;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  z-index: 70;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.search-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--separator);
}

.search-header h2 {
  margin: 0;
  font-size: 19px;
}

.search-body {
  display: grid;
  gap: 10px;
  padding: 12px 14px 14px;
  min-height: 0;
}

.search-input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  padding: 0 12px;
}

.search-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.search-results {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  min-height: 0;
  max-height: min(56vh, 460px);
}

.search-result-item {
  margin: 0;
}

.search-result-btn {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 10px 8px;
  border-radius: 9px;
  display: grid;
  gap: 4px;
  cursor: pointer;
}

.search-result-btn:hover {
  background: var(--panel-hover);
}

.search-result-title {
  font-weight: 600;
  font-size: 14px;
}

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

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100vh - 40px);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--separator);
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.close-btn {
  width: 34px;
  height: 34px;
}

.modal-body {
  padding: 16px 18px 20px;
  display: grid;
  gap: 18px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) var(--panel);
}

.settings-block {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: var(--panel);
}

.settings-block.hidden {
  display: none;
}

.settings-block h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.font-select {
  width: 100%;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0 12px;
}

.theme-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) var(--panel);
}

.theme-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  width: 100%;
  padding: 8px 10px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.theme-item.active {
  border-color: var(--accent);
}

.theme-name {
  font-size: 14px;
  font-weight: 600;
}

.theme-swatches {
  display: flex;
  gap: 6px;
}

.theme-swatches span {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.custom-theme-list {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.custom-color-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--text);
  font-size: 15px;
}

.custom-color-control {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.custom-color-value {
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
  min-width: 70px;
  text-align: right;
  text-transform: uppercase;
}

.custom-color-input {
  width: 46px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  padding: 0;
}

#applyCustomThemeBtn {
  width: 100%;
  justify-content: center;
}

.danger-zone p {
  color: var(--muted);
  margin: 8px 0 0;
  font-size: 13px;
}

.danger-btn {
  border: 1px solid #944a4a;
  background: #261315;
  color: #f2c7c7;
  border-radius: 10px;
  height: 38px;
  padding: 0 12px;
  cursor: pointer;
}

.danger-btn:hover {
  background: #32191c;
}

@media (max-width: 1280px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .top-controls {
    flex-wrap: wrap;
  }

  .title-input {
    width: 100%;
  }
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    height: 100svh;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(84vw, 320px);
    z-index: 60;
    transform: translateX(-104%);
    transition: transform 180ms ease;
    box-shadow: 0 0 0 1px var(--separator), 0 16px 40px rgba(0, 0, 0, 0.45);
  }

  .app[data-mobile-sidebar='open'] .sidebar {
    transform: translateX(0);
  }

  .app[data-sidebar='collapsed'] .brand-text-wrap,
  .app[data-sidebar='collapsed'] .file-list-header,
  .app[data-sidebar='collapsed'] .file-list {
    display: block;
  }

  .app[data-sidebar='collapsed'] .sidebar-actions {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    padding: 18px;
    gap: 10px;
  }

  .app[data-sidebar='collapsed'] .brand-block {
    padding: 20px 18px;
    justify-content: flex-start;
  }

  .mobile-nav-btn {
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
    display: grid;
  }

  .topbar {
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
    gap: 8px;
  }

  .current-file-wrap {
    width: 100%;
    gap: 6px;
  }

  .file-icon {
    display: none;
  }

  .title-input {
    min-width: 0;
    width: 100%;
    font-size: 19px;
    padding: 3px 2px;
  }

  .mobile-format-btn,
  .mobile-actions-btn {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    display: grid;
  }

  .top-controls {
    width: 100%;
    display: grid;
    gap: 8px;
  }

  .tool-group {
    display: none;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .app[data-mobile-format='open'] .tool-group {
    display: inline-flex;
  }

  .tool-group::-webkit-scrollbar {
    width: 0;
    height: 0;
  }

  .tool-group > * {
    flex: 0 0 auto;
  }

  #saveBtn,
  .export-wrap {
    display: none;
  }

  .mode-toggle {
    width: 100%;
    display: flex;
  }

  .mode-btn {
    flex: 1;
  }

  .editor-content,
  .preview {
    font-size: 16px;
    padding: 14px 14px 24px;
  }

  .status-bar {
    gap: 10px;
    padding: 7px 12px calc(7px + env(safe-area-inset-bottom));
    flex-wrap: wrap;
    font-size: 12px;
    justify-content: space-between;
  }

  #saveState {
    width: 100%;
    margin-right: 0;
  }

  .modal {
    width: min(560px, calc(100vw - 18px));
    max-height: calc(100dvh - 18px);
  }

  .search-modal {
    top: calc(10px + env(safe-area-inset-top));
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 20px - env(safe-area-inset-top));
  }

  .custom-theme-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 500px) {
  .sidebar {
    width: 92vw;
  }

  .topbar {
    padding: calc(6px + env(safe-area-inset-top)) 10px 8px;
  }

  .tool-group {
    padding: 5px;
    border-radius: 10px;
  }

  .tool-btn {
    min-width: 30px;
    height: 30px;
  }

  .size-control {
    height: 30px;
  }

  .status-bar {
    font-size: 11px;
  }
}
