/* The citation generator (/cite). Colors come from the site's tokens in
   /style.css, so light and dark follow the light bulb. */
.cite-page {
  --card: #ffffff;
  --field: #ffffff;
  --field-line: rgba(0, 0, 0, 0.14);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 28px rgba(0, 0, 0, 0.05);
  --danger: #d70015;
  --ok: #248a3d;
  --serif: "Times New Roman", Times, Georgia, serif;
  background: var(--bg-alt);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .cite-page {
    --card: #1c1c1e;
    --field: #2c2c2e;
    --field-line: rgba(255, 255, 255, 0.14);
    --shadow: none;
    --danger: #ff453a;
    --ok: #30d158;
    background: var(--bg);
  }
}
:root[data-theme="dark"] .cite-page {
  --card: #1c1c1e;
  --field: #2c2c2e;
  --field-line: rgba(255, 255, 255, 0.14);
  --shadow: none;
  --danger: #ff453a;
  --ok: #30d158;
  background: var(--bg);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.spacer { flex: 1; }

.cite {
  max-width: 820px;
  margin: 0 auto;
  padding: 104px 22px 56px;
}
.cite-head { text-align: center; margin-bottom: 36px; }
.cite-head h1 {
  margin: 0;
  font-size: clamp(40px, 7vw, 64px);
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: -0.035em;
}
.cite-sub {
  max-width: 540px;
  margin: 14px auto 0;
  color: var(--muted);
  font-size: clamp(17px, 2.2vw, 21px);
  line-height: 1.38;
  letter-spacing: -0.02em;
}

.cite-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

/* ---------- buttons and fields ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border: 1px solid var(--field-line);
  border-radius: 980px;
  background: var(--field);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .2s var(--ease), opacity .2s, transform .15s var(--ease);
}
.btn:hover { background: var(--line); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; transform: none; }
.btn:focus-visible, .chip:focus-visible, .link-btn:focus-visible, .seg button:focus-visible, .result:focus-visible {
  outline: 2px solid var(--link); outline-offset: 2px;
}
.btn-primary { border-color: transparent; background: var(--button); color: #fff; }
.btn-primary:hover { background: var(--button-hover); }
.btn-danger { border-color: transparent; background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); opacity: .9; }
.btn-icon { width: 36px; padding: 0; }
.btn-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.btn-icon svg circle { fill: currentColor; stroke: none; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--faint); }
.chev { width: 10px; height: 10px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.link-btn {
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--link);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }

.select {
  height: 36px;
  max-width: 100%;
  padding: 0 34px 0 14px;
  border: 1px solid var(--field-line);
  border-radius: 980px;
  background: var(--field) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 7.5l3-3' fill='none' stroke='%2386868b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center / 11px;
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.select:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.select-sm { height: 32px; font-size: 13px; }

/* ---------- the search box ---------- */
.find {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 46px;
  border: 1px solid var(--field-line);
  border-radius: 16px;
  background: var(--field);
  transition: border-color .2s, box-shadow .2s;
}
.find:focus-within { border-color: var(--button); box-shadow: 0 0 0 4px color-mix(in srgb, var(--button) 18%, transparent); }
.find-icon {
  position: absolute; left: 16px; top: 50%;
  width: 20px; height: 20px; margin-top: -10px;
  fill: none; stroke: var(--faint); stroke-width: 1.8; stroke-linecap: round;
}
.find input {
  flex: 1;
  min-width: 0;
  height: 42px;
  border: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 17px;
  outline: none;
}
.find input::placeholder { color: var(--faint); }
.find .btn { height: 42px; padding: 0 22px; border-radius: 12px; font-size: 15px; }
.btn.busy { color: transparent; position: relative; }
.btn.busy::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.manual { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-top: 14px; }
.manual-label { color: var(--muted); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 980px;
  background: var(--bg-alt);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background-color .2s var(--ease);
}
.chip:hover { background: var(--line); }

.results { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.results-note { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--muted);
  animation: spin .8s linear infinite;
}
.result-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.result {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color .2s var(--ease);
}
.result:hover { background: var(--bg-alt); }
.result-type { color: var(--link); font-size: 12px; font-weight: 600; }
.result-title { font-size: 15px; font-weight: 600; line-height: 1.3; }
.result-meta { color: var(--muted); font-size: 13px; }

/* ---------- the list ---------- */
.bib-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.list-pick { display: flex; gap: 6px; min-width: 0; flex: 1 1 260px; }
.select-list { flex: 0 1 auto; min-width: 0; font-weight: 600; }

.bib-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 20px 0 8px; }
.bib-head h2 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.025em; }
.bib-count { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.bib-actions { display: flex; gap: 8px; }

.bib-list { list-style: none; margin: 0; padding: 0; }
.entry {
  padding: 16px 12px;
  margin: 0 -12px;
  border-radius: 14px;
  border-bottom: 1px solid var(--line);
  transition: background-color .6s var(--ease);
}
.entry:last-child { border-bottom: 0; }
.entry.flash { background: color-mix(in srgb, var(--button) 10%, transparent); }
.entry-ref {
  margin: 0;
  padding-left: 2em;
  text-indent: -2em;
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.5;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}
.entry-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-top: 8px; font-size: 13px; }
.entry-type { color: var(--faint); }
.entry-intext { color: var(--muted); font-family: var(--serif); font-size: 15px; letter-spacing: 0; }
@media (hover: hover) {
  .entry .entry-meta .link-btn { opacity: 0; transition: opacity .15s; }
  .entry:hover .entry-meta .link-btn, .entry:focus-within .entry-meta .link-btn { opacity: 1; }
}

