:root {
  color-scheme: dark;
  --bg: #0d1114;
  --bg-sidebar: #10151a;
  --bg-editor: #0d1114;
  --panel: #161b22;
  --border: #21262d;
  --border-light: #30363d;
  --text: #e6edf3;
  --text-muted: #7d8590;
  --text-dim: #484f58;
  --primary: #58a6ff;
  --primary-hover: #4090e0;
  --danger: #f85149;
  --sidebar-width: 230px;
  --header-height: 44px;
}

* { box-sizing: border-box; margin: 0; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Centered-card layout (landing) ---------- */
.app {
  width: 100%;
  max-width: 400px;
  padding: 40px 32px;
  text-align: center;
}
.app h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: 2px; letter-spacing: -0.5px; }
.app > .tagline { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 36px; font-weight: 400; }

.app-panel { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.hidden { display: none !important; }

button {
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  width: 100%;
  max-width: 280px;
  font-family: inherit;
  transition: background 0.12s;
}
button:hover { background: #1c2129; }
button.primary { background: #1f6feb; border-color: #1f6feb; color: #fff; }
button.primary:hover { background: #388bfd; }
button.danger { color: var(--danger); border-color: rgba(248,81,73,0.35); background: transparent; }
button.danger:hover { background: rgba(248,81,73,0.1); }
button.small { font-size: 12px; padding: 5px 10px; border-radius: 5px; max-width: none; width: auto; }
button:disabled { opacity: 0.4; cursor: default; }

input[type="email"],
input[type="password"],
input[type="text"],
input[type="file"],
textarea {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0d1114;
  color: var(--text);
  width: 100%;
  max-width: 280px;
  font-family: inherit;
  transition: border-color 0.12s;
}
input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(31,111,235,0.2); }

/* ---------- Landing / Auth ---------- */
.landing-auth { width: 100%; max-width: 280px; }
.landing-auth h3 { margin-bottom: 14px; font-size: 0.95rem; font-weight: 600; }

.auth-form {
  display: flex; flex-direction: column; gap: 8px;
  width: 100%; max-width: 280px;
}
.auth-form input { max-width: none; }
.auth-error { color: var(--danger); font-size: 12px; min-height: 1.2em; }
.auth-switch { color: var(--text-muted); font-size: 12px; }
.auth-switch a { color: var(--primary); text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

/* ---------- Full-screen dashboard ---------- */
body.body-dashboard { align-items: stretch; padding: 0; }
body.body-dashboard .app {
  max-width: none;
  padding: 0;
  text-align: left;
  width: 100%;
  height: 100vh;
  /* 100vh is unstable on mobile browsers -- the address bar showing/hiding
     resizes the viewport and causes jumpy layout. 100dvh tracks the actual
     visible area instead; keep the 100vh line above as a fallback for
     browsers that don't support dvh yet. */
  height: 100dvh;
}
body.body-dashboard .app > h1,
body.body-dashboard .app > .tagline { display: none; }

.app-dashboard {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: stretch; gap: 0;
  background: var(--bg);
}

.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sidebar);
  flex-shrink: 0;
}
.dash-brand { font-weight: 700; font-size: 13px; color: var(--text); letter-spacing: 0.3px; flex-shrink: 0; }
.dash-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dash-email {
  color: var(--text-muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.mobile-back-btn { display: none; }

/* ---------- Editor layout ---------- */
.editor-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-new-btn {
  margin: 10px;
  padding: 7px;
  border: 1px dashed var(--border-light);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  max-width: none;
  width: auto;
  transition: all 0.12s;
}
.sidebar-new-btn:hover {
  background: var(--panel);
  color: var(--text);
  border-color: var(--text-dim);
}
.sidebar-count {
  margin: 0 10px 6px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}
.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 5px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.08s;
  min-height: 34px;
}
.sidebar-item:hover { background: rgba(255,255,255,0.03); }
.sidebar-item.active { background: rgba(31,111,235,0.1); border-color: rgba(31,111,235,0.25); }
.sidebar-item-title {
  flex: 1;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  color: var(--text);
  line-height: 1.3;
}
.sidebar-item-date {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}

/* ---------- Editor ---------- */
.editor-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-editor);
}
.editor-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  gap: 4px;
  font-size: 13px;
  user-select: none;
}
.editor-empty-hint { font-size: 12px; color: var(--text-dim); }
.editor-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.editor-title {
  max-width: none;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  font-size: 20px;
  font-weight: 600;
  padding: 14px 20px;
  color: var(--text);
  flex-shrink: 0;
  letter-spacing: -0.3px;
}
.editor-title::placeholder { color: var(--text-dim); }
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-sidebar);
}
.save-status {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-dim);
  user-select: none;
}
.save-status.saving { color: var(--primary); }
.editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  font-size: 15px;
  line-height: 1.75;
  outline: none;
  color: var(--text);
  word-wrap: break-word;
  max-width: 780px;
}
.editor-body:empty::before {
  content: 'Start writing...';
  color: var(--text-dim);
  pointer-events: none;
}
.editor-body img {
  max-width: 100%;
  border-radius: 4px;
  cursor: pointer;
  margin: 10px 0;
  display: block;
  border: 1px solid var(--border);
}
.editor-body video {
  max-width: 100%;
  max-height: 400px;
  border-radius: 4px;
  cursor: pointer;
  margin: 10px 0;
  display: block;
  border: 1px solid var(--border);
}
.editor-body audio {
  display: block;
  margin: 8px 0;
  width: 100%;
  max-width: 500px;
}
.editor-body h1 { font-size: 1.6rem; font-weight: 600; margin: 20px 0 8px; letter-spacing: -0.5px; }
.editor-body h2 { font-size: 1.3rem; font-weight: 600; margin: 16px 0 6px; }
.editor-body h3 { font-size: 1.1rem; font-weight: 600; margin: 14px 0 4px; }
.editor-body p { margin: 0 0 10px; }
.editor-body ul, .editor-body ol { padding-left: 22px; margin: 8px 0; }
.editor-body li { margin: 3px 0; }
.editor-body pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.5;
  margin: 10px 0;
}
.editor-body code {
  font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
  font-size: 13px;
  background: var(--panel);
  padding: 2px 6px;
  border-radius: 4px;
}
.editor-body blockquote {
  border-left: 3px solid #1f6feb;
  padding-left: 14px;
  color: var(--text-muted);
  margin: 10px 0;
}
.editor-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}
.editor-body a { color: var(--primary); }

