/* ------------------------------------------------------------------ *
 * Shared visual style for the whole experiment.
 * ------------------------------------------------------------------ */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #5b6470;
  --border: #e2e5ea;
  --primary: #2f6fed;
  --primary-dark: #2557c4;
  --primary-soft: #eef3fe;
  --user-bubble: #2f6fed;
  --assistant-bubble: #f0f2f5;
  --danger: #c23b3b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --maxw: 820px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.6;
  font-size: 17px;
}

.page {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 40px 20px 80px;
}

/* Card-based reading pages */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 36px;
}

h1 { font-size: 1.7rem; line-height: 1.3; margin: 0 0 .6em; }
h2 { font-size: 1.3rem; margin: 1.4em 0 .5em; }
p { margin: .7em 0; }
ul { padding-left: 1.3em; }
li { margin: .25em 0; }
a { color: var(--primary); }

.prose :first-child { margin-top: 0; }
.prose :last-child { margin-bottom: 0; }

/* ------------------------------------------------------------------ *
 * Buttons
 * ------------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4em;
  font: inherit;
  font-weight: 600;
  padding: 12px 22px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: #f7f8fa; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn:disabled,
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn .timer { font-variant-numeric: tabular-nums; opacity: .9; font-weight: 600; }

.actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 28px;
}

/* ------------------------------------------------------------------ *
 * Consent
 * ------------------------------------------------------------------ */
.consent-box {
  background: var(--primary-soft);
  border: 1px solid #d7e2fb;
  border-radius: 10px;
  padding: 18px 20px;
  margin-top: 18px;
}
.consent-check {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 16px;
  cursor: pointer;
  font-weight: 500;
}
.consent-check input { margin-top: 5px; width: 18px; height: 18px; flex: 0 0 auto; }
.form-error { color: var(--danger); font-weight: 600; margin-top: 14px; }

/* ------------------------------------------------------------------ *
 * Products (Story page)
 * ------------------------------------------------------------------ */
/* Live-debug bar (only shown to allow-listed IPs) */
.debug-bar {
  background: #2b2d31;
  color: #f1f1f3;
  font-size: .82rem;
  padding: 6px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.debug-bar a { color: #ffd166; text-decoration: none; font-weight: 600; }
.debug-bar a:hover { text-decoration: underline; }
.debug-bar .debug-tag { font-weight: 700; }
.debug-bar .debug-sep { opacity: .5; }

.product {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 22px;
  margin: 16px 0;
  background: #fff;
  display: flex;
  align-items: flex-start;
  gap: 22px;
}
.product-media {
  flex: 0 0 140px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.product-img {
  width: 140px;
  height: 140px;
  object-fit: contain;
  border-radius: 8px;
  background: #f6f6f8;
}
.product-body { flex: 1 1 auto; min-width: 0; }
.product-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px 16px;
  margin-bottom: 6px;
}
.product-head .name { font-size: 1.15rem; font-weight: 700; }
.product-head .price { color: var(--text); font-weight: 600; }
.product .specs ul { margin: .3em 0; }
.product-rating {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.product-rating .reviews { color: var(--muted); font-size: .9rem; }
.stars { display: inline-flex; line-height: 0; }
.stars-svg { display: block; }
@media (max-width: 560px) {
  .product { flex-direction: column; gap: 14px; }
  .product-media { flex-basis: auto; }
}

/* ------------------------------------------------------------------ *
 * Pick page
 * ------------------------------------------------------------------ */
.option-list { list-style: none; padding: 0; margin: 20px 0 0; }
.option {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin: 10px 0;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.option:hover { background: #f7f8fa; }
.option input { width: 20px; height: 20px; flex: 0 0 auto; }
.option.selected { border-color: var(--primary); background: var(--primary-soft); }
.option .opt-name { font-weight: 600; }

/* ------------------------------------------------------------------ *
 * Questionnaire (Likert)
 * ------------------------------------------------------------------ */
.likert-legend {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin: 18px 0 6px;
  font-size: .82rem;
  color: var(--muted);
}
.likert-legend div { text-align: center; }

.likert-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin: 14px 0;
  background: #fff;
}
.likert-item.missing { border-color: #e9b8b8; background: #fdf4f4; }
.likert-text { font-weight: 500; margin-bottom: 12px; }
.likert-scale {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}
.likert-scale label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--muted);
  transition: border-color .15s, background .15s, color .15s;
}
.likert-scale label:hover { background: #f7f8fa; }
.likert-scale input { accent-color: var(--primary); }
.likert-scale label:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

/* Labeled (non-numeric) scale, e.g. the time-bracket Experience items */
.likert-scale-labeled label { font-weight: 500; }
.likert-scale-labeled label span {
  font-size: .78rem;
  line-height: 1.15;
  text-align: center;
  font-variant-numeric: normal;
}

/* Sticky progress bar at the top of the questionnaire card */
.q-progress {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--card);
  padding: 10px 0 12px;
  margin-bottom: 4px;
}
.q-progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  overflow: hidden;
}
.q-progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--primary);
  transition: width .25s ease;
}
.q-progress-label {
  margin-top: 6px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
  text-align: right;
}

/* Demographics form fields (text / number / select) */
.field {
  width: 100%;
  font: inherit;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}
.field:focus { border-color: var(--primary); }
select.field { cursor: pointer; }

/* ------------------------------------------------------------------ *
 * Chat page (ChatGPT-like)
 * ------------------------------------------------------------------ */
.chat-page { max-width: 880px; }
.chat-wrapper {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 80px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.chat-header .chat-title { font-size: .95rem; color: var(--muted); flex: 1; }
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg-assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border-bottom-left-radius: 4px;
}
.msg-user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.typing { color: var(--muted); font-style: italic; }
.chat-input {
  display: flex;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: #fafbfc;
}
.chat-input textarea {
  flex: 1;
  resize: none;
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  max-height: 160px;
  outline: none;
}
.chat-input textarea:focus { border-color: var(--primary); }
.chat-note { color: var(--muted); font-size: .85rem; padding: 0 18px 12px; background: #fafbfc; }

/* ------------------------------------------------------------------ *
 * Modal (time up)
 * ------------------------------------------------------------------ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 28px 30px;
  max-width: 440px;
  text-align: center;
  box-shadow: var(--shadow);
}
.modal h2 { margin-top: 0; }
.modal .btn { margin-top: 12px; }

.hint { color: var(--muted); font-size: .92rem; }
.code-pill {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--primary-soft);
  border: 1px solid #d7e2fb;
  border-radius: 8px;
  padding: 2px 8px;
}

@media (max-width: 640px) {
  body { font-size: 16px; }
  .card { padding: 22px 18px; }
  .likert-legend { display: none; }
  .likert-scale label { font-size: .9rem; }
  .msg { max-width: 88%; }
}

/* Access gate (blank first page before language selection) */
.gate-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gate-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 30px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.gate-label { color: var(--muted); font-size: .92rem; }
.gate-input { text-align: center; }
.gate-btn { width: 100%; }
