/* DermaCloud clinic quiz
   Theme: a prescription pad. Calamine-pink desk, paper cases, rubber-stamp ink in brand teal. */

:root {
  --calamine: #f6ddd5;
  --calamine-deep: #e9bcae;
  --paper: #fffbf8;
  --paper-under: #fbeee8;
  --ink: #2e2330;
  --ink-soft: #6b5965;
  --line: #ecd2c9;
  --teal: #0f766e;
  --teal-press: #0a524c;
  --teal-tint: #dcefea;
  --rose: #b3264a;
  --rose-tint: #fbe4e8;
  --on-teal: #fffbf8;
  --shadow-card: 0 1px 0 rgb(120 60 50 / 0.06), 0 18px 32px -18px rgb(120 60 50 / 0.45);
  --shadow-under: 0 10px 22px -16px rgb(120 60 50 / 0.5);
  --shadow-slip: rgb(120 60 50 / 0.32);
  --stamp-blend: multiply;

  --font-ui: "Bricolage Grotesque", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-hand: "Kalam", "Bradley Hand", "Segoe Print", cursive;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --calamine: #241b25;
    --calamine-deep: #4b3540;
    --paper: #31262f;
    --paper-under: #2a2029;
    --ink: #f8ebe6;
    --ink-soft: #cdb6bb;
    --line: #4a3843;
    --teal: #5fc8b9;
    --teal-press: #2f8f83;
    --teal-tint: #1d3b38;
    --rose: #f28ba2;
    --rose-tint: #4a2533;
    --on-teal: #13211f;
    --shadow-card: 0 1px 0 rgb(0 0 0 / 0.2), 0 18px 32px -18px rgb(0 0 0 / 0.75);
    --shadow-under: 0 10px 22px -16px rgb(0 0 0 / 0.8);
    --shadow-slip: rgb(0 0 0 / 0.55);
    --stamp-blend: normal;
    color-scheme: dark;
  }
}

/* Base */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  margin: 0;
  overflow-x: clip;
}

body {
  background: var(--calamine);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.5;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 3px;
}

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

.noscript {
  max-width: 460px;
  margin: 0 auto;
  padding: 18px;
}

/* Layout */

.screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 460px;
  margin: 0 auto;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
}

/* Buttons */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 58px;
  padding: 0 22px;
  border: 0;
  border-radius: 16px;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.005em;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.2s;
}

.btn--primary {
  background: var(--teal);
  color: var(--on-teal);
  box-shadow: 0 4px 0 var(--teal-press);
}

.btn--primary:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--teal-press);
}

.btn--ghost {
  min-height: 52px;
  background: transparent;
  color: var(--teal);
  border: 1.5px solid var(--calamine-deep);
}

.btn--ghost:active { transform: translateY(1px); }

/* The ℞ mark, drawn stroke by stroke */

.rx {
  display: block;
  overflow: visible;
  color: var(--teal);
}

.rx path {
  fill: none;
  stroke: currentColor;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1 3;
  stroke-dashoffset: 1.02;
}

.rx.is-drawing path { animation: draw 0.42s cubic-bezier(0.6, 0, 0.4, 1) forwards; }
.rx.is-drawing path:nth-child(1) { animation-delay: calc(var(--rx-delay, 0.15s) + 0s); }
.rx.is-drawing path:nth-child(2) { animation-delay: calc(var(--rx-delay, 0.15s) + 0.36s); }
.rx.is-drawing path:nth-child(3) { animation-delay: calc(var(--rx-delay, 0.15s) + 0.76s); animation-duration: 0.32s; }
.rx.is-drawing path:nth-child(4) { animation-delay: calc(var(--rx-delay, 0.15s) + 1.06s); animation-duration: 0.2s; }

@keyframes draw { to { stroke-dashoffset: 0; } }

/* Welcome */

.welcome-body { margin-top: clamp(28px, 8vh, 72px); }

.rx--hero {
  width: 60px;
  height: 68px;
  margin-bottom: 20px;
}

.welcome-title {
  margin: 0;
  font-size: clamp(36px, 10.5vw, 46px);
  font-weight: 750;
  line-height: 1.02;
  letter-spacing: -0.03em;
  text-wrap: balance;
}

.welcome-lede {
  max-width: 34ch;
  margin: 16px 0 0;
  color: var(--ink-soft);
  font-size: 17.5px;
  text-wrap: pretty;
}

.start-form { margin-top: 30px; }

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 600;
}

.name-field {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 58px;
  padding: 0 16px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.name-field:focus-within {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px var(--teal-tint);
}

.name-prefix {
  color: var(--teal);
  font-family: var(--font-hand);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
  transform: translateY(2px);
}

.name-field input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 19px;
  font-weight: 500;
  outline: none;
}

.name-field input::placeholder {
  color: var(--ink-soft);
  opacity: 0.6;
}

