:root {
  --bg: #0b0b0d;
  --bg-elevated: #161618;
  --bg-hover: #1e1e21;
  --border: #242427;
  --border-strong: #38383d;
  --text: #e6e6e8;
  --text-strong: #ffffff;
  --text-mute: #9a9aa0;
  --text-faint: #66666c;
  --accent: #e23b3b;
  --accent-soft: rgba(226, 59, 59, 0.18);
  --accent-grad: linear-gradient(135deg, #ff5a4d 0%, #b51616 100%);
  --accent-glow: 0 0 0 1px rgba(226, 59, 59, 0.35), 0 4px 14px rgba(181, 22, 22, 0.35);
  --danger: #ff6b6b;
  --search-hit: #6a1f1f;
  --search-hit-text: #ffd9d4;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  min-height: 100vh;
}

button, input { font-family: inherit; }

.view {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.view[hidden] { display: none !important; }

.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ─── Auth ─── */

#view-login {
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at top, var(--accent-soft), transparent 60%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.brand {
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--text-faint);
  font-weight: 600;
  text-align: center;
  text-transform: uppercase;
}

.auth-card h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-strong);
  margin: 0;
  text-align: center;
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#auth-form label span {
  font-size: 12px;
  color: var(--text-mute);
  font-weight: 500;
}

#auth-form input {
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;       /* >=16px évite le zoom auto iOS */
  outline: none;
  transition: border-color 0.1s, box-shadow 0.1s;
}

#auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

#auth-submit, .modal-btn {
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 4px;
}

#auth-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error {
  font-size: 13px;
  color: var(--danger);
  background: rgba(217, 107, 107, 0.15);
  border: 1px solid rgba(217, 107, 107, 0.3);
  border-radius: 6px;
  padding: 8px 10px;
}

.switch {
  font-size: 13px;
  color: var(--text-mute);
  text-align: center;
}

.switch button {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  padding: 0;
  margin-left: 4px;
  cursor: pointer;
}

/* ─── List ─── */

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

.top h1 {
  flex: 1;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-strong);
  margin: 0;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 22px;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

.search {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.search input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 16px;
  outline: none;
}

.search input:focus { border-color: var(--accent); }

/* ─── Breadcrumb (folder navigation) ─── */

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 12px;
  overflow-x: auto;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.breadcrumb::-webkit-scrollbar { display: none; }
.breadcrumb[hidden] { display: none; }
.crumb {
  background: transparent;
  border: none;
  color: var(--text-mute);
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  flex: none;
}
.crumb:active { background: var(--bg-hover); }
.crumb.current { color: var(--text-strong); font-weight: 600; }
.crumb-sep { color: var(--text-faint); font-size: 13px; flex: none; }

.notes-list {
  list-style: none;
  padding: 4px 0;
  margin: 0;
  flex: 1;
}

.notes-list li {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 15px;
  color: var(--text);
}

.notes-list li:active { background: var(--bg-hover); }

.notes-list .folder-prefix {
  color: var(--text-faint);
  font-size: 12px;
  margin-bottom: 2px;
}

.empty {
  padding: 40px 24px;
  text-align: center;
  color: var(--text-faint);
  font-style: italic;
}

/* ─── Note view ─── */

.markdown {
  flex: 1;
  padding: 16px 20px 80px;
  line-height: 1.65;
  font-size: 15.5px;
  color: var(--text);
}

.markdown h1 { font-size: 1.85em; font-weight: 700; color: var(--text-strong); margin: 0.6em 0 0.3em; }
.markdown h2 { font-size: 1.5em; font-weight: 700; color: var(--text-strong); margin: 0.6em 0 0.3em; }
.markdown h3 { font-size: 1.25em; font-weight: 700; color: var(--text-strong); margin: 0.6em 0 0.3em; }
.markdown h4 { font-size: 1.1em; font-weight: 700; color: var(--text); margin: 0.6em 0 0.3em; }
.markdown h5, .markdown h6 { font-size: 1em; font-weight: 700; color: var(--text); margin: 0.6em 0 0.3em; }
.markdown p { margin: 0.5em 0; }
.markdown strong { color: var(--text-strong); font-weight: 700; }
.markdown em { font-style: italic; }
.markdown del { color: var(--text-mute); text-decoration: line-through; }
.markdown a { color: var(--accent); text-decoration: underline; text-decoration-style: dotted; }
.markdown ul, .markdown ol { padding-left: 1.5em; margin: 0.5em 0; }
.markdown li { margin: 0.2em 0; }
.markdown blockquote {
  margin: 0.6em 0;
  padding: 0.4em 0.9em;
  border-left: 3px solid var(--border-strong);
  color: var(--text-mute);
  font-style: italic;
}
.markdown code {
  background: var(--bg-elevated);
  color: #e0c2a8;
  padding: 1px 6px;
  border-radius: 3px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
}
.markdown pre {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  overflow-x: auto;
  margin: 0.6em 0;
}
.markdown pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
}
.markdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.2em 0;
}
.markdown .task-bullet {
  display: inline-block;
  width: 1em;
  text-align: center;
  margin-right: 0.3em;
}
.markdown .wikilink {
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 5px;
  border-radius: 3px;
  text-decoration: none;
}

