:root {
  color-scheme: light dark;
  --bg: #f7f8f6;
  --panel: #ffffff;
  --text: #1c2521;
  --muted: #66746d;
  --line: #dce3dd;
  --primary: #1f5b43;
  --primary-strong: #123a2b;
  --accent: #8a2443;
  --gold: #a77926;
  --soft: #eaf2ed;
  --green: #1f5b43;
  --header-bg: #ffffff;
  --field-bg: #ffffff;
  --subtle-panel: #f8faf8;
  --tag-bg: #edf4ef;
  --tag-text: #2f4a3d;
  --footer-text: #eef6f0;
  --shadow: 0 10px 24px rgba(27, 43, 36, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  scroll-behavior: smooth;
  padding-bottom: 86px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 54px) 24px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  border-top: 6px solid var(--primary);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 4vw, 3.8rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.lede {
  max-width: 780px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 1.05rem;
}

.source-callout {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 780px;
  margin-bottom: 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: var(--field-bg);
  color: var(--text);
  font-weight: 700;
}

.source-callout a {
  color: var(--primary);
}

.header-actions {
  display: flex;
  align-items: start;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 220px;
}

.button {
  appearance: none;
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: var(--primary);
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
}

.button.secondary {
  background: var(--field-bg);
  color: var(--primary);
}

.button.secondary:hover,
.button.secondary:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.button:disabled,
.button:disabled:hover {
  cursor: not-allowed;
  opacity: 0.55;
}

main {
  padding: 22px clamp(18px, 4vw, 54px) 48px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.controls,
.explain-panel,
.results-bar,
.insight-panel,
.journal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 16px;
}

.metric-value {
  display: block;
  color: var(--primary);
  font-size: 1.8rem;
  font-weight: 800;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}

.metric-detail {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.controls {
  padding: 16px;
  margin-bottom: 14px;
}

.search-label {
  display: block;
  margin-bottom: 4px;
  font-weight: 700;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 240px) minmax(150px, 190px);
  gap: 10px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cbd9ca;
  border-radius: 8px;
  background: var(--field-bg);
  color: var(--text);
  font: inherit;
  padding: 0 12px;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--field-bg);
  color: var(--text);
  cursor: pointer;
  min-height: 34px;
  padding: 0 12px;
  font: inherit;
}

.chip[aria-pressed="true"] {
  border-color: var(--primary);
  background: var(--soft);
  color: var(--primary-strong);
  font-weight: 700;
}

.explain-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.8fr);
  gap: 18px;
  margin-bottom: 14px;
  padding: 16px;
}

.explain-panel h2 {
  margin-bottom: 8px;
  font-size: 1.05rem;
}

