: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;
}

.brand span { color: var(--accent); }

.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; }

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

kbd {
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 1px 4px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 3px;
  background: var(--paper);
}

button {
  font: inherit;
  cursor: pointer;
}

.ghost {
  font-size: 13px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  white-space: nowrap;
}

.ghost:hover { background: #eaecf0; }

#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 #a2a9b1;
  border-top: 3px solid hsl(var(--hue) 60% 50%);
  border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22), 0 2px 6px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  resize: both;
  animation: wx-pop-in 120ms ease-out;
}

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

.wx-popup.pinned { border-color: hsl(var(--hue) 50% 45%); }

.wx-popup.flash { animation: wx-flash 600ms ease-out; }

@keyframes wx-pop-in {
  from { transform: translateY(4px) scale(0.99); }
}

@keyframes wx-flash {
  0%, 60% { box-shadow: 0 0 0 4px hsl(var(--hue) 70% 55% / 0.6), 0 12px 40px rgba(0, 0, 0, 0.22); }
}

.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,
.wx-bar a {
  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;
  text-decoration: none;
  cursor: pointer;
}

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

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

.wx-bar .pin { filter: grayscale(1); opacity: 0.45; font-size: 12px; }

.wx-bar .pin[aria-pressed="true"] { filter: none; opacity: 1; }

.wx-bar .pin[aria-pressed="true"] { color: hsl(var(--hue) 60% 42%); background: hsl(var(--hue) 70% 94%); }

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

.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;
  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;
}

#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; }
  .hint { display: none; }
  .topbar-actions { flex: none; }
  #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: 12px; }
  .wx-popup.sheet .wx-bar { height: 40px; cursor: default; }
  .wx-popup.sheet .wx-bar button,
  .wx-popup.sheet .wx-bar a { width: 36px; height: 32px; font-size: 16px; }
  .wx-popup.sheet .wx-bar .pin { display: none; }
  .wx-popup.sheet .wx-title { font-size: 14px; }
  .wx-popup.sheet .wx-scroll { padding: 10px 14px 20px; }
}
