/* Dermatordle — game board (index.html). Requires base.css. */

/* ---------- Page frame ---------- */
.game-wrapper {
  width: 100%; max-width: var(--board-max);
  margin: 0 auto; padding: 22px 20px 40px;
}
.game-wrapper.case-transitioning { opacity: 0.5; pointer-events: none; transition: opacity 120ms; }

/* ---------- Case header ---------- */
.case-header {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 14px 24px;
  padding-bottom: 18px; margin-bottom: 22px;
  border-bottom: 2px solid var(--ink);
}
.case-kicker {
  margin-bottom: 4px;
  color: var(--ink-2); font-size: 0.9rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
#case-title { font-size: clamp(1.7rem, 4vw, 2.5rem); font-weight: 900; letter-spacing: -0.04em; }
.case-stats { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.stat-guesses, .stat-chip, .phase-pill {
  display: inline-flex; align-items: center; gap: 10px;
  height: 36px; padding: 0 12px;
  border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  font-size: 0.85rem; font-weight: 700; white-space: nowrap;
}
.guess-dots { display: flex; gap: 4px; }
.guess-dots i {
  width: 10px; height: 10px; border-radius: 3px;
  background: var(--tile); box-shadow: inset 0 0 0 1.5px var(--line-strong);
  transition: background-color 200ms;
}
.guess-dots i.used { background: var(--miss); box-shadow: none; }
.guess-dots i.won { background: var(--green); box-shadow: none; }
#attempt-count { font-variant-numeric: tabular-nums; }
.stat-chip strong { font-weight: 700; color: var(--ink-2); }
.stat-chip strong.is-complete { color: var(--green-deep); }
.phase-pill { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- Board ---------- */
#dermatordle-phase {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(0, 1fr);
  gap: 28px; align-items: start;
}
.board-play { display: grid; gap: 18px; min-width: 0; }

/* Images */
.image-gallery {
  position: sticky; top: 76px;
  display: grid; gap: 10px; min-width: 0;
}
.image-box {
  position: relative; overflow: hidden;
  aspect-ratio: 4 / 3.4;
  border-radius: var(--radius-lg);
  background: #e9e6dc;
  cursor: zoom-in;
}
.image-box img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform 300ms var(--ease-out);
}
.image-box:hover img { transform: scale(1.02); }
.image-label {
  position: absolute; left: 10px; top: 10px; z-index: 2;
  padding: 4px 9px; border-radius: 7px;
  background: rgba(255, 255, 255, 0.94); color: var(--ink);
  font-size: 0.75rem; font-weight: 800;
}
.image-label.is-alt { background: var(--slate); color: #fff; }
.zoom-hint {
  position: absolute; right: 10px; bottom: 10px; z-index: 2;
  padding: 4px 9px; border-radius: 7px;
  background: rgba(20, 22, 18, 0.7); color: #fff;
  font-size: 0.72rem; font-weight: 700;
  opacity: 0; transition: opacity 150ms;
}
.image-box:hover .zoom-hint { opacity: 1; }
@media (hover: none) { .zoom-hint { opacity: 1; } }

/* Case images: labels hidden; a second image stacks under the first. */
#image-gallery .image-label { display: none; }
/* Two case images stack vertically, each a little shorter so both fit on screen. */
#image-gallery.has-two .image-box { aspect-ratio: auto; height: clamp(200px, calc((100 * var(--vh) - 240px) / 2), 440px); }
.image-box.just-revealed { animation: image-in 420ms var(--ease-out); box-shadow: 0 0 0 3px var(--hint); }
.image-box.just-revealed::after {
  content: "New"; position: absolute; left: 10px; top: 10px; z-index: 3;
  padding: 3px 9px; border-radius: 7px;
  background: var(--hint); color: var(--ink);
  font-size: 0.75rem; font-weight: 900;
}
@keyframes image-in { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: none; } }

/* No photo yet: the clues and guesses take the full width. */
#dermatordle-phase:has(#image-gallery > .image-box:first-child.hidden) { grid-template-columns: minmax(0, 680px); justify-content: center; }
#dermatordle-phase:has(#image-gallery > .image-box:first-child.hidden) #image-gallery { display: none; }

.image-credit-row { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 0 2px; }
.image-credit-link {
  color: var(--ink-3); font-size: 0.74rem; font-weight: 600;
  text-decoration: underline; text-underline-offset: 2px; text-decoration-color: var(--line-strong);
}
.image-credit-link:hover { color: var(--ink); }

/* Clues */
.section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-heading h2 { font-size: 1.1rem; font-weight: 900; }
.clue-progress { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-3); font-size: 0.8rem; font-weight: 700; }
.clue-progress i { width: 16px; height: 5px; border-radius: 3px; background: var(--line); }
.clue-progress i.on { background: var(--hint); }
#clues-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; counter-reset: clue; }
#clues-list li {
  position: relative;
  padding: 12px 14px 12px 50px;
  border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  font-size: 0.97rem; line-height: 1.45;
}
#clues-list li:not(.placeholder-text) { counter-increment: clue; }
#clues-list li:not(.placeholder-text)::before {
  content: counter(clue);
  position: absolute; left: 12px; top: 11px;
  display: grid; place-items: center; width: 26px; height: 26px;
  border-radius: 7px; background: var(--tile);
  font-size: 0.82rem; font-weight: 900; font-variant-numeric: tabular-nums;
}
#clues-list li.opening-clue { background: var(--tile); border-color: transparent; }
#clues-list li.opening-clue::before { background: var(--ink); color: #fff; }
#clues-list li.is-new { border-color: var(--hint); background: var(--hint-soft); animation: clue-in 380ms var(--ease-out); }
#clues-list li.is-new::before { background: var(--hint); }
#clues-list li.placeholder-text {
  padding: 14px; border-style: dashed; background: transparent;
  color: var(--ink-3); font-size: 0.92rem; text-align: center;
}
@keyframes clue-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* Guess tiles */
.guess-grid { display: grid; gap: 6px; }
.guess-row {
  display: flex; align-items: center; gap: 12px;
  min-height: 50px; padding: 6px 14px 6px 8px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 2px solid var(--line);
  font-weight: 800; font-size: 1rem;
}
.guess-num {
  flex: none; display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--tile); color: var(--ink-2);
  font-size: 0.82rem; font-weight: 900;
}
.guess-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guess-mark { flex: none; font-size: 1.1rem; font-weight: 900; }
.guess-row.empty { border-style: dashed; background: transparent; color: var(--ink-3); }
.guess-row.empty .guess-num { background: transparent; color: var(--line-strong); }
.guess-row.unused { opacity: 0.4; }
.guess-row.active { border-color: var(--ink); cursor: text; }
.guess-row.active .guess-num { background: var(--ink); color: #fff; }
.guess-row.active .guess-text { color: var(--ink-3); font-weight: 600; }
.guess-row.active.has-text .guess-text { color: var(--ink); font-weight: 800; }
.guess-row.active.has-text .guess-text::after {
  content: ""; display: inline-block; width: 2px; height: 1.1em; margin-left: 2px;
  vertical-align: -3px; background: var(--ink); animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }
.guess-row.wrong { background: var(--miss); border-color: var(--miss); color: #fff; }
.guess-row.wrong .guess-num { background: rgba(255,255,255,0.18); color: #fff; }
.guess-row.correct { background: var(--green); border-color: var(--green); color: #fff; }
.guess-row.correct .guess-num { background: rgba(255,255,255,0.2); color: #fff; }
.guess-row.is-new { animation: tile-flip 480ms var(--ease-out); }
.guess-row.is-new.wrong { animation: tile-flip 480ms var(--ease-out), tile-shake 360ms 480ms; }
.guess-row.is-new.correct { animation: tile-flip 480ms var(--ease-out), tile-pop 300ms 480ms; }
@keyframes tile-flip {
  0% { transform: rotateX(0); }
  45% { transform: rotateX(90deg); background: var(--surface); color: var(--ink); border-color: var(--ink); }
  55% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}
@keyframes tile-shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes tile-pop { 50% { transform: scale(1.04); } }

.guess-feedback {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px; padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--hint-soft); color: #5c4700;
  font-size: 0.92rem; font-weight: 700;
  animation: clue-in 260ms var(--ease-out);
}
.guess-feedback::before { content: "↑"; font-weight: 900; }
.guess-feedback.success { background: var(--green-soft); color: var(--green-deep); }
.guess-feedback.success::before { content: "✓"; }

/* Input */
.input-section {
  position: relative;
  display: grid; grid-template-columns: 1fr auto; gap: 8px;
  margin-top: 12px;
}
.input-field { position: relative; }
.input-icon {
  position: absolute; left: 14px; top: 50%; width: 20px; height: 20px; margin-top: -10px;
  fill: none; stroke: var(--ink-3); stroke-width: 2.2; stroke-linecap: round; pointer-events: none;
}
#guess-input {
  width: 100%; height: 52px; padding: 0 44px 0 44px;
  border: 2px solid var(--ink); border-radius: var(--radius);
  background: var(--surface);
  font-size: 1.05rem; font-weight: 600;
  outline: none;
}
#guess-input::placeholder { color: var(--ink-3); font-weight: 500; }
#guess-input:focus { box-shadow: 0 0 0 4px rgba(240, 189, 63, 0.45); }
#guess-input:disabled { background: var(--tile); border-color: var(--line-strong); color: var(--ink-2); }
.clear-guess-btn {
  position: absolute; right: 8px; top: 50%; margin-top: -15px;
  width: 30px; height: 30px; padding: 0;
  border: 0; border-radius: 50%; background: var(--tile);
  font-size: 1.2rem; line-height: 1; color: var(--ink-2);
}
.clear-guess-btn:disabled { visibility: hidden; }
#submit-btn { height: 52px; min-width: 96px; }
#submit-btn.is-ready { background: var(--green); box-shadow: 0 3px 0 var(--green-deep); }
.input-helper { margin-top: 8px; color: var(--ink-3); font-size: 0.84rem; }
.input-helper:empty { display: none; }

/* Answer revealed after five misses */
.input-section.diagnosis-revealed { grid-template-columns: 1fr; }
.input-section.diagnosis-revealed .input-field::before {
  content: "Out of guesses · the answer";
  display: block; margin-bottom: 6px;
  color: var(--ink-2); font-size: 0.78rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em;
}
.input-section.diagnosis-revealed .input-icon { display: none; }
.input-section.diagnosis-revealed #guess-input { padding-left: 16px; }
.input-section.diagnosis-revealed #guess-input:disabled {
  background: var(--surface); border: 2px solid var(--ink); color: var(--ink);
  font-weight: 900; opacity: 1; -webkit-text-fill-color: var(--ink);
}
.input-section.diagnosis-revealed #submit-btn,
.input-section.diagnosis-revealed .clear-guess-btn { display: none; }

/* Autocomplete (opens downward) */
.autocomplete-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 60;
  max-height: min(320px, calc(50 * var(--vh))); overflow-y: auto;
  margin: 0; padding: 6px; list-style: none;
  background: var(--surface); border: 2px solid var(--ink); border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
}
.autocomplete-item {
  padding: 10px 12px; border-radius: 8px;
  font-size: 0.97rem; cursor: pointer;
}
.autocomplete-item mark { background: none; color: inherit; font-weight: 900; }
.autocomplete-item:hover, .autocomplete-item.active { background: var(--hint-soft); }


/* The guess field stays on screen while you type. */
.input-section {
  position: sticky; bottom: 0; z-index: 30;
  margin-top: 8px; padding: 10px 0 max(12px, env(safe-area-inset-bottom));
  background: var(--bg);
  box-shadow: 0 -10px 12px -8px var(--bg);
}
.input-section.diagnosis-revealed { position: static; box-shadow: none; }
.autocomplete-list.open-up { top: auto; bottom: calc(100% - 4px); }
.guess-row { scroll-margin-bottom: 100px; scroll-margin-top: 80px; }
.guess-row.empty { min-height: 40px; }


/* ---------- Case format v2: image clues, modality, tone strip ---------- */
#clues-list li.image-clue { display: flex; align-items: center; gap: 12px; }
.clue-thumb {
  flex: none; width: 52px; height: 52px; padding: 0;
  border: 0; border-radius: 9px; overflow: hidden; background: var(--tile);
  cursor: zoom-in; box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--line-strong);
}
.clue-thumb img { width: 100%; height: 100%; object-fit: cover; }
.clue-body { min-width: 0; }
.clue-tag {
  display: inline-block; margin-right: 8px; padding: 1px 7px; border-radius: 6px;
  background: var(--slate); color: #fff;
  font-size: 0.72rem; font-weight: 800; letter-spacing: 0.02em; vertical-align: 1px;
}
#image-gallery .image-box.has-modality .image-label { display: inline-block; background: var(--slate); color: #fff; }
.label-chip {
  display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 6px;
  background: var(--slate); color: #fff; letter-spacing: 0.02em; text-transform: none; font-size: 0.74rem;
}
.tone-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.tone-item {
  display: grid; gap: 4px; padding: 0; border: 0; background: none; cursor: zoom-in; text-align: left;
}
.tone-item img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--tile); }
.tone-item span { color: var(--ink-2); font-size: 0.78rem; font-weight: 800; }
/* One teaching card spans the full width when the other is empty. */
.teaching-points:has(> .hidden) { grid-template-columns: 1fr; }
.teaching-points:has(.tone-strip:not(.hidden)) { grid-template-columns: 1fr; }

