:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #14161a;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --ok: #1a7f4b;
  --warn: #b42318;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .2px; }
.progress { flex: 1; max-width: 520px; }
.progress-bar {
  height: 8px; background: var(--line); border-radius: 999px; overflow: hidden;
}
.progress-bar > span {
  display: block; height: 100%; width: 0%; background: var(--accent);
  transition: width .25s ease;
}
.progress-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

main { max-width: 880px; margin: 0 auto; padding: 24px 20px 80px; }

.screen { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

h1 { font-size: clamp(22px, 3.2vw, 30px); line-height: 1.2; margin: 8px 0 8px; }
h2 { font-size: 17px; margin: 0 0 10px; }
.lede { color: #374151; font-size: 17px; margin: 0 0 18px; }
.muted { color: var(--muted); font-size: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin: 16px 0;
}
.card-title { margin-bottom: 8px; }
.bullets { margin: 0; padding-left: 20px; }
.bullets li { margin: 6px 0; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
input[type="text"] {
  width: 100%; max-width: 360px; padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
input[type="text"]:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

.choices { border: 0; padding: 0; margin: 0 0 16px; }
.choices legend { font-weight: 600; font-size: 14px; margin-bottom: 6px; padding: 0; }
.choices label { margin-right: 18px; font-size: 15px; }

.consent { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; }
.consent input { margin-top: 4px; }

.actions { display: flex; align-items: center; gap: 16px; margin-top: 8px; }
button {
  font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); padding: 10px 16px;
}
button:hover:not(:disabled) { border-color: #c9ced6; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  font-weight: 600; padding: 11px 22px;
}
button.primary:hover:not(:disabled) { background: #2560d8; }
.error { color: var(--warn); font-size: 14px; margin: 0; }

/* ---- study ---- */
.refpanel {
  position: sticky; top: 64px; z-index: 5;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; margin-bottom: 18px;
}
.refpanel h2 { margin-bottom: 4px; }
.refpanel .prompt { font-size: 15px; color: #374151; margin: 6px 0 12px; }
.refgrid { display: flex; flex-wrap: wrap; gap: 10px; }
.refitem {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fbfbfc;
}
.refitem .who { font-weight: 600; font-size: 13px; }
.refitem .meta { font-size: 12px; color: var(--muted); }

.playbtn {
  display: inline-flex; align-items: center; gap: 8px;
  border-radius: 999px; padding: 8px 14px; font-weight: 600;
  border: 1px solid var(--accent); color: var(--accent); background: #fff;
}
.playbtn.playing { background: var(--accent); color: #fff; }
.playbtn .icon { width: 12px; }

.clipgrid { display: grid; gap: 14px; }
.clipcard {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px;
}
.cliphead { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cliplabel { font-weight: 700; }
.qrow { margin-top: 12px; }
.qrow .q { font-size: 14px; margin-bottom: 6px; }
.scale { display: flex; align-items: center; gap: 10px; }
.scale .anchor { font-size: 12px; color: var(--muted); min-width: 84px; }
.scale .anchor.right { text-align: right; }
.scale .dots { display: flex; gap: 6px; }
.dot {
  width: 42px; height: 38px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; font-size: 15px; font-weight: 600;
}
.dot:hover { border-color: #c9ced6; }
.dot.sel { background: var(--accent); color: #fff; border-color: var(--accent); }

.picksection { margin-top: 18px; }
.pickopts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.pickopts button.sel { background: var(--accent); color: #fff; border-color: var(--accent); }

.voicefooter { display: flex; justify-content: flex-end; margin-top: 18px; }

.footer {
  max-width: 880px; margin: 0 auto; padding: 0 20px 40px;
  color: var(--muted); font-size: 12px;
}

.resumebar .resume-text { margin: 0 0 10px; font-size: 15px; }
.resume-actions { display: flex; gap: 10px; }
.resume-actions button { min-height: 44px; }

@media (max-width: 620px) {
  main { padding: 16px 14px 84px; }
  .topbar { padding: 10px 14px; }
  .card, .refpanel { padding: 14px; }
  /* the reference panel is tall on phones: don't pin it */
  .refpanel { position: static; }
  .refgrid { display: grid; grid-template-columns: 1fr; }
  .refitem { justify-content: space-between; }
  /* scale: dots on their own row, labels below */
  .scale { flex-wrap: wrap; row-gap: 6px; }
  .scale .dots { order: 1; flex: 1 1 100%; gap: 6px; }
  .dot { flex: 1 1 0; max-width: 64px; width: auto; height: 48px; font-size: 17px; }
  .scale .anchor { order: 2; flex: 1 1 auto; min-width: 0; font-size: 11px; }
  .scale .anchor.right { text-align: right; }
  .playbtn { min-height: 44px; }
  .pickopt { min-height: 44px; }
  /* keep the primary action reachable while scrolling a long voice */
  .voicefooter {
    position: sticky; bottom: 0; z-index: 6;
    padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
    background: linear-gradient(transparent, var(--bg) 40%);
  }
  .voicefooter .primary { width: 100%; padding: 14px; font-size: 16px; }
  .actions .primary { width: 100%; padding: 14px; font-size: 16px; }
}
