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

:root {
  --bg: #0f0f1a;
  --surface: #1e1e2a;
  --text: #e0e0e0;
  --accent: #bb86fc;
  --cyan: #00e5ff;
  --yellow: #ffeb3b;
  --red: #cf6679;
  --shadow: rgba(0, 0, 0, 0.4);
}

body.light {
  --bg: #f5f5fa;
  --surface: #ffffff;
  --text: #1a1a1a;
  --accent: #6200ee;
  --shadow: rgba(0, 0, 0, 0.15);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

#mindmap-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#mindmap-canvas.grabbing { cursor: grabbing; }
#mindmap-canvas.lasso { cursor: crosshair; }

/* Search Bar */
.search-bar {
  position: absolute;
  top: 12px;
  left: 16px;
  right: 80px;
  z-index: 10;
}

.search-bar .search-logo {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  z-index: 2;
  pointer-events: none;
  border-radius: 8px;
}

.search-bar .search-icon {
  position: absolute;
  left: 48px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  z-index: 2;
  pointer-events: none;
}

.search-bar input {
  width: 100%;
  padding: 12px 40px 12px 76px;
  border: none;
  border-radius: 28px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  box-shadow: 0 4px 12px var(--shadow);
  outline: none;
}

.search-bar input::placeholder {
  color: var(--text);
  opacity: 0.5;
}

.search-bar .btn-icon {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text);
  opacity: 0.6;
  font-size: 16px;
  cursor: pointer;
  padding: 8px;
}

.search-results {
  margin-top: 4px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 6px 16px var(--shadow);
  max-height: 250px;
  overflow-y: auto;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(128,128,128,0.1);
}

.search-result-item:hover {
  background: rgba(187, 134, 252, 0.1);
}

.search-result-item:last-child { border-bottom: none; }

.search-result-item.create {
  color: var(--accent);
  font-weight: 600;
}

/* Action Buttons */
.action-buttons {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 10;
}

.fab {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  box-shadow: 0 4px 12px var(--shadow);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
}

.fab:hover { transform: scale(1.05); }
.fab.active { background: var(--accent); }

/* Indicators */
.zoom-indicator, .help-text {
  position: absolute;
  background: var(--surface);
  opacity: 0.85;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  box-shadow: 0 2px 8px var(--shadow);
  z-index: 5;
}

.zoom-indicator {
  bottom: 16px;
  right: 16px;
}

.help-text {
  bottom: 16px;
  left: 16px;
  line-height: 1.5;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  max-width: 420px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px var(--shadow);
}

.modal h2 {
  margin-bottom: 16px;
  font-size: 20px;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.modal input[type="text"],
.modal textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(128,128,128,0.3);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  outline: none;
}

.modal textarea {
  min-height: 80px;
  resize: vertical;
  font-family: inherit;
}

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.chip {
  padding: 6px 12px;
  border-radius: 16px;
  border: 1px solid rgba(128,128,128,0.3);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}

.chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}

.btn-primary { background: var(--accent); color: white; }
.btn-danger { background: var(--red); color: white; }
.btn-secondary { background: transparent; color: var(--text); border: 1px solid rgba(128,128,128,0.3); }
.btn-block { width: 100%; }

.btn-icon {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

/* Page Overlays */
.page-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 50;
  overflow-y: auto;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
}

.page-header-centered {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  text-align: center;
}

.page-header-centered h1 {
  grid-column: 2;
}

.page-header-centered .header-side {
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#all-notes-header-action {
  justify-content: flex-end;
}

.folder-close-btn {
  font-size: 20px;
}

.all-notes-toolbar {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.all-notes-toolbar .btn-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--surface);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.all-notes-toolbar .btn-icon:hover {
  background: rgba(187, 134, 252, 0.2);
}

.all-notes-search {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: none;
  background: var(--surface);
  color: var(--text);
  margin-bottom: 16px;
  font-size: 16px;
  text-align: center;
}

.all-notes-search::placeholder {
  text-align: center;
}

.all-notes-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.all-notes-layout .list-item {
  text-align: center;
  padding: 12px 16px;
}

.all-notes-breadcrumb {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  font-weight: 600;
  color: var(--accent);
}

.folder-item {
  border: 1px solid rgba(187, 134, 252, 0.25);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
}

.folder-item .folder-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-item .folder-meta {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
}

.note-item {
  cursor: grab;
  touch-action: pan-y;
}

.note-item:active {
  cursor: grabbing;
}

.note-item.dragging {
  opacity: 0.45;
  transform: scale(0.98);
}

