/* ------------------------------------------------------------------ */
/* RAG Evaluation — stylesheet                                         */
/* No external fonts. CJK-safe system stack. Warm academic palette.    */
/* Dark-mode-aware via prefers-color-scheme.                            */
/* ------------------------------------------------------------------ */

:root {
  color-scheme: light dark;

  /* Palette — light mode (warm academic) */
  --bg: #faf7f2;
  --bg-elev: #ffffff;
  --bg-soft: #f1ebe0;
  --fg: #2a2722;
  --fg-muted: #6b645b;
  --fg-subtle: #8a8279;
  --border: #e5dfd3;
  --border-strong: #c9c0af;

  --accent: #8a5a3b;           /* warm brown */
  --accent-hover: #704930;
  --accent-soft: #f1e3d5;

  --side-a: #3b6a8a;           /* cool blue for Response A */
  --side-a-soft: #e3edf5;
  --side-a-strong: #2c5470;
  --side-b: #a85b3a;           /* warm terracotta for Response B */
  --side-b-soft: #f5e5dc;
  --side-b-strong: #85482e;

  --ok: #2d7a3a;
  --warn: #a86a1f;
  --err: #b3322a;
  --err-soft: #f9e4e2;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(42, 39, 34, 0.06), 0 4px 12px rgba(42, 39, 34, 0.04);
  --shadow-card: 0 1px 2px rgba(42, 39, 34, 0.05), 0 2px 8px rgba(42, 39, 34, 0.05);

  --touch-min: 44px;
  --content-max: 68rem;
  --prose-max: 46rem;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "微软雅黑", "Noto Sans CJK SC",
               "Source Han Sans SC", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1814;
    --bg-elev: #23201b;
    --bg-soft: #2b2721;
    --fg: #e8e3d9;
    --fg-muted: #a8a296;
    --fg-subtle: #7a7468;
    --border: #3a352d;
    --border-strong: #524b40;

    --accent: #d4a37a;
    --accent-hover: #e8b891;
    --accent-soft: #3a2f24;

    --side-a: #7fb3d5;
    --side-a-soft: #1f3040;
    --side-a-strong: #a9cce3;
    --side-b: #e0a48a;
    --side-b-soft: #3b2820;
    --side-b-strong: #eab89e;

    --ok: #7fc28a;
    --warn: #d4a86e;
    --err: #e68982;
    --err-soft: #3a2421;

    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.25);
    --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 2px 8px rgba(0,0,0,0.25);
  }
}

/* ------------------------------------------------------------------ */
/* Reset + base                                                         */
/* ------------------------------------------------------------------ */

*, *::before, *::after { box-sizing: border-box; }
html { text-size-adjust: 100%; }
body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { line-height: 1.25; font-weight: 600; color: var(--fg); margin: 0 0 .6em 0; }
h1 { font-size: clamp(1.6rem, 4vw, 2.1rem); letter-spacing: -0.01em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; }

p { margin: 0 0 1em 0; }
p:last-child { margin-bottom: 0; }

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

small, .small { font-size: 0.85rem; }
.muted { color: var(--fg-muted); }
.lead { font-size: 1.08rem; color: var(--fg); }

code { font: 0.88em var(--font-mono); background: var(--bg-soft); padding: 1px 5px; border-radius: 3px; }

hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

/* ------------------------------------------------------------------ */
/* Layout                                                               */
/* ------------------------------------------------------------------ */

.container {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 1rem;
}

.prose {
  max-width: var(--prose-max);
  padding-top: 1.5rem;
  padding-bottom: 4rem;
}

/* ------------------------------------------------------------------ */
/* Top bar                                                              */
/* ------------------------------------------------------------------ */

.top-bar {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(180%) blur(8px);
}
.top-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .6rem 1rem;
}
.brand-link {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  line-height: 1.25;
}
.brand-title {
  font-weight: 600;
  font-size: 0.98rem;
  color: var(--fg);
}
.brand-tagline { font-size: 0.78rem; }

