/* ─── Reset & base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:      #2563eb;
  --brand-dark: #1d4ed8;
  --brand-lite: #dbeafe;
  --accent:     #7c3aed;
  --success:    #16a34a;
  --danger:     #dc2626;
  --bg:         #f8fafc;
  --surface:    #ffffff;
  --border:     #e2e8f0;
  --text:       #1e293b;
  --muted:      #64748b;
  --radius:     12px;
  --shadow:     0 4px 24px rgba(0,0,0,.08);
  --font:       'Inter', 'Segoe UI', system-ui, sans-serif;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Nav ─────────────────────────────────────────────────────── */
.site-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 8px rgba(0,0,0,.06);
}

.nav-logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--brand);
  display: flex;
  align-items: center;
  gap: .4rem;
}
.nav-logo span { color: var(--text); }

.nav-links { display: flex; gap: 1.5rem; }
.nav-links a { font-size: .9rem; color: var(--muted); font-weight: 500; }
.nav-links a:hover { color: var(--brand); text-decoration: none; }

/* ─── Hero ────────────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, #1e40af 0%, #4f46e5 50%, #7c3aed 100%);
  padding: 3rem 1.5rem 2.5rem;
  text-align: center;
  color: #fff;
}
.hero-badge {
  display: inline-block;
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 99px;
  padding: .2rem .8rem;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .05em;
  margin-bottom: .9rem;
}
.hero h1 {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 800;
  margin-bottom: .6rem;
  line-height: 1.2;
}
.hero p {
  font-size: 1rem;
  color: rgba(255,255,255,.85);
  max-width: 540px;
  margin: 0 auto;
}

/* ─── Tool card ───────────────────────────────────────────────── */
.tool-wrap {
  max-width: 780px;
  margin: -1.5rem auto 2rem;
  padding: 0 1rem;
}

.tool-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ─── Step bar ────────────────────────────────────────────────── */
.steps-bar {
  display: flex;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.step-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .75rem .5rem;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  transition: all .2s;
  cursor: default;
}
.step-item.active { color: var(--brand); border-color: var(--brand); background: var(--brand-lite); }
.step-item.done   { color: var(--success); border-color: var(--success); }
.step-num {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem;
  background: currentColor;
  color: #fff;
  flex-shrink: 0;
}
.step-item.active .step-num { background: var(--brand); }
.step-item.done   .step-num { background: var(--success); }
.step-item.done .step-num::before { content: '✓'; }
.step-item:not(.done) .step-num { color: var(--surface); }

/* ─── Panel ───────────────────────────────────────────────────── */
.panel { padding: 1.8rem 2rem; display: none; }
.panel.active { display: block; }
.panel-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: .3rem;
}
.panel-sub { font-size: .875rem; color: var(--muted); margin-bottom: 1.25rem; }

/* ─── Source cards ────────────────────────────────────────────── */
.source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: .75rem;
}
.source-card {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 1rem .75rem;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
  background: var(--surface);
  user-select: none;
}
.source-card:hover { border-color: var(--brand); background: var(--brand-lite); }
.source-card.selected { border-color: var(--brand); background: var(--brand-lite); color: var(--brand); }
.source-icon { font-size: 1.8rem; margin-bottom: .35rem; }
.source-label { font-size: .8rem; font-weight: 600; }

