:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #f7f7f7;
  --panel-strong: #efefef;
  --ink: #242424;
  --muted: #777777;
  --quiet: #9a9a9a;
  --line: #dedede;
  --blue: #336dff;
  --blue-dark: #2453c9;
  --danger: #a63b3b;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.16);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

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

button,
input,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.login-view,
.app-shell {
  min-height: 100dvh;
}

.login-view {
  align-items: center;
  background: #f4f5f7;
  display: none;
  justify-content: center;
  overflow: hidden;
  padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  width: 100vw;
}

.login-panel {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(30, 41, 59, 0.08);
  max-width: 360px;
  overflow: hidden;
  padding: 34px;
  width: calc(100vw - 80px);
}

.login-mark {
  align-items: center;
  background: var(--blue);
  border-radius: 8px;
  color: #ffffff;
  display: flex;
  font-size: 22px;
  font-weight: 700;
  height: 44px;
  justify-content: center;
  margin-bottom: 22px;
  width: 44px;
}

.login-kicker {
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  margin: 0 0 8px;
}

.login-panel h1 {
  color: var(--ink);
  font-size: 28px;
  letter-spacing: 0;
  line-height: 1.15;
  margin: 0 0 12px;
}

.login-copy,
.login-note {
  color: #5f6670;
  font-size: 15px;
  line-height: 1.55;
  margin: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.login-button {
  align-items: center;
  background: var(--blue);
  border-radius: 8px;
  color: #ffffff;
  display: flex;
  font-size: 15px;
  font-weight: 700;
  justify-content: center;
  margin: 24px 0 14px;
  min-height: 46px;
  padding: 0 18px;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  white-space: normal;
  width: 100%;
}

.login-button:focus-visible,
.login-button:hover {
  background: var(--blue-dark);
  outline: none;
}

.login-button:disabled {
  cursor: progress;
  opacity: 0.72;
}

.login-note {
  font-size: 13px;
}

.app-shell {
  display: none;
  grid-template-columns: 320px minmax(0, 1fr);
  width: 100vw;
}

body.authenticated .app-shell {
  display: grid;
}

body.auth-loading .login-view,
body.needs-login .login-view {
  display: flex;
}

body.auth-loading .app-shell,
body.needs-login .app-shell {
  display: none;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100dvh;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

.sidebar-header {
  border-bottom: 1px solid var(--line);
  padding: max(14px, env(safe-area-inset-top)) 12px 12px;
}

.brand-row {
  align-items: center;
  display: flex;
  justify-content: space-between;
  min-height: 34px;
}

.brand-row strong {
  font-size: 17px;
  letter-spacing: 0;
}

.search-row {
  align-items: center;
  background: var(--panel-strong);
  border: 1px solid transparent;
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: 18px minmax(0, 1fr);
  margin-top: 12px;
  padding: 0 10px;
}

.search-row:focus-within {
  background: #ffffff;
  border-color: #c9d6ff;
}

.search-row svg,
.new-note-button svg,
.icon-button svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.search-row svg {
  color: var(--quiet);
  height: 17px;
  width: 17px;
}

#searchInput {
  background: transparent;
  border: 0;
  color: var(--ink);
  font-size: 14px;
  min-height: 38px;
  min-width: 0;
  outline: none;
  padding: 0;
}

input::placeholder,
textarea::placeholder {
  color: #aaa;
}

.note-list {
  min-height: 0;
  overflow: auto;
}

.note-item {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 4px;
  min-height: 78px;
  padding: 12px 14px;
  text-align: left;
  width: 100%;
}

.note-item:hover,
.note-item:focus-visible {
  background: #ffffff;
  outline: none;
}

.note-item.active {
  background: #ffffff;
  box-shadow: inset 3px 0 0 var(--blue);
}

.note-title,
.note-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-title {
  font-size: 15px;
  font-weight: 700;
}

.note-preview {
  color: var(--muted);
  font-size: 13px;
}

.note-date {
  color: var(--quiet);
  font-size: 12px;
}

.empty-list {
  color: var(--muted);
  font-size: 14px;
  margin: 24px 14px;
}

.sidebar-footer {
  border-top: 1px solid var(--line);
  padding: 12px;
}

.new-note-button {
  align-items: center;
  background: var(--blue);
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  font-weight: 700;
  gap: 8px;
  justify-content: center;
  min-height: 42px;
  width: 100%;
}

.new-note-button:hover,
.new-note-button:focus-visible {
  background: var(--blue-dark);
  outline: none;
}

.new-note-button svg {
  height: 19px;
  width: 19px;
}

.account-row {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 12px;
  gap: 10px;
  justify-content: space-between;
  margin-top: 11px;
  min-width: 0;
}

#userBadge {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#logoutButton {
  background: transparent;
  border: 0;
  color: var(--danger);
  cursor: pointer;
  flex: 0 0 auto;
  font-size: 12px;
  padding: 4px 0;
}