.top-nav { display: flex; gap: .5rem; align-items: center; }
.lang-toggle {
  display: inline-block;
  padding: .45rem .85rem;
  min-height: var(--touch-min);
  line-height: calc(var(--touch-min) - 2 * .45rem - 2px);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--fg);
  text-decoration: none;
  font-size: 0.9rem;
  background: var(--bg);
  transition: background .15s;
}
.lang-toggle:hover { background: var(--bg-soft); color: var(--fg); }

/* ------------------------------------------------------------------ */
/* Footer                                                               */
/* ------------------------------------------------------------------ */

.site-foot {
  margin-top: 4rem;
  padding: 1.5rem 0;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
}

/* ------------------------------------------------------------------ */
/* Banner / info boxes                                                  */
/* ------------------------------------------------------------------ */

.banner {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin: 1rem 0;
  font-size: 0.95rem;
  border: 1px solid var(--border-strong);
}
.banner.info {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--fg);
}

/* ------------------------------------------------------------------ */
/* Cards                                                                */
/* ------------------------------------------------------------------ */

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
  margin: 1.5rem 0;
}

.example-card {
  background: var(--bg-soft);
  border-style: dashed;
  box-shadow: none;
}
.small-heading { font-size: 0.85rem; text-transform: uppercase; letter-spacing: .04em;
                 color: var(--fg-muted); margin-bottom: .4em; font-weight: 600; }

/* ------------------------------------------------------------------ */
/* Forms — shared                                                       */
/* ------------------------------------------------------------------ */

.form-card { display: flex; flex-direction: column; gap: 1.25rem; }

.field { display: flex; flex-direction: column; gap: .4rem; }
.field-label { font-weight: 600; font-size: 0.95rem; }
.field-label em { color: var(--err); font-style: normal; margin-left: .2em; }
.field-help { font-size: 0.82rem; color: var(--fg-muted); }
.field-error {
  color: var(--err);
  font-size: 0.88rem;
  background: var(--err-soft);
  border: 1px solid var(--err);
  border-radius: var(--radius);
  padding: .5rem .75rem;
}

fieldset { border: none; padding: 0; margin: 0; }
legend { padding: 0; }

input[type=text],
input[type=email],
select,
textarea {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: .55rem .75rem;
  min-height: var(--touch-min);
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input[type=text]:focus, input[type=email]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

select { appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-muted) 50%),
                    linear-gradient(135deg, var(--fg-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2rem;
}

.radio-stack, .checkbox-stack { display: flex; flex-direction: column; gap: .5rem; }
.radio-opt, .checkbox-opt, .checkbox-field {
  display: flex; align-items: flex-start; gap: .6rem;
  padding: .5rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  min-height: var(--touch-min);
  transition: background .15s, border-color .15s;
}
.radio-opt:hover, .checkbox-opt:hover, .checkbox-field:hover { background: var(--bg-soft); }
.radio-opt input, .checkbox-opt input, .checkbox-field input {
  flex-shrink: 0;
  width: 18px; height: 18px;
  accent-color: var(--accent);
  margin-top: 3px;
}
.radio-opt:has(input:checked),
.checkbox-opt:has(input:checked),
.checkbox-field:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ------------------------------------------------------------------ */
/* Buttons                                                              */
/* ------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .65rem 1.25rem;
  min-height: var(--touch-min);
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--bg-soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled=true] { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }

.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-soft); }

/* ------------------------------------------------------------------ */
/* Consent / howto lists                                                */
/* ------------------------------------------------------------------ */

.consent-list, .howto-list { padding-left: 1.25em; }
.consent-list li, .howto-list li { margin-bottom: .5rem; }

/* ------------------------------------------------------------------ */
/* Progress + sticky prompt bar                                         */
/* ------------------------------------------------------------------ */

.progress-bar {
  height: 4px;
  background: var(--bg-soft);
  position: sticky;
  top: 0;
  z-index: 49;
}
.progress-fill { height: 100%; background: var(--accent); transition: width .3s ease; }

.sticky-prompt {
  position: sticky;
  top: 4px;
  z-index: 48;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  padding: .75rem 0 .9rem 0;
  box-shadow: var(--shadow);
}
.prompt-meta { display: flex; align-items: center; gap: .75rem; margin-bottom: .25rem; }
.prompt-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  letter-spacing: .02em;
}
.prompt-progress { margin-left: auto; }
.prompt-text { font-size: 1.05rem; font-weight: 500; line-height: 1.4; margin: 0; }

