/* ------------------------------ Shared motion tokens ------------------------------ */
:root {
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-soft: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.42, 0.64, 1);
  --motion-slow: 420ms var(--ease-out);
  --motion-theme: 420ms var(--ease-soft);
}

/* ------------------------------ Theme switch: cross-fade every surface ------------------------------ */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
  transition: background-color var(--motion-theme), color var(--motion-theme),
    border-color var(--motion-theme), outline-color var(--motion-theme),
    fill var(--motion-theme), stroke var(--motion-theme),
    box-shadow var(--motion-theme) !important;
  transition-delay: 0s !important;
}

html.theme-transition .theme-swatch,
html.theme-transition .accent-dot {
  transition: none !important;
}

/* Gentle entrance for the whole app shell */
@keyframes dianwofade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dianwo-pop {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ============================================================
   App shell — sidebar collapse
   ============================================================ */

.workspace {
  transition: grid-template-columns var(--motion-slow);
}

.sidebar {
  transition: opacity 220ms var(--ease-soft), transform var(--motion-slow);
  will-change: opacity;
}

body.sidebar-collapsed .workspace {
  grid-template-columns: 0px var(--list-width) minmax(0, 1fr);
}

body.sidebar-collapsed .sidebar {
  opacity: 0;
  transform: translateX(-12px);
  pointer-events: none;
  overflow: hidden;
  border-right-color: transparent;
}

.topbar-sidebar-toggle {
  transition: transform var(--normal), background var(--fast), color var(--fast);
}

body.sidebar-collapsed .topbar-sidebar-toggle {
  transform: rotate(180deg);
}

/* Refined editor surface */
.editor-doc {
  animation: dianwofade-up 420ms var(--ease-out) both;
}

.editor-title {
  letter-spacing: -0.035em;
}

.editor-toolbar {
  transition: border-color var(--normal), box-shadow var(--normal),
    background var(--normal);
}

/* Mode + preview transitions */
.mode-toggle button {
  transition: background var(--fast), color var(--fast), transform var(--fast),
    box-shadow var(--fast);
}

.mode-toggle button:active {
  transform: scale(0.96);
}

.mode-toggle button.is-active {
  animation: none;
}

.preview-btn {
  transition: background var(--fast), color var(--fast), transform var(--fast),
    border-color var(--fast);
}

.preview-btn:active {
  transform: scale(0.97);
}

/* Markdown panes slide gently into place when preview opens */
.md-shell {
  transition: opacity var(--normal);
}

.md-shell.show-preview .md-pane--preview {
  animation: dianwofade-up 320ms var(--ease-out) both;
}

.md-shell.show-preview .md-source {
  transition: padding var(--normal), background var(--normal), font-size var(--normal);
}

/* Buttons: subtle press feedback */
.btn {
  transition: transform 200ms var(--ease-spring), box-shadow var(--fast),
    background var(--fast), border-color var(--fast), color var(--fast);
}

.btn:not(:disabled):hover {
  transform: none;
}

.btn:active:not(:disabled) {
  transform: translateY(0.5px) scale(0.99);
  transition-duration: 90ms;
}

.btn-primary:not(:disabled):hover {
  box-shadow: 0 3px 10px color-mix(in srgb, var(--accent) 18%, transparent);
}

.btn-primary:not(:disabled):active {
  box-shadow: 0 1px 4px color-mix(in srgb, var(--accent) 16%, transparent);
}

.icon-btn {
  transition: transform 200ms var(--ease-spring), background var(--fast),
    color var(--fast);
}

.icon-btn:active {
  transform: scale(0.88);
}

/* List polish */
.note-card {
  border-radius: var(--radius);
}

.note-card.is-active::before {
  border-radius: var(--radius);
}

.side-item {
  transition: background var(--fast), color var(--fast), transform var(--fast);
}

.side-item:active {
  transform: scale(0.985);
}

/* Search box focus glow */
.search-box {
  transition: box-shadow var(--normal), border-color var(--normal), background var(--normal);
}

.search-box:focus-within {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent);
}

/* Storage bar animate on change */
.storage-bar i {
  transition: width var(--motion-slow);
}

/* ============================================================
   Auth pages — centered brand copy, local-mode toggle
   ============================================================ */

.auth-brand {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

/* Soft ambient glow behind the brand copy */
.auth-brand::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: -20%;
  left: -30%;
  width: 115%;
  height: 115%;
  background: radial-gradient(
    circle at 32% 42%,
    color-mix(in srgb, var(--accent) 12%, transparent) 0%,
    color-mix(in srgb, var(--accent) 5%, transparent) 32%,
    transparent 62%
  );
  pointer-events: none;
}

