:root {
  color-scheme: light;
  --bg: #f5f2ea;
  --ink: #15171a;
  --muted: #626a73;
  --line: #d8d7d0;
  --panel: #ffffff;
  --panel-strong: #fdfbf5;
  --accent: #0f766e;
  --accent-dark: #0d4f4a;
  --gold: #c98b21;
  --red: #a5483d;
  --blue: #315f9b;
  --shadow: 0 18px 44px rgba(26, 31, 37, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.12), transparent 28rem),
    linear-gradient(135deg, rgba(49, 95, 155, 0.08), transparent 34rem),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 34px;
}

.masthead {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: end;
  min-height: 142px;
  padding: 30px;
  border: 1px solid rgba(21, 23, 26, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.92), rgba(253, 251, 245, 0.82)),
    repeating-linear-gradient(90deg, rgba(15, 118, 110, 0.12) 0 8px, transparent 8px 22px);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 760;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  max-width: 900px;
  font-size: clamp(2.15rem, 4.4vw, 4.9rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.source-block {
  display: grid;
  gap: 1px;
  min-width: 150px;
  padding: 18px;
  border-left: 4px solid var(--accent);
  background: rgba(255, 255, 255, 0.78);
}

.source-block span {
  font-size: 2rem;
  font-weight: 800;
}

.source-block small {
  color: var(--muted);
  font-weight: 650;
  text-transform: uppercase;
}

.metrics,
.controls,
.rating-strip,
.table-wrap,
footer {
  margin-top: 18px;
}

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

.metric,
.controls,
.rating-strip,
.table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

.metric {
  display: grid;
  gap: 4px;
  min-width: 0;
  min-height: 86px;
  padding: 18px;
}

.metric-value {
  overflow: hidden;
  font-size: 1.7rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 720;
  text-transform: uppercase;
}

.controls {
  display: grid;
  grid-template-columns: minmax(250px, 1.25fr) minmax(180px, 0.82fr) minmax(190px, 0.9fr) minmax(250px, 1fr) minmax(224px, auto);
  gap: 12px;
  align-items: end;
  padding: 16px;
}

.control,
.sort-control,
.utility-actions,
.download-actions {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.control span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 780;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  height: 46px;
  min-width: 0;
  border: 1px solid #c8c8c0;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 13px;
  outline: none;
}

input:focus,
select:focus,
button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}

.button-row,
.download-buttons {
  display: grid;
  gap: 8px;
}

.button-row {
  grid-template-columns: minmax(80px, 1fr);
}

.sort-control {
  grid-template-columns: minmax(120px, 1fr) 46px;
  align-items: end;
}

.sort-direction {
  grid-template-columns: 1fr;
}

.utility-actions {
  grid-template-columns: minmax(82px, 1fr) 124px;
  align-items: end;
}

.download-actions {
  gap: 0;
}

.download-actions > span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.download-buttons {
  grid-template-columns: 1fr;
  gap: 4px;
}

button {
  cursor: pointer;
}

.button-row button,
.sort-direction button,
.download-buttons button,
.download-buttons a,
.rating-pill {
  height: 46px;
  border: 1px solid rgba(15, 118, 110, 0.28);
  border-radius: 6px;
  background: #eef7f5;
  color: var(--accent-dark);
  font-weight: 760;
}

.sort-direction button {
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
}

.download-buttons button,
.download-buttons a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 21px;
  border-color: rgba(49, 95, 155, 0.36);
  background: #edf3fb;
  color: #234a7a;
  font-size: 0.72rem;
  line-height: 1;
  text-decoration: none;
}

.button-row button:hover,
.sort-direction button:hover,
.rating-pill:hover {
  background: #dff1ee;
}

.download-buttons button:hover,
.download-buttons a:hover {
  background: #dfeaf8;
}

.rating-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
}

.rating-pill {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-width: 0;
  padding: 0 15px;
}

.rating-pill.is-active {
  background: var(--accent);
  color: #fff;
}

.ft50-pill {
  border-color: rgba(201, 139, 33, 0.42);
  background: #fbf2dd;
  color: #7a4f0f;
}

.ft50-pill:hover {
  background: #f5e5c1;
}

.ft50-pill.is-active {
  background: var(--gold);
  color: #fff;
}

.table-wrap {
  position: relative;
  overflow: auto;
  max-height: calc(100vh - 150px);
  box-shadow: 0 8px 22px rgba(26, 31, 37, 0.08);
}

table {
  width: 100%;
  min-width: 1040px;
  border-collapse: collapse;
  table-layout: fixed;
}

.col-journal {
  width: 29%;
}

.col-rating {
  width: 8%;
}

.col-discipline {
  width: 24%;
}

.col-publisher {
  width: 22%;
}

.col-year {
  width: 7%;
}

.col-issn {
  width: 10%;
}

thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

th {
  background: #24313d;
  color: #fff;
  font-size: 0.76rem;
  text-align: left;
  text-transform: uppercase;
}

th button {
  width: 100%;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 10px 14px;
  text-align: left;
  font-weight: 800;
}

