/* Logo */
.logo {
  font-weight: 600;
  font-size: var(--text-lg);
  letter-spacing: -0.02em;
  text-transform: lowercase;
  user-select: none;
}

.logo-serif {
  font-family: var(--font-serif);
  font-weight: 400;
  font-style: italic;
  letter-spacing: 0.01em;
}

/* Theme toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding-bottom: 2px;
  border-radius: var(--radius-full);
  color: var(--color-text-secondary);
  background-color: light-dark(#fcfcfd, var(--gray-800));
  box-shadow:
    light-dark(rgba(45, 35, 66, 0.3), rgba(0, 0, 0, 0.35)) 0 1px 3px,
    light-dark(#d6d6e7, rgba(255, 255, 255, 0.06)) 0 -2px 0 inset;
  transition: color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
  will-change: box-shadow, transform;
}

.theme-toggle:hover {
  color: var(--color-text);
  transform: translateY(-2px);
  box-shadow:
    light-dark(rgba(45, 35, 66, 0.35), rgba(0, 0, 0, 0.4)) 0 3px 6px,
    light-dark(#d6d6e7, rgba(255, 255, 255, 0.08)) 0 -2px 0 inset;
}

.theme-toggle:active {
  transform: translateY(1px);
  box-shadow:
    light-dark(#d6d6e7, rgba(255, 255, 255, 0.04)) 0 2px 5px inset;
}

/* Editor */
.editor {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  padding: var(--space-lg);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.7;
  color: var(--color-text);
  caret-color: var(--color-accent);
  background-color: var(--color-surface);
  border: none;
  border-radius: var(--radius-lg);
  outline: none;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow:
    light-dark(rgba(35, 17, 120, 0.15), rgba(255, 255, 255, 0.08)) 0 0 0 1px,
    0 1px 3px light-dark(rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.4)),
    0 8px 24px light-dark(rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.15));
  transition: border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
  -webkit-overflow-scrolling: touch;
}

.editor:focus {
  box-shadow:
    var(--accent-ring) 0 0 0 1px,
    0 0 0 3px var(--accent-ring-glow),
    0 1px 3px light-dark(rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.4)),
    0 8px 24px light-dark(rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.15));
}

.editor:empty::before {
  content: attr(data-placeholder);
  color: var(--color-text-tertiary);
  pointer-events: none;
}

.editor.flash {
  animation: editor-flash 400ms var(--ease-out);
}

/* Action button */
.action-btn {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  height: 48px;
  padding: 0 var(--space-lg);
  font-weight: 500;
  font-size: var(--text-sm);
  color: var(--color-accent-text);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
  background: linear-gradient(
    to bottom,
    var(--accent-gradient-top) 0%,
    light-dark(var(--accent-500), var(--accent-400)) 100%
  );
  border: none;
  border-radius: var(--radius-lg);
  box-shadow:
    inset 0 1px 0 0 light-dark(rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0.15)),
    var(--accent-btn-base) 0 -3px 0 0 inset,
    var(--accent-btn-shadow) 0 2px 4px,
    var(--accent-btn-shadow-lg) 0 7px 13px -3px;
  transition: box-shadow var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
  will-change: box-shadow, transform;
}

.action-btn:hover {
  transform: translateY(-2px);
  box-shadow:
    inset 0 1px 0 0 light-dark(rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.2)),
    var(--accent-btn-base) 0 -3px 0 0 inset,
    light-dark(rgba(21, 10, 100, 0.4), rgba(0, 0, 0, 0.5)) 0 4px 8px,
    light-dark(rgba(21, 10, 100, 0.3), rgba(0, 0, 0, 0.35)) 0 7px 13px -3px;
}

.action-btn:active {
  transform: translateY(2px);
  box-shadow:
    light-dark(rgba(15, 7, 102, 0.5), rgba(0, 0, 0, 0.4)) 0 3px 7px inset;
}

.action-btn-chevron {
  flex-shrink: 0;
  opacity: 0.7;
}