.auth-brand::after {
  content: "";
  position: absolute;
  z-index: -1;
  right: -60px;
  bottom: -90px;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--accent) 8%, transparent),
    transparent 70%
  );
  pointer-events: none;
}

.brand-top,
.brand-copy,
.brand-foot {
  position: relative;
  z-index: 1;
}

/* Center the two lines of copy vertically on the left panel */
.brand-copy {
  margin: auto 0;
  padding-top: 0;
  animation: dianwofade-up 520ms var(--ease-out) both;
}

.brand-foot {
  margin-top: 0;
  padding-top: 0;
  opacity: 0.7;
  font-size: 11.5px;
}

.brand-copy h1 {
  font-size: clamp(30px, 3.4vw, 44px);
  line-height: 1.16;
}

.brand-copy p {
  font-size: 14px;
}

/* Auth card entrance */
@keyframes auth-card-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.965);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.auth-card {
  animation: auth-card-in 560ms var(--ease-spring) both;
}

.auth-form .field {
  animation: dianwofade-up 420ms var(--ease-out) both;
}

.auth-form .field:nth-child(2) { animation-delay: 45ms; }
.auth-form .field:nth-child(3) { animation-delay: 90ms; }
.auth-form .field:nth-child(4) { animation-delay: 135ms; }
.auth-form .field:nth-child(5) { animation-delay: 180ms; }

/* Input focus glow */
.auth-form .input:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent);
}

/* One-click local mode button */
.auth-local-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 0;
}

.auth-local-btn [data-icon] {
  display: inline-flex;
}

/* Optional email badge */
.label-optional {
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  vertical-align: 1px;
}

.auth-switch {
  animation: dianwofade-up 420ms var(--ease-out) 200ms both;
}

/* Account popover avatar — guarantee centered glyph */
.account-pop-head .avatar,
.topbar-avatar-btn .avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  text-align: center;
}

/* ============================================================
   Quiet color controls — match the restrained design language
   ============================================================ */

.accent-row {
  gap: 10px;
  flex-wrap: wrap;
}

.accent-swatch {
  width: 26px;
  height: 26px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--swatch, var(--accent));
  box-shadow: none;
  filter: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  cursor: pointer;
  position: relative;
  transition: transform var(--fast), box-shadow var(--fast), border-color var(--fast);
}

.accent-swatch svg {
  width: 12px;
  height: 12px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.25));
}

.accent-swatch:hover {
  transform: scale(1.14);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.accent-swatch.is-active {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--swatch, var(--accent));
  border-color: transparent;
  filter: none;
  transform: scale(1.05);
}

.accent-swatch.is-active::after {
  display: none;
}

.accent-custom {
  width: 26px;
  height: 26px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: transform var(--fast), border-color var(--fast), color var(--fast);
}

.accent-custom:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.08);
}

.color-input-wrap {
  height: 32px;
  border-color: var(--border);
}

.custom-theme-box {
  border: 1px solid var(--border);
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 960px) {
  body.sidebar-collapsed .workspace {
    grid-template-columns: 0px var(--list-width) minmax(0, 1fr);
  }
}

@media (max-width: 820px) {
  body.sidebar-collapsed .workspace {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }

  .topbar-sidebar-toggle {
    display: none;
  }
}

.announcement-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 12px 10px;
  padding: 9px 11px;
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent-soft) 78%, var(--surface));
  color: var(--text-secondary);
  font-size: 11.5px;
  line-height: 1.6;
}

.announcement-banner[hidden] {
  display: none;
}

.announcement-mark {
  display: inline-flex;
  flex: 0 0 auto;
  margin-top: 1px;
  color: var(--accent);
}

.announcement-mark svg {
  width: 13px;
  height: 13px;
}

.announcement-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