/* ------------------------------------------------------------------ */
/* Pair page layout                                                     */
/* ------------------------------------------------------------------ */

.pair-main { padding-top: 1.25rem; padding-bottom: 4rem; }

/* Scenario context (collapsible) */
.scenario-context {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.scenario-context > summary {
  list-style: none;
  cursor: pointer;
  padding: .75rem 1rem;
  font-size: 0.95rem;
  font-weight: 500;
  user-select: none;
  display: flex;
  align-items: center;
  gap: .4rem;
  color: var(--accent);
}
.scenario-context > summary::-webkit-details-marker { display: none; }
.scenario-context > summary::before {
  content: "▸";
  display: inline-block;
  transition: transform .15s;
  color: var(--fg-muted);
}
.scenario-context[open] > summary::before { transform: rotate(90deg); }
.scenario-context > summary .summary-collapse { display: none; }
.scenario-context[open] > summary .summary-expand { display: none; }
.scenario-context[open] > summary .summary-collapse { display: inline; }
.scenario-body {
  padding: 0 1rem 1rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.94rem;
  color: var(--fg);
}
.scen-summary { font-style: italic; color: var(--fg-muted); margin-top: .75rem; }
.scen-details { color: var(--fg); margin-top: .75rem; }
.scen-details p { margin-bottom: .6em; }
.scen-details strong { color: var(--fg); }

/* Responses grid */
.responses-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 2rem;
}
.response-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
  overflow-wrap: anywhere;
}
.response-card.card-a { border-top: 3px solid var(--side-a); }
.response-card.card-b { border-top: 3px solid var(--side-b); }

.response-title {
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .9rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}
.slot-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.8rem;
  color: white;
}
.slot-badge.slot-a { background: var(--side-a); }
.slot-badge.slot-b { background: var(--side-b); }

.response-body { font-size: 0.96rem; line-height: 1.65; color: var(--fg); }
.response-body p { margin-bottom: .85em; }
.response-body h2, .response-body h3, .response-body h4 {
  margin-top: 1em; margin-bottom: .4em; font-size: 1rem;
}
.response-body strong { color: var(--fg); font-weight: 600; }

/* ------------------------------------------------------------------ */
/* Likert grid                                                          */
/* ------------------------------------------------------------------ */

.section-heading {
  font-size: 1.05rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: baseline;
  gap: .75rem;
  flex-wrap: wrap;
}
.likert-scale-note { font-weight: 400; }

.likert-section, .preference-section {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-card);
}

.criterion-block {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}
.criterion-block:first-child { padding-top: 0; }
.criterion-block:last-child  { border-bottom: none; padding-bottom: 0; }

.criterion-label { font-weight: 600; font-size: 0.98rem; margin-bottom: .25rem; }
.criterion-question { font-size: 0.9rem; color: var(--fg-muted); margin-bottom: .5rem; line-height: 1.5; }
.criterion-anchors {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.8rem;
  margin-bottom: .75rem;
}
.anchor-low { color: var(--fg-muted); }
.anchor-high { color: var(--fg-muted); text-align: right; }

.likert-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.likert-col { min-width: 0; }
.likert-col-label {
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: .4rem;
  padding: .15rem .5rem;
  border-radius: var(--radius);
  display: inline-block;
}
.likert-col-label.a { color: var(--side-a-strong); background: var(--side-a-soft); }
.likert-col-label.b { color: var(--side-b-strong); background: var(--side-b-soft); }

