:root {
  color-scheme: light;
  --bg: #f5f6f2;
  --ink: #17201b;
  --muted: #65736a;
  --line: #d8ded5;
  --panel: #ffffff;
  --green: #11623f;
  --green-dark: #0d4530;
  --amber: #b76e00;
  --blue: #1f5f9d;
  --red: #b93232;
  --shadow: 0 10px 24px rgba(21, 35, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 88px;
  padding: 18px 28px;
  background: #113c2b;
  color: #fff;
  border-bottom: 5px solid #d3a73a;
}

.eyebrow {
  margin: 0 0 4px;
  color: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  opacity: 0.75;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 18px;
}

.header-stats {
  min-width: 140px;
  text-align: right;
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.control-panel,
.results-panel {
  min-width: 0;
}

.control-panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.panel-block,
.race-summary,
.status,
.table-wrap,
.active-filters {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-block {
  padding: 14px;
}

label {
  display: block;
  margin-bottom: 8px;
  color: #26352c;
  font-size: 13px;
  font-weight: 700;
}

.url-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c8d0c6;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(17, 98, 63, 0.14);
}

textarea {
  resize: vertical;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.preset-btn,
.source-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0 13px;
  font-weight: 700;
  text-decoration: none;
}

.primary-btn {
  background: var(--green);
  color: #fff;
}

.secondary-btn {
  background: #eef4f0;
  border-color: #cdd9d0;
  color: #183827;
}

.ghost-btn {
  min-height: 34px;
  background: transparent;
  border-color: #cfd7d1;
  color: var(--muted);
}

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

.section-head label {
  margin: 0;
}

.section-head select {
  width: auto;
  min-width: 120px;
  padding: 7px 9px;
}

.target-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  margin-top: 10px;
}

.target-grid label {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: #36443a;
  font-size: 13px;
  font-weight: 600;
}

.target-grid input {
  width: 16px;
  height: 16px;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preset-btn {
  justify-content: flex-start;
  background: #fff;
  border-color: #d7ddd5;
  color: #243329;
  gap: 8px;
}

.preset-btn.active {
  border-color: var(--green);
  background: #edf7f2;
}

.swatch {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.18);
  background: var(--swatch, #d6d6d6);
}

.dictionary-detail {
  margin-top: 12px;
}

.dictionary-detail summary {
  color: var(--green-dark);
  cursor: pointer;
  font-weight: 700;
}

.dictionary-detail textarea {
  margin: 10px 0;
}

.results-panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.race-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
}

.summary-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.source-link {
  background: #fff;
  border-color: #ccd5cf;
  color: var(--green-dark);
}

.status,
.active-filters {
  display: none;
  padding: 10px 12px;
  color: #334139;
  font-size: 13px;
}

.status.visible,
.active-filters.visible {
  display: block;
}

.active-filters {
  box-shadow: none;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  margin: 2px 6px 2px 0;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef4f0;
  color: #243329;
  font-size: 12px;
  font-weight: 700;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid #e4e8e2;
  padding: 10px 9px;
  vertical-align: top;
  text-align: left;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #23362e;
  color: #fff;
  font-size: 12px;
}

tbody tr:nth-child(even) {
  background: #fbfcfa;
}

.frame-cell {
  width: 40px;
  text-align: center;
  font-weight: 800;
}

.number-cell {
  width: 54px;
  text-align: center;
  font-weight: 800;
}

.horse-name {
  display: inline-block;
  color: #104c35;
  font-weight: 800;
}

.horse-sub {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.meaning {
  min-width: 260px;
  line-height: 1.6;
}

.blood {
  min-width: 180px;
  color: #35443a;
  line-height: 1.6;
}

.match-cell {
  min-width: 180px;
}

.match-badge {
  display: inline-flex;
  margin: 2px 4px 2px 0;
  padding: 4px 7px;
  border-radius: 999px;
  background: #fff2ce;
  color: #5f4200;
  font-size: 12px;
  font-weight: 800;
}

mark {
  background: #ffe08a;
  color: inherit;
  padding: 0 2px;
}

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

.error {
  color: #9e2222;
}

@media (max-width: 920px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
  }

  .header-stats {
    min-width: 0;
    text-align: left;
  }

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

  .race-summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .summary-actions {
    width: 100%;
  }

  .summary-actions > * {
    flex: 1;
  }
}

@media (max-width: 520px) {
  .url-row,
  .preset-grid,
  .target-grid {
    grid-template-columns: 1fr;
  }
}