/* ─── Search bar ──────────────────────────────────────────────── */
.search-row {
  display: flex;
  gap: .5rem;
  margin-bottom: .75rem;
}
.search-row input {
  flex: 1;
  padding: .65rem 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
  transition: border-color .15s;
  outline: none;
  font-family: inherit;
}
.search-row input:focus { border-color: var(--brand); }
.btn-search {
  padding: .65rem 1.25rem;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.btn-search:hover { background: var(--brand-dark); }
.btn-search:disabled { opacity: .5; cursor: not-allowed; }

/* Space is always reserved so the search row and links below never jump
   when the hint appears or disappears (avoids missed clicks). */
.detect-hint {
  font-size: .8rem;
  padding: .3rem .6rem;
  border-radius: 6px;
  margin-bottom: .5rem;
  min-height: 1.6rem;
  display: inline-flex;
  align-items: center;
}
.detect-hint:empty { visibility: hidden; }
.detect-hint.ok   { background: #dcfce7; color: #166534; display: inline-flex; align-items: center; gap: .3rem; }
.detect-hint.err  { background: #fee2e2; color: var(--danger); display: inline-flex; align-items: center; gap: .3rem; }
.detect-hint.info { background: var(--brand-lite); color: var(--brand); display: inline-flex; align-items: center; gap: .3rem; }

.manual-link {
  font-size: .85rem;
  color: var(--brand);
  cursor: pointer;
  display: inline-block;
  margin-top: .4rem;
  padding: .35rem 0;
  background: none;
  border: none;
  font-family: inherit;
}
.manual-link:hover { text-decoration: underline; }

/* ─── Search results ──────────────────────────────────────────── */
.results-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-top: .75rem;
  display: none;
}
.results-box.open { display: block; }
.result-header {
  padding: .5rem 1rem;
  background: var(--bg);
  font-size: .8rem;
  color: var(--muted);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.result-close { cursor: pointer; font-size: 1rem; color: var(--muted); }
.result-item {
  padding: .8rem 1rem;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
  display: flex;
  gap: .75rem;
  align-items: flex-start;
}
.result-item:hover { background: var(--brand-lite); }
.result-item-info { flex: 1; min-width: 0; }
/* Both naming conventions supported */
.result-item-title, .result-title { font-size: .9rem; font-weight: 600; color: var(--text); line-height: 1.3; }
.result-item-meta,  .result-meta  { font-size: .78rem; color: var(--muted); margin-top: .15rem; }
.result-item-type  { font-size: .7rem; font-weight: 700; background: var(--brand-lite); color: var(--brand); border-radius: 4px; padding: .1rem .4rem; flex-shrink: 0; margin-top: .15rem; }
.no-results { padding: 1rem; text-align: center; color: var(--muted); font-size: .9rem; }

/* ─── Form ────────────────────────────────────────────────────── */
.form-grid { display: grid; gap: .9rem; }
.form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.form-field { display: flex; flex-direction: column; gap: .3rem; }
.form-check { display: flex; align-items: flex-start; gap: .5rem; }
.form-check input { margin-top: .2rem; width: 1rem; height: 1rem; accent-color: var(--brand); flex-shrink: 0; }
.form-check label { font-size: .85rem; color: var(--muted); cursor: pointer; }
.form-field label { font-size: .8rem; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.form-field input,
.form-field select,
.form-field textarea {
  padding: .55rem .85rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
  width: 100%;
  background: var(--surface);
  color: var(--text);
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus { border-color: var(--brand); }

.authors-section { margin-top: .5rem; }
.authors-section h4 { font-size: .85rem; font-weight: 700; color: var(--text); margin-bottom: .5rem; }
.author-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: .5rem;
  margin-bottom: .5rem;
  align-items: end;
}
.author-row input { padding: .5rem .75rem; }
.author-field { display: flex; flex-direction: column; gap: .25rem; }
.author-field label { font-size: .75rem; font-weight: 600; color: var(--muted); }
.btn-remove-author {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  transition: all .15s;
  flex-shrink: 0;
}
.btn-remove-author:hover { border-color: var(--danger); color: var(--danger); }
.btn-add-author {
  font-size: .85rem;
  color: var(--brand);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  border: none;
  background: none;
  padding: 0;
  font-family: inherit;
  margin-top: .25rem;
}
.btn-add-author:hover { text-decoration: underline; }

.form-actions { display: flex; gap: .75rem; margin-top: 1.25rem; }
.btn-primary {
  flex: 1;
  padding: .75rem;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-back {
  padding: .75rem 1.25rem;
  background: var(--bg);
  color: var(--muted);
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.btn-back:hover { border-color: var(--brand); color: var(--brand); }

/* ─── Output ──────────────────────────────────────────────────── */
.output-section { margin-bottom: 1.25rem; }
.output-label {
  font-size: .72rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: .4rem;
}
.output-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .9rem 1rem;
  font-size: .9rem;
  line-height: 1.7;
  position: relative;
  cursor: pointer;
  transition: border-color .15s;
  min-height: 3em;
}
.output-box:hover { border-color: var(--brand); }
.output-box em { font-style: italic; }
.output-box.copied { border-color: var(--success); background: #dcfce7; }

.copy-tip {
  font-size: .7rem;
  color: var(--muted);
  margin-top: .25rem;
}

.output-actions {
  display: flex;
  gap: .75rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}
.btn-word {
  flex: 1;
  min-width: 160px;
  padding: .7rem 1rem;
  background: var(--surface);
  color: var(--brand);
  border: 2px solid var(--brand);
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
}
.btn-word:hover { background: var(--brand-lite); }
.btn-new {
  flex: 1;
  min-width: 160px;
  padding: .7rem 1rem;
  background: var(--brand);
  color: #fff;
  border: 2px solid var(--brand);
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
}
.btn-new:hover { background: var(--brand-dark); }

.citations-list { margin-bottom: 1rem; }
.saved-title { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: .6rem; }
.saved-cite {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .7rem .9rem;
  font-size: .875rem;
  line-height: 1.6;
  margin-bottom: .5rem;
  position: relative;
  display: flex;
  gap: .6rem;
  align-items: flex-start;
}
.saved-text { flex: 1; min-width: 0; }
.saved-cite em { font-style: italic; }
/* Both naming conventions supported */
.saved-cite-actions, .saved-actions {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  flex-shrink: 0;
}
.btn-tiny {
  font-size: .75rem;
  padding: .2rem .55rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all .1s;
}
.btn-tiny:hover { border-color: var(--brand); color: var(--brand); }
.btn-tiny.del:hover { border-color: var(--danger); color: var(--danger); }

/* ─── Loading spinner ─────────────────────────────────────────── */
.spinner {
  display: none;
  width: 20px; height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin: 0 auto;
}
.spinner.show { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Separator ───────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* ─── Content section ─────────────────────────────────────────── */
.content-wrap {
  max-width: 780px;
  margin: 0 auto 3rem;
  padding: 0 1rem;
}
.content-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  margin-bottom: 1.5rem;
}
.content-card h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text);
}
.content-card h3 {
  font-size: 1rem;
  font-weight: 700;
  margin: 1rem 0 .4rem;
  color: var(--brand);
}
.content-card p { margin-bottom: .75rem; font-size: .95rem; color: #374151; }
.content-card ul { padding-left: 1.4rem; margin-bottom: .75rem; }
.content-card li { font-size: .95rem; color: #374151; margin-bottom: .3rem; }

/* ─── Footer ──────────────────────────────────────────────────── */
.site-footer {
  background: var(--text);
  color: rgba(255,255,255,.7);
  text-align: center;
  padding: 1.5rem 1rem;
  font-size: .85rem;
}
.site-footer a { color: rgba(255,255,255,.85); }
.footer-links { display: flex; justify-content: center; gap: 1.5rem; margin-bottom: .5rem; flex-wrap: wrap; }

/* ─── Responsive ──────────────────────────────────────────────── */
@media (max-width: 600px) {
  .panel { padding: 1.25rem 1rem; }
  .form-grid.cols-2 { grid-template-columns: 1fr; }
  .author-row { grid-template-columns: 1fr 1fr auto; }
  .source-grid { grid-template-columns: repeat(3, 1fr); }
  .nav-links { display: none; }
  .output-actions { flex-direction: column; }
  .btn-word, .btn-new { min-width: 0; }
}
