:root {
  --bg: #f4f2ed;
  --card: #ffffff;
  --ink: #1c2321;
  --muted: #6b726f;
  --line: #e4e1d9;
  --soft: #eef3f1;
  --accent: #0f766e;
  --accent-2: #14b8a6;
  --accent-soft: #d5ede9;
  --warn: #b45309;
  --danger: #c2410c;
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, 'JetBrains Mono', monospace;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 90px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
}
.topbar-inner { max-width: 760px; margin: 0 auto; display: flex; align-items: center; gap: 14px; }
.brand { font-family: var(--mono); font-size: 13px; color: var(--accent); font-weight: 600; letter-spacing: 0.04em; white-space: nowrap; }
.progress { flex: 1; height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 99px; transition: width 0.35s ease; }
.progress-label { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.save-state { font-size: 12px; color: var(--muted); min-width: 84px; text-align: right; white-space: nowrap; }
.save-state.err { color: var(--danger); }

/* ---------- Layout ---------- */
.wrap { max-width: 760px; margin: 0 auto; padding: 22px 16px calc(60px + env(safe-area-inset-bottom)); }

.hero {
  position: relative;
  overflow: hidden;
  background: var(--ink);
  color: #f3f5f4;
  border-radius: 24px;
  padding: 28px 24px 26px;
  margin-bottom: 18px;
}
.hero::after {
  content: '';
  position: absolute;
  right: -70px; top: -70px;
  width: 240px; height: 240px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--accent-2), transparent 68%);
  opacity: 0.45;
}
.hero .kicker { font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: #8be0d4; }
.hero h1 { font-size: clamp(26px, 6vw, 34px); line-height: 1.1; margin: 8px 0 6px; letter-spacing: -0.02em; position: relative; z-index: 1; }
.hero .sub { color: #b9c2bf; margin: 0 0 16px; position: relative; z-index: 1; }
.hero p.intro { margin: 0; color: #dfe5e3; font-size: 15px; position: relative; z-index: 1; max-width: 56ch; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; position: relative; z-index: 1; }
.chip { font-size: 13px; padding: 5px 11px; border-radius: 99px; background: rgba(255,255,255,0.09); color: #e6ecea; }
.chip.warn { background: rgba(251, 191, 36, 0.18); color: #fde68a; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 18px;
  margin-bottom: 16px;
}

/* ---------- Sections & questions ---------- */
.section { margin-top: 30px; }
.section-head { display: flex; align-items: center; gap: 12px; margin: 0 4px 12px; }
.section-num {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  font-family: var(--mono);
}
.section-head h2 { font-size: 21px; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
.section-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.q { padding: 18px 18px 16px; }
.q + .q { margin-top: -6px; }
.q-label { font-weight: 650; font-size: 16.5px; margin: 0; }
.q-teacher { display: block; font-weight: 500; font-size: 13.5px; color: var(--muted); margin-top: 1px; }
.q-hint { color: var(--muted); font-size: 14px; margin: 2px 0 0; }
.q.answered .q-label::after {
  content: '';
  display: inline-block;
  width: 7px; height: 7px;
  margin-left: 8px;
  border-radius: 50%;
  background: var(--accent-2);
  vertical-align: middle;
}

/* Rating 1-5 */
.rating { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin-top: 14px; }
.rating button {
  border: 1.5px solid var(--line);
  background: var(--bg);
  border-radius: 12px;
  padding: 10px 2px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: transform 0.12s, background 0.15s, border-color 0.15s, color 0.15s;
}
.rating button b { font-size: 18px; font-variant-numeric: tabular-nums; }
.rating button span { font-size: 11px; color: var(--muted); line-height: 1.15; text-align: center; }
.rating button:active { transform: scale(0.95); }
.rating button.on { border-color: var(--accent); background: var(--accent); color: #fff; }
.rating button.on span { color: #d5f3ee; }
.rating button.on[data-v="1"], .rating button.on[data-v="2"] { background: #9a3412; border-color: #9a3412; }
.rating button.on[data-v="1"] span, .rating button.on[data-v="2"] span { color: #fde2d4; }
.rating button.on[data-v="3"] { background: #a16207; border-color: #a16207; }
.rating button.on[data-v="3"] span { color: #fdf0c8; }

/* Choices */
.options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.options.scale { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
.options button {
  border: 1.5px solid var(--line);
  background: var(--bg);
  border-radius: 99px;
  padding: 9px 15px;
  font-size: 15px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.options.scale button { border-radius: 12px; padding: 10px 6px; font-size: 14px; }
.options button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.options button.multi::before { content: '+ '; opacity: 0.6; }
.options button.multi.on::before { content: '✓ '; opacity: 1; }

/* Text */
textarea, input[type=text], input[type=password] {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 11px 13px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
textarea { resize: none; min-height: 48px; overflow: hidden; line-height: 1.45; display: block; }
textarea:focus, input:focus { border-color: var(--accent); background: #fff; }
.q textarea { margin-top: 12px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 0 -6px; text-transform: uppercase; letter-spacing: 0.04em; }
textarea:disabled, input:disabled, .rating button:disabled, .options button:disabled { opacity: 0.6; cursor: not-allowed; }

/* Name card */
.name-card label { font-weight: 650; display: block; }
.name-card small { display: block; color: var(--muted); font-size: 13.5px; margin: 2px 0 10px; }

/* Submit */
.submit-card { text-align: center; padding: 26px 20px; margin-top: 30px; }
.submit-card h3 { margin: 0 0 4px; font-size: 20px; }
.submit-card p { margin: 0 0 16px; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0;
  border-radius: 14px;
  padding: 14px 22px;
  font-weight: 650;
  font-size: 16px;
  background: var(--accent);
  color: #fff;
  transition: transform 0.12s, opacity 0.15s;
  text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--soft); color: var(--accent); }
.btn.dark { background: var(--ink); }
.btn.small { padding: 9px 14px; font-size: 14px; border-radius: 11px; }
.btn.danger-ghost { background: #fbeee7; color: var(--danger); }

.done-banner {
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--accent-soft);
  border: 1px solid #b4dfd8;
  color: #0b4f49;
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.done-banner .ico { flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
.done-banner b { display: block; }
.closed-banner { background: #fff4e5; border-color: #f6d8ab; color: #7c4a03; }
.closed-banner .ico { background: var(--warn); }

/* ---------- Join / login screens ---------- */
.gate { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 18px; }
.gate-card { width: 100%; max-width: 400px; }
.gate .hero { margin-bottom: 14px; }
.gate form label { display: block; font-size: 14px; font-weight: 600; margin: 4px 0 8px; }
.code-input { font-family: var(--mono); font-size: 22px !important; letter-spacing: 0.25em; text-transform: uppercase; text-align: center; }
.err-msg { color: var(--danger); font-size: 14px; min-height: 22px; margin: 8px 0 6px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; z-index: 50;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2); max-width: calc(100% - 32px);
}

@media (min-width: 640px) {
  .wrap { padding-top: 32px; }
  .hero { padding: 36px 34px 32px; }
  .q { padding: 22px 24px 20px; }
  .rating button span { font-size: 12px; }
}