/* ---------- Round 2: matching ---------- */
#phase-divider { border: 0; border-top: 2px solid var(--ink); margin: 40px 0 28px; }
#match-phase {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "head" "reflabel" "refs" "choicelabel" "options" "feedback";
  align-items: start;
}
.target-section { display: contents; }
.round-heading { grid-area: head; display: grid; gap: 6px; margin-bottom: 22px; padding-right: 160px; }
.round-tag {
  justify-self: start;
  padding: 3px 9px; border-radius: 6px;
  background: var(--hint); color: var(--ink);
  font-size: 0.74rem; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase;
}
.round-heading h2 { font-size: clamp(1.6rem, 3.6vw, 2.2rem); font-weight: 900; letter-spacing: -0.04em; }
.instruction { color: var(--ink-2); font-size: 1rem; }
.instruction strong { color: var(--ink); }
.review-btn { grid-area: head; justify-self: end; align-self: end; margin-bottom: 22px; }
.section-label {
  margin-bottom: 10px;
  color: var(--ink-2); font-size: 0.78rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.07em;
}
.target-section .section-label { grid-area: reflabel; }
.choice-label { grid-area: choicelabel; margin-top: 26px; }
.reference-strip {
  grid-area: refs;
  position: static; /* not sticky like the main case images */
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px;
}
.reference-strip .image-label { display: none; }
.reference-strip:not(:has(.match-reference-item + .match-reference-item)) { grid-template-columns: minmax(0, 560px); justify-content: center; }
.match-reference-item { display: grid; gap: 6px; min-width: 0; }
.reference-strip .image-box { aspect-ratio: 5 / 4; border-radius: var(--radius-lg); }
.reference-strip:has(.match-reference-item + .match-reference-item) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.reference-strip:not(:has(.match-reference-item + .match-reference-item)) .image-box { aspect-ratio: 16 / 10; }

