:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary: #64748b;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --chat-bg: #f8fafc;
  --bot-bg: #eff6ff;
  --user-bg: #dcfce7;
  --private-bg: #fff7ed;
  --private-border: #fdba74;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 4px 12px rgba(0, 0, 0, .04);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  letter-spacing: 0;
}

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

#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
}

.hero {
  text-align: center;
  min-height: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.hero h1 {
  font-size: 1.9rem;
  margin-bottom: .5rem;
}

.eyebrow {
  color: var(--primary);
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: .4rem;
}

.subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.subtitle.compact {
  margin-bottom: 1rem;
}

h2 {
  font-size: 1.35rem;
  margin-bottom: 1rem;
}

h3 {
  font-size: 1.1rem;
  margin-bottom: .75rem;
}

.hero-actions {
  width: min(440px, 100%);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .6rem 1.2rem;
  border: none;
  border-radius: 8px;
  font-size: .95rem;
  cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s;
  font-family: inherit;
}

.btn:active {
  transform: scale(.98);
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: #cbd5e1;
}

.btn-lg {
  flex-direction: column;
  padding: 1.25rem 1.5rem;
  text-align: left;
  width: 100%;
}

.btn-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.btn-desc {
  font-size: .85rem;
  opacity: .85;
  font-weight: 400;
}

.btn-row {
  display: flex;
  gap: .75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

.consent-text {
  font-size: .95rem;
  color: var(--text);
}

.consent-text ul {
  margin: .5rem 0 .5rem 1.5rem;
}

.consent-text li {
  margin-bottom: .3rem;
}

.consent-check {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: 1rem;
  font-size: .92rem;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .75rem 1rem;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.exp-title {
  font-weight: 700;
}

.phase-badge {
  font-size: .8rem;
  background: #dbeafe;
  color: var(--primary);
  padding: .2rem .7rem;
  border-radius: 20px;
}

.form-group {
  margin-bottom: 1.25rem;
}

.text-input,
.text-area,
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: .65rem .8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .95rem;
  font-family: inherit;
  background: #fff;
}

.text-area,
.form-group textarea {
  min-height: 80px;
  resize: vertical;
}

/* Survey */
.survey-list {
  display: grid;
  gap: 1rem;
}

.question-card,
.survey-question {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 0;
  display: grid;
  gap: .75rem;
}

fieldset.question-card {
  border: 1px solid var(--border);
}

.question-text,
.survey-question .q-text {
  font-weight: 600;
}

.likert-scale,
.likert-group {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

.likert-option {
  flex: 1;
  min-width: 54px;
  text-align: center;
  position: relative;
}

.likert-option input,
.choice-option input {
  display: none;
}

.likert-option span,
.likert-option label,
.choice-option span {
  display: block;
  padding: .52rem;
  border: 2px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: .88rem;
  transition: all .15s;
  background: #fff;
}

.choice-option span {
  text-align: left;
  line-height: 1.5;
}

.likert-option input:checked + span,
.likert-option input:checked + label,
.choice-option input:checked + span {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary);
  font-weight: 700;
}

.scale-labels,
.likert-labels {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: .75rem;
  color: var(--text-muted);
}

.option-stack {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

/* Chat */
.chat-layout {
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 1rem;
  min-height: 520px;
}

.member-sidebar {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.member-sidebar h4 {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: .75rem;
}

.member-list {
  margin-bottom: .75rem;
}

.member-item {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  padding: .45rem 0;
  font-size: .9rem;
}

.member-item-you {
  background: #eff6ff;
  border-radius: 6px;
  padding: .45rem .35rem;
  margin: 0 -.35rem;
}

.member-avatar,
.msg-avatar {
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: #dbeafe;
  color: var(--primary);
  font-weight: 800;
  font-size: 1.05rem;
}

.member-info {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  min-width: 0;
}

.member-name {
  font-weight: 600;
}

.member-role {
  font-size: .72rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.sidebar-note {
  font-size: .74rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin-top: .5rem;
  padding-top: .65rem;
  border-top: 1px solid var(--border);
}

.chat-panel {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background: var(--chat-bg);
  min-height: 390px;
  max-height: 520px;
}

.chat-msg {
  display: flex;
  gap: .55rem;
  margin-bottom: .75rem;
  animation: fadeIn .25s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-msg.bot .msg-bubble {
  background: var(--bot-bg);
}

.chat-msg.user {
  flex-direction: row-reverse;
}

.chat-msg.user .msg-bubble {
  background: var(--user-bg);
}

.msg-body {
  max-width: 78%;
}

.msg-sender {
  font-size: .75rem;
  color: var(--text-muted);
  margin-bottom: .15rem;
}

.msg-bubble {
  padding: .65rem .9rem;
  border-radius: 12px;
  font-size: .93rem;
  line-height: 1.55;
}

.read-only-footer {
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  color: var(--text-muted);
  font-size: .85rem;
  text-align: center;
}

/* Rules */
.rules-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.rule-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  background: #f8fafc;
}

.rule-block p {
  font-size: .93rem;
  color: var(--text);
}

.next-note {
  color: var(--warning);
  font-weight: 600;
  margin-top: 1rem;
}

/* Dice */
.task-header {
  margin-bottom: 1rem;
}

.task-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.timer-pill {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 5.5rem;
  padding: .35rem .7rem;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  font-weight: 800;
  font-size: .85rem;
}

.section-kicker {
  color: var(--primary);
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: .25rem;
}

.embedded-task {
  margin-top: .75rem;
  animation: fadeIn .25s ease;
}

.embedded-task .task-header {
  margin: .25rem 0 .75rem;
}

.die-panel,
.private-panel,
.confirmation-panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.die-panel {
  text-align: center;
}

.private-dice-area {
  box-shadow: none;
  border: 1px solid var(--border);
  margin: .75rem 0;
}

.die-label,
.metric-label {
  color: var(--text-muted);
  font-size: .9rem;
}

@keyframes rollDice {
  0% {
    transform: rotate(0) scale(.5);
  }
  50% {
    transform: rotate(180deg) scale(1.12);
  }
  100% {
    transform: rotate(360deg) scale(1);
  }
}

.dice-display {
  display: flex;
  justify-content: center;
  margin: 1rem 0 .25rem;
}

.die-object {
  width: 104px;
  height: 104px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  padding: 16px;
  border-radius: 18px;
  background:
    radial-gradient(circle at 28% 22%, rgba(255, 255, 255, .95), transparent 30%),
    linear-gradient(145deg, #ffffff, #e5e7eb);
  border: 1px solid #cbd5e1;
  box-shadow:
    inset 0 -8px 18px rgba(15, 23, 42, .08),
    0 12px 24px rgba(15, 23, 42, .12);
  animation: rollDice .55s ease;
}

.die-pip {
  width: 13px;
  height: 13px;
  border-radius: 999px;
  align-self: center;
  justify-self: center;
  background: transparent;
}

.die-pip.visible {
  background: #0f172a;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, .25);
}

.private-panel {
  background: var(--private-bg);
  border: 1px solid var(--private-border);
  box-shadow: 0 1px 3px rgba(154, 52, 18, .1), 0 8px 18px rgba(154, 52, 18, .08);
}

.private-heading {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  margin-bottom: 1rem;
}

.private-heading h2 {
  margin-bottom: .15rem;
}

.private-heading p {
  color: var(--text-muted);
  font-size: .9rem;
}

.lock-icon {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: #fed7aa;
  color: #9a3412;
  font-size: 0;
}

.lock-icon::before {
  content: "🔒";
  font-size: 1rem;
}

.number-selector {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: .55rem;
  margin: 1rem 0;
}

.number-button {
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
  min-height: 56px;
  font-size: 1.2rem;
  font-weight: 800;
  cursor: pointer;
  transition: all .15s;
}

.number-button:hover:not(:disabled),
.number-button.selected {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.effort-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.effort-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  background: #f8fafc;
}

.effort-number {
  font-size: 2rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: .75rem;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .5rem;
}

.segment {
  border: 2px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: .55rem;
  cursor: pointer;
  font-weight: 700;
}

.segment.selected {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.income-report-box {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 1rem;
  align-items: center;
  margin: 1rem 0;
}

.income-range {
  width: 100%;
  margin: .75rem 0;
}

.income-preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin: 1rem 0;
  padding-top: 1rem;
  border-top: 1px solid var(--private-border);
}

.income-round-list {
  margin: 1rem 0;
  padding-left: 1.25rem;
  color: var(--text);
  line-height: 1.8;
  font-weight: 700;
}

.full-width {
  width: 100%;
}

.confirmation-panel {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
}

.ai-confirmation {
  color: var(--success);
  font-weight: 700;
  margin-bottom: 1rem;
}

.reward-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.metric-value {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text);
}

.feedback-box,
.error-box {
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.feedback-box {
  background: #fef3c7;
  border: 1px solid #fcd34d;
}

.feedback-box ul {
  margin-left: 1.25rem;
  margin-top: .5rem;
}

.error-box {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
}

.step-nav {
  margin-top: 1.5rem;
  text-align: right;
}

.step-nav-cta {
  padding: 1rem;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 0 0 8px 8px;
}

.step-nav-hint {
  margin: 0 0 .6rem;
  font-size: .88rem;
  color: var(--primary);
  font-weight: 600;
}

.step-nav-cta .btn-primary {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

.survey-card.is-missing {
  border-color: #fca5a5;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .08);
}

.survey-card.has-field-error {
  border-color: #dc2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .12);
}

.survey-card.has-field-error .text-input,
.survey-card.has-field-error .text-area {
  border-color: #dc2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .12);
}

.field-error {
  color: var(--danger);
  font-size: .85rem;
  font-weight: 700;
}

.survey-error-summary {
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: var(--danger);
  border-radius: var(--radius);
  padding: .85rem 1rem;
}

.thank-you {
  text-align: center;
  font-size: 1.05rem;
  margin-top: 1.5rem;
  color: var(--primary);
}

.participant-info-card {
  display: grid;
  gap: .85rem;
}

.participant-info-card h3 {
  margin: 0;
  font-size: 1.15rem;
}

.participant-info-row {
  display: grid;
  gap: .25rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--border);
}

.participant-info-label {
  color: var(--muted);
  font-size: .9rem;
}

.participant-info-value,
.completion-code {
  color: var(--text);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.completion-code {
  text-align: center;
  margin: 1rem 0 0;
}

.admin-page {
  width: min(920px, calc(100% - 32px));
  margin: 32px auto;
  display: grid;
  gap: 18px;
}

.code-output {
  background: #0f172a;
  color: #f8fafc;
  border-radius: 8px;
  padding: 16px;
  overflow: auto;
}

.export-grid {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .6rem 1.2rem;
  border: none;
  border-radius: 8px;
  font-size: .95rem;
  cursor: pointer;
  text-decoration: none;
}

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

.secondary-button {
  background: var(--border);
  color: var(--text);
}

@media (max-width: 720px) {
  #app {
    padding: 1rem;
  }

  .chat-layout,
  .rules-grid,
  .reward-grid {
    grid-template-columns: 1fr;
  }

  .number-selector {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .btn-row {
    justify-content: stretch;
  }

  .btn-row .btn {
    flex: 1;
  }
}


/* Fixed-width 5-point pre-survey layout */
.likert-scale--5 {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: .5rem;
}

.likert-scale--5 .likert-option {
  min-width: 0;
}

@media (max-width: 620px) {
  .likert-scale--5 {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}
