*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border-radius: 0;
  transition: none;
  animation: none;
}

html, body {
  height: 100%;
  background: #111111;
  color: #fff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.screen {
  display: none;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}
.screen.active { display: flex; }

/* ── Setup & Unlock screens ─────────────────────────────────────────────── */

#screen-setup,
#screen-unlock {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  background: #111111;
}

#screen-setup {
  justify-content: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-top: 40px;
  padding-bottom: 40px;
}

#screen-setup h1,
#screen-unlock h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 40px;
}

.form-copy {
  width: 100%;
  max-width: 360px;
  margin-bottom: 20px;
  color: #888888;
  line-height: 1.4;
}

#screen-setup form,
#screen-unlock form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 360px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 18px;
  font-weight: 500;
}

input[type="password"],
input[type="text"],
input[type="search"] {
  background: #1a1a1a;
  color: #f5f5f5;
  border: 1px solid #333333;
  font-family: inherit;
  font-size: 18px;
  padding: 10px 12px;
  outline: none;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  -webkit-text-fill-color: #f5f5f5;
}

input[type="password"]:focus,
input[type="text"]:focus,
input[type="search"]:focus {
  border-width: 2px;
  padding: 9px 11px;
}

input:-webkit-autofill,
input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 200px #1a1a1a inset;
  -webkit-text-fill-color: #f5f5f5;
  caret-color: #f5f5f5;
}

input::placeholder { color: #888888; }
input::-webkit-search-cancel-button { display: none; }

.btn-primary {
  background: #e0e0e0;
  color: #111111;
  border: none;
  font-family: inherit;
  font-size: 18px;
  font-weight: 600;
  padding: 12px 24px;
  cursor: pointer;
  width: 100%;
  margin-top: 4px;
}
.btn-primary:active { background: #e0e0e0; }
.btn-primary:disabled {
  background: #333333;
  color: #f5f5f5;
  cursor: default;
}

.form-error {
  color: #d17373;
  font-size: 18px;
  min-height: 22px;
}

.btn-link {
  background: none;
  border: none;
  color: #888888;
  font-family: inherit;
  font-size: 15px;
  padding: 4px;
  cursor: pointer;
  text-decoration: underline;
}
.btn-link:hover { color: #f5f5f5; }

/* ── App shell ───────────────────────────────────────────────────────────── */

#screen-app {
  flex-direction: column;
  overflow: hidden;
}

#app-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #111111;
  padding-bottom: calc(60px + env(safe-area-inset-bottom));
}

#top-bar {
  flex-shrink: 0;
  padding: 12px 16px;
  border-bottom: none;
  background: #111111;
  color: #f5f5f5;
}

#top-bar.page-mode {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 10px;
}

#top-bar.search-mode {
  display: block;
}

.topbar-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

#left-rail {
  display: none;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-count {
  white-space: nowrap;
}

#search-input {
  width: 100%;
  background: transparent;
  color: #f5f5f5;
  border: none;
  font-family: inherit;
  font-size: 18px;
  padding: 4px 0;
  outline: none;
}

#content-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #111111;
  color: #f5f5f5;
  padding-bottom: calc(20px + 60px + env(safe-area-inset-bottom));
}

#pages-list:empty::before {
  content: 'No pages yet';
  display: block;
  padding: 20px 16px;
  color: #888888;
}

#pages-list {
  width: 100%;
}

.page-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: transparent;
  color: #f5f5f5;
  border: none;
  border-bottom: 1px solid #333333;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.page-row:hover {
  background: #1a1a1a;
}

.page-row:focus-visible {
  outline: 1px solid #888888;
  outline-offset: -1px;
}

.page-row.selected {
  background: #1a1a1a;
}

.page-row.renaming,
.page-row.renaming:hover {
  background: #1a1a1a;
}

