:root {
  color-scheme: light dark;
  --accent: #2b6cb0;
  --bg: #ffffff;
  --fg: #1a202c;
  --border: #e2e8f0;
  --muted: #718096;
}

* {
  box-sizing: border-box;
}

/* Form controls don't inherit font-family by default, so without this they
   would ignore the user's interface font. */
button, input, select, textarea {
  font-family: inherit;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif);
  background: var(--bg);
  color: var(--fg);
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  padding-top: calc(12px + env(safe-area-inset-top));
  min-height: 100vh;
  min-height: 100dvh;
}

#app.editor-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#app.editor-view .view-header,
#app.editor-view .title-input {
  flex-shrink: 0;
}

#app.list-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#app.list-view .view-header,
#app.list-view .search-row {
  flex-shrink: 0;
}

#app.list-view .note-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.view-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.view-header h1 {
  font-size: 1.4rem;
  margin: 0;
  flex: 1;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
}

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

.status-text {
  flex: 1;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

#search-input {
  flex: 1;
  min-width: 0;
  width: auto;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 1rem;
}

.search-clear-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--border);
  color: #000;
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
}

.note-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* A real anchor rather than a div with a click handler, so rows are reachable by
   keyboard and by a screen reader's activation gesture, and support middle-click
   and open-in-new-tab for free. */
.note-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  color: inherit;
  text-decoration: none;
}

/* The focus ring is the point of the change — without it keyboard users can tab
   through the list with no idea where they are. Inset so it isn't clipped by the
   scroll container. */
.note-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.note-row-main {
  flex: 1;
  min-width: 0;
}

.note-row-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.note-row-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}

.note-row-preview {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-row-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

.note-row-date {
  color: var(--muted);
  font-size: 0.75rem;
  flex-shrink: 0;
  white-space: nowrap;
}

.badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--border);
  color: var(--muted);
}

.badge-synced { background: #c6f6d5; color: #22543d; }
.badge-pending { background: #feebc8; color: #7b341e; }
.badge-conflict, .badge-error { background: #fed7d7; color: #822727; }

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 40px 0;
  list-style: none;
}

.fab {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 1.8rem;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.title-input {
  width: 100%;
  font-size: 1.3rem;
  font-weight: 600;
  font-family: var(--font-title, inherit);
  border: none;
  outline: none;
  padding: 8px 4px;
  margin-bottom: 8px;
  background: transparent;
  color: var(--fg);
}


.content-input {
  width: 100%;
  min-height: 60vh;
  min-height: 60dvh;
  border: none;
  outline: none;
  resize: vertical;
  font-size: 1rem;
  line-height: 1.5;
  padding: 4px;
  background: transparent;
  color: var(--fg);
  font-family: var(--font-editor, Menlo, ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace);
}

#app.editor-view .content-input {
  flex: 1;
  min-height: 0;
  resize: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
  color: var(--muted);
}

.settings-form input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 1rem;
  color: var(--fg);
  background: var(--bg);
}

.password-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.password-row input {
  flex: 1;
}

.help-text {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

.button-row {
  display: flex;
  gap: 8px;
}

.button-row button,
#sync-now-btn {
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  font-size: 0.95rem;
  cursor: pointer;
}

#test-btn,
#reset-fonts-btn {
  background: none;
  color: var(--accent);
}

.test-result {
  font-size: 0.85rem;
  min-height: 1.2em;
}

.test-result.success { color: #22543d; }
.test-result.error { color: #822727; }

.version-info {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.version-info p {
  font-size: 0.8rem;
  color: var(--muted);
}

.version-info #refresh-btn {
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: none;
  color: var(--accent);
  font-size: 0.95rem;
  cursor: pointer;
}

.fonts-panel,
.sync-panel {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.sync-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sync-icon {
  display: block;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a202c;
    --fg: #f7fafc;
    --border: #2d3748;
    --muted: #a0aec0;
  }
}