th button::after {
  content: "";
  display: inline-block;
  margin-left: 7px;
  color: #b9c9d7;
}

th button[aria-sort="ascending"]::after {
  content: "↑";
}

th button[aria-sort="descending"]::after {
  content: "↓";
}

td {
  border-top: 1px solid #ece9e1;
  padding: 13px 14px;
  vertical-align: top;
  overflow-wrap: anywhere;
}

tbody tr {
  background: var(--panel);
}

tbody tr:nth-child(even) {
  background: var(--panel-strong);
}

tbody tr:hover {
  background: #edf7f5;
}

.journal-title {
  font-weight: 760;
}

.journal-name {
  vertical-align: middle;
}

.ft50-chip {
  display: inline-flex;
  align-items: center;
  height: 22px;
  margin-left: 7px;
  border: 1px solid rgba(201, 139, 33, 0.38);
  border-radius: 999px;
  background: #fbf2dd;
  color: #7a4f0f;
  padding: 0 7px;
  font-size: 0.68rem;
  font-weight: 850;
  line-height: 1;
  vertical-align: middle;
  white-space: nowrap;
}

.publisher,
.discipline {
  color: #39424c;
}

.issn {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: normal;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 30px;
  border-radius: 999px;
  color: #fff;
  font-weight: 840;
}

.rating-a-star {
  background: var(--gold);
}

.rating-a {
  background: var(--accent);
}

.rating-b {
  background: var(--blue);
}

.rating-c {
  background: var(--red);
}

.for-code {
  display: inline-flex;
  margin-left: 5px;
  border-radius: 999px;
  background: #f0f1ee;
  color: var(--muted);
  padding: 1px 6px;
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.empty-state {
  padding: 34px;
  color: var(--muted);
  text-align: center;
}

footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  justify-content: flex-start;
  color: var(--muted);
  font-size: 0.85rem;
}

footer a {
  color: var(--accent-dark);
  font-weight: 720;
}

.credit-footer {
  margin-top: 8px;
}

@media (max-width: 1400px) {
  .controls {
    grid-template-columns: minmax(220px, 1fr) minmax(180px, 0.85fr) minmax(210px, 1fr) minmax(260px, 1.1fr) minmax(224px, auto);
  }
}

@media (max-width: 1180px) {
  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-wide,
  .sort-control,
  .utility-actions {
    grid-column: 1 / -1;
  }
}

@media (max-width: 980px) {
  .masthead {
    grid-template-columns: 1fr;
  }

  .source-block {
    width: 100%;
    border-left: 0;
    border-top: 4px solid var(--accent);
  }

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

@media (max-width: 1080px) {
  .table-wrap {
    overflow: visible;
    max-height: none;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  colgroup,
  thead {
    display: none;
  }

  tbody {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  tbody tr,
  tbody tr:nth-child(even) {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 7px 10px;
    position: relative;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 12px;
    box-shadow: 0 8px 22px rgba(26, 31, 37, 0.08);
  }

  tbody tr:hover {
    background: var(--panel);
  }

  td {
    width: auto;
    min-width: 0;
    border-top: 0;
    padding: 0;
    overflow-wrap: anywhere;
  }

  td::before {
    content: attr(data-label) ": ";
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
  }

  .journal-title {
    flex: 1 1 calc(100% - 58px);
    padding-right: 4px;
    font-size: 0.98rem;
    line-height: 1.25;
  }

  .journal-title::before,
  td[data-label="Rating"]::before,
  .discipline::before {
    display: none;
  }

  td[data-label="Rating"] {
    flex: 0 0 auto;
    margin-left: auto;
  }

  td[data-label="Rating"] .badge {
    min-width: 38px;
    height: 26px;
    font-size: 0.84rem;
  }

  .discipline {
    flex: 1 0 100%;
    min-width: 0;
    color: #313a43;
    font-size: 0.9rem;
    line-height: 1.35;
  }

  .for-code {
    margin-left: 4px;
    padding: 1px 6px;
    font-size: 0.7rem;
  }

  .publisher,
  td[data-label="Year"],
  .issn {
    flex: 0 1 auto;
    color: var(--muted);
    font-size: 0.76rem;
    line-height: 1.3;
    white-space: normal;
  }

  .publisher::before,
  td[data-label="Year"]::before,
  .issn::before {
    display: inline;
  }
}

@media (max-width: 720px) {
  .shell {
    width: calc(100vw - 20px);
    max-width: 1480px;
    padding-top: 10px;
  }

  .masthead {
    min-height: 0;
    padding: 20px;
  }

  h1 {
    font-size: 2rem;
    line-height: 1.05;
  }

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

  .rating-strip {
    grid-template-columns: 1fr;
  }

  .controls {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .control-wide,
  .sort-control,
  .utility-actions {
    grid-column: auto;
  }

  .sort-control {
    grid-template-columns: minmax(0, 1fr) 46px;
  }

  .utility-actions {
    grid-template-columns: 1fr;
  }

  .button-row {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: 78px;
    padding: 14px;
  }

  tbody {
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

@media (max-width: 480px) {
  .for-code {
    margin-top: 3px;
  }
}
