:root {
  --bg-color: #ffffff;
  --text-color: #333333;
  --text-secondary: #888888;
  --text-muted: #999999;
  --border-color: #eeeeee;
  --bullet-color: #808000;
  --bullet-hover: #555500;
  --title-color: #555500;
  --header-bg: #ffffff;
  --toolbar-bg: #f0f0f0;
  --button-bg: #ffffff;
  --button-border: #cccccc;
  --breadcrumb-color: #888888;
  --node-focus-bg: transparent;
  --drag-opacity: 0.4;
  --drop-line: #007bff;
  --drop-bg: rgba(0, 123, 255, 0.1);
}

.dark-mode {
  --bg-color: #1a1a1a;
  --text-color: #e0e0e0;
  --text-secondary: #aaaaaa;
  --text-muted: #777777;
  --border-color: #333333;
  --bullet-color: #a0a000;
  --bullet-hover: #c0c000;
  --title-color: #808000;
  --header-bg: #1a1a1a;
  --toolbar-bg: #2d2d2d;
  --button-bg: #333333;
  --button-border: #444444;
  --breadcrumb-color: #aaaaaa;
  --node-focus-bg: #252525;
  --drag-opacity: 0.5;
  --drop-line: #4dabff;
  --drop-bg: rgba(77, 171, 255, 0.15);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  color: var(--text-color);
  margin: 0;
  padding: 0;
  background-color: var(--bg-color);
}

#app {
  /* Remove max-width from #app to allow background to fill */
}
.node {
  position: relative;
  transition: padding 0.1s ease;
}
.node.dragging {
  opacity: var(--drag-opacity);
}
.node.drop-before::before {
  content: "";
  position: absolute;
  top: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background-color: var(--drop-line);
  z-index: 10;
}
.node.drop-after::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background-color: var(--drop-line);
  z-index: 10;
}
.node.drop-as-child > .node-content {
  background-color: var(--drop-bg);
  border-radius: 4px;
}
.node-body {
  display: flex;
  align-items: flex-start;
  position: relative;
}
.node-controls {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  height: 1.5rem; /* 24px */
  position: absolute;
  right: 100%;
  top: 0.125rem; /* 2px, alignment with bullet */
}
.node-main {
  flex-grow: 1;
}
.node-content {
  display: flex;
  align-items: flex-start;
  padding: 0.125rem 0; /* 2px */
  position: relative;
  width: 100%;
}
.expand-handle {
  cursor: pointer;
  margin-right: 0.0625rem; /* 1px */
  color: var(--bullet-color);
  width: 1.5rem; /* 24px */
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  height: 1.5rem; /* 24px */
  border-radius: 50%;
  transition: background-color 0.2s, color 0.2s;
}
.expand-handle svg {
  width: 1.25rem; /* 20px */
  height: 1.25rem; /* 20px */
}
.expand-handle:hover {
  color: var(--text-color);
  background-color: var(--toolbar-bg);
}
.kebab-icon {
  cursor: pointer;
  margin-right: 0.125rem; /* 2px */
  font-size: 1rem; /* 16px */
  color: var(--text-muted);
  width: 1.5rem; /* 24px */
  height: 1.5rem; /* 24px */
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  visibility: hidden;
  position: relative;
  font-weight: bolder;
  border-radius: 50%;
  transition: background-color 0.2s, color 0.2s;
}
@media (hover: hover) {
  .node-body:hover:not(:has(.node-body:hover)) > .node-controls > .kebab-icon {
    visibility: visible;
  }
}
.kebab-icon:hover {
  color: var(--text-color);
  background-color: var(--toolbar-bg);
}
.context-menu {
  position: absolute;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: 0 0.125rem 0.625rem rgba(0,0,0,0.1); /* 2px 10px */
  z-index: 1000;
  top: 1.25rem; /* 20px */
  left: 0;
  min-width: 7.5rem; /* 120px */
  font-size: 0.875rem; /* 14px */
  font-weight: initial;
  overflow: hidden;
}
.context-menu-item {
  padding: 0.5rem 1rem; /* 8px 16px */
  cursor: pointer;
  font-size: 0.875rem; /* 14px */
  color: var(--text-color);
  text-align: left;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.menu-icon {
  display: flex;
  align-items: center;
  color: var(--text-secondary);
}
.menu-icon svg {
  width: 1rem;
  height: 1rem;
}
.menu-icon.icon-shortcut {
  width: 0.75rem;
  margin-left: 0.125rem;
  margin-right: 0.125rem;
}
.context-menu-item:hover {
  background-color: var(--toolbar-bg);
}
.bullet {
  width: 1.5rem; /* 24px */
  height: 1.5rem; /* 24px */
  margin-left: -0.1875rem; /* -3px */
  margin-right: 0.1475rem; /* ~2.3px */
  margin-top: 0;
  cursor: pointer;
  flex-shrink: 0;
  position: relative; /* For centering the dot */
  text-decoration: none;
  color: inherit;
  border-radius: 50%;
  transition: background-color 0.2s, color 0.2s;
}
.bullet::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 0.5rem; /* 8px */
  height: 0.5rem; /* 8px */
  background-color: var(--bullet-color);
  border-radius: 2px;
}
.bullet:hover {
  background-color: var(--toolbar-bg);
}
.bullet:hover::after {
  background-color: var(--bullet-hover);
}
.bullet::before {
  /* Hit area visualization debug */
  /* content: ""; width: 100%; height: 100%; position: absolute; background: rgba(0,0,0,0.1); */
}
.node-text {
  border: none;
  outline: none;
  width: fit-content;
  min-width: 2rem;
  max-width: 100%;
  padding: 0.125rem 6rem 0.125rem 0.25rem; /* 2px 96px 2px 4px */
  font-size: 1rem; /* 16px */
  min-height: 1.5em;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}