.options-grid { grid-area: options; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
/* Cards keep their natural height, so opening one card's review never stretches the others' buttons. */
.options-grid { align-items: start; }
.option-card { align-content: start; }
/* After the match is found, the remaining cards become "see what this was" reviews. */
#match-phase:has(#feedback-section.success) .option-card:not(.correct):not(.eliminated) .option-status {
  font-size: 0; background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 2px var(--line-strong);
}
#match-phase:has(#feedback-section.success) .option-card:not(.correct):not(.eliminated) .option-status::before {
  content: "What is this?"; font-size: 0.95rem;
}
#match-phase:has(#feedback-section.success) .option-card.expanded:not(.correct) .option-status::before { content: "Look-alike"; }
.option-card { display: grid !important; grid-template-columns: minmax(0, 1fr) auto; }
.option-card .card-img-wrapper { grid-column: 1 / -1; aspect-ratio: 4 / 3; }
.option-card > .image-credit-link { grid-column: 1 / -1; padding: 8px 12px 0 !important; }
.option-card .option-status { grid-column: 1 / -1; margin: 8px 10px 10px !important; padding: 10px !important; }
.option-card .card-reveal { grid-column: 1 / -1; }
#feedback-section { grid-area: feedback; }
.option-card {
  position: relative; display: flex; flex-direction: column;
  border: 2px solid var(--line); border-radius: var(--radius-lg);
  background: var(--surface); overflow: hidden;
  cursor: pointer;
  transition: transform 120ms var(--ease-out), border-color 120ms, box-shadow 120ms;
}
.option-card:hover { border-color: var(--ink); transform: translateY(-2px); box-shadow: 0 4px 0 var(--ink); }
.card-img-wrapper { position: relative; aspect-ratio: 1; background: #e9e6dc; }
.card-img-wrapper img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.zoom-btn {
  position: absolute; right: 8px; top: 8px;
  width: 36px; height: 36px; padding: 0;
  border: 0; border-radius: 9px;
  background: rgba(255,255,255,0.94); color: var(--ink);
  display: grid; place-items: center;
}
.zoom-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.option-card > .image-credit-link { padding: 8px 12px 0; }
.option-status {
  margin: 10px 12px 12px;
  padding: 10px; border-radius: 10px;
  background: var(--ink); color: #fff; text-align: center;
  font-weight: 800; font-size: 0.95rem;
}
.card-reveal { display: none; padding: 0 14px 14px; gap: 4px; flex-direction: column; }
.review-kicker { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); }
.review-title { font-weight: 900; font-size: 1.02rem; letter-spacing: -0.01em; }
.review-text { color: var(--ink-2); font-size: 0.9rem; line-height: 1.45; }