.list-item.drop-target-active,
.drop-root-zone.drop-target-active {
  outline: 2px solid var(--accent);
  background: rgba(187, 134, 252, 0.18);
  opacity: 1;
}

.drop-root-label {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
}

.folder-meta {
  opacity: 0.5;
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
}

.folder-move-btn {
  text-align: left;
}

.all-notes-layout .auto-scroll-bar {
  justify-content: center;
}

.page-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
}

.list-item {
  background: var(--surface);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.15s;
}

.list-item:hover { opacity: 1; }

.list-item-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.list-item .time {
  color: var(--text);
  opacity: 0.6;
  font-size: 14px;
  min-width: 50px;
}

/* Note View */
.note-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

.note-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
  text-align: center;
}

.note-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 16px;
  justify-content: center;
}

/* Floating toolbar pinned to the bottom of the note page */
.note-toolbar-floating {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 120;
  margin-bottom: 0;
  flex-wrap: nowrap;
  max-width: calc(100% - 24px);
  overflow-x: auto;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 16px;
  background: rgba(30, 30, 40, 0.82);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  scrollbar-width: none;
}

.note-toolbar-floating::-webkit-scrollbar { display: none; }

.note-toolbar-floating button,
.note-toolbar-floating .timer {
  flex: 0 0 auto;
}

.note-toolbar button {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: var(--surface);
  font-size: 16px;
  cursor: pointer;
}

.note-toolbar button:hover { background: rgba(187,134,252,0.2); }

.note-toolbar .timer {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--surface);
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.note-content {
  flex: 1;
  overflow-y: auto;
  margin-bottom: 16px;
  padding-bottom: 72px;
}

.note-content.reading {
  font-size: 16px;
  line-height: 1.6;
  text-align: center;
  -webkit-user-select: text;
  user-select: text;
  touch-action: auto;
}

.note-content.reading img.note-image {
  max-width: 100%;
  max-height: 400px;
  border-radius: 12px;
  margin: 0 auto 16px;
  display: block;
  cursor: zoom-in;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  touch-action: none;
}

.image-lightbox.hidden {
  display: none;
}

.image-lightbox-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  z-index: 3;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
}

.image-lightbox-toolbar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.image-lightbox-toolbar .btn-icon {
  color: #fff;
  font-size: 22px;
  min-width: 36px;
}

#img-zoom-level {
  min-width: 52px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
}

.image-lightbox-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 64px 16px 24px;
  cursor: grab;
}

.image-lightbox-stage.is-dragging {
  cursor: grabbing;
}

#image-lightbox-img {
  max-width: none;
  max-height: none;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
}

.note-content.reading .youtube-preview {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 200px;
  border-radius: 12px;
  overflow: hidden;
  margin: 0 auto 16px;
  cursor: pointer;
}

.note-content.reading .youtube-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  margin: 0;
}

.note-content.reading .youtube-preview .play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.4);
  font-size: 32px;
}

.note-content.reading a, .note-content.reading .wikilink {
  color: inherit;
  font-weight: inherit;
  text-decoration: none;
  cursor: pointer;
  pointer-events: auto;
}

.note-content.reading strong {
  font-weight: 700;
}

.note-editor-wrap {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 300px;
}

.note-editor-wrap .note-editor {
  flex: 1;
  min-height: 300px;
}

.wiki-suggestions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 4px 16px var(--shadow);
}

.wiki-suggestion-item {
  width: 100%;
  text-align: center;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}

.wiki-suggestion-item:hover,
.wiki-suggestion-item.active {
  background: rgba(187, 134, 252, 0.2);
  color: var(--accent);
}

.note-editor {
  width: 100%;
  height: 100%;
  min-height: 300px;
  padding: 12px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  resize: none;
  outline: none;
  font-family: inherit;
  text-align: center;
}

.note-mode-label {
  font-size: 13px;
  opacity: 0.6;
  margin-bottom: 8px;
  text-align: center;
}

.note-created-at {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid rgba(128, 128, 128, 0.2);
  font-size: 13px;
  opacity: 0.5;
  text-align: center;
}

.note-breadcrumb {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid rgba(128, 128, 128, 0.2);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  opacity: 0.6;
}

.note-breadcrumb .crumb-sep {
  opacity: 0.5;
}

.note-breadcrumb .crumb-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  pointer-events: auto;
}

.note-content.reading .note-breadcrumb .crumb-link {
  pointer-events: auto;
}

.note-breadcrumb .crumb-link:hover {
  opacity: 1;
  color: var(--accent);
}