.node-text:focus {
  /* background-color: #f9f9f9; Removed for cleaner look */
}
.node-text.complete {
  color: var(--text-muted);
  text-decoration: line-through;
}

.system-root > .node-body > .node-main > .node-content > .node-text {
  color: var(--text-secondary);
}

.system-root {
  margin-top: 2rem;
}

.system-root > .node-body::before {
  content: "";
  position: absolute;
  top: -1rem;
  left: -0.1875rem;
  right: 0;
  border-top: 3px double var(--bullet-color);
  pointer-events: none;
}

.node-text.read-only {
  cursor: default;
}

.node-text:not(.focused) .horizontal-line {
  display: block;
  border-top: 1px solid var(--bullet-color);
  height: 0;
  margin: 0.75rem 0;
  font-size: 0;
  line-height: 0;
  overflow: hidden;
  color: transparent;
  text-indent: -9999px;
}

.node-text.node-hr {
  width: 100%;
  padding-right: 0.25rem;
  padding-left: 0;
  margin-left: -0.1875rem;
  display: flex;
  align-items: center;
  cursor: pointer;
}

.hr-line {
  width: 100%;
  border-top: 1px solid var(--bullet-color);
  pointer-events: none;
}

.md-marker {
  display: none;
}

code {
  background-color: var(--toolbar-bg);
  padding: 0.125rem 0.25rem;
  border-radius: 0.1875rem; /* 3px */
  font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 85%;
}

mark {
  background-color: #ffff00;
  color: #000000;
  border-radius: 2px;
  padding: 0 2px;
}

.dark-mode mark {
  background-color: #808000;
  color: #ffffff;
}

.node-text a, .zoom-view .zoom-title a {
  color: #007bff;
  text-decoration: none;
  cursor: pointer;
}

.node-text a:hover, .zoom-view .zoom-title a:hover {
  text-decoration: underline;
}

.dark-mode .node-text a, .dark-mode .zoom-view .zoom-title a {
  color: #4dabff;
}

.node-text a.shortcut-link, .zoom-view .zoom-title a.shortcut-link,
.dark-mode .node-text a.shortcut-link, .dark-mode .zoom-view .zoom-title a.shortcut-link {
  color: var(--bullet-color);
  text-decoration: underline;
}

.node-text a.shortcut-link.broken, .zoom-view .zoom-title a.shortcut-link.broken,
.dark-mode .node-text a.shortcut-link.broken, .dark-mode .zoom-view .zoom-title a.shortcut-link.broken {
  color: #ff0000;
  text-decoration: underline;
  cursor: default;
}