.explain-panel p {
  margin-bottom: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.explain-panel p:last-child {
  margin-bottom: 0;
}

.priority-guide {
  display: grid;
  gap: 8px;
  margin: 0;
}

.priority-guide div {
  border-left: 3px solid var(--primary);
  background: var(--subtle-panel);
  padding: 8px 10px;
}

.priority-guide dt {
  color: var(--text);
  font-size: 0.82rem;
  text-transform: none;
}

.priority-guide dd {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.results-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  margin-bottom: 16px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.insight-panel {
  padding: 18px;
  position: sticky;
  top: 14px;
}

.insight-panel h2 {
  font-size: 1rem;
  margin-bottom: 12px;
}

.focus-list {
  display: grid;
  gap: 10px;
}

.focus-item {
  border-left: 3px solid var(--primary);
  padding-left: 10px;
}

.focus-item:nth-child(2) {
  border-left-color: var(--accent);
}

.focus-item:nth-child(3) {
  border-left-color: var(--gold);
}

.focus-item strong {
  display: block;
  font-size: 0.9rem;
}

.focus-item span {
  color: var(--muted);
  font-size: 0.86rem;
}

.note {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.note h3 {
  font-size: 0.95rem;
  margin-bottom: 6px;
}

.note p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0;
}

.journal-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 14px;
}

.journal-card {
  position: relative;
  padding: 16px;
  min-width: 0;
}

.card-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.priority,
.score,
.tag {
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  font-size: 0.78rem;
  font-weight: 700;
}

.priority {
  background: #e7f5ec;
  border: 1px solid #96c9a8;
  color: #175739;
}

.priority.medium {
  background: #fff2cd;
  border-color: #d5a941;
  color: #6b4a09;
}

.priority.review {
  background: #f8e8ef;
  border-color: #d58ba5;
  color: #862746;
}

.score {
  background: var(--soft);
  color: var(--primary-strong);
  border: 1px solid transparent;
}

.select-journal {
  position: absolute;
  right: 16px;
  top: 52px;
  border: 1px solid var(--primary);
  border-radius: 999px;
  background: var(--field-bg);
  color: var(--primary);
  cursor: pointer;
  min-height: 34px;
  padding: 0 12px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
}

.select-journal.is-selected {
  background: var(--primary);
  color: #ffffff;
}

.card-help {
  margin: -4px 0 10px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.journal-card h2 {
  padding-right: 132px;
  margin-bottom: 6px;
  font-size: 1.08rem;
  line-height: 1.25;
}

.publisher {
  margin-bottom: 10px;
  color: var(--muted);
  font-weight: 700;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.tag {
  background: var(--tag-bg);
  color: var(--tag-text);
  font-weight: 600;
}

.site-footer {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 18;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px clamp(18px, 4vw, 54px);
  background: var(--primary-strong);
  color: var(--footer-text);
  box-shadow: 0 -10px 24px rgba(18, 58, 43, 0.16);
}

.site-footer p {
  margin: 0;
  max-width: 720px;
  font-size: 0.84rem;
  line-height: 1.45;
}

.site-footer a {
  color: #ffffff;
  font-weight: 700;
}

.back-to-top {
  position: fixed;
  right: 18px;
  bottom: 82px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--primary);
  border-radius: 999px;
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(18, 58, 43, 0.2);
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
}

.back-to-top:hover,
.back-to-top:focus-visible {
  background: var(--accent);
  border-color: var(--accent);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(12, 28, 21, 0.52);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  width: min(680px, 100%);
  max-height: min(720px, calc(100vh - 44px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.26);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin-bottom: 0;
  font-size: 1.2rem;
}

.modal-close {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field-bg);
  color: var(--text);
  cursor: pointer;
  min-height: 36px;
  padding: 0 12px;
  font: inherit;
  font-weight: 700;
}

.modal-body {
  padding: 18px;
}

.modal-body p {
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 12px;
}

.modal-body a {
  color: var(--primary);
  font-weight: 700;
}

.resource-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 0 12px;
  text-decoration: none;
}

.shortlist-help {
  margin-bottom: 14px;
}

.shortlist-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.shortlist-list {
  display: grid;
  gap: 10px;
}

.shortlist-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--subtle-panel);
}

.shortlist-item h3 {
  margin-bottom: 4px;
  font-size: 1rem;
}

.shortlist-item p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.remove-shortlist {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field-bg);
  color: var(--text);
  cursor: pointer;
  min-height: 34px;
  padding: 0 10px;
  font: inherit;
  font-weight: 700;
}