.field-hint {
  margin: 8px 2px 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.start-form .btn { margin-top: 22px; }

/* Quiz */

.quiz { padding-bottom: 0; }

.quiz-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.case-count {
  color: var(--ink-soft);
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.progress {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.progress li {
  height: 6px;
  border-radius: 3px;
  background: var(--calamine-deep);
  opacity: 0.55;
  transition: background-color 0.35s, opacity 0.35s;
}

.progress li.is-current { background: var(--teal); opacity: 0.35; }
.progress li.is-right { background: var(--teal); opacity: 1; }
.progress li.is-wrong { background: var(--rose); opacity: 1; }

/* The case stack: papers underneath show how many cases are left */

.deck {
  position: relative;
  margin-top: 18px;
  padding-bottom: 18px;
}

.deck::before,
.deck::after {
  content: "";
  position: absolute;
  height: 90px;
  border-radius: 22px;
  background: var(--paper-under);
  box-shadow: var(--shadow-under);
}

.deck::before { left: 10px; right: 10px; bottom: 8px; z-index: 1; }
.deck::after { left: 22px; right: 22px; bottom: 0; z-index: 0; opacity: 0.8; }

.deck[data-remaining="1"]::after,
.deck[data-remaining="0"]::before,
.deck[data-remaining="0"]::after { display: none; }

.card {
  position: relative;
  z-index: 2;
  padding: 16px 18px 22px;
  background: var(--paper);
  border-radius: 22px;
  box-shadow: var(--shadow-card);
}

.card.is-entering { animation: card-in 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) both; }

.card.is-answered { animation: thud 0.32s 0.2s ease-out; }

.card.is-leaving {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  pointer-events: none;
  animation: card-out 0.4s cubic-bezier(0.5, 0, 0.75, 0) forwards;
}

@keyframes card-in {
  from { transform: translateY(18px) scale(0.955); opacity: 0.3; }
}

@keyframes card-out {
  to { transform: translate(-112%, -8px) rotate(-8deg); opacity: 0; }
}

@keyframes thud {
  40% { transform: translateY(2px) scale(0.997); }
}

.card-head {
  display: flex;
  align-items: center;
  min-height: 34px;
  padding-right: 120px;
}

.topic {
  display: inline-flex;
  align-items: center;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--calamine);
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 600;
}

.question {
  margin: 14px 0 20px;
  font-size: clamp(21px, 6vw, 24px);
  font-weight: 650;
  line-height: 1.28;
  letter-spacing: -0.015em;
  text-wrap: pretty;
  outline: none;
}

/* Answer options */

.options {
  display: grid;
  gap: 10px;
}

.options--pair { grid-template-columns: 1fr 1fr; }

.option {
  position: relative;
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  padding: 13px 16px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  font-size: 17px;
  font-weight: 550;
  line-height: 1.3;
  text-align: left;
  transition: border-color 0.2s, background-color 0.25s, opacity 0.3s, transform 0.12s;
}

.options--pair .option {
  grid-template-columns: auto auto;
  justify-content: center;
  min-height: 76px;
  font-size: 20px;
  font-weight: 700;
}

.option:active:not(:disabled) { transform: scale(0.98); }
.option:disabled { cursor: default; }

@media (hover: hover) {
  .option:hover:not(:disabled) { border-color: var(--teal); }
}

.option-mark {
  position: relative;
  width: 24px;
  height: 24px;
  border: 2px solid var(--calamine-deep);
  border-radius: 50%;
  transition: background-color 0.25s, border-color 0.25s;
}

.option.is-correct,
.option.is-answer { border-color: var(--teal); }
.option.is-correct { background: var(--teal-tint); }

.option.is-correct .option-mark,
.option.is-answer .option-mark {
  background: var(--teal);
  border-color: var(--teal);
}

.option.is-correct .option-mark::after,
.option.is-answer .option-mark::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 6px;
  height: 11px;
  border: solid var(--on-teal);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

.option.is-wrong {
  border-color: var(--rose);
  background: var(--rose-tint);
  animation: shake 0.42s;
}

.option.is-wrong .option-mark {
  background: var(--rose);
  border-color: var(--rose);
}

.option.is-wrong .option-mark::before,
.option.is-wrong .option-mark::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 2.5px;
  border-radius: 2px;
  background: var(--paper);
  transform: translate(-50%, -50%) rotate(45deg);
}

.option.is-wrong .option-mark::after { transform: translate(-50%, -50%) rotate(-45deg); }

.options.is-locked .option:not(.is-correct):not(.is-wrong):not(.is-answer) { opacity: 0.45; }

