:root {
  color-scheme: light;
  --bg: #f0f4f9;
  --surface: #ffffff;
  --surface-alt: #f5f8fc;
  --stripe: #f8fafd;
  --text: #17202a;
  --muted: #64748b;
  --border: #d7e0ea;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --accent-soft: #e6f4f3;
  --danger: #b42318;
  --pos: #15803d;
  --pos-bg: #f0fdf4;
  --neg: #b91c1c;
  --neg-bg: #fef2f2;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.07), 0 1px 4px rgba(15, 23, 42, 0.04);
  --header-color: #0f766e;
  --seed-a-bg: #fef3c7; --seed-a-text: #92400e;
  --seed-b-bg: #dbeafe; --seed-b-text: #1e40af;
  --seed-c-bg: #ede9fe; --seed-c-text: #5b21b6;
  --seed-d-bg: #d1fae5; --seed-d-text: #065f46;
  --seed-other-bg: #e0e7ef; --seed-other-text: #475569;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1623;
  --surface: #182232;
  --surface-alt: #1e2d42;
  --stripe: #1a2840;
  --text: #f0f5fb;
  --muted: #94a3b8;
  --border: #2d3f58;
  --accent: #2dd4bf;
  --accent-text: #062622;
  --accent-soft: #0d2e2c;
  --danger: #f87171;
  --pos: #4ade80;
  --pos-bg: #052e16;
  --neg: #f87171;
  --neg-bg: #2d0a0a;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3), 0 1px 4px rgba(0, 0, 0, 0.2);
  --header-color: #2dd4bf;
  --seed-a-bg: #78350f; --seed-a-text: #fde68a;
  --seed-b-bg: #1e3a5f; --seed-b-text: #93c5fd;
  --seed-c-bg: #3b0764; --seed-c-text: #c4b5fd;
  --seed-d-bg: #064e3b; --seed-d-text: #6ee7b7;
  --seed-other-bg: #263549; --seed-other-text: #94a3b8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 28px clamp(16px, 4vw, 44px);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.5rem, 3vw, 2.3rem);
  line-height: 1.1;
}

#updatedAt {
  margin-top: 8px;
  color: var(--muted);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
}

.theme-icon {
  font-size: 1.1rem;
}

main {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px clamp(16px, 4vw, 44px) 44px;
}

.table-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.table-section {
  overflow: hidden;
}

.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.table-head h2 {
  font-size: 1.1rem;
}

.table-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

input,
select {
  width: min(260px, 100%);
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface-alt);
  color: var(--text);
}

select {
  width: 150px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
  font-size: 0.875rem;
}

th,
td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-alt);
  color: var(--header-color);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 2px solid var(--border);
  text-align: center;
}

th button {
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: inherit;
  text-transform: inherit;
}

th button::after {
  content: "";
  display: inline-block;
  width: 1em;
  color: var(--accent);
}

th button[data-direction="asc"]::after {
  content: "▲";
}

th button[data-direction="desc"]::after {
  content: "▼";
}

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

tbody tr:hover {
  background: var(--accent-soft);
  transition: background 0.1s;
}

tbody tr:last-child td {
  border-bottom: none;
}

.change-pos {
  color: var(--pos);
  font-weight: 600;
}

.change-neg {
  color: var(--neg);
  font-weight: 600;
}

.seed-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--seed-other-bg);
  color: var(--seed-other-text);
}

.seed-badge--a { background: var(--seed-a-bg); color: var(--seed-a-text); }
.seed-badge--b { background: var(--seed-b-bg); color: var(--seed-b-text); }
.seed-badge--c { background: var(--seed-c-bg); color: var(--seed-c-text); }
.seed-badge--d { background: var(--seed-d-bg); color: var(--seed-d-text); }

.val-arrow {
  font-size: 0.65rem;
  margin-right: 3px;
  vertical-align: middle;
}

.val-arrow--up { color: var(--pos); }
.val-arrow--down { color: var(--neg); }

.formula-hint {
  display: inline-block;
  padding: 1px 5px;
  margin-left: 4px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
  vertical-align: middle;
}

.status-ok {
  color: var(--accent);
  font-weight: 700;
}

.status-error {
  color: var(--danger);
  font-weight: 700;
}

@media (max-width: 760px) {
  .topbar,
  .table-head {
    align-items: stretch;
    flex-direction: column;
  }

  .theme-toggle,
  input,
  select {
    width: 100%;
  }

  .table-controls,
  label {
    align-items: stretch;
    flex-direction: column;
  }
}