.note-limit {
  font-size: 11px;
  line-height: 1;
  padding: 3px 7px;
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.note-limit[hidden] {
  display: none;
}

.note-limit.is-full {
  color: var(--accent);
  border-color: var(--border-strong);
}

.manage-user-row {
  align-items: center;
}

.manage-user-row .select {
  min-width: 116px;
}

.editor-content,
.md-shell {
  transition: opacity var(--normal) var(--ease-out);
}

.md-tools .tool-btn,
.rich-tools .tool-btn {
  animation: dianwo-pop 200ms var(--ease-out) both;
}

.editor-toolbar.is-preview .md-tools .tool-btn {
  animation: dianwofade-up 260ms var(--ease-out) both;
}

.editor-toolbar.is-preview .md-tools .tool-btn:nth-child(2) { animation-delay: 12ms; }
.editor-toolbar.is-preview .md-tools .tool-btn:nth-child(3) { animation-delay: 24ms; }
.editor-toolbar.is-preview .md-tools .tool-btn:nth-child(4) { animation-delay: 36ms; }

/* ============================================================
   Interaction micro-motion
   ============================================================ */

/* Theme toggle icons spin in whenever the theme flips */
#themeBtn svg,
#themeQuickBtn svg {
  animation: theme-icon-in 460ms var(--ease-spring) both;
}

@keyframes theme-icon-in {
  from {
    opacity: 0;
    transform: rotate(-100deg) scale(0.5);
  }
  to {
    opacity: 1;
    transform: rotate(0deg) scale(1);
  }
}

/* Large dialogs: springy pop with a subtler travel */
.settings-modal {
  transform: translateY(14px) scale(0.975);
}

.modal-backdrop.is-open .settings-modal {
  transform: translateY(0) scale(1);
}

/* Segmented control — springy selection */
.segmented button {
  transition: background var(--fast), color var(--fast), box-shadow var(--fast),
    transform 220ms var(--ease-spring);
}

.segmented button:active {
  transform: scale(0.95);
}

.segmented button.is-active,
.segmented button[aria-selected="true"] {
  animation: dianwo-pop 240ms var(--ease-spring);
}

/* Settings nav — press feedback, pane fades in on switch */
.settings-nav-item {
  transition: background var(--fast), color var(--fast),
    transform 200ms var(--ease-spring);
}

.settings-nav-item:active {
  transform: scale(0.98);
}

.settings-pane {
  animation: dianwofade-up 260ms var(--ease-out) both;
}

/* Lists — a touch of lift on hover */
.note-card {
  transition: background var(--fast), border-color var(--fast),
    box-shadow var(--fast), transform 220ms var(--ease-spring);
}

.note-card:hover {
  transform: translateY(-1px);
}

.note-card:active {
  transform: translateY(0) scale(0.995);
}

.side-item {
  transition: background var(--fast), color var(--fast),
    transform 200ms var(--ease-spring);
}

.side-item:active {
  transform: scale(0.98);
}

/* Menu items — quick press feedback */
.menu-item {
  transition: background var(--fast), color var(--fast),
    transform 160ms var(--ease-spring);
}

.menu-item:active {
  transform: scale(0.985);
}

/* Theme cards — hover lift, selected pop */
.theme-card {
  transition: transform 240ms var(--ease-spring), border-color var(--fast),
    box-shadow var(--fast), background var(--fast);
}

.theme-card:hover {
  transform: translateY(-2px);
}

.theme-card:active {
  transform: translateY(0) scale(0.985);
}

/* Accent swatches — tactile press */
.accent-dot,
.theme-swatch {
  transition: transform 200ms var(--ease-spring), box-shadow var(--fast);
}

.accent-dot:active,
.theme-swatch:active {
  transform: scale(0.9);
}

/* Switch — squash while pressed for a tactile feel */
.switch:active .switch-track::after {
  transform: scale(0.92);
}

.switch input:checked:active + .switch-track::after {
  transform: translateX(16px) scale(0.92);
}

@media (prefers-reduced-motion: reduce) {
  .editor-doc,
  .auth-brand::before,
  .brand-copy,
  .auth-card,
  .auth-form .field,
  .auth-switch,
  .md-shell.show-preview .md-pane--preview,
  .mode-toggle button.is-active,
  .settings-pane,
  .segmented button.is-active,
  .segmented button[aria-selected="true"],
  .md-tools .tool-btn,
  .rich-tools .tool-btn,
  #themeBtn svg,
  #themeQuickBtn svg {
    animation: none !important;
  }

  .workspace,
  .sidebar,
  .md-shell,
  .btn,
  .icon-btn,
  .note-card,
  .side-item,
  .menu-item,
  .theme-card,
  .settings-nav-item,
  .accent-dot,
  .theme-swatch,
  .switch-track::after,
  .modal,
  .modal-backdrop {
    transition: none !important;
  }

  html.theme-transition,
  html.theme-transition * {
    transition: none !important;
  }
}