:root {
  --bg: #f6f6f6;
  --paper: #fff;
  --ink: #202122;
  --muted: #54595d;
  --line: #c8ccd1;
  --accent: #36c;
  --topbar-h: 52px;
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: "Linux Libertine", Georgia, Times, serif;
  font-size: 22px;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.search { flex: 0 1 460px; }

.search input {
  width: 100%;
  height: 34px;
  padding: 0 12px;
  font: inherit;
  font-size: 15px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}

.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  font: inherit;
  cursor: pointer;
}

#main-host {
  display: block;
  max-width: 1040px;
  margin: 16px auto 80px;
  padding: 24px 40px 40px;
  background: var(--paper);
  border: 1px solid #eaecf0;
  border-radius: 4px;
}

.wx-popup {
  --hue: 215;
  position: fixed;
  display: flex;
  flex-direction: column;
  min-width: 280px;
  min-height: 160px;
  background: var(--paper);
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-top: 3px solid hsl(var(--hue) 25% 70%);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  resize: both;
  transition: box-shadow 220ms ease, border-color 220ms ease;
}

.wx-popup.note { min-height: 0; }

/* The key window: the one Cmd+W and Esc close. Background windows recede like inactive macOS windows. */
.wx-popup.focused {
  border-top-color: hsl(var(--hue) 60% 50%);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.26), 0 3px 10px rgba(0, 0, 0, 0.12);
}

.wx-popup.dragging {
  transition: none;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.14);
}

.wx-popup:not(.focused) .wx-bar { background: #fbfbfc; }

.wx-popup:not(.focused) .wx-title { color: var(--muted); }

.wx-popup:not(.focused) .wx-depth { background: hsl(var(--hue) 20% 72%); }

.wx-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 32px;
  padding: 0 4px;
  background: #f8f9fa;
  border-bottom: 1px solid #eaecf0;
  cursor: grab;
  user-select: none;
}

.wx-bar:active { cursor: grabbing; }

.wx-bar button {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.wx-bar button:hover:not(:disabled) { background: #eaecf0; color: var(--ink); }

.wx-bar button:active:not(:disabled),
#trail button:active { transform: scale(0.92); }

.wx-bar button:disabled { opacity: 0.3; cursor: default; }

.wx-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
  font-size: 13px;
  font-weight: 600;
  transition: color 220ms ease;
}

.wx-title-text {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.wx-depth {
  flex: none;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: hsl(var(--hue) 60% 50%);
  color: #fff;
  transition: background-color 220ms ease;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

.wx-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 12px 20px 24px;
}

.note .wx-scroll { padding: 10px 14px 12px; }

#trail {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 2147483000;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  max-width: calc(100vw - 24px);
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  font-size: 12px;
}

#trail button {
  max-width: 220px;
  padding: 2px 8px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--accent);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: background-color 120ms ease, transform 120ms ease;
}

#trail button:hover { background: #eaecf0; }

#trail .sep { color: var(--muted); }

@media (max-width: 699px) {
  .topbar { gap: 10px; padding: 0 10px; }
  .brand { font-size: 18px; }
  .search { flex: 1 1 auto; min-width: 0; }
  #main-host { margin: 0; padding: 12px 16px 40px; border: 0; border-radius: 0; }
  #trail { display: none !important; }
  .wx-popup.sheet { resize: none; min-width: 0; border-radius: 14px; }
  .wx-popup.sheet .wx-bar { height: 40px; cursor: default; }
  .wx-popup.sheet .wx-bar button { width: 36px; height: 32px; font-size: 16px; }
  .wx-popup.sheet .wx-title { font-size: 14px; }
  .wx-popup.sheet .wx-scroll { padding: 10px 14px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; scroll-behavior: auto !important; }
}
