:root {
  color-scheme: light;
  --bg: #f6f8f5;
  --panel: #ffffff;
  --panel-alt: #eef4f0;
  --ink: #122019;
  --muted: #58645f;
  --line: #d9e2dc;
  --accent: #0b6b57;
  --accent-strong: #084d40;
  --blue: #245b9c;
  --red: #a13f34;
  --amber: #9b6a13;
  --shadow: 0 16px 42px rgba(18, 32, 25, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
  letter-spacing: 0;
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

button:hover,
a:hover {
  color: var(--accent-strong);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  min-height: 60px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 248, 245, 0.96);
  padding: 0 24px;
  backdrop-filter: blur(10px);
}

.brand,
.topnav {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
  text-decoration: none;
  font-weight: 780;
}

.brand-mark {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-size: 12px;
  letter-spacing: 0;
}

.topnav {
  gap: 14px;
  color: var(--muted);
  font-size: 14px;
}

.shell {
  width: min(1460px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.control-panel {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(380px, 1.2fr) 260px;
  gap: 18px;
  align-items: end;
  padding: 20px;
}

.intro p {
  max-width: 680px;
  margin: 8px 0 0;
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 780;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.12;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

.track-form {
  min-width: 0;
}

.track-form label,
.metric-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.input-row {
  display: flex;
  min-width: 0;
  gap: 8px;
}

.input-row input {
  width: 100%;
  min-height: 42px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
}

.input-row button,
#refresh,
#copy-digest,
#copy-post,
#export-watchlist {
  border-color: transparent;
  background: var(--accent);
  color: white;
  padding: 0 14px;
  font-weight: 720;
}

#copy-digest,
#copy-post,
#export-watchlist {
  background: var(--blue);
}

.mode-grid,
.topic-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mode,
.topic {
  padding: 0 13px;
}

.mode.active,
.topic.active {
  border-color: var(--accent);
  background: var(--panel-alt);
  color: var(--accent-strong);
  font-weight: 760;
}

.topic-row,
.metric-grid {
  grid-column: 1 / -1;
}

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

.metric-grid > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-alt);
  padding: 12px;
}

.metric-grid strong {
  display: block;
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  gap: 20px;
  margin-top: 20px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.section-head.compact {
  align-items: center;
  margin: 0 0 12px;
}

.head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.item-list {
  display: grid;
  gap: 12px;
}

.item-card {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.score-box {
  display: grid;
  min-height: 78px;
  align-content: center;
  justify-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: white;
}

.score-box strong {
  font-size: 28px;
  line-height: 1;
}

.score-box span {
  margin-top: 5px;
  color: #c9d8d0;
  font-size: 12px;
}

.item-body {
  min-width: 0;
}

.item-topline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.item-card h3 {
  margin: 5px 0 7px;
  font-size: 20px;
  line-height: 1.2;
}

.item-card h3 button {
  height: auto;
  min-height: 0;
  border: 0;
  background: transparent;
  padding: 0;
  color: inherit;
  font: inherit;
  font-weight: 790;
  text-align: left;
}

.item-card p {
  display: -webkit-box;
  margin-bottom: 10px;
  overflow: hidden;
  color: var(--muted);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.stat-row,
.reason-row,
.card-actions,
.link-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stat-row span,
.reason-row span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-alt);
  padding: 5px 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.reason-row {
  margin-bottom: 10px;
}

.reason-row span:first-child {
  border-color: rgba(11, 107, 87, 0.25);
  color: var(--accent-strong);
}

.card-actions a,
.card-actions button,
.link-grid a {
  display: inline-grid;
  min-height: 36px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  font-weight: 720;
  text-decoration: none;
}

.detail-panel,
.watch-panel {
  padding: 16px;
}

.watch-panel {
  margin-top: 16px;
}

.detail-empty,
.watchlist-empty,
.loading,
.error {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--panel-alt);
  padding: 16px;
  color: var(--muted);
}

.error {
  border-color: rgba(161, 63, 52, 0.38);
  color: var(--red);
}

.detail-title {
  margin-bottom: 8px;
  font-size: 21px;
}

.detail-meta {
  color: var(--muted);
  font-size: 14px;
}

.reason-list {
  margin: 14px 0;
  padding-left: 20px;
}

.reason-list li {
  margin-bottom: 5px;
}

.embed-box {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
}

.watch-list {
  display: grid;
  gap: 8px;
}

.watch-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.watch-row strong,
.watch-row span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.watch-row span {
  color: var(--muted);
  font-size: 12px;
}

.watch-row button {
  min-height: 32px;
  padding: 0 10px;
}

.answer-section {
  margin-top: 22px;
  padding: 20px;
  color: var(--muted);
}

.answer-section h2 {
  color: var(--ink);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 40px));
  border-radius: 8px;
  background: var(--ink);
  color: white;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

@media (max-width: 1080px) {
  .control-panel,
  .main-grid {
    grid-template-columns: 1fr;
  }

  .side-column {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }

  .watch-panel {
    margin-top: 0;
  }
}

@media (max-width: 720px) {
  .topbar,
  .shell {
    padding-right: 14px;
    padding-left: 14px;
  }

  .topnav {
    display: none;
  }

  .control-panel {
    padding: 14px;
  }

  .metric-grid,
  .side-column {
    grid-template-columns: 1fr;
  }

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

  .score-box {
    min-height: 58px;
    grid-template-columns: auto auto;
    justify-content: center;
    gap: 8px;
  }

  .section-head,
  .input-row {
    flex-direction: column;
  }

  .input-row button {
    width: 100%;
  }
}