.page-dot-hitbox {
  width: 40px;
  min-width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-dot {
  width: 12px;
  height: 12px;
  border: 1px solid #333333;
}

.page-main {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  flex: 1 1 auto;
}

.page-expand-toggle {
  min-width: 28px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: #f5f5f5;
  font: inherit;
  line-height: 1;
  padding: 2px;
  margin: -2px;
  cursor: pointer;
  flex: 0 0 auto;
  font-size: 23px;
}

.page-title {
  min-width: 0;
  display: block;
  flex: 0 1 auto;
  font-size: 32px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-count,
.page-subpage,
.page-meta {
  white-space: nowrap;
}

.page-meta {
  justify-self: end;
  color: #888888;
  font-weight: 500;
  cursor: text;
}

.page-row[data-subpage="1"] .page-meta {
  cursor: default;
}

.page-row[data-level="1"] {
  padding-left: 20px;
}

.page-count[hidden],
.page-subpage[hidden] {
  display: none;
}

.page-header-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.page-header-title {
  min-width: 0;
  font-size: 28px;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: text;
}

.page-header-title-row {
  min-width: 0;
  display: inline-flex;
  align-items: baseline;
  gap: 0;
}

.page-header-parent-link {
  background: transparent;
  color: #f5f5f5;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 28px;
  line-height: 1.1;
  cursor: pointer;
}

.page-header-title-separator {
  color: #f5f5f5;
  font-size: 28px;
  line-height: 1.1;
  white-space: pre;
}

.page-header-main .page-title-input {
  font-size: 28px;
  line-height: 1.1;
}

.page-header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: nowrap;
  font-size: 18px;
  line-height: 1.2;
  color: #ffffff;
}

.page-back-button {
  width: 36px;
  min-width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #f5f5f5;
  border: 1px solid #333333;
  border-radius: 10px;
  padding: 0;
  cursor: pointer;
}

.page-title-input {
  width: 100%;
  min-width: 0;
  background: #1a1a1a;
  color: #f5f5f5;
  border: 1px solid #333333;
  font: inherit;
  padding: 4px 8px;
}

.page-title-input.list-inline {
  max-width: 100%;
  background: transparent;
  color: inherit;
  border: none;
  padding: 0;
  margin: 0;
  outline: none;
  text-align: left;
  line-height: 1.2;
}

.page-header-date {
  white-space: nowrap;
  cursor: text;
  font-size: 18px;
}

.page-header-date[role="button"],
.page-header-reminder {
  background: transparent;
  color: #ffffff;
  border: none;
  font-size: 18px;
  line-height: 1.2;
  padding: 0;
  cursor: pointer;
  white-space: nowrap;
}

.page-header-separator,
.page-header-stats {
  white-space: nowrap;
  font-size: 18px;
  color: #ffffff;
}

.page-date-input {
  min-width: 118px;
  background: #1a1a1a;
  color: #f5f5f5;
  border: 1px solid #333333;
  font: inherit;
  padding: 4px 8px;
}

.page-body {
  min-height: 100%;
  width: 100%;
  max-width: 920px;
  padding: 20px 16px;
  color: #f5f5f5;
}

.block-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.page-top-drop-zone {
  min-height: 14px;
  margin-bottom: 4px;
}

.page-top-drop-zone.active {
  box-shadow: inset 0 2px 0 #ffffff;
}

.block-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
  position: relative;
}

.block-row.selected:not(.editing) {
  background: #366cbb;
  color: #ffffff;
}

.block-row.text-selected {
  background: rgba(54, 108, 187, 0.35);
}

.block-row.text-selected .block-editor::selection {
  background: rgba(54, 108, 187, 0.65);
}

.block-drag-handle {
  width: 32px;
  min-width: 32px;
  /* Equal to the editor's first-line box (line-height: 1.4), so the handle
     centers on the first text line for text, numbered, toggle and multiline
     blocks without per-type offsets. */
  height: 1.4em;
  min-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: #f5f5f5;
  font: inherit;
  line-height: 1;
  padding: 0;
}

.block-row[data-draggable="1"] .block-drag-handle {
  cursor: grab;
}

.block-row.dragging .block-drag-handle {
  cursor: grabbing;
}

.block-row.drop-before {
  box-shadow: inset 0 2px 0 #ffffff;
}

.block-row.drop-after {
  box-shadow: inset 0 -2px 0 #ffffff;
}

.block-row.editing .block-editor {
  border-bottom: 1px solid #333333;
}

.block-children {
  padding-left: 20px;
}

