/* xwalk NER demo. Tokens on :root; dark theme via prefers-color-scheme or data-theme. */

:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f1f1ed;
  --text: #1b1e22;
  --muted: #5a6370;
  --border: #dddcd6;
  --accent: #4338ca;
  --accent-hover: #3730a3;
  --accent-text: #ffffff;
  --accent-soft: #eceafd;
  --focus: #4338ca;
  --danger-bg: #fdecec;
  --danger-border: #e8a3a3;
  --danger-text: #8a1c1c;
  --warn-bg: #fff6e0;
  --warn-border: #ecc977;
  --warn-text: #6b4a00;

  --chemical-bg: #dbe9fe;
  --chemical-fg: #1e3f8f;
  --chemical-dot: #3b72e0;
  --disease-bg: #fde1e5;
  --disease-fg: #8f1435;
  --disease-dot: #d8456a;
  --gene-bg: #d9f5e3;
  --gene-fg: #12542f;
  --gene-dot: #2f9e5e;
  --food-bg: #fdefc8;
  --food-fg: #7a3d06;
  --food-dot: #d98a12;
  --other-bg: #e9e7e3;
  --other-fg: #45403b;
  --other-dot: #8b847c;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.05), 0 2px 8px rgba(20, 20, 30, 0.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111316;
    --surface: #1a1d22;
    --surface-2: #22262c;
    --text: #e7e9ec;
    --muted: #a1a9b4;
    --border: #2f343b;
    --accent: #8e96ff;
    --accent-hover: #a9afff;
    --accent-text: #11131a;
    --accent-soft: #262a4a;
    --focus: #a9afff;
    --danger-bg: #3a1b1d;
    --danger-border: #7a3236;
    --danger-text: #ffc9c9;
    --warn-bg: #352a12;
    --warn-border: #6f5520;
    --warn-text: #f5dc9a;

    --chemical-bg: #1c3557;
    --chemical-fg: #c4dbff;
    --chemical-dot: #6c9cf0;
    --disease-bg: #4a1d2a;
    --disease-fg: #ffcfd8;
    --disease-dot: #ee7391;
    --gene-bg: #15402a;
    --gene-fg: #bff2d2;
    --gene-dot: #55c584;
    --food-bg: #47320f;
    --food-fg: #fde3a0;
    --food-dot: #e7a73c;
    --other-bg: #35322f;
    --other-fg: #e4e1dc;
    --other-dot: #a8a198;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111316;
  --surface: #1a1d22;
  --surface-2: #22262c;
  --text: #e7e9ec;
  --muted: #a1a9b4;
  --border: #2f343b;
  --accent: #8e96ff;
  --accent-hover: #a9afff;
  --accent-text: #11131a;
  --accent-soft: #262a4a;
  --focus: #a9afff;
  --danger-bg: #3a1b1d;
  --danger-border: #7a3236;
  --danger-text: #ffc9c9;
  --warn-bg: #352a12;
  --warn-border: #6f5520;
  --warn-text: #f5dc9a;
  --chemical-bg: #1c3557;
  --chemical-fg: #c4dbff;
  --chemical-dot: #6c9cf0;
  --disease-bg: #4a1d2a;
  --disease-fg: #ffcfd8;
  --disease-dot: #ee7391;
  --gene-bg: #15402a;
  --gene-fg: #bff2d2;
  --gene-dot: #55c584;
  --food-bg: #47320f;
  --food-fg: #fde3a0;
  --food-dot: #e7a73c;
  --other-bg: #35322f;
  --other-fg: #e4e1dc;
  --other-dot: #a8a198;
  --shadow: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  overflow-wrap: break-word;
}

[hidden] {
  display: none !important;
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

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

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -100px;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  z-index: 10;
}

.skip-link:focus {
  top: 12px;
}

.page {
  max-width: 60rem;
  margin: 0 auto;
  padding: 40px 16px 48px;
}

/* ---------- intro ---------- */

.intro {
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 10px;
  font-size: clamp(1.7rem, 4.5vw, 2.2rem);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

h2 {
  margin: 0;
  font-size: 1.3rem;
}

.lede {
  margin: 0 0 10px;
  max-width: 44rem;
  font-size: 1.05rem;
}

.caveat {
  margin: 0;
  max-width: 44rem;
  color: var(--muted);
}

.caveat strong {
  color: var(--text);
}

/* ---------- panels and fields ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

label,
summary {
  font-weight: 600;
}

.label-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
}

.counter,
.hint {
  color: var(--muted);
  font-size: 0.875rem;
}

.counter.over {
  color: var(--danger-text);
  font-weight: 600;
}

textarea,
select,
input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

textarea {
  resize: vertical;
  min-height: 7.5rem;
  line-height: 1.5;
}

#prompt {
  font-size: 0.925rem;
}

select,
input {
  min-height: 44px;
}

textarea:focus-visible,
select:focus-visible,
input:focus-visible {
  outline-offset: 0;
  border-color: var(--focus);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

button {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

button.primary {
  background: var(--accent);
  color: var(--accent-text);
  min-width: 8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

button.secondary {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

button.secondary:hover {
  border-color: var(--accent);
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

button.ghost:hover {
  color: var(--text);
}

button.small {
  font-size: 0.875rem;
  padding: 0 12px;
}

.prompt-editor {
  margin: 18px 0 0;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.prompt-editor summary {
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}

.prompt-editor summary::-webkit-details-marker {
  display: none;
}

.prompt-editor summary::before {
  content: "";
  width: 0.5em;
  height: 0.5em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  margin: 0 4px 0 2px;
}

.prompt-editor[open] summary::before {
  transform: rotate(45deg);
}

.prompt-editor .field {
  margin-top: 4px;
}

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.options .field {
  flex: 1 1 14rem;
}

.options .field.narrow {
  flex: 0 1 11rem;
}

.run-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin-top: 20px;
}

kbd {
  font-family: var(--mono);
  font-size: 0.8em;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text);
}

.spinner {
  display: none;
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

button[aria-busy="true"] .spinner {
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
  .prompt-editor summary::before {
    transition: none;
  }
}

/* ---------- messages ---------- */

.banner {
  margin: 0 0 16px;
  padding: 12px 16px;
  border: 1px solid var(--warn-border);
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: var(--radius);
}

.banner p {
  margin: 0;
}

.banner p + p {
  margin-top: 6px;
}

.alert {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin: 16px 0 0;
  padding: 12px 16px;
  border: 1px solid var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger-text);
  border-radius: var(--radius);
}