/* ---------- Media Viewer ---------- */
.media-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  cursor: zoom-out;
}
.media-close {
  position: fixed;
  top: 14px;
  right: 18px;
  font-size: 28px;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  width: auto;
  max-width: none;
  padding: 4px 8px;
  line-height: 1;
  opacity: 0.6;
  z-index: 101;
}
.media-close:hover { opacity: 1; }
.media-preview {
  max-width: 94vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 6px;
  cursor: default;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ---------- Mobile ---------- */
@media (max-width: 680px) {
  .app { padding: 28px 18px; }
  .landing-auth, .auth-form { max-width: 320px; }
  button, input[type="email"], input[type="password"], input[type="text"], input[type="file"], textarea {
    max-width: 320px;
  }

  /* iOS Safari auto-zooms the whole page on focusing any form field under
     16px -- jarring on every login/note-title tap. 16px is the threshold
     that suppresses it. */
  input[type="email"], input[type="password"], input[type="text"], textarea, .editor-title {
    font-size: 16px;
  }

  /* Sidebar and editor become a master-detail pair instead of two side-by-side
     panes -- a 230px fixed sidebar next to the editor would leave almost no
     room for actual note content on a phone-width screen. JS toggles
     .note-open on .app-dashboard whenever a note is selected/deselected. */
  .sidebar { width: 100%; min-width: 0; border-right: none; }
  .editor-main { display: none; }
  .app-dashboard.note-open .sidebar { display: none; }
  .app-dashboard.note-open .editor-main { display: flex; }

  .mobile-back-btn { display: inline-flex; }

  .editor-title { padding: 12px 16px; font-size: 18px; }
  .editor-toolbar { padding: 6px 16px; }
  .editor-body { padding: 16px 18px; }

  /* Bumps compact desktop tap targets up toward the ~44px touch-target
     guideline without changing their look on desktop. */
  button.small { padding: 9px 13px; }
}