.option-card.eliminated { border-color: var(--miss); cursor: default; }
.option-card.eliminated:hover { transform: none; box-shadow: none; }
.option-card.eliminated .card-img-wrapper img { filter: grayscale(0.7) brightness(0.8); }
.option-card.eliminated .card-img-wrapper::after,
.option-card.correct .card-img-wrapper::after {
  position: absolute; left: 10px; top: 10px;
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  color: #fff; font-weight: 900; font-size: 1.1rem;
}
.option-card.eliminated .card-img-wrapper::after { content: "✕"; background: var(--miss); }
.option-card.eliminated .option-status { background: var(--miss-soft); color: var(--miss-deep); }
.option-card.eliminated .option-status::before { content: "Not this one"; }
.option-card.eliminated .option-status { font-size: 0; }
.option-card.eliminated .option-status::before { font-size: 0.95rem; }
.option-card.correct { border-color: var(--green); box-shadow: 0 4px 0 var(--green-deep); }
.option-card.correct .card-img-wrapper::after { content: "✓"; background: var(--green); }
.option-card.correct .option-status { font-size: 0; background: var(--green-soft); color: var(--green-deep); }
.option-card.correct .option-status::before { content: "Match"; font-size: 0.95rem; }
.option-card.expanded .card-reveal,
.option-card.eliminated .card-reveal { display: flex; }
.option-card.eliminated:not(.expanded) .review-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.feedback-container {
  margin-top: 22px; padding: 22px;
  border-radius: var(--radius-lg);
  background: var(--surface); border: 2px solid var(--ink);
  display: grid; gap: 10px;
}
.feedback-container.success { border-color: var(--green); background: var(--green-soft); }
.feedback-header span {
  display: inline-block; margin-bottom: 6px;
  color: var(--green-deep); font-size: 0.78rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em;
}
.feedback-header h3 { font-size: 1.5rem; font-weight: 900; letter-spacing: -0.03em; }
#feedback-text { color: var(--ink-2); }
.educational-deep-dive { padding: 14px 16px; border-radius: var(--radius); background: var(--surface); }
.educational-deep-dive h4 { margin-bottom: 4px; font-size: 0.95rem; }
.educational-deep-dive p { color: var(--ink-2); font-size: 0.95rem; }
#next-case-btn { justify-self: start; margin-top: 4px; }