.alert p {
  margin: 0;
  flex: 1 1 16rem;
}

.alert button.ghost {
  color: var(--danger-text);
  border-color: var(--danger-border);
}

.status {
  margin: 14px 2px 0;
  min-height: 1.5em;
  color: var(--muted);
  font-size: 0.875rem;
}

.status .sep {
  margin: 0 8px;
}

/* ---------- results ---------- */

.results {
  margin-top: 28px;
}

.results-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  margin-bottom: 12px;
}

.summary {
  margin: 0;
  color: var(--muted);
}

.highlighted {
  margin: 0;
  font-size: 1.05rem;
  line-height: 2.1;
  white-space: pre-wrap;
}

.mention {
  border-radius: 5px;
  padding: 2px 3px 2px 5px;
  text-decoration: none;
  color: inherit;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  white-space: normal;
}

.mention:hover .mention-text {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.mention-tag {
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 4px;
  font-size: 0.68em;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  vertical-align: 0.12em;
  white-space: nowrap;
}

.type-chemical { --t-bg: var(--chemical-bg); --t-fg: var(--chemical-fg); --t-dot: var(--chemical-dot); }
.type-disease { --t-bg: var(--disease-bg); --t-fg: var(--disease-fg); --t-dot: var(--disease-dot); }
.type-gene { --t-bg: var(--gene-bg); --t-fg: var(--gene-fg); --t-dot: var(--gene-dot); }
.type-food { --t-bg: var(--food-bg); --t-fg: var(--food-fg); --t-dot: var(--food-dot); }
.type-other { --t-bg: var(--other-bg); --t-fg: var(--other-fg); --t-dot: var(--other-dot); }

.mention,
.badge {
  background: var(--t-bg);
  color: var(--t-fg);
}

.mention-tag {
  background: var(--surface);
  color: var(--t-fg);
}

.mention:hover,
.mention:focus-visible {
  color: var(--t-fg);
}

.swatch,
.dot {
  display: inline-block;
  flex: none;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: var(--t-dot);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 18px 0 0;
  padding: 14px 0 0;
  list-style: none;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
}

.legend li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-type {
  font-weight: 600;
}

.legend-target {
  color: var(--muted);
}

.warnings {
  margin: 12px 0 0;
  padding: 10px 16px 10px 34px;
  border: 1px solid var(--warn-border);
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.cards {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px 16px;
  min-width: 0;
  scroll-margin-top: 16px;
}

.card:target,
.card:focus {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

.card-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 1.05rem;
}

.badge {
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.card-onto {
  color: var(--muted);
  font-size: 0.875rem;
}

.matches {
  width: 100%;
  margin-top: 10px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.9rem;
}

.matches th:nth-child(1) {
  width: 11rem;
}

.matches th:nth-child(3) {
  width: 5.5rem;
}

.matches th:nth-child(4) {
  width: 15rem;
  padding-left: 16px;
}

.matches td.c-ranks {
  padding-left: 16px;
}

.matches th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 6px 10px 6px 0;
  border-bottom: 1px solid var(--border);
}

.matches td {
  padding: 7px 10px 7px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.matches tr:last-child td {
  border-bottom: 0;
}

.matches tr.top .c-label {
  font-weight: 600;
}

.matches .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.c-id {
  font-family: var(--mono);
  font-size: 0.85rem;
  white-space: nowrap;
}

.c-ranks {
  color: var(--muted);
  font-size: 0.85rem;
}

.empty {
  margin: 10px 0 0;
  color: var(--muted);
}

.notes {
  margin: 10px 0 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 0.875rem;
}

.footer {
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.875rem;
}

.footer p {
  margin: 0;
}

/* ---------- narrow screens ---------- */

@media (max-width: 560px) {
  .page {
    padding-top: 24px;
  }

  .panel {
    padding: 16px;
  }

  .card {
    padding: 12px 14px 14px;
  }

  .matches thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .matches,
  .matches tbody,
  .matches tr,
  .matches td {
    display: block;
    width: 100%;
  }

  .matches tr {
    display: grid;
    grid-template-columns: 4.5rem minmax(0, 1fr);
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
  }

  .matches tr:last-child {
    border-bottom: 0;
  }

  .matches td {
    display: contents;
  }

  .matches td::before {
    content: attr(data-label);
    font-family: var(--font);
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 2px 0;
  }

  .matches td > *,
  .matches .c-label,
  .matches .c-score,
  .matches .c-ranks {
    text-align: left;
  }

  .c-id {
    white-space: normal;
  }

  .matches td.c-ranks {
    padding-left: 0;
  }
}
