:root {
  color-scheme: light;
  --background: #f5f5f1;
  --surface: #ffffff;
  --text: #181817;
  --muted: #6b6b65;
  --line: #deded7;
  --accent: #24573f;
  --accent-soft: #e5efe9;
  --selected: #c9dfd1;
  --selected-text: #45493f;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--background);
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  padding: 2rem clamp(1rem, 4vw, 4rem);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.12em;
}

h1,
h2 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.035em;
}

h1 {
  font-size: clamp(1.75rem, 4vw, 2.6rem);
}

.result-count,
.question-details,
.notice {
  color: var(--muted);
}

main {
  display: grid;
  grid-template-columns: clamp(210px, 20vw, 270px) minmax(0, 1fr) clamp(230px, 21vw, 290px);
  gap: clamp(1.25rem, 2.5vw, 2.5rem);
  max-width: 1680px;
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 4rem);
}

.filters,
.selection-panel {
  display: flex;
  flex-direction: column;
  align-self: start;
  gap: 1.4rem;
  position: sticky;
  top: 1.5rem;
  padding: 1.3rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.selection-panel {
  gap: 0.9rem;
  max-height: calc(100vh - 3rem);
}

.selection-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.selection-heading h2 {
  font-size: 1rem;
  letter-spacing: 0;
}

#selection-count,
.selection-empty {
  color: var(--muted);
  font-size: 0.8rem;
}

.selection-empty {
  margin: 0;
  line-height: 1.5;
}

.selection-list {
  display: grid;
  flex: 0 1 auto;
  gap: 0.25rem;
  min-height: 0;
  max-height: 40vh;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.selection-list:empty {
  display: none;
}

.selection-list li {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.35rem;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 0.78rem;
}

.selection-list li:hover {
  border-color: var(--line);
}

.selection-list li.dragging {
  opacity: 0.45;
}

.selection-list li.drop-before {
  box-shadow: inset 0 2px 0 var(--accent);
}

.selection-list li.drop-after {
  box-shadow: inset 0 -2px 0 var(--accent);
}

.drag-handle {
  color: var(--muted);
  cursor: grab;
  user-select: none;
}

.selection-open {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  padding: 0;
  text-align: left;
  color: var(--text);
  border: 0;
  background: none;
  cursor: pointer;
  font: inherit;
}

.selection-open:hover span:first-child {
  color: var(--accent);
  text-decoration: underline;
}

.selection-details {
  color: var(--muted);
  font-size: 0.72rem;
}

.selection-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 0.1rem;
}

.selection-action {
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  color: var(--accent);
  border: 0;
  border-radius: 6px;
  background: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1;
}

.selection-action:hover:not(:disabled) {
  background: var(--accent-soft);
}

.selection-action:disabled {
  cursor: default;
  opacity: 0.3;
}

.selection-tools {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.selection-tools[hidden] {
  display: none;
}

.sort-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.selection-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
}

.text-button {
  padding: 0;
  color: var(--accent);
  border: 0;
  background: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
}

.text-button {
  align-self: flex-start;
}

.export-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 0.85rem;
}

.export-options legend {
  width: 100%;
  margin: 0;
  padding: 0.9rem 0 0.4rem;
  border-top: 1px solid var(--line);
}

.export-options label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.export-actions {
  display: grid;
  gap: 0.5rem;
}

.export-actions .secondary-button {
  font-size: 0.78rem;
}

.export-actions .secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.filters label,
.filters fieldset {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 0.85rem;
  font-weight: 650;
}

.filters fieldset label {
  flex-direction: row;
  align-items: center;
  font-weight: 450;
}

legend {
  margin-bottom: 0.55rem;
  font-weight: 650;
}

input[type="search"],
select {
  width: 100%;
  padding: 0.7rem 0.8rem;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: var(--surface);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 2px;
}

input[type="radio"],
input[type="checkbox"] {
  accent-color: var(--accent);
}

.question-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
}

.question-card {
  display: flex;
  position: relative;
  min-height: 185px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  transition: border-color 150ms ease, background-color 150ms ease, transform 150ms ease,
    box-shadow 150ms ease;
}

.question-card:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 22px rgb(20 30 24 / 8%);
  transform: translateY(-2px);
}

.question-card.selected {
  border-color: var(--accent);
  background: var(--selected);
}

.question-card.selected .question-id,
.question-card.selected .question-details,
.question-card.selected .chip:not(.chip-primary, .chip-review) {
  color: var(--selected-text);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.card-open {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 1.15rem;
  text-align: left;
  color: inherit;
  border: 0;
  border-radius: inherit;
  background: none;
  cursor: pointer;
}

.card-select {
  display: flex;
  position: absolute;
  top: 0;
  right: 0;
  padding: 1rem;
  cursor: pointer;
}

.card-select input {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  cursor: pointer;
}

.card-section {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.question-card strong {
  margin: 1rem 0 0.45rem;
  font-size: 1.2rem;
}

.question-id {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.78rem;
}

.question-details {
  margin-top: auto;
  padding-top: 1rem;
  font-size: 0.8rem;
}

.secondary-button,
.icon-button {
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
}

.secondary-button {
  padding: 0.7rem 1rem;
  border-radius: 8px;
  color: var(--text);
}

.load-more {
  display: block;
  margin: 1.5rem auto 0;
}

.notice {
  padding: 1rem;
  text-align: center;
}

.error {
  margin-bottom: 1rem;
  color: #8f231d;
  border: 1px solid #e8b9b5;
  border-radius: 8px;
  background: #fff2f1;
}

dialog {
  width: min(1000px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgb(0 0 0 / 25%);
}

dialog::backdrop {
  background: rgb(16 20 17 / 58%);
  backdrop-filter: blur(3px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 1.1rem 1.35rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.icon-button {
  flex: 0 0 auto;
  width: 2.4rem;
  height: 2.4rem;
  color: var(--muted);
  border-radius: 50%;
  font-size: 1.65rem;
  line-height: 1;
}

#dialog-content {
  padding: 1.35rem;
}

.question-image {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.structured-data {
  margin-top: 1.25rem;
  padding: 1rem;
  border-radius: 8px;
  background: var(--accent-soft);
}

.structured-data h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.structured-data dl {
  display: grid;
  grid-template-columns: minmax(110px, 0.25fr) 1fr;
  gap: 0.6rem 1rem;
  margin: 0;
  font-size: 0.88rem;
}

.structured-data dt {
  color: var(--muted);
  font-weight: 650;
}

.structured-data dd {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
  }

  .filters,
  .selection-panel {
    position: static;
  }

  .results {
    order: 1;
  }

  .selection-panel {
    max-height: none;
  }

  .selection-list {
    max-height: 9rem;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: start;
    flex-direction: column;
    gap: 0.5rem;
  }

  .structured-data dl {
    grid-template-columns: 1fr;
  }

  .structured-data dd {
    margin-bottom: 0.5rem;
  }
}

.topic-filters {
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.topic-filters[hidden] {
  display: none;
}

.filters .checkbox-row {
  flex-direction: row;
  align-items: flex-start;
  gap: 0.5rem;
  margin-top: -0.8rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 450;
}

.checkbox-row input {
  margin: 0.15rem 0 0;
  accent-color: var(--accent);
}

.topic-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.8rem;
}

.chip {
  padding: 0.2rem 0.5rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.72rem;
  line-height: 1.3;
}

.chip-primary {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  background: var(--accent-soft);
  font-weight: 650;
}

.chip-review {
  color: #8a5a00;
  border-color: #ecd49a;
  background: #fff7e3;
}

.topic-details {
  margin: 0 0 1.25rem;
  background: #f1f4f8;
}