.toggle-button,
.block-spacer {
  width: 24px;
  min-width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.toggle-button {
  background: none;
  border: none;
  color: #f5f5f5;
  cursor: pointer;
  padding: 0;
}

.toggle-button.empty {
  color: #888888;
}

.toggle-label.empty .block-editor {
  color: #888888;
}

.block-index,
.toggle-count {
  white-space: nowrap;
}

.toggle-label {
  display: inline-flex;
  align-items: flex-start;
  gap: 0;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
}

.toggle-label .block-editor,
.toggle-label .block-search-text {
  flex: 0 1 auto;
  min-width: 0;
  width: auto;
  max-width: 100%;
  field-sizing: content;
}

.toggle-count {
  margin-left: 0.3ch;
  margin-top: 1px;
  flex: 0 0 auto;
}

.block-menu {
  width: 100%;
  margin-left: 32px;
  border: 1px solid #333333;
  background: #1a1a1a;
}

.block-menu-item {
  display: block;
  width: 100%;
  padding: 6px 8px;
  background: #1a1a1a;
  color: #f5f5f5;
  border: none;
  text-align: left;
  font: inherit;
}

.block-menu-item.active {
  background: #222222;
  color: #f5f5f5;
}

.block-editor {
  flex: 1;
  min-height: 24px;
  background: transparent;
  color: #f5f5f5;
  caret-color: #f5f5f5;
  border: none;
  font: inherit;
  line-height: 1.4;
  padding: 0;
  resize: none;
  overflow: hidden;
  outline: none;
  white-space: pre-wrap;
}

/* Explicit insertion-point marker for logical cross-block selections: WebKit
   hides the native caret while a selection exists. Blinks like a real caret. */
.text-caret-marker {
  position: fixed;
  width: 2px;
  background: #f5f5f5;
  pointer-events: none;
  z-index: 2147483000;
  animation: command-caret-blink 1.05s steps(1) infinite;
}

@keyframes command-caret-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.orphan-child-pages {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.orphan-child-pages-label {
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #888888;
}

.orphan-child-page {
  text-align: left;
  background: #1c1c1c;
  color: #f5f5f5;
  border: 1px solid #333333;
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  cursor: pointer;
}

.orphan-child-page:hover {
  background: #242424;
}

.page-title-default {
  color: #ffffff;
}

.rail-label-default {
  color: #ffffff;
}

.block-row[data-block-type="page_ref"] {
  cursor: pointer;
}

.block-row[data-block-type="page_ref"] .block-editor {
  min-height: 28px;
  padding: 3px 8px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.04);
  cursor: inherit;
}

.block-row[data-block-type="page_ref"]:hover .block-editor {
  background: rgba(255, 255, 255, 0.06);
}

.block-page-icon {
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
  color: rgba(245, 245, 245, 0.72);
  margin-right: 6px;
  margin-top: 6px;
  user-select: none;
}

.block-search-text {
  flex: 1;
  min-height: 24px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.search-mark {
  background: #366cbb;
  color: #ffffff;
}

.search-mark.active {
  background: #366cbb;
  color: #ffffff;
}

.block-actions-menu {
  position: fixed;
  z-index: 1080;
  min-width: 220px;
  border: 1px solid #333333;
  background: #1a1a1a;
}

.block-actions-list {
  display: flex;
  flex-direction: column;
}

.block-actions-item,
.move-page-item {
  width: 100%;
  padding: 8px 10px;
  background: #1a1a1a;
  color: #f5f5f5;
  border: none;
  text-align: left;
  font: inherit;
}

.page-actions-menu .block-actions-item,
.page-actions-menu .move-page-item {
  padding: 10px 14px;
  font-size: 28px;
  line-height: 1.05;
  color: #ffffff;
  background: #000000;
}

.page-actions-menu .block-actions-search {
  padding: 10px 14px;
  font-size: 28px;
  color: #ffffff;
  background: #000000;
  border: none;
  border-bottom: 2px solid #ffffff;
}

.page-actions-menu .block-actions-search::placeholder {
  color: #ffffff;
}

.page-actions-menu .block-actions-search:focus {
  padding: 10px 14px;
  border: none;
  border-bottom: 2px solid #ffffff;
}

.block-actions-item + .block-actions-item,
.move-page-item + .move-page-item {
  border-top: 1px solid #333333;
}

.block-actions-search {
  padding: 8px 10px;
  border-bottom: 1px solid #333333;
}

.page-actions-menu {
  min-width: 240px;
  border: 2px solid #ffffff;
  background: #000000;
}

.mobile-page-action-sheet,
.mobile-page-action-sheet .block-actions-item {
  -webkit-user-select: none;
  user-select: none;
}

.page-color-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.page-color-option {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.page-color-swatch {
  width: 80px;
  height: 80px;
  border: none;
  border-radius: 999px;
}

.view-toggle {
  display: inline-flex;
  gap: 8px;
}

.view-toggle button {
  background: #1a1a1a;
  color: #888888;
  border: 1px solid #333333;
  padding: 6px 10px;
  font: inherit;
}

.view-toggle button.active {
  background: #222222;
  color: #f5f5f5;
  border-color: #333333;
}

.calendar-shell {
  padding: 16px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px 4px;
}

.calendar-header-group {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.calendar-nav-button,
.calendar-today-button,
.calendar-entry,
.calendar-day-add {
  background: transparent;
  border: none;
  color: #ffffff;
  font: inherit;
}

.calendar-nav-button,
.calendar-today-button {
  cursor: pointer;
}

.calendar-nav-button {
  padding: 0;
  line-height: 1;
}

.calendar-header-label {
  font-size: 28px;
  line-height: 1.1;
  color: #ffffff;
  text-align: center;
}

.calendar-today-button {
  padding: 0 0 0 8px;
}

.calendar-grid,
.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  background: #ffffff;
}

.calendar-weekdays span,
.calendar-day {
  background: #000000;
  color: #ffffff;
}

.calendar-weekdays span {
  padding: 8px;
  text-align: center;
  color: #ffffff;
  user-select: none;
}

.calendar-day {
  background: #1a1a1a;
  height: 90px;
  border: none;
  padding: 6px;
  text-align: left;
  font: inherit;
  position: relative;
  overflow: hidden;
}

.calendar-day-number {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 14px;
  line-height: 1;
  color: #ffffff;
  user-select: none;
}

.calendar-day.today .calendar-day-number {
  min-width: 22px;
  min-height: 22px;
  padding: 4px;
  border-radius: 999px;
  background: #ff3b30;
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.calendar-day-entries {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
}

.calendar-entry {
  width: auto;
  max-width: 100%;
  padding: 3px 10px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: grab;
  user-select: none;
  border: 1px solid #e0e0e0;
  background: #e0e0e0;
  color: #000000;
  border-radius: 999px;
}

.calendar-entry-more {
  color: #888888;
  cursor: pointer;
}

.calendar-entry.dragging {
  cursor: grabbing;
}

.calendar-touch-ghost {
  position: fixed;
  z-index: 1200;
  pointer-events: none;
  opacity: 0.9;
  transform: translate(-50%, -50%);
  max-width: 200px;
}

.calendar-day.drag-target {
  outline: 1px solid #ffffff;
  outline-offset: -1px;
}

.calendar-day-add {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 0;
  line-height: 1;
  cursor: pointer;
  visibility: hidden;
}

.calendar-day:hover .calendar-day-add,
.calendar-day:focus-within .calendar-day-add {
  visibility: visible;
}

/* Touch has no hover: the add control and empty-day tap must stay reachable. */
@media (hover: none), (pointer: coarse) {
  .calendar-day-add {
    visibility: visible;
  }

  .calendar-day-empty {
    cursor: pointer;
  }
}

.calendar-picker {
  position: fixed;
  z-index: 1140;
  width: 308px;
  background: #000000;
  border: 2px solid #ffffff;
  padding: 12px;
}

.calendar-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.calendar-picker-label {
  color: #ffffff;
  font-size: 18px;
  text-align: center;
  flex: 1;
}

.calendar-picker-nav {
  background: transparent;
  color: #ffffff;
  border: none;
  font-size: 18px;
  cursor: pointer;
}

.calendar-picker-weekdays,
.calendar-picker-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.calendar-picker-weekdays {
  margin-bottom: 6px;
}

.calendar-picker-weekdays span {
  color: #888888;
  font-size: 16px;
  text-align: center;
}

.calendar-picker-day {
  min-height: 36px;
  background: #1a1a1a;
  color: #ffffff;
  border: 1px solid #333333;
  font: inherit;
  cursor: pointer;
}

.calendar-picker-day.muted {
  color: #888888;
}

.calendar-picker-day.today {
  border-color: #ff3b30;
}

.calendar-picker-day.selected {
  background: #ff3b30;
  border-color: #ff3b30;
  color: #ffffff;
}

.agenda-panel {
  border-top: 1px solid #333333;
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.agenda-item {
  width: 100%;
  background: #1a1a1a;
  color: #f5f5f5;
  border: 1px solid #333333;
  padding: 10px 12px;
  text-align: left;
  font: inherit;
}

.utility-shell {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.utility-shell.rail-utility {
  flex: 0 0 auto;
}

.sync-status-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 0 10px 0 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  flex: 0 0 auto;
  pointer-events: none;
  cursor: default;
  opacity: 0.92;
  color: #d7d3cb;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.sync-status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
  flex: 0 0 auto;
}

.sync-status-label {
  display: inline-block;
}

.sync-status-dot.idle {
  color: #888888;
  opacity: 0.45;
}

.sync-status-dot.synced {
  color: #6fbf8f;
  opacity: 0.8;
  border-color: rgba(111, 191, 143, 0.2);
}

.sync-status-dot.pending {
  color: #d5b46a;
  opacity: 0.95;
  border-color: rgba(213, 180, 106, 0.2);
}

.sync-status-dot.syncing {
  color: #d5b46a;
  opacity: 0.95;
  animation: sync-dot-pulse 1.2s ease-in-out infinite;
}

.sync-status-dot.failed {
  color: #ff6b5e;
  opacity: 1;
  border-color: rgba(255, 107, 94, 0.24);
}

@keyframes sync-dot-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

.utility-button {
  background: transparent;
  color: #ffffff;
  border: none;
  padding: 4px 6px;
  font: inherit;
  line-height: 1;
  cursor: pointer;
}

.utility-button.icon-only {
  width: 28px;
  min-width: 28px;
  padding: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.utility-menu {
  position: fixed;
  min-width: 168px;
  max-width: 200px;
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 2px solid #ffffff;
  background: #000000;
  z-index: 1100;
}

.utility-menu button {
  width: 100%;
  background: #000000;
  color: #ffffff;
  border: none;
  border-bottom: 1px solid #333333;
  padding: 8px 10px;
  text-align: left;
  font-size: 18px;
}

.utility-menu button:last-child {
  border-bottom: none;
}

.utility-menu-label {
  padding: 8px 10px 4px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #888888;
  border-bottom: 1px solid #333333;
}

.utility-menu-label-danger {
  color: #d17373;
}

.utility-menu button.utility-menu-danger {
  color: #d17373;
}

.utility-menu button.utility-menu-build {
  color: #888888;
  font-size: 13px;
  cursor: default;
}

html[data-theme="light"] .utility-menu,
html[data-theme="light"] .utility-menu button {
  background: #ebebeb;
  color: #111111;
}

html[data-theme="light"] .utility-menu {
  border-color: #bbbbbb;
}

html[data-theme="light"] .utility-menu-label {
  color: #666666;
}

html[data-theme="light"] .utility-menu button.utility-menu-danger {
  color: #b03030;
}

.hidden {
  display: none;
}

.page-footer {
  width: 100%;
  text-align: left;
}

.search-results {
  display: flex;
  flex-direction: column;
}

.search-result {
  width: 100%;
  background: #111111;
  color: #f5f5f5;
  border: none;
  border-bottom: 1px solid #333333;
  text-align: left;
  padding: 14px 16px;
  font: inherit;
}

.search-result-page,
.search-result-snippet {
  display: block;
}

#bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(60px + env(safe-area-inset-bottom));
  padding: 0 10px env(safe-area-inset-bottom);
  display: flex;
  align-items: center;
  justify-content: space-around;
  flex-shrink: 0;
  background: #111111;
  border-top: 1px solid #333333;
  color: #888888;
  z-index: 1000;
}

#bottom-bar button {
  background: none;
  border: none;
  color: #888888;
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  line-height: 1;
}

.mobile-bottom-nav {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.mobile-root-tabs {
  flex: 1 1 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.mobile-root-tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #888888;
  font: inherit;
  font-size: 22px;
  line-height: 1;
  text-align: center;
  padding: 0 10px;
}

.mobile-root-tab.active {
  background: #1d1d1d;
  color: #f5f5f5;
}

.mobile-new-page {
  flex: 0 0 auto;
  width: 44px;
  min-width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #f5f5f5;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.utility-shell .mobile-new-page {
  order: 3;
}

.mobile-block-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: stretch;
  z-index: 1160;
}

.mobile-block-sheet {
  width: 100%;
  max-height: 70dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: env(safe-area-inset-bottom);
  background: #111111;
  border-top: 1px solid #333333;
  animation: mobile-block-sheet-slide-up 160ms ease-out;
}

.mobile-block-sheet-action {
  width: 100%;
  min-height: 48px;
  background: transparent;
  color: #ffffff;
  border: none;
  border-top: 1px solid #333333;
  text-align: left;
  font: inherit;
  font-size: 18px;
  padding: 0 16px;
}

@keyframes mobile-block-sheet-slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.left-rail-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.left-rail-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.left-rail-group.top-actions {
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  padding-bottom: 2px;
}

.left-rail-group.bottom-actions {
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px;
}

.left-rail-group.favorite-pages {
  margin-top: 18px;
}

.left-rail-spacer {
  flex: 1;
}

.rail-button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  color: #ffffff;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.rail-button.icon-only {
  width: 40px;
  min-width: 40px;
  justify-content: center;
  gap: 0;
  padding: 10px;
}

.rail-button.active {
  background: #2a2a2a;
  color: #ffffff;
  border-color: #3a3a3a;
}

.rail-button[disabled] {
  color: #888888;
  cursor: default;
}

.rail-button:not([disabled]):hover {
  background: #1a1a1a;
}

.rail-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.rail-label {
  min-width: 0;
  font-size: 28px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rail-page-button {
  padding-left: 12px;
  justify-content: flex-start;
}

.rail-page-main {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.rail-expand-toggle {
  min-width: 28px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  line-height: 1;
  padding: 2px;
  margin: -2px;
  cursor: pointer;
  flex: 0 0 auto;
  font-size: 23px;
  color: rgba(245, 245, 245, 0.92);
}

.rail-page-button[data-favorite-root="1"] {
  cursor: grab;
}

.rail-page-button .rail-label {
  font-size: 22px;
  line-height: 1.2;
}

.rail-page-button[data-level="1"] {
  padding-left: 16px;
}

.rail-page-button[data-favorite-root="1"].dragging {
  cursor: grabbing;
}

.rail-page-button.drop-before {
  box-shadow: inset 0 2px 0 #ffffff;
}

.rail-page-button.drop-after {
  box-shadow: inset 0 -2px 0 #ffffff;
}

.rail-page-button.active .rail-label {
  color: #ffffff !important;
}

.block-editor[data-block-kind="page-ref"] {
  text-align: left;
  cursor: pointer;
}

.help-overlay {
  position: fixed;
  inset: 0;
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1120;
}

.help-modal {
  width: min(860px, 90vw);
  background: #1a1a1a;
  border: 1px solid #333333;
  border-radius: 14px;
  padding: 40px 48px 32px;
}

.help-modal h2 {
  margin: 0;
  font-size: 28px;
  font-weight: 400;
  margin-bottom: 18px;
  line-height: 1.2;
  text-align: center;
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1130;
}

.confirm-modal {
  width: min(420px, 100%);
  background: #1a1a1a;
  border: 1px solid #333333;
  border-radius: 14px;
  padding: 22px 24px 18px;
}

.confirm-modal h2 {
  margin: 0 0 10px;
  font-size: 28px;
  font-weight: 400;
  line-height: 1.2;
}

.confirm-copy {
  font-size: 18px;
  line-height: 1.35;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.confirm-button {
  background: #1a1a1a;
  color: #ffffff;
  border: 1px solid #333333;
  font: inherit;
  font-size: 18px;
  padding: 10px 14px;
  cursor: pointer;
}

.confirm-button.danger {
  background: #d17373;
  color: #ffffff;
  border-color: transparent;
}

.delete-confirm-popup {
  position: fixed;
  z-index: 1135;
  min-width: 320px;
  background: #000000;
  border: 2px solid #ffffff;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  font-size: 28px;
}

.delete-confirm-label {
  color: #ffffff;
  font-size: 28px;
  line-height: 1.05;
  white-space: nowrap;
}

.delete-confirm-actions {
  display: flex;
  gap: 12px;
}

.delete-confirm-button {
  flex: 1 1 0;
  background: #000000;
  color: #ffffff;
  border: 2px solid #ffffff;
  font: inherit;
  font-size: 28px;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}

.delete-confirm-button.danger {
  background: #ff3b30;
  color: #ffffff;
  border-color: #ff3b30;
}

.page-reminder-popup {
  position: fixed;
  z-index: 1140;
  width: 320px;
  background: #000000;
  border: 2px solid #ffffff;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.page-reminder-title {
  color: #ffffff;
  font-size: 18px;
}

.page-reminder-date-button {
  background: #1a1a1a;
  color: #ffffff;
  border: 1px solid #333333;
  font: inherit;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
}

.page-reminder-time-input {
  width: 100%;
}

.page-reminder-error {
  min-height: 20px;
  color: #d17373;
  font-size: 16px;
}

.page-reminder-actions {
  display: flex;
  gap: 10px;
}

.page-reminder-button {
  flex: 1 1 0;
  background: #1a1a1a;
  color: #ffffff;
  border: 1px solid #333333;
  font: inherit;
  padding: 10px 12px;
  cursor: pointer;
}

.page-reminder-button.danger {
  background: #ff3b30;
  border-color: #ff3b30;
}

.reminder-due-overlay {
  position: fixed;
  inset: 0;
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1150;
}

.reminder-due-modal {
  width: min(420px, 100%);
  background: #1a1a1a;
  border: 1px solid #333333;
  padding: 22px 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.reminder-due-modal h2 {
  margin: 0;
  font-size: 28px;
  font-weight: 400;
  line-height: 1.2;
}

.reminder-due-copy {
  font-size: 18px;
  line-height: 1.35;
}

.reminder-due-actions {
  display: flex;
  gap: 10px;
}

.reminder-due-button {
  flex: 1 1 0;
  background: #1a1a1a;
  color: #ffffff;
  border: 1px solid #333333;
  font: inherit;
  padding: 10px 14px;
  cursor: pointer;
}

.reminder-due-button.danger {
  background: #ff3b30;
  border-color: #ff3b30;
}

.help-shortcut-group {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  column-gap: 16px;
  row-gap: 10px;
  margin-top: 18px;
}

.help-shortcut-group:first-of-type {
  margin-top: 0;
}

.help-shortcut-title {
  grid-column: 1 / -1;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: #f5f5f5;
  margin-bottom: 2px;
}

.help-shortcut-row {
  display: contents;
}

.help-shortcut-keys {
  color: #888888;
  white-space: nowrap;
  padding: 4px 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.35;
}

.help-shortcut-label {
  min-width: 0;
  text-align: left;
  padding: 4px 0;
  font-size: 18px;
  line-height: 1.35;
}

html[data-theme="light"] body,
html[data-theme="light"] #screen-setup,
html[data-theme="light"] #screen-unlock,
html[data-theme="light"] #app-main,
html[data-theme="light"] #top-bar,
html[data-theme="light"] #content-area,
html[data-theme="light"] #left-rail,
html[data-theme="light"] #bottom-bar,
html[data-theme="light"] .search-result {
  background: #f5f5f5;
  color: #111111;
}

html[data-theme="light"] input[type="password"],
html[data-theme="light"] input[type="text"],
html[data-theme="light"] input[type="search"],
html[data-theme="light"] .page-title-input,
html[data-theme="light"] .page-date-input,
html[data-theme="light"] .page-row:hover,
html[data-theme="light"] .page-row.selected,
html[data-theme="light"] .page-row.renaming,
html[data-theme="light"] .page-row.renaming:hover,
html[data-theme="light"] .block-menu,
html[data-theme="light"] .block-menu-item,
html[data-theme="light"] .block-menu-item.active,
html[data-theme="light"] .block-actions-menu,
html[data-theme="light"] .block-actions-item,
html[data-theme="light"] .move-page-item,
html[data-theme="light"] .view-toggle button,
html[data-theme="light"] .view-toggle button.active,
html[data-theme="light"] .calendar-day,
html[data-theme="light"] .calendar-picker-day,
html[data-theme="light"] .agenda-item,
html[data-theme="light"] .help-modal,
html[data-theme="light"] .confirm-modal,
html[data-theme="light"] .confirm-button,
html[data-theme="light"] .reminder-due-modal,
html[data-theme="light"] .reminder-due-button {
  background: #ebebeb;
  color: #111111;
  border-color: #cccccc;
}

html[data-theme="light"] .form-copy,
html[data-theme="light"] input::placeholder,
html[data-theme="light"] #pages-list:empty::before,
html[data-theme="light"] .page-meta,
html[data-theme="light"] #bottom-bar,
html[data-theme="light"] #bottom-bar button,
html[data-theme="light"] .mobile-root-tab,
html[data-theme="light"] .help-shortcut-keys {
  color: #666666;
}

@media (min-width: 980px) {
  #app-main {
    padding-bottom: 0;
  }

  #pages-list {
    width: min(860px, calc(100% - 6px));
    margin: 0 0 0 6px;
  }

  .page-row {
    color: #ffffff;
    gap: 16px;
    padding: 12px 0;
  }

  .page-title {
    color: #ffffff;
    font-size: 28px;
    line-height: 1.2;
  }

  .page-title-input.list-inline {
    color: #ffffff;
    font-size: 28px;
    font-weight: inherit;
  }

  .page-main {
    gap: 10px;
  }

  .page-meta {
    color: #ffffff;
    font-size: 18px;
    line-height: 1.25;
  }

  .help-modal {
    width: min(860px, 90vw);
  }

  .help-shortcut-group {
    grid-template-columns: 140px minmax(0, 1fr) 140px minmax(0, 1fr);
    column-gap: 22px;
    row-gap: 10px;
  }

  #screen-app {
    flex-direction: row;
  }

  #left-rail {
    display: block;
    width: 228px;
    flex-shrink: 0;
    border-right: 1px solid #333333;
    padding: 20px 14px 18px;
    overflow: hidden;
    background: #111111;
  }

  #top-bar {
    padding: 16px 28px;
  }

  #content-area {
    padding-left: 18px;
    padding-right: 18px;
    padding-bottom: 0;
  }

  #bottom-bar {
    position: static;
    justify-content: flex-start;
    height: auto;
    padding: 10px 20px;
    border-top: none;
    background: transparent;
  }

  #bottom-bar button {
    display: none;
  }

  .page-back-button {
    display: none;
  }

  .calendar-day {
    min-height: 108px;
    height: auto;
    padding: 28px 8px 8px;
    overflow: visible;
  }

  .calendar-day-number {
    top: 6px;
    right: 8px;
    white-space: nowrap;
  }

  .calendar-day-entries {
    gap: 3px;
  }

  .calendar-entry {
    padding: 2px 8px;
  }
}