/* ---------- Completion ---------- */
.completion-banner {
  max-width: var(--board-max); margin: 0 auto 48px; padding: 0 20px;
}
.completion-banner > * { max-width: 100%; }
.completion-banner {
  display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px 28px; align-items: center;
}
.completion-banner::before {
  content: ""; grid-column: 1 / -1; border-top: 2px solid var(--ink);
}
.completion-copy span { color: var(--green-deep); font-size: 0.8rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }
.completion-copy h2 { margin: 6px 0; font-size: 1.8rem; font-weight: 900; letter-spacing: -0.04em; }
.completion-copy p { color: var(--ink-2); }
.learner-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.learner-summary div {
  display: grid; justify-items: center; gap: 2px; padding: 14px 8px;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
}
.learner-summary strong { font-size: 1.7rem; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.learner-summary span { color: var(--ink-3); font-size: 0.78rem; font-weight: 700; }
.completion-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Result / teaching modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(20, 24, 16, 0.5);
  animation: fade-in 160ms ease-out;
}
.modal-content {
  display: flex; flex-direction: column;
  width: min(720px, 100%); max-height: min(880px, calc(100 * var(--vh) - 40px));
  border-radius: 22px; background: var(--bg);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
  animation: sheet-up 280ms var(--ease-out);
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
#modal-body { overflow-y: auto; padding: 26px 26px 20px; display: grid; gap: 16px; overscroll-behavior: contain; }
.diagnosis-banner { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 6px 0 4px; }
.result-headline {
  padding: 5px 12px; border-radius: 999px;
  background: var(--green); color: #fff;
  font-size: 0.82rem; font-weight: 800;
}
#results-modal.error .result-headline { background: var(--ink); }
.diagnosis-highlight { font-size: clamp(1.6rem, 4.5vw, 2.3rem); font-weight: 900; letter-spacing: -0.04em; }
.result-tiles { display: flex; gap: 6px; }
.result-tiles i { width: 30px; height: 30px; border-radius: 7px; background: var(--tile); box-shadow: inset 0 0 0 2px var(--line); }
.result-tiles i.wrong { background: var(--miss); box-shadow: none; }
.result-tiles i.correct { background: var(--green); box-shadow: none; }
.result-tiles i { animation: tile-flip 420ms var(--ease-out) both; }
.result-tiles i:nth-child(2) { animation-delay: 80ms; }
.result-tiles i:nth-child(3) { animation-delay: 160ms; }
.result-tiles i:nth-child(4) { animation-delay: 240ms; }
.result-tiles i:nth-child(5) { animation-delay: 320ms; }
#teaching-guidance-copy { max-width: 46ch; color: var(--ink-2); font-size: 0.95rem; }
#teaching-guidance-copy:empty { display: none; }

.teaching-points { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.teaching-card {
  padding: 18px; border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--line);
}
.teaching-card h4 { margin-bottom: 8px; font-size: 1.02rem; font-weight: 900; }
.teaching-card p { color: var(--ink-2); font-size: 0.95rem; }
.skin-tone-card { border-top: 4px solid var(--hint); }
.facts-card { border-top: 4px solid var(--green); }
#high-yield-facts { margin: 0; padding: 0; list-style: none; counter-reset: fact; display: grid; gap: 8px; }
#high-yield-facts li { position: relative; padding-left: 32px; color: var(--ink-2); font-size: 0.93rem; counter-increment: fact; }
#high-yield-facts li::before {
  content: counter(fact); position: absolute; left: 0; top: 1px;
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 6px;
  background: var(--green-soft); color: var(--green-deep); font-size: 0.75rem; font-weight: 900;
}