.empty { padding: 36px 12px 20px; text-align: center; color: var(--muted); font-size: 15px; }
.empty p { margin: 0 0 4px; }
.empty strong { color: var(--fg); font-weight: 600; }

.cite-foot { max-width: 640px; margin: 28px auto 0; color: var(--faint); font-size: 12px; line-height: 1.5; text-align: center; }

/* ---------- menus ---------- */
.pop { position: relative; }
.pop-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 5;
  min-width: 220px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--menu);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.16), 0 2px 8px rgba(0, 0, 0, 0.06);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px) scale(.98);
  transform-origin: top right;
  transition: opacity .15s var(--ease), transform .25s var(--ease-out), visibility 0s .25s;
}
/* The list menu hangs from the whole list picker, so it stays on screen on phones. */
.list-pick { position: relative; }
.list-pick .pop { position: static; }
.list-pick .pop-panel { left: 0; right: auto; transform-origin: top left; }
.pop.open .pop-panel { opacity: 1; visibility: visible; transform: none; transition: opacity .15s var(--ease), transform .25s var(--ease-out), visibility 0s; }
.pop-panel button {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.pop-panel button:hover, .pop-panel button:focus-visible { background: var(--line); outline: none; }
.pop-panel button.danger { color: var(--danger); }
.pop-panel hr { margin: 6px 4px; border: 0; border-top: 1px solid var(--line); }

/* ---------- editor sheet ---------- */
.sheet {
  width: min(680px, calc(100vw - 24px));
  max-height: calc(100svh - 48px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--card);
  color: var(--fg);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.sheet[open] { display: flex; animation: sheet-in .3s var(--ease-out); }
.sheet::backdrop { background: rgba(0, 0, 0, 0.35); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
@keyframes sheet-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.sheet-small { width: min(420px, calc(100vw - 24px)); }
.finder { width: min(560px, calc(100vw - 24px)); height: min(640px, calc(100svh - 48px)); }
.finder-field { margin: 14px 0 12px; }
.finder .result { padding: 10px 14px; }
.finder .result-title { font-size: 14px; }
.cite-foot a { color: inherit; }
.cite-foot + .cite-foot { margin-top: 10px; }
.sheet-form { display: flex; flex-direction: column; width: 100%; min-height: 0; margin: 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 22px; }
.sheet-head h2, .sheet-small h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 22px 18px; overscroll-behavior: contain; }
.sheet-small .sheet-body { padding: 22px 22px 10px; }
.ask-text { margin: 8px 0 0; color: var(--muted); font-size: 15px; }
.sheet-small .field { margin-top: 14px; }
.sheet-foot { border-top: 1px solid var(--line); background: var(--bg-alt); }
.sheet-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
.save-to { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.save-to .select { max-width: 180px; }

.notice {
  margin: 0 0 14px;
  padding: 10px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, #ff9f0a 16%, transparent);
  font-size: 14px;
  line-height: 1.4;
}

.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.seg button {
  height: 32px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 980px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.seg button:hover { background: var(--line); }
.seg button[aria-checked="true"] { border-color: var(--fg); background: var(--fg); color: var(--bg); }

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.field { display: grid; gap: 5px; min-width: 0; margin: 0; padding: 0; border: 0; }
.field.wide, .field-people, .field-date { grid-column: 1 / -1; }
.field > span, .field legend { padding: 0; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0; }
.field legend { display: flex; gap: 10px; align-items: baseline; margin-bottom: 5px; }
.field legend .link-btn { font-size: 12px; font-weight: 500; }
.field input, .field select {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--field-line);
  border-radius: 10px;
  background: var(--field);
  color: var(--fg);
  font: inherit;
  font-size: 16px;
  transition: border-color .15s, box-shadow .15s;
}
.field select { -webkit-appearance: none; appearance: none; padding-right: 28px; background: var(--field) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 7.5l3-3' fill='none' stroke='%2386868b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 10px center / 10px; }
.field input:focus, .field select:focus { outline: none; border-color: var(--button); box-shadow: 0 0 0 3px color-mix(in srgb, var(--button) 18%, transparent); }
.field input::placeholder { color: var(--faint); }
.person { display: grid; grid-template-columns: 1fr 1fr 36px; gap: 8px; margin-bottom: 8px; align-items: center; }
.person .btn-icon { height: 36px; }
.add-person { justify-self: start; font-size: 13px; }
.hint { margin: 2px 0 0; color: var(--faint); font-size: 12px; }
.date-row { display: grid; grid-template-columns: 76px 1fr 96px; gap: 8px; max-width: 380px; }

.preview { padding: 14px 22px 0; }
.preview-label { color: var(--faint); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.preview-ref {
  margin: 4px 0 0;
  padding-left: 2em;
  text-indent: -2em;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.45;
  letter-spacing: 0;
  overflow-wrap: anywhere;
  max-height: 7.5em;
  overflow-y: auto;
}
.preview-intext { margin: 4px 0 0; color: var(--muted); font-family: var(--serif); font-size: 14px; letter-spacing: 0; }
.preview-intext:empty { display: none; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border-radius: 980px;
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 10px);
  transition: opacity .2s var(--ease), transform .3s var(--ease-out), visibility 0s .3s;
}
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition: opacity .2s var(--ease), transform .3s var(--ease-out), visibility 0s; }
.toast button { padding: 0; border: 0; background: none; color: inherit; font: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- phones ---------- */
@media (max-width: 600px) {
  .cite { padding: 84px 16px 40px; }
  .cite-head { margin-bottom: 24px; }
  .cite-card { padding: 16px; border-radius: 18px; }
  .find { padding-left: 40px; }
  .find-icon { left: 13px; }
  .find input { font-size: 16px; }
  .find .btn { padding: 0 16px; }
  .bib-bar > .select { flex: 1 1 100%; }
  .bib-actions { width: 100%; }
  .bib-actions > .btn, .bib-actions > .pop { flex: 1; }
  .bib-actions .pop-btn { width: 100%; }
  .entry-ref { font-size: 17px; }
  .fields { grid-template-columns: 1fr; }
  .person { grid-template-columns: 1fr 1fr 32px; gap: 6px; }
  .sheet {
    width: 100vw;
    max-width: 100vw;
    max-height: calc(100svh - 24px);
    margin: auto 0 0;
    border-radius: 22px 22px 0 0;
    border-bottom: 0;
  }
  .sheet-small { margin: auto; width: calc(100vw - 32px); border-radius: 22px; border-bottom: 1px solid var(--line); }
  .sheet-actions { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .save-to { width: 100%; }
  .save-to .select { max-width: none; flex: 1; }
}

/* ---------- printing prints just the list ---------- */
@media print {
  .cite-page { background: #fff; }
  .nav, .footer, .cite-head, .find-card, .bib-bar, .bib-actions, .bib-count, .entry-meta, .cite-foot, .toast { display: none !important; }
  .cite { padding: 0; max-width: none; }
  .cite-card { border: 0; box-shadow: none; padding: 0; background: none; }
  .bib-head { justify-content: center; margin: 0 0 12pt; }
  .bib-head h2 { font: 12pt var(--serif); color: #000; }
  .entry { border: 0; padding: 0; margin: 0; }
  .entry-ref { font-size: 12pt; line-height: 2; color: #000; padding-left: 0.5in; text-indent: -0.5in; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet[open] { animation: none; }
  .btn.busy::after, .spinner { animation-duration: 2s; }
}
