/* View Transition */
.view { display: none; width: 100%; min-height: 100%; opacity: 0; transform: translateY(8px); transition: opacity var(--transition), transform var(--transition); }
.view.active { display: block; opacity: 1; transform: translateY(0); }
#view-bookmarks.active, #view-status.active {
  display: flex; flex-direction: column; align-items: center;
  justify-content: flex-start;
  overflow: auto; padding: 24px 16px;
  box-sizing: border-box;
  position: absolute; inset: 0;
}
#view-bookmarks #bookmarksList { width: 100%; max-width: 560px; }
.view h2 { text-align: center; }

/* Top Bar */
#topbar {
  height: 52px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; flex-shrink: 0; z-index: 100;
  background: linear-gradient(180deg, rgba(7,26,15,0.97) 0%, rgba(7,26,15,0.5) 100%);
  border-bottom: 1px solid var(--border);
}
.logo-area { display: flex; align-items: center; gap: 10px; position: relative; }
.logo-icon { font-size: 22px; filter: drop-shadow(0 0 6px var(--primary-glow)); animation: logoFloat 3s ease-in-out infinite; }
@keyframes logoFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }
.logo-text { font-size: 17px; font-weight: 700; color: var(--primary); letter-spacing: 2px; text-shadow: 0 0 20px var(--primary-glow); margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.user-display {
  font-size: 13px; color: var(--text2); padding: 5px 14px;
  background: var(--bg-surface); border-radius: 20px;
  border: 1px solid var(--border); transition: border-color var(--transition-fast), color var(--transition-fast);
}
.user-display:hover { border-color: var(--border-active); color: var(--text); }

/* Main Layout */
#main { flex: 1; display: flex; overflow: hidden; position: relative; z-index: 1; }

/* Floating Sidebar */
#sidebar {
  position: absolute; left: 12px; top: 12px; bottom: 12px; z-index: 50;
  width: 48px; background: rgba(255,255,255,0.04);
  border: 1px solid var(--border); border-radius: 14px;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  display: flex; flex-direction: column; align-items: center; padding: 6px; gap: 2px;
  transition: width var(--transition); overflow: hidden;
  box-shadow: 0 4px 24px rgba(0,0,0,0.2);
}
#sidebar:hover { width: 150px; border-color: rgba(255,255,255,0.12); box-shadow: 0 4px 32px rgba(0,0,0,0.3); }
.nav-btn {
  width: 100%; display: flex; align-items: center; justify-content: flex-start; gap: 8px; padding: 8px 10px;
  border: none; background: transparent; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 13px; color: var(--text2); white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast); flex-shrink: 0; position: relative;
}
.nav-btn:hover { background: var(--bg-surface); color: var(--text); }
.nav-btn:hover .nav-icon { transform: scale(1.1); }
.nav-btn.active { background: rgba(82,183,136,0.1); color: var(--primary); }
.nav-btn.active::before {
  content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 2px;
  background: var(--primary); border-radius: 1px; box-shadow: 0 0 8px var(--primary-glow);
}
.nav-btn .nav-icon { font-size: 16px; flex-shrink: 0; width: 24px; text-align: center; transition: transform var(--transition-fast); }
.nav-btn .nav-label { opacity: 0; transition: opacity var(--transition); }
#sidebar:hover .nav-btn .nav-label { opacity: 1; }
#sidebar hr { width: 80%; border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* Content Area */
#content {
  flex: 1; display: flex; flex-direction: column; overflow: auto; position: relative;
  margin-left: 60px; padding: 16px;
}

/* Footer */
#bottombar {
  height: 28px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; font-size: 11px; color: var(--text3); flex-shrink: 0;
  background: linear-gradient(0deg, rgba(7,26,15,0.85) 0%, transparent 100%);
  position: relative; z-index: 1;
}
#bottombar span { display: flex; align-items: center; gap: 4px; }