#case-results { display: grid; }
.results-card {
  display: grid; gap: 12px; padding: 16px 18px;
  border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--line);
}
.results-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.results-card-head h4 { font-size: 1.02rem; font-weight: 900; }
.results-time { color: var(--ink-3); font-size: 0.85rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.result-bars { display: grid; gap: 5px; }
.result-bar-row { display: grid; grid-template-columns: 18px 1fr; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.result-bar-label { color: var(--ink-2); font-size: 0.82rem; font-weight: 800; text-align: center; }
.result-bar-track { height: 24px; }
.result-bar-track span {
  display: flex; align-items: center; justify-content: flex-end;
  height: 100%; padding: 0 8px; border-radius: 6px;
  background: var(--miss-soft); color: var(--ink-2);
  font-size: 0.8rem; font-weight: 900;
}
.result-bar-track span:empty { width: 6px !important; padding: 0; background: var(--line); }
.result-bar-row.is-you .result-bar-label { color: var(--ink); }
.result-bar-row.is-you .result-bar-track span { background: var(--green); color: #fff; }
.result-bar-row.is-you:last-child .result-bar-track span { background: var(--ink); }
.results-caption, .results-community { color: var(--ink-3); font-size: 0.82rem; }
.results-community { padding-top: 10px; border-top: 1px solid var(--line); }

.modal-buttons {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 26px calc(14px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.modal-next-step { display: grid; gap: 1px; min-width: 0; }
.modal-next-step span { color: var(--ink-3); font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }
.modal-next-step strong { font-size: 0.95rem; }

/* ---------- Archive ---------- */
.archive-panel {
  position: fixed; inset: 0; z-index: 450;
  display: grid; place-items: center; padding: 20px;
  background: rgba(20, 24, 16, 0.5);
  animation: fade-in 150ms ease-out;
}
.archive-dialog {
  width: min(460px, 100%); max-height: calc(100 * var(--vh) - 40px); overflow-y: auto;
  padding: 22px; border-radius: 22px; background: var(--bg);
  box-shadow: var(--shadow-pop);
  animation: sheet-up 240ms var(--ease-out);
}
.archive-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.archive-heading h2 { font-size: 1.6rem; font-weight: 900; letter-spacing: -0.04em; }
.archive-heading p { color: var(--ink-2); font-size: 0.92rem; margin-top: 4px; }
.archive-controls { display: grid; gap: 14px; }
.archive-month { display: grid; gap: 4px; font-size: 0.78rem; font-weight: 800; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.06em; }
.archive-month select {
  height: 44px; padding: 0 12px; border: 2px solid var(--ink); border-radius: var(--radius);
  background: var(--surface); font-size: 0.97rem; font-weight: 600; text-transform: none; letter-spacing: 0;
}
.archive-calendar { padding: 14px; border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--line); }
.archive-calendar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.archive-calendar-header strong { font-weight: 900; }
.archive-calendar-weekdays, .archive-calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.archive-calendar-weekdays span { text-align: center; color: var(--ink-3); font-size: 0.74rem; font-weight: 800; }
.archive-calendar-day {
  display: grid; place-items: center; aspect-ratio: 1;
  border: 0; border-radius: 9px;
  font-size: 0.9rem; font-weight: 800; font-variant-numeric: tabular-nums;
}
.archive-calendar-day.empty { color: var(--line-strong); font-weight: 600; }
.archive-calendar-day.has-case { background: var(--tile); color: var(--ink); box-shadow: inset 0 -2px 0 var(--line-strong); }
.archive-calendar-day.has-case:hover { background: var(--hint-soft); }
.archive-calendar-day.completed { background: var(--green); color: #fff; box-shadow: inset 0 -2px 0 var(--green-deep); }
.archive-calendar-day.started { background: var(--hint); color: var(--ink); box-shadow: inset 0 -2px 0 #c6961c; }
.archive-calendar-day.active { outline: 3px solid var(--ink); outline-offset: 1px; }
.archive-legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 0; padding: 0; list-style: none; color: var(--ink-2); font-size: 0.8rem; font-weight: 700; }
.archive-legend li { display: flex; align-items: center; gap: 6px; }
.archive-legend i { width: 12px; height: 12px; border-radius: 3px; }
.key-complete { background: var(--green); }
.key-progress { background: var(--hint); }
.key-open { background: var(--tile); box-shadow: inset 0 0 0 1.5px var(--line-strong); }

/* ---------- Lightbox ---------- */
.lightbox-modal {
  display: block;
  z-index: 1000; padding: 0; background: rgb(14, 16, 12);
}
.lightbox-toolbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px max(14px, env(safe-area-inset-left)); color: #fff;
}
.lightbox-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#lightbox-caption { font-weight: 800; }
.lightbox-source { color: rgba(255,255,255,0.75); font-size: 0.82rem; }
.lightbox-controls { display: flex; gap: 6px; }
.lightbox-controls button {
  min-width: 44px; height: 44px; padding: 0 12px;
  border: 0; border-radius: 10px;
  background: rgba(255,255,255,0.12); color: #fff;
  font-size: 1.1rem; font-weight: 800;
}
.lightbox-controls button:hover { background: rgba(255,255,255,0.22); }
.close-lightbox { background: #fff !important; color: var(--ink) !important; font-size: 1.5rem !important; }
.lightbox-stage { position: absolute; inset: 68px 0 0; overflow: hidden; touch-action: none; cursor: grab; }
.lightbox-stage:active { cursor: grabbing; }
.lightbox-content {
  position: absolute; left: 50%; top: 50%;
  width: calc(100% - 24px); height: calc(100% - 24px);
  object-fit: contain; user-select: none; -webkit-user-drag: none;
  transform: translate(-50%, -50%);
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  #dermatordle-phase { grid-template-columns: 1fr; gap: 18px; }
  .image-gallery { position: static; }
  .image-box { aspect-ratio: 4 / 3; }
  #image-gallery.has-two .image-box { aspect-ratio: 16 / 10; height: auto; }
  #match-phase { grid-template-areas: "head" "review" "reflabel" "refs" "choicelabel" "options" "feedback"; }
  .round-heading { padding-right: 0; margin-bottom: 8px; }
  .review-btn { grid-area: review; justify-self: start; align-self: start; margin-bottom: 18px; }
  .options-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
  .completion-banner { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .topbar { height: 56px; }
  .brand-name { font-size: 1.15rem; }
  .topbar-logo { width: 32px; height: 32px; }
  .account-link span { display: none; }
  .account-link { padding: 0 8px; }
  .game-wrapper { padding: 14px 14px 32px; }
  .case-header { gap: 10px; padding-bottom: 14px; margin-bottom: 16px; }
  .case-stats { width: 100%; }
  .stat-guesses, .stat-chip, .phase-pill { height: 32px; padding: 0 10px; font-size: 0.8rem; }
  .phase-pill { margin-left: auto; }
  .comparison-stat { order: 3; }
  #clues-list li { padding: 10px 12px 10px 46px; font-size: 0.94rem; }
  #clues-list li:not(.placeholder-text)::before { left: 10px; top: 9px; }
  .guess-row { min-height: 46px; }
  .guess-row.empty, .guess-row.unused, .guess-row.active { display: none; }
  .guess-grid:empty, .guess-grid:not(:has(.wrong, .correct)) { display: none; }
  #submit-btn { min-width: 76px; padding: 0 16px; }
  .options-grid { gap: 10px; }
  .option-card .card-img-wrapper { aspect-ratio: 16 / 10; }
  .option-status { margin: 8px; padding: 8px; font-size: 0.88rem; }
  .modal { align-items: flex-end; padding: 0; }
  .modal-content { width: 100%; max-height: 92vh; border-radius: 22px 22px 0 0; }
  #modal-body { padding: 22px 16px 16px; }
  .teaching-points { grid-template-columns: 1fr; }
  .modal-buttons { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .modal-next-step { display: none; }
  #start-match-btn { width: 100%; }
  .learner-summary strong { font-size: 1.4rem; }
  .completion-banner { padding: 0 14px; }
  .archive-panel { place-items: end center; padding: 0; }
  .archive-dialog { border-radius: 22px 22px 0 0; max-height: 92vh; }
}

@media (max-width: 380px) {
  .beta-tag { display: none; }
  .options-grid { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}

/* Tone strip in the Round 2 result (shown only after the match is found). */
#feedback-tone-strip { margin-top: 4px; }
#feedback-tone-strip::before {
  content: "Across skin tones"; grid-column: 1 / -1;
  color: var(--green-deep); font-size: 0.78rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em;
}
#feedback-tone-strip .tone-item img { aspect-ratio: 4 / 3; }

/* The review shows the sheet's pearls only: one full-width card. */
.teaching-points { grid-template-columns: 1fr; }

/* After Round 2: difficulty rating + account nudge */
.difficulty-rating {
  display: grid; gap: 10px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 2px solid var(--ink); box-shadow: 0 3px 0 var(--ink);
}
.difficulty-rating.hidden { display: none; }
.difficulty-rating.is-rated { border-color: var(--line-strong); box-shadow: none; }
.difficulty-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
#difficulty-rating-label { color: var(--ink); font-size: 1rem; font-weight: 900; letter-spacing: -0.01em; }
.difficulty-head small { color: var(--ink-3); font-size: 0.8rem; font-weight: 600; }
.difficulty-scale { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.difficulty-scale button {
  display: grid; justify-items: center; gap: 1px; padding: 8px 4px; border-radius: 10px;
  border: 2px solid var(--line-strong); background: var(--bg); color: var(--ink-2);
  font-size: 0.78rem; font-weight: 700; line-height: 1.15; box-shadow: 0 2px 0 var(--line-strong);
  transition: transform 80ms ease, border-color 120ms, background-color 120ms, color 120ms;
}
.difficulty-scale button b { color: var(--ink); font-size: 1.15rem; font-weight: 900; }
.difficulty-scale button:hover { border-color: var(--ink); background: var(--surface); }
.difficulty-scale button:active { transform: translateY(2px); box-shadow: none; }
.difficulty-scale button[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: #e8ecd9; box-shadow: 0 2px 0 #000; }
.difficulty-scale button[aria-pressed="true"] b { color: #fff; }
.difficulty-thanks { color: var(--green-deep); font-size: 0.84rem; font-weight: 700; }
.difficulty-thanks.hidden { display: none; }

.account-prompt {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px 16px;
  padding: 16px 18px; border-radius: var(--radius);
  background: var(--surface); border: 2px solid var(--line-strong);
  transition: border-color 200ms, box-shadow 200ms;
}
.account-prompt.hidden { display: none; }
.account-prompt.is-highlighted { border-color: var(--ink); box-shadow: 0 3px 0 var(--ink); }
.account-prompt-copy { display: grid; gap: 3px; grid-row: span 2; }
.account-prompt-copy strong { color: var(--ink); font-size: 1rem; font-weight: 900; letter-spacing: -0.01em; }
.account-prompt-copy p { color: var(--ink-2); font-size: 0.88rem; line-height: 1.45; }
.account-prompt-btn { min-height: 44px; padding: 0 18px; font-size: 0.95rem; text-decoration: none; background: var(--green) !important; box-shadow: 0 3px 0 var(--green-deep) !important; }
.account-prompt-btn:hover { background: var(--green-deep) !important; }
.account-prompt-note { justify-self: center; color: var(--ink-3); font-size: 0.74rem; font-weight: 600; }
.results-community a { color: var(--ink); font-weight: 800; text-decoration-color: var(--hint); text-decoration-thickness: 2px; text-underline-offset: 3px; }
@media (max-width: 560px) {
  .difficulty-scale button { font-size: 0.68rem; padding: 7px 2px; }
  .account-prompt { grid-template-columns: 1fr; }
  .account-prompt-copy { grid-row: auto; }
  .account-prompt-btn { width: 100%; }
}

.clue-hidden-caption { color: var(--ink-3); font-style: italic; }

.case-report-link { justify-self: start; color: var(--ink-3); font-size: 0.84rem; font-weight: 700; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.case-report-link:hover { color: var(--ink); text-decoration-color: var(--hint); }
.case-report-link.hidden { display: none; }

/* Guess box: alternate-name label, no-match row, and the not-in-list notice. */
.autocomplete-alias {
  margin-left: 8px; color: var(--ink-3);
  font-size: 0.85em; font-weight: 600;
}
.autocomplete-alias::before { content: "· "; }
.autocomplete-empty {
  padding: 10px 12px; color: var(--ink-2);
  font-size: 0.92rem; cursor: default;
}
.guess-feedback.notice { background: var(--miss-soft); color: var(--ink); }
.guess-feedback.notice::before { content: "!"; }
.autocomplete-empty.is-notice {
  margin: 2px 0; border-radius: 8px;
  background: var(--hint-soft); color: #5c4700; font-weight: 700;
}