@keyframes shake {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

/* The explanation that opens after answering */

.reveal {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
  scroll-margin-bottom: 110px;
}

.card.is-answered .reveal { grid-template-rows: 1fr; }

.reveal-inner {
  min-height: 0;
  overflow: hidden;
}

.reaction {
  margin: 20px 0 6px;
  color: var(--teal);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card.is-wrong .reaction { color: var(--rose); }

.why {
  margin: 0;
  font-size: 16.5px;
  line-height: 1.55;
  text-wrap: pretty;
}

.note {
  margin: 14px 0 0;
  padding: 2px 0 2px 14px;
  border-left: 2.5px solid var(--calamine-deep);
  color: var(--teal);
  font-family: var(--font-hand);
  font-size: 19.5px;
  line-height: 1.35;
}

/* Rubber stamp */

.stamp {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 2;
  padding: 6px 11px 5px;
  border: 4px double currentColor;
  border-radius: 8px;
  color: var(--teal);
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.01em;
  white-space: nowrap;
  mix-blend-mode: var(--stamp-blend);
  opacity: 0;
  transform: rotate(-8deg);
  pointer-events: none;
}

.card.is-wrong .stamp { color: var(--rose); }
.card.is-answered .stamp { animation: stamp-in 0.45s cubic-bezier(0.25, 1.5, 0.5, 1) forwards; }

@keyframes stamp-in {
  0% { opacity: 0; transform: scale(2.3) rotate(-20deg); }
  55% { opacity: 0.95; }
  100% { opacity: 0.9; transform: scale(1) rotate(-8deg); }
}

/* Sticky next button */

.next-bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin-top: auto;
  padding: 16px 0 max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--calamine) 72%, transparent);
  opacity: 0;
  transform: translateY(14px);
  pointer-events: none;
  transition: opacity 0.3s, transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.next-bar.is-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* Result: the prescription slip */

.slip-wrap { filter: drop-shadow(0 18px 26px var(--shadow-slip)); }

.result.is-shown .slip-wrap { animation: slip-in 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both; }

@keyframes slip-in {
  from { transform: translateY(40px) rotate(1.5deg); opacity: 0; }
}

.slip {
  position: relative;
  padding: 30px 22px 24px;
  background: var(--paper);
  border-radius: 4px 4px 22px 22px;
  /* perforated top edge, torn off the pad */
  -webkit-mask: radial-gradient(circle at 9px 0, transparent 5.5px, #000 6px) 0 0 / 18px 100% repeat-x;
  mask: radial-gradient(circle at 9px 0, transparent 5.5px, #000 6px) 0 0 / 18px 100% repeat-x;
}

.slip-head {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1.5px solid var(--line);
}

.slip-date {
  color: var(--ink-soft);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.slip-for {
  margin: 20px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.slip-name {
  margin: 0;
  padding-bottom: 4px;
  border-bottom: 1.5px dashed var(--calamine-deep);
  font-family: var(--font-hand);
  font-size: 36px;
  font-weight: 700;
  line-height: 1.15;
  overflow-wrap: anywhere;
  outline: none;
}

.slip-row { margin-top: 18px; }

.slip-label {
  display: block;
  color: var(--ink-soft);
  font-size: 14px;
}

.diagnosis {
  display: block;
  margin-top: 2px;
  font-size: 25px;
  font-weight: 750;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.tally {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 6px;
}

.tally-list {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tally-list li {
  position: relative;
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

.tally-list li.is-right { background: var(--teal); }
.tally-list li.is-wrong { background: var(--rose-tint); box-shadow: inset 0 0 0 1.5px var(--rose); }

.tally-list li.is-right::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 4px;
  width: 6px;
  height: 11px;
  border: solid var(--on-teal);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

.tally-list li.is-wrong::before,
.tally-list li.is-wrong::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 11px;
  height: 2.5px;
  border-radius: 2px;
  background: var(--rose);
  transform: translate(-50%, -50%) rotate(45deg);
}

.tally-list li.is-wrong::after { transform: translate(-50%, -50%) rotate(-45deg); }

.tally-text {
  font-size: 16px;
  font-weight: 650;
}

.slip-message {
  margin: 18px 0 0;
  font-size: 17px;
  line-height: 1.55;
  text-wrap: pretty;
}

.rx-block {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 14px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1.5px solid var(--line);
}

.rx--slip {
  --rx-delay: 0.75s;
  width: 36px;
  height: 41px;
}

.rx--slip path { stroke-width: 6.5; }

.advice {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 4px 0 0;
  list-style: none;
  counter-reset: rx;
}

.advice li {
  counter-increment: rx;
  font-family: var(--font-hand);
  font-size: 19.5px;
  line-height: 1.32;
}

.advice li::before {
  content: counter(rx) ". ";
  color: var(--teal);
  font-weight: 700;
}

.slip-foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
}

.followup {
  margin: 0 0 6px;
  color: var(--ink-soft);
  font-size: 14px;
}

.followup strong {
  display: block;
  color: var(--ink);
  font-family: var(--font-hand);
  font-size: 21px;
  font-weight: 700;
}

.seal {
  flex: none;
  width: 104px;
  height: 104px;
  margin: -10px -4px -6px 0;
  color: var(--teal);
  mix-blend-mode: var(--stamp-blend);
  opacity: 0;
  transform: rotate(-14deg);
}

.result.is-shown .seal { animation: seal-in 0.5s 1.7s cubic-bezier(0.25, 1.5, 0.5, 1) forwards; }

@keyframes seal-in {
  0% { opacity: 0; transform: scale(2.4) rotate(-30deg); }
  60% { opacity: 0.95; }
  100% { opacity: 0.9; transform: scale(1) rotate(-14deg); }
}

.seal-ring {
  fill: currentColor;
  font-size: 11px;
  font-weight: 800;
}

.seal-score {
  fill: currentColor;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.again { margin-top: 26px; }

/* Respect reduced motion: everything lands in its final state at once */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}