.editor-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100dvh;
  min-width: 0;
}

.editor-toolbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 8px;
  grid-template-columns: 44px minmax(0, 1fr) auto 44px 44px;
  min-height: 58px;
  padding: max(7px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 7px 10px;
}

.icon-button {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: #555;
  cursor: pointer;
  display: inline-flex;
  height: 40px;
  justify-content: center;
  width: 40px;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

.icon-button svg {
  height: 21px;
  width: 21px;
}

.mobile-only {
  display: none;
}

.title-input {
  background: transparent;
  border: 0;
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  min-width: 0;
  outline: none;
  padding: 10px 0;
}

.toolbar-meta {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 12px;
  gap: 10px;
  white-space: nowrap;
}

.status {
  color: var(--blue);
}

.editor-surface {
  min-height: 0;
  overflow: hidden;
}

#editor {
  background: #ffffff;
  border: 0;
  color: var(--ink);
  font-size: 18px;
  height: 100%;
  line-height: 1.62;
  outline: none;
  padding: 34px clamp(22px, 8vw, 120px) 34vh;
  resize: none;
  width: 100%;
}

.editor-footer {
  align-items: center;
  border-top: 1px solid var(--line);
  color: var(--muted);
  display: flex;
  font-size: 12px;
  gap: 14px;
  justify-content: space-between;
  min-height: 36px;
  padding: 0 max(14px, env(safe-area-inset-right)) max(0px, env(safe-area-inset-bottom)) 14px;
}

#savedAt,
#updatedAt {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.focused .sidebar,
body.focused #libraryToggle,
body.focused .toolbar-meta,
body.focused #syncNow {
  display: none;
}

body.focused .app-shell {
  grid-template-columns: minmax(0, 1fr);
}

body.focused .editor-toolbar {
  grid-template-columns: minmax(0, 1fr) 44px;
}

body.focused #focusToggle {
  grid-column: 2;
}

@media (max-width: 780px) {
  .app-shell,
  body.authenticated .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    box-shadow: var(--shadow);
    height: 100dvh;
    left: 0;
    max-width: min(88vw, 360px);
    position: fixed;
    top: 0;
    transform: translateX(-104%);
    transition: transform 160ms ease;
    width: 100%;
    z-index: 5;
  }

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

  .mobile-only {
    display: inline-flex;
  }

  .editor-toolbar {
    grid-template-columns: 44px minmax(0, 1fr) 44px 44px;
    min-height: 56px;
  }

  .toolbar-meta {
    display: none;
  }

  #editor {
    font-size: 18px;
    line-height: 1.6;
    padding: 22px clamp(18px, 5vw, 30px) 32vh;
  }

  .editor-footer {
    min-height: 34px;
  }

  #updatedAt {
    display: none;
  }

  .login-panel {
    padding: 28px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #161616;
    --panel: #202020;
    --panel-strong: #2a2a2a;
    --ink: #eeeeee;
    --muted: #a7a7a7;
    --quiet: #7e7e7e;
    --line: #333333;
    --blue: #7da2ff;
    --blue-dark: #9bb8ff;
    --danger: #ff9b9b;
    --shadow: 0 18px 60px rgba(0, 0, 0, 0.36);
  }

  .login-view {
    background: #151515;
  }

  .login-panel,
  .note-item:hover,
  .note-item:focus-visible,
  .note-item.active,
  #editor {
    background: #191919;
  }

  .login-panel {
    border-color: var(--line);
  }

  .login-copy,
  .login-note {
    color: var(--muted);
  }

  .search-row:focus-within {
    background: #191919;
    border-color: #3d5caa;
  }
}