/* Undo button */
.undo-btn {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  color: var(--color-text-secondary);
  background-color: light-dark(#fcfcfd, var(--gray-800));
  border: none;
  border-radius: var(--radius-lg);
  box-shadow:
    light-dark(rgba(45, 35, 66, 0.4), rgba(0, 0, 0, 0.45)) 0 2px 4px,
    light-dark(rgba(45, 35, 66, 0.3), rgba(0, 0, 0, 0.3)) 0 7px 13px -3px,
    light-dark(#d6d6e7, rgba(255, 255, 255, 0.08)) 0 -3px 0 inset;
  transition: opacity var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
  will-change: box-shadow, transform;
}

.undo-btn:disabled {
  opacity: 0.35;
}

.undo-btn:not(:disabled):hover {
  color: var(--color-text);
  transform: translateY(-2px);
  box-shadow:
    light-dark(rgba(45, 35, 66, 0.4), rgba(0, 0, 0, 0.5)) 0 4px 8px,
    light-dark(rgba(45, 35, 66, 0.3), rgba(0, 0, 0, 0.35)) 0 7px 13px -3px,
    light-dark(#d6d6e7, rgba(255, 255, 255, 0.1)) 0 -3px 0 inset;
}

.undo-btn:not(:disabled):active {
  transform: translateY(2px);
  box-shadow:
    light-dark(#d6d6e7, rgba(255, 255, 255, 0.06)) 0 3px 7px inset;
}

/* Bottom sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: var(--color-backdrop);
  backdrop-filter: blur(0px);
  -webkit-backdrop-filter: blur(0px);
  opacity: 0;
  z-index: 100;
  transition: opacity var(--duration-normal) var(--ease-out),
    backdrop-filter var(--duration-normal) var(--ease-out),
    -webkit-backdrop-filter var(--duration-normal) var(--ease-out);
  pointer-events: none;
}

.sheet-backdrop.open {
  opacity: 1;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 70dvh;
  background: var(--color-surface-elevated);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-sheet);
  z-index: 101;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform var(--duration-slow) var(--ease-spring);
}

.sheet.open {
  transform: translateY(0);
}

@media (min-width: 641px) {
  .sheet {
    left: 50%;
    right: auto;
    width: 480px;
    margin-left: -240px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
}

.sheet-handle {
  display: flex;
  justify-content: center;
  padding: var(--space-sm) 0 var(--space-xs);
  flex-shrink: 0;
}

.sheet-handle::after {
  content: '';
  width: 36px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--color-text-tertiary);
}

.sheet-search-wrapper {
  padding: var(--space-xs) var(--space-md) var(--space-sm);
  flex-shrink: 0;
}

.sheet-search {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-surface);
  border: none;
  border-radius: var(--radius-md);
  outline: none;
  box-shadow: light-dark(rgba(35, 17, 120, 0.15), rgba(255, 255, 255, 0.08)) 0 0 0 1px;
  transition: box-shadow var(--duration-fast) var(--ease-out);
}

.sheet-search::placeholder {
  color: var(--color-text-tertiary);
}

.sheet-search:focus {
  box-shadow:
    var(--accent-ring) 0 0 0 1px,
    0 0 0 3px var(--accent-ring-glow);
}

.sheet-list {
  overflow-y: auto;
  padding: 0 var(--space-sm) max(var(--space-md), env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

.sheet-category {
  padding: var(--space-sm) var(--space-sm) var(--space-xs);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-tertiary);
}

.sheet-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-lg);
  text-align: left;
  transition: background-color var(--duration-normal) var(--ease-out),
              box-shadow var(--duration-normal) var(--ease-out);
}

.sheet-item:hover {
  background: light-dark(var(--gray-900), var(--gray-100));
  box-shadow:
    light-dark(rgba(0, 0, 0, 0.15), rgba(255, 255, 255, 0.08)) 0 2px 8px,
    light-dark(rgba(0, 0, 0, 0.08), rgba(255, 255, 255, 0.04)) 0 8px 24px;
}

.sheet-item:active {
  background: light-dark(var(--gray-800), var(--gray-200));
  box-shadow: none;
}

.sheet-item-name {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  transition: color var(--duration-normal) var(--ease-out);
}

.sheet-item:hover .sheet-item-name {
  color: light-dark(var(--white), var(--gray-900));
}

.sheet-item:active .sheet-item-name {
  color: light-dark(var(--gray-100), var(--gray-950));
}

.sheet-item-desc {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  transition: color var(--duration-normal) var(--ease-out);
}

.sheet-item:hover .sheet-item-desc {
  color: light-dark(var(--gray-400), var(--gray-500));
}

.sheet-item:active .sheet-item-desc {
  color: light-dark(var(--gray-500), var(--gray-600));
}

.sheet-empty {
  padding: var(--space-xl) var(--space-md);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
}

/* Focus-visible styles */
.action-btn:focus-visible {
  outline: none;
  box-shadow:
    inset 0 1px 0 0 light-dark(rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0.15)),
    var(--accent-btn-base) 0 -3px 0 0 inset,
    0 0 0 2px light-dark(var(--color-bg), var(--gray-950)),
    0 0 0 4px light-dark(var(--accent-500), var(--accent-400));
}

.undo-btn:focus-visible {
  outline: none;
  box-shadow:
    light-dark(#d6d6e7, rgba(255, 255, 255, 0.08)) 0 -3px 0 inset,
    0 0 0 2px light-dark(var(--color-bg), var(--gray-950)),
    0 0 0 4px light-dark(var(--accent-500), var(--accent-400));
}

.theme-toggle:focus-visible {
  outline: none;
  box-shadow:
    light-dark(#d6d6e7, rgba(255, 255, 255, 0.06)) 0 -2px 0 inset,
    0 0 0 2px light-dark(var(--color-bg), var(--gray-950)),
    0 0 0 4px light-dark(var(--accent-500), var(--accent-400));
}

.sheet-item:focus-visible {
  outline: none;
  background: light-dark(var(--gray-900), var(--gray-100));
  box-shadow:
    inset 0 0 0 2px var(--accent-ring-subtle);
}

.sheet-item:focus-visible .sheet-item-name {
  color: light-dark(var(--white), var(--gray-900));
}

.sheet-item:focus-visible .sheet-item-desc {
  color: light-dark(var(--gray-400), var(--gray-500));
}

/* Tooltip */
.tooltip {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  padding: 6px 12px;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  color: light-dark(var(--gray-100), var(--gray-900));
  background-color: light-dark(var(--gray-900), var(--gray-200));
  border-radius: var(--radius-md);
  white-space: nowrap;
  pointer-events: none;
  z-index: 50;
  opacity: 0;
  transform: translateX(-50%) scale(0.95);
  transform-origin: bottom center;
  transition: opacity var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}

.tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: light-dark(var(--gray-900), var(--gray-200));
}

.tooltip-right {
  left: auto;
  right: 0;
  transform: translateX(0) scale(0.95);
}

.tooltip-right::after {
  left: auto;
  right: 12px;
  transform: none;
}

[data-tooltip]:hover .tooltip,
[data-tooltip]:focus-visible .tooltip {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

[data-tooltip]:hover .tooltip-right,
[data-tooltip]:focus-visible .tooltip-right {
  transform: translateX(0) scale(1);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%) translateY(8px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  color: light-dark(var(--gray-100), var(--gray-900));
  background-color: light-dark(var(--gray-900), var(--gray-200));
  border-radius: var(--radius-full);
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  white-space: nowrap;
}

.toast::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: var(--radius-full);
  background-color: #34d399;
  box-shadow: 0 0 6px 1px rgba(52, 211, 153, 0.5);
  flex-shrink: 0;
}

/* Marker highlight */
.content-lede-heading mark {
  margin: 0 -0.4em;
  padding: 0.1em 0.4em;
  border-radius: 0.8em 0.3em;
  background-color: transparent;
  background-image: linear-gradient(
    to right,
    light-dark(rgba(255, 225, 0, 0.1), rgba(255, 225, 0, 0.05)),
    light-dark(rgba(255, 225, 0, 0.7), rgba(255, 225, 0, 0.25)) 4%,
    light-dark(rgba(255, 225, 0, 0.3), rgba(255, 225, 0, 0.12))
  );
  color: inherit;
  text-shadow: 0 1px 1px light-dark(rgba(255, 240, 150, 0.9), rgba(0, 0, 0, 0.5));
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

/* Prevent iOS Safari auto-zoom on focus (triggers at < 16px) */
@supports (-webkit-touch-callout: none) {
  .editor,
  .sheet-search {
    font-size: var(--text-base);
  }
}