/* ── Light theme: editor, rail, list text, caret ──────────────────────────── */
/* These win on specificity (html[data-theme] + class), so they are safe to
   append after the desktop media queries that hardcode dark colors. */
html[data-theme="light"] .block-editor,
html[data-theme="light"] .block-row,
html[data-theme="light"] .block-spacer,
html[data-theme="light"] .toggle-button,
html[data-theme="light"] .toggle-label,
html[data-theme="light"] .page-title,
html[data-theme="light"] .page-title-input.list-inline,
html[data-theme="light"] .page-meta,
html[data-theme="light"] .page-row,
html[data-theme="light"] .page-title-default,
html[data-theme="light"] .rail-button,
html[data-theme="light"] .rail-label,
html[data-theme="light"] .rail-label-default {
  color: #111111;
  caret-color: #111111;
}

html[data-theme="light"] .block-row.selected:not(.editing) {
  color: #ffffff;
}

html[data-theme="light"] .block-row[data-block-type="page_ref"] .block-editor {
  background: rgba(0, 0, 0, 0.05);
}

html[data-theme="light"] .rail-button:not(.active):not([disabled]):hover {
  background: #e2e2e2;
}

html[data-theme="light"] .rail-button.active,
html[data-theme="light"] .rail-button.active .rail-label {
  color: #ffffff !important;
}