/* ─── Auth extras (forgot / reset / register) ─── */

.muted { font-size: 13px; color: var(--text-mute); text-align: center; margin: 0; line-height: 1.5; }

.info {
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(226, 59, 59, 0.3);
  border-radius: 6px;
  padding: 8px 10px;
}

.link-btn {
  background: transparent;
  border: none;
  color: var(--text-mute);
  font-size: 13px;
  padding: 0;
  cursor: pointer;
  text-align: center;
  text-decoration: underline;
  text-decoration-style: dotted;
}
.link-btn:active { color: var(--accent); }

.switch-row {
  font-size: 13px;
  color: var(--text-mute);
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
}
.switch-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.switch-btn:active { background: var(--bg-hover); }

/* ─── List rows with actions ─── */

.notes-list .row {
  display: flex;
  align-items: center;
  padding: 0;
  border-bottom: 1px solid var(--border);
}
.notes-list .row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 8px 14px 16px;
  cursor: pointer;
}
.notes-list .row-text { flex: 1; min-width: 0; }
.notes-list .row-chevron {
  flex: none;
  color: var(--text-faint);
  font-size: 20px;
  line-height: 1;
}
.notes-list .row-main:active { background: var(--bg-hover); }
.notes-list .row-name {
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.notes-list .folder-row .row-name { color: var(--text-strong); font-weight: 500; }
.row-more {
  flex: none;
  width: 44px;
  align-self: stretch;
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  color: var(--text-mute);
  font-size: 20px;
  cursor: pointer;
}
.row-more:active { background: var(--bg-hover); }

/* ─── FAB ─── */

.fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent-grad);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(181, 22, 22, 0.4), 0 2px 6px rgba(0, 0, 0, 0.4);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab:active { transform: scale(0.94); }

/* ─── Header text button ─── */

.text-btn {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  padding: 8px 4px;
  cursor: pointer;
}
.text-btn:disabled { opacity: 0.5; }

/* ─── Editor ─── */

.editor-area {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 15px;
  line-height: 1.6;
  padding: 16px 18px 80px;
}
.editor-status {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 16px;
  font-size: 12px;
  color: var(--text-mute);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  min-height: 0;
}
.editor-status:empty { display: none; }

/* ─── Prompt modal ─── */

.modal-backdrop, .sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 50;
  display: flex;
}
.modal-backdrop { align-items: center; justify-content: center; padding: 24px; }
.modal-backdrop[hidden], .sheet-backdrop[hidden] { display: none !important; }

.modal {
  width: 100%;
  max-width: 360px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal h2 { margin: 0; font-size: 17px; color: var(--text-strong); }
.modal input {
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  outline: none;
}
.modal input:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-btn {
  padding: 10px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin: 0;
}
.modal-btn.ghost { background: transparent; color: var(--text-mute); border: 1px solid var(--border-strong); }

/* ─── Action sheet ─── */

.sheet-backdrop { align-items: flex-end; }
.sheet {
  width: 100%;
  background: var(--bg-elevated);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sheet-title {
  font-size: 12px;
  color: var(--text-faint);
  padding: 12px 14px 8px;
  text-align: center;
}
.sheet-item {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 16px;
  padding: 15px;
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
}
.sheet-item:active { background: var(--bg-hover); }
.sheet-item.danger { color: var(--danger); }
.sheet-item.cancel { color: var(--text-mute); font-weight: 600; margin-top: 4px; background: var(--bg); }

/* ─── Toast ─── */

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 10px;
  z-index: 60;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: 80%;
  text-align: center;
}
.toast[hidden] { display: none; }
.toast.ok { border-color: rgba(226, 59, 59, 0.5); }
.toast.err { border-color: rgba(217, 107, 107, 0.5); color: var(--danger); }

/* ── Editor toolbar (v0.5.0) ── */
.editor-toolbar {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.editor-toolbar button {
  flex: 0 0 auto;
  min-width: 40px;
  height: 34px;
  padding: 0 10px;
  background: var(--bg);
  color: var(--text, #e6e6e8);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.editor-toolbar button:active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