.likert-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .35rem;
}
.likert-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-min);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--fg);
  position: relative;
  transition: background .15s, border-color .15s, color .15s;
  user-select: none;
}
.likert-cell input { position: absolute; opacity: 0; pointer-events: none; }
.likert-cell:hover { background: var(--bg-soft); }
.likert-cell.cell-a:has(input:checked) {
  background: var(--side-a);
  border-color: var(--side-a-strong);
  color: white;
}
.likert-cell.cell-b:has(input:checked) {
  background: var(--side-b);
  border-color: var(--side-b-strong);
  color: white;
}
.likert-cell:focus-within { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ------------------------------------------------------------------ */
/* Preference row                                                       */
/* ------------------------------------------------------------------ */

.pref-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: .6rem;
}
.pref-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .65rem .75rem;
  min-height: calc(var(--touch-min) + 4px);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  user-select: none;
  transition: background .15s, border-color .15s, color .15s;
  position: relative;
}
.pref-btn input { position: absolute; opacity: 0; pointer-events: none; }
.pref-btn:hover { background: var(--bg-soft); }
.pref-btn.cell-a:has(input:checked), .pref-btn.cell-a.is-selected {
  background: var(--side-a); border-color: var(--side-a-strong); color: white;
}
.pref-btn.cell-b:has(input:checked), .pref-btn.cell-b.is-selected {
  background: var(--side-b); border-color: var(--side-b-strong); color: white;
}
.pref-btn.pref-none:has(input:checked), .pref-btn.pref-none.is-selected {
  background: var(--fg-muted); border-color: var(--fg-muted); color: var(--bg-elev);
}
.pref-btn:focus-within { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ------------------------------------------------------------------ */
/* Form foot (actions bar)                                              */
/* ------------------------------------------------------------------ */

.form-foot {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.actions { display: flex; gap: .75rem; justify-content: flex-end; flex-wrap: wrap; }

/* ------------------------------------------------------------------ */
/* Flash-invalid animation                                              */
/* ------------------------------------------------------------------ */

@keyframes flashInvalid {
  0%   { box-shadow: 0 0 0 0 var(--err); }
  40%  { box-shadow: 0 0 0 4px var(--err-soft); border-color: var(--err); }
  100% { box-shadow: 0 0 0 0 var(--err); }
}
.flash-invalid {
  animation: flashInvalid .45s ease-out 0s 2;
  border-color: var(--err) !important;
}

@media (prefers-reduced-motion: reduce) {
  .flash-invalid { animation: none; border-color: var(--err) !important; }
  .progress-fill { transition: none; }
}

/* ------------------------------------------------------------------ */
/* Responsive — mobile                                                  */
/* ------------------------------------------------------------------ */

@media (max-width: 720px) {
  .container { padding: 0 .75rem; }
  .sticky-prompt { padding: .5rem 0 .7rem 0; }
  .prompt-text { font-size: 0.98rem; }
  .brand-tagline { display: none; }

  .responses-grid { grid-template-columns: 1fr; }
  .likert-columns { grid-template-columns: 1fr; gap: .75rem; }
  .likert-col-label { width: 100%; text-align: center; }

  .pref-row { grid-template-columns: 1fr; }
  .actions { justify-content: stretch; }
  .actions .btn { flex: 1; }

  .response-card { padding: 1rem; }
  .likert-section, .preference-section, .card { padding: 1rem; }

  .brand-title { font-size: 0.92rem; }
}

@media (max-width: 400px) {
  .likert-row { gap: .25rem; }
  .likert-cell { font-size: 0.88rem; }
}

/* ------------------------------------------------------------------ */
/* Utility                                                              */
/* ------------------------------------------------------------------ */

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

[hidden] { display: none !important; }

/* ------------------------------------------------------------------ */
/* Sticky responses (desktop only, >=900px)                             */
/* Responses pin under the sticky prompt bar while Likert grid scrolls. */
/* ------------------------------------------------------------------ */

@media (min-width: 900px) {
  .responses-grid {
    position: sticky;
    top: 8.25rem;              /* below progress bar + sticky prompt */
    z-index: 30;
    background: var(--bg);     /* opaque so scrolling content hides beneath */
    padding-top: .5rem;
    padding-bottom: .5rem;
    margin-bottom: 1.25rem;
  }
  .response-card {
    max-height: calc(58vh - 8rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }
  /* Subtle shadow at bottom of pinned area to cue that content scrolls under */
  .responses-grid::after {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: -8px;
    height: 8px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.08), transparent);
    pointer-events: none;
  }
}