html[data-theme="light"] .text-caret-marker {
  background: #111111;
}

html[data-theme="light"] .orphan-child-pages-label {
  color: #666666;
}

html[data-theme="light"] .orphan-child-page {
  background: #ebebeb;
  color: #111111;
  border-color: #cccccc;
}

html[data-theme="light"] input:-webkit-autofill,
html[data-theme="light"] input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 200px #ebebeb inset;
  -webkit-text-fill-color: #111111;
  caret-color: #111111;
}

/* ── Interaction foundation ─────────────────────────────────────────────── */

#content-area {
  overscroll-behavior: contain;
}

html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

button,
[role="button"],
.page-row,
.rail-button,
.utility-menu button,
.block-actions-item,
.move-page-item,
.search-result {
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease, opacity 120ms ease;
}

button:focus-visible,
[role="button"]:focus-visible,
.search-result:focus-visible,
input:focus-visible,
.calendar-picker-day:focus-visible {
  outline: 1px solid #888888;
  outline-offset: -1px;
}

input[type="password"]:focus-visible,
input[type="text"]:focus-visible,
input[type="search"]:focus-visible {
  border-color: #888888;
}

.block-editor:focus-visible {
  outline: none;
  border-bottom: 1px solid #888888;
}

#search-input:focus-visible {
  outline: 1px solid #888888;
  outline-offset: 2px;
}