.children {
  border-left: 1px solid var(--border-color);
  margin-left: 0.5625rem; /* 9px, Align with bullet center */
  padding-left: 0.8125rem; /* 13px, Align handle center with guideline */
}
.breadcrumbs {
  margin-bottom: 1.25rem; /* 20px */
  color: var(--breadcrumb-color);
  font-size: 0.875rem; /* 14px */
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}
.breadcrumb {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  transition: color 0.2s;
  text-decoration: none;
  color: inherit;
}
.breadcrumb:hover {
  text-decoration: underline;
  color: var(--text-color);
}
.breadcrumb.current {
  cursor: default;
  color: var(--text-color);
  font-weight: 500;
}
.breadcrumb.current:hover {
  text-decoration: none;
}
.breadcrumb-home {
  display: inline-flex;
  align-items: center;
}
.breadcrumb-home svg {
  width: 1.125rem;
  height: 1.125rem;
}
.breadcrumb-separator {
  display: inline-flex;
  align-items: center;
  margin: 0 0.125rem;
  color: var(--text-muted);
}
.breadcrumb-separator svg {
  width: 1rem;
  height: 1rem;
}
.breadcrumb-ellipsis {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
.breadcrumb-ellipsis:hover {
  text-decoration: underline;
}
.zoom-title {
  font-size: 1.5rem; /* 24px */
  margin: 0;
  width: fit-content;
  min-width: 5rem;
  max-width: 100%;
  font-weight: bold;
  padding: 0.125rem 6rem 0.125rem 0.25rem;
  color: var(--bullet-color);
}

.zoom-title.read-only {
  cursor: default;
}

.zoom-title-row {
  display: flex;
  align-items: flex-start;
  margin-bottom: 1rem;
  width: 100%;
}

.node-whitespace {
  flex-grow: 1;
  align-self: stretch;
}

.mobile-toolbar {
  display: none;
  background: var(--toolbar-bg);
  padding: 0;
  border-top: 1px solid var(--button-border);
  z-index: 1000;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.toolbar-button {
  flex: 0 0 auto;
  min-width: 5rem; /* 80px */
  background: var(--button-bg);
  color: var(--text-color);
  border: none;
  border-right: 1px solid var(--button-border);
  padding: 0.5rem 1rem; /* 8px 16px */
  border-radius: 0;
  font-size: 0.875rem; /* 14px */
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.toolbar-button.symbol-btn {
  /* Use standard toolbar-button padding */
}
.toolbar-button svg {
  width: 1.25rem;
  height: 1.25rem;
  display: block;
}
.toolbar-button:last-child {
  border-right: none;
}

.toolbar-button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.dark-mode-mobile-only {
  display: none;
}

/* Auth and Header Styles */
.app-main-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-container {
  max-width: 50rem; /* 800px */
  margin: 0 auto;
  padding: 1.25rem 1.25rem 5.25rem 4.5rem; /* 20px 20px 84px 72px */
  padding-top: calc(1.25rem + env(safe-area-inset-top));
  padding-left: calc(4.5rem + env(safe-area-inset-left));
  padding-right: calc(1.25rem + env(safe-area-inset-right));
  flex: 1 0 auto;
  box-sizing: border-box;
  width: 100%;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem; /* 20px */
  padding-bottom: 0.625rem; /* 10px */
  border-bottom: 1px solid var(--border-color);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: -0.5rem;
  text-decoration: none;
  cursor: pointer;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.9375rem; /* 15px */
}

.app-logo {
  width: 4.25rem;
  height: 4.25rem;
  border-radius: 0.5rem;
  object-fit: contain;
}

.app-title {
  margin: 0;
  font-size: 1.5rem;
  color: var(--title-color);
  font-family: Georgia, 'Times New Roman', Times, serif;
}

.auth-section {
  display: flex;
  align-items: center;
  gap: 0.625rem; /* 10px */
  font-size: 0.875rem; /* 14px */
}

.login-btn, .logout-btn {
  background: #007bff;
  color: white;
  border: none;
  padding: 0.5rem 1rem; /* 8px 16px */
  border-radius: 0.25rem; /* 4px */
  cursor: pointer;
  font-size: 0.875rem; /* 14px */
}

.logout-btn {
  display: none;
}

.login-btn:hover, .logout-btn:hover {
  background: #0056b3;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem; /* 8px */
}

.user-photo {
  width: 1.75rem; /* 28px */
  height: 1.75rem; /* 28px */
  border-radius: 50%;
  object-fit: cover;
}

.dark-mode-toggle {
  background: var(--button-bg);
  color: var(--text-color);
  border: 1px solid var(--button-border);
  border-radius: 50%;
  width: 2rem; /* 32px */
  height: 2rem; /* 32px */
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem; /* 18px */
  padding: 0;
}

.dark-mode-toggle:hover {
  background-color: var(--toolbar-bg);
}

.main-view {
  /* Main content area when not zoomed */
}

@media (hover: none), (max-width: 600px) {
  .mobile-toolbar {
    display: flex;
    flex-wrap: nowrap;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@media (max-width: 600px) {
  html, body {
    scrollbar-width: none;
    -ms-overflow-style: none;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  html::-webkit-scrollbar, body::-webkit-scrollbar {
    display: none;
  }
  .toolbar-button {
    /* Allow buttons to keep their min-width and scroll horizontally */
  }
  .app-container {
    padding: 0.625rem 0.625rem 4.625rem 2.5rem; /* 10px 10px 74px 40px */
    padding-top: calc(0.625rem + env(safe-area-inset-top));
    padding-left: calc(2.5rem + env(safe-area-inset-left));
    padding-right: calc(0.625rem + env(safe-area-inset-right));
  }
  .node-text {
    min-width: calc(100vw - 4rem);
  }
  .zoom-title {
    min-width: calc(100vw - 4rem);
  }
  .logout-btn, .header-dark-mode-toggle {
    display: none;
  }
  .dark-mode-mobile-only {
    display: flex;
  }
}

.mobile-toolbar::-webkit-scrollbar {
  display: none;
}

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  background-color: #808000; /* olive green */
  color: #ffffff;
  padding: 0.75rem 1.5rem;
  border-radius: 2rem;
  font-size: 0.875rem;
  z-index: 2000;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease, bottom 0.3s ease;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.dark-mode .toast {
  background-color: #a0a000; /* dark mode olive green */
  color: #e0e0e0;
}

@media (max-width: 600px) {
  .toast {
    bottom: 5rem; /* Above the mobile toolbar */
  }
}