.note-breadcrumb .crumb-current {
  font-weight: 600;
  opacity: 0.85;
}

.note-breadcrumb + .note-created-at {
  margin-top: 6px;
  padding-top: 0;
  border-top: none;
}

.note-view .page-header {
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.note-view .page-header > div:first-child {
  width: 100%;
}

.note-view .page-header .btn-icon {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
}

/* Home view — All Notes as landing page */
body.home-view #mindmap-canvas,
body.home-view .search-bar,
body.home-view .zoom-indicator,
body.home-view .help-text {
  visibility: hidden;
  pointer-events: none;
}

/* Note view — hide mind map chrome while a note is open or loading */
body.note-tab #mindmap-canvas,
body.note-tab .search-bar,
body.note-tab .zoom-indicator,
body.note-tab .help-text,
body.note-tab .action-buttons,
body.note-view #mindmap-canvas,
body.note-view .search-bar,
body.note-view .zoom-indicator,
body.note-view .help-text,
body.note-view .action-buttons,
body.folder-tab #mindmap-canvas,
body.folder-tab .search-bar,
body.folder-tab .zoom-indicator,
body.folder-tab .help-text,
body.folder-tab .action-buttons {
  visibility: hidden;
  pointer-events: none;
}

body.note-tab,
body.note-view,
body.folder-tab {
  background: var(--bg);
}

/* Croix rouge de fermeture d'un dossier ouvert dans son onglet */
.btn-folder-close {
  color: #ff4d4f;
  font-size: 18px;
}

.note-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  opacity: 0.6;
  font-size: 16px;
}

/* Diaporama */
.diaporama-controls {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  opacity: 0.95;
  padding: 12px 24px;
  border-radius: 32px;
  box-shadow: 0 6px 20px var(--shadow);
  z-index: 60;
}

.diaporama-controls .divider {
  width: 1px;
  height: 24px;
  background: rgba(128,128,128,0.3);
}

.diaporama-controls #dia-counter {
  font-weight: 600;
  color: var(--accent);
  min-width: 60px;
  text-align: center;
}

.diaporama-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
  transform-origin: left;
  z-index: 61;
  transition: none;
}

/* Diaporama page */
.dia-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border-radius: 12px;
  opacity: 0.85;
}

.dia-list-item .num {
  color: var(--accent);
  font-weight: 600;
  min-width: 30px;
}

.dia-list-item .word { flex: 1; }

.dia-options {
  display: flex;
  gap: 12px;
  margin: 16px 0;
  flex-wrap: wrap;
}

.toggle-chip {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid rgba(128,128,128,0.3);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}

.toggle-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Auto-scroll controls */
.auto-scroll-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: 12px;
  margin-top: 16px;
}

.auto-scroll-bar input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  padding: 12px 24px;
  border-radius: 24px;
  box-shadow: 0 4px 16px var(--shadow);
  z-index: 200;
  font-size: 14px;
}

.hidden { display: none !important; }

/* Spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 600px) {
  .help-text { display: none; }
  .search-bar { right: 70px; }
  .action-buttons { right: 8px; }
  .fab { width: 44px; height: 44px; font-size: 18px; }
}

/* Auth */
.auth-box {
  max-width: 400px;
  margin: 10vh auto;
  padding: 32px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 8px 32px var(--shadow);
}

.auth-box h1 {
  text-align: center;
  margin-bottom: 8px;
  font-size: 24px;
}

.site-logo {
  display: block;
  width: 80px;
  height: 80px;
  margin: 0 auto 16px;
  border-radius: 20px;
  box-shadow: 0 4px 16px var(--shadow);
}

.auth-subtitle {
  text-align: center;
  opacity: 0.7;
  font-size: 14px;
  margin-bottom: 24px;
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}

.auth-tab.active {
  background: var(--accent);
  color: white;
}

.auth-box input {
  width: 100%;
  padding: 12px;
  margin-bottom: 12px;
  border: 1px solid rgba(128,128,128,0.3);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.auth-error {
  color: var(--red);
  font-size: 13px;
  margin-bottom: 12px;
}

.auth-hint {
  text-align: center;
  opacity: 0.5;
  font-size: 12px;
  margin-top: 16px;
}

/* Sync status */
.sync-status {
  position: absolute;
  top: 12px;
  right: 16px;
  z-index: 10;
  background: var(--surface);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  box-shadow: 0 2px 8px var(--shadow);
}

.sync-status.syncing { color: var(--accent); }
.sync-status.synced { color: #4caf50; }
.sync-status.error { color: var(--red); }