.shortlist-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.rationale {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.metadata {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.metadata div {
  min-width: 0;
}

dt {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

dd {
  margin: 2px 0 0;
  font-size: 0.9rem;
}

.empty {
  grid-column: 1 / -1;
  padding: 34px;
  text-align: center;
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

@media (max-width: 880px) {
  .app-header,
  .results-bar,
  .site-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-row,
  .explain-panel,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .insight-panel {
    position: static;
  }
}

@media (max-width: 520px) {
  body {
    padding-bottom: 132px;
  }

  .app-header {
    padding-top: 22px;
  }

  h1 {
    font-size: 2rem;
  }

  .header-actions,
  .button {
    width: 100%;
  }

  .header-actions {
    min-width: 0;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .journal-list {
    grid-template-columns: 1fr;
  }

  .metadata {
    grid-template-columns: 1fr;
  }

  .card-topline {
    align-items: flex-start;
    flex-direction: column;
  }

  .select-journal {
    position: static;
    width: 100%;
    margin-bottom: 12px;
  }

  .journal-card h2 {
    padding-right: 0;
  }

  .priority,
  .score,
  .tag {
    max-width: 100%;
    white-space: normal;
  }

  .back-to-top {
    right: 12px;
    bottom: 118px;
    min-height: 38px;
    padding: 0 12px;
    font-size: 0.82rem;
  }

  .site-footer {
    padding: 10px 14px;
  }

  .site-footer p {
    font-size: 0.78rem;
  }

  .modal-overlay {
    padding: 12px;
  }

  .modal-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .modal-close,
  .resource-link {
    width: 100%;
    justify-content: center;
  }

  .shortlist-actions,
  .shortlist-actions .button {
    width: 100%;
  }

  .shortlist-item {
    grid-template-columns: 1fr;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1211;
    --panel: #181d1b;
    --text: #f2f5f3;
    --muted: #b7c0bb;
    --line: #343b38;
    --primary: #8ec7a8;
    --primary-strong: #0b2018;
    --accent: #d98aa3;
    --gold: #d2b66a;
    --soft: #24312b;
    --green: #a8dfbd;
    --header-bg: #151917;
    --field-bg: #111513;
    --subtle-panel: #1e2421;
    --tag-bg: #26342d;
    --tag-text: #dcefe4;
    --footer-text: #eef6f0;
    --shadow: 0 14px 30px rgba(0, 0, 0, 0.34);
  }

  .button {
    color: #0e1a14;
  }

  .button.secondary {
    color: var(--primary);
  }

  .priority {
    background: #173624;
    border-color: #5da879;
    color: #d9fbe3;
  }

  .score {
    background: #d9f5e3;
    border-color: #8ec7a8;
    color: #102018;
  }

  .priority.medium {
    background: #3a2f13;
    border-color: #c49b35;
    color: #ffe59a;
  }

  .priority.review {
    background: #3b1f2b;
    border-color: #c56d8f;
    color: #ffc9db;
  }

  .source-callout,
  input,
  select,
  .chip,
  .modal-close {
    border-color: var(--line);
  }

  input::placeholder {
    color: #8d9892;
  }

  .back-to-top {
    color: #0e1a14;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f8f6;
  --panel: #ffffff;
  --text: #1c2521;
  --muted: #66746d;
  --line: #dce3dd;
  --primary: #1f5b43;
  --primary-strong: #123a2b;
  --accent: #8a2443;
  --gold: #a77926;
  --soft: #eaf2ed;
  --green: #1f5b43;
  --header-bg: #ffffff;
  --field-bg: #ffffff;
  --subtle-panel: #f8faf8;
  --tag-bg: #edf4ef;
  --tag-text: #2f4a3d;
  --footer-text: #eef6f0;
  --shadow: 0 10px 24px rgba(27, 43, 36, 0.07);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1211;
  --panel: #181d1b;
  --text: #f2f5f3;
  --muted: #b7c0bb;
  --line: #343b38;
  --primary: #8ec7a8;
  --primary-strong: #0b2018;
  --accent: #d98aa3;
  --gold: #d2b66a;
  --soft: #24312b;
  --green: #a8dfbd;
  --header-bg: #151917;
  --field-bg: #111513;
  --subtle-panel: #1e2421;
  --tag-bg: #26342d;
  --tag-text: #dcefe4;
  --footer-text: #eef6f0;
  --shadow: 0 14px 30px rgba(0, 0, 0, 0.34);
}

:root[data-theme="dark"] .button {
  color: #0e1a14;
}

:root[data-theme="dark"] .button.secondary {
  color: var(--primary);
}

:root[data-theme="dark"] .priority {
  background: #173624;
  border-color: #5da879;
  color: #d9fbe3;
}

:root[data-theme="dark"] .score {
  background: #d9f5e3;
  border-color: #8ec7a8;
  color: #102018;
}

:root[data-theme="dark"] .priority.medium {
  background: #3a2f13;
  border-color: #c49b35;
  color: #ffe59a;
}

:root[data-theme="dark"] .priority.review {
  background: #3b1f2b;
  border-color: #c56d8f;
  color: #ffc9db;
}

:root[data-theme="dark"] .source-callout,
:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] .chip,
:root[data-theme="dark"] .modal-close {
  border-color: var(--line);
}

:root[data-theme="dark"] input::placeholder {
  color: #8d9892;
}

:root[data-theme="dark"] .back-to-top {
  color: #0e1a14;
}