/* Loading Overlay */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.35s ease;
}
.loading-overlay.active { opacity: 1; pointer-events: auto; }
.loading-spinner {
  width: 44px; height: 44px; border: 3px solid rgba(255,255,255,0.06);
  border-top-color: var(--primary); border-right-color: var(--primary-light);
  border-radius: 50%; animation: spin 0.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  box-shadow: 0 0 40px var(--primary-glow);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal Overlay */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 900;
}
.modal-box {
  background: var(--bg-mid); border: 1px solid var(--border-active);
  border-radius: var(--radius); padding: 24px; max-width: 560px; width: 90%;
  max-height: 80vh; overflow-y: auto; box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.modal-box h3 { font-size: 18px; margin-bottom: 16px; color: var(--text); }
.modal-box .form-group { margin-bottom: 14px; }
.modal-box .form-group label {
  font-size: 12px; color: var(--text2); margin-bottom: 6px; display: block; font-weight: 500; letter-spacing: 0.3px;
}
.modal-box input[type="text"],
.modal-box textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; background: rgba(0,0,0,0.2); color: var(--text); outline: none; font-family: inherit;
  transition: all var(--transition-fast); box-sizing: border-box;
}
.modal-box input[type="text"]:focus,
.modal-box textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 12px var(--primary-glow);
}
.modal-box input[type="text"]:hover,
.modal-box textarea:hover {
  border-color: var(--border-active);
}
.modal-box textarea { resize: vertical; }
.modal-close {
  float: right; background: none; border: none; color: var(--text3); cursor: pointer;
  font-size: 20px; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.path-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-radius: var(--radius-sm); transition: background var(--transition-fast);
}
.path-item:hover { background: var(--bg-surface); }
.path-item input[type="checkbox"] { accent-color: var(--primary); width: 16px; height: 16px; flex-shrink: 0; }
.path-item .path-title { font-size: 14px; color: var(--text); flex: 1; }
.path-item .path-depth { font-size: 11px; color: var(--text3); flex-shrink: 0; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.compose-context {
  background: rgba(0,0,0,0.2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; margin-top: 12px; max-height: 200px; overflow-y: auto;
  font-size: 12px; color: var(--text2); white-space: pre-wrap; line-height: 1.5;
  font-family: var(--font-mono);
}

/* Centered views */
#view-login.active, #view-create.active { display: flex; align-items: center; justify-content: center; }
#view-search {
  position: absolute; inset: 0; padding: 40px 16px;
  box-sizing: border-box; overflow-y: auto;
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }
::-webkit-scrollbar-corner { background: transparent; }

/* Help Overlay */
body.keyboard-active, body.keyboard-active * { cursor: none !important; }
#helpTrigger {
  position: fixed; bottom: 20px; right: 20px; z-index: 998;
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,0.08); backdrop-filter: blur(8px);
  display: none; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text2); font-size: 16px; font-weight: 700;
  border: 1px solid var(--border);
  transition: all var(--transition);
  font-family: var(--font);
}
#helpTrigger:hover { background: rgba(255,255,255,0.15); color: var(--text); border-color: var(--border-active); }
#helpOverlay {
  position: fixed; bottom: 64px; right: 20px; z-index: 998;
  background: rgba(13,40,24,0.92); backdrop-filter: blur(16px);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 20px; min-width: 220px;
  transition: opacity 0.4s ease;
  opacity: 0; pointer-events: none;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}
#helpOverlay .help-table { width: 100%; border-collapse: collapse; }
#helpOverlay .help-table th {
  font-size: 14px; color: var(--primary); padding: 4px 8px 10px;
  text-align: center; font-weight: 700; letter-spacing: 1px;
}
#helpOverlay .help-table td { font-size: 12px; color: var(--text2); padding: 4px 8px; }
#helpOverlay .help-table td.key {
  color: var(--text); font-weight: 600; font-family: var(--font-mono);
  white-space: nowrap; width: 80px; text-align: right;
}
#helpOverlay .help-table td.key .key-sub { font-size: 10px; color: var(--text3); font-family: var(--font); }
#helpOverlay .help-table td.help-sep {
  text-align: center; color: var(--text3); font-size: 11px;
  padding: 8px 8px 4px; letter-spacing: 0.5px;
}
#helpDismissBtn {
  display: block; margin: 10px auto 0; padding: 4px 14px;
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px; color: rgba(255,255,255,0.7); font-size: 12px; cursor: pointer;
  font-family: var(--font);
}
#helpDismissBtn:hover { background: rgba(255,255,255,0.2); }

@media (max-width: 768px) {
  .reading-toggle-btn { display: inline-flex !important; }
  #view-node > .action-bar { gap: 6px; }
  #view-node > .action-bar .btn {
    padding: 6px 12px; font-size: 12px;
  }
  #storyActions.action-bar { gap: 6px; }
  #storyActions.action-bar .btn {
    padding: 6px 12px; font-size: 12px;
  }
}
@media (max-width: 400px) {
  .modal-box { padding: 16px; }
}