html[data-theme="light"] button:focus-visible,
html[data-theme="light"] [role="button"]:focus-visible,
html[data-theme="light"] .search-result:focus-visible,
html[data-theme="light"] input:focus-visible,
html[data-theme="light"] .calendar-picker-day:focus-visible {
  outline-color: #555555;
}

html[data-theme="light"] input[type="password"]:focus-visible,
html[data-theme="light"] input[type="text"]:focus-visible,
html[data-theme="light"] input[type="search"]:focus-visible {
  border-color: #555555;
}

html[data-theme="light"] .block-editor:focus-visible {
  border-bottom-color: #555555;
}

html[data-theme="light"] #search-input:focus-visible {
  outline-color: #555555;
}

::selection {
  background: rgba(54, 108, 187, 0.65);
  color: #ffffff;
}

.page-row,
.calendar-entry,
.rail-page-button,
.mobile-block-sheet-action {
  -webkit-touch-callout: none;
}

.calendar-entry {
  -webkit-user-select: none;
}

button,
input,
textarea,
select,
[role="button"],
.search-result,
.calendar-entry {
  touch-action: manipulation;
}

.search-close {
  flex: 0 0 auto;
  width: 44px;
  min-width: 44px;
  height: 44px;
  background: transparent;
  color: #f5f5f5;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

html[data-theme="light"] .search-close {
  color: #111111;
}

.search-result.active {
  background: #1a1a1a;
}

html[data-theme="light"] .search-result.active {
  background: #e2e2e2;
}

#bottom-bar .mobile-root-tab.active {
  background: #1d1d1d;
  color: #f5f5f5;
}