/* ========== Reading Mode ========== */
.reading-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 900;
}
.reading-box {
  background: var(--bg-mid);
  border: 1px solid var(--border-active);
  border-radius: var(--radius);
  width: 90%; max-width: 800px; height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
  overflow: hidden;
}
.reading-topbar {
  display: flex; align-items: center; padding: 10px 12px;
  border-bottom: 1px solid var(--border); gap: 8px; flex-shrink: 0;
}
.reading-parent-btn {
  border: none; background: none; color: var(--primary); font-size: 14px;
  cursor: pointer; padding: 4px 8px; border-radius: 6px; white-space: nowrap;
}
.reading-parent-btn:hover { background: rgba(82,183,136,0.1); }
.reading-topbar-title {
  flex: 1; font-size: 16px; font-weight: 700; text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reading-close-btn {
  border: none; background: none; color: var(--text2); font-size: 22px;
  cursor: pointer; padding: 4px 8px; border-radius: 6px; line-height: 1;
}
.reading-close-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.reading-stage {
  flex: 1; display: flex; overflow: hidden; position: relative;
  touch-action: pan-y; user-select: none;
}
.reading-card {
  flex: 0 0 100%; display: flex; flex-direction: column;
  overflow-y: auto;
}
.reading-card-inner {
  padding: 24px 10%; font-size: 18px; line-height: 1.9;
  word-wrap: break-word; overflow-wrap: break-word;
  color: var(--text);
}
.reading-card-inner h1 { font-size: 22px; margin-bottom: 16px; }
.reading-card-inner .node-detail-signature {
  display: block; margin-top: 20px; text-align: right;
  font-size: 14px; color: var(--text3);
}
.reading-children-bar {
  flex-shrink: 0; border-top: 1px solid var(--border);
  overflow-x: auto; overflow-y: hidden; padding: 10px 20px;
  -webkit-overflow-scrolling: touch;
  display: flex; align-items: center;
}
.reading-children-wrap { display: flex; gap: 8px; white-space: nowrap; justify-content: flex-end; }
.reading-child {
  display: inline-flex; align-items: center; padding: 6px 14px;
  border-radius: 8px; cursor: pointer; font-size: 13px;
  background: var(--bg-surface); color: var(--primary);
  transition: all var(--transition-fast); flex-shrink: 0;
}
.reading-child:hover { background: var(--primary); color: #fff; }
.reading-child:active { transform: scale(0.95); }
.reading-child.empty { background: none; color: var(--text3); cursor: default; }
.reading-foreshadow {
  margin-top: 40px; padding: 20px 16px 16px;
  border-top: 1px dashed var(--border);
  font-family: 'KaiTi', 'STKaiti', 'Noto Serif SC', serif;
  color: var(--text2); line-height: 1.9;
}
.reading-foreshadow-label {
  font-size: 13px; font-weight: 600; color: var(--text3);
  margin-bottom: 10px; letter-spacing: 0.5px;
}
.reading-foreshadow-content {
  font-size: 15px; font-style: italic;
  opacity: 0.85;
}
.reading-preview {
  position: absolute; top: 0; bottom: 0;
  display: flex; align-items: center;
  padding: 0 12px; font-size: 14px; font-weight: 600;
  color: var(--primary); pointer-events: none;
  z-index: 10; opacity: 0;
  white-space: nowrap; overflow: hidden;
  max-width: 45%; text-overflow: ellipsis;
}
.reading-preview:first-child { left: 0; justify-content: flex-start; }
.reading-preview:last-child { right: 0; justify-content: flex-end; }
body.read-mode-off .btn-read { display: none !important; }
.reading-exit-btn {
  flex-shrink: 0; width: 30px; height: 30px; margin-right: 8px; align-self: center;
  border: 1px solid var(--border); border-radius: 50%; cursor: pointer;
  background: var(--bg-surface); color: var(--text2);
  display: inline-flex; align-items: center; justify-content: center;
  outline: none; transition: all 0.15s;
}
.reading-exit-btn:hover { border-color: var(--text3); color: var(--text); }
.reading-exit-btn:active { transform: scale(0.9); }
@media (max-width: 768px) {
  .reading-overlay { background: rgba(0,0,0,0.5); }
  .reading-box { width: 100%; max-width: 100%; height: 100%; border-radius: 0; border: none; }
}