#bottom-bar .mobile-new-page {
  color: #f5f5f5;
}

#bottom-bar .mobile-root-tab:active,
#bottom-bar .mobile-new-page:active {
  opacity: 0.7;
}

@media (pointer: coarse) {
  .block-drag-handle,
  .toggle-button,
  .page-expand-toggle,
  .rail-expand-toggle,
  .utility-button,
  .page-back-button,
  .calendar-nav-button,
  .calendar-today-button,
  .calendar-day-add,
  .calendar-picker-nav,
  .page-header-date[role="button"],
  .page-header-reminder {
    position: relative;
  }

  .block-drag-handle::before,
  .toggle-button::before,
  .page-expand-toggle::before,
  .rail-expand-toggle::before,
  .utility-button::before,
  .calendar-nav-button::before,
  .calendar-today-button::before,
  .calendar-day-add::before,
  .calendar-picker-nav::before,
  .page-header-date[role="button"]::before,
  .page-header-reminder::before {
    content: '';
    position: absolute;
    inset: -8px;
  }

  .block-drag-handle::before { inset: -10px 0; }
  .toggle-button::before { inset: -8px -4px; }
  .utility-button.icon-only { min-width: 44px; min-height: 44px; }
  .page-back-button { width: 44px; min-width: 44px; height: 44px; }
  .calendar-picker-day { min-height: 44px; }
  .utility-menu button,
  .block-actions-item,
  .move-page-item,
  .block-menu-item,
  .orphan-child-page,
  .btn-link {
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .text-caret-marker { animation: none; opacity: 1; }
  .sync-status-dot.syncing { animation: none; }
  .mobile-block-sheet { animation: none; }
}
