/* ============================================================
   Anachrogen — styles
   Exhibit-placard aesthetic, sized to read from the back of a room.
   ============================================================ */

:root {
  --bg:        #f4efe6;   /* warm paper */
  --bg-deep:   #e7dfd0;
  --ink:       #2a2620;   /* near-black warm */
  --ink-soft:  #6b6152;
  --line:      #d6cbb6;
  --card:      #fbf8f1;

  --invented:  #b4302a;   /* red    — wrong / inaccurate            */
  --unlikely:  #cf6a2b;   /* orange — probably wrong                */
  --disputed:  #c8871b;   /* amber  — genuinely contested           */
  --plausible: #6f9a4e;   /* sage   — no evidence for, none against  */
  --authentic: #2f7d4f;   /* green  — attested & period-correct      */
  --todo:      #8a8073;   /* grey   — answer key pending             */
  --wikilink:  #3366cc;   /* blue   — Wikipedia-style internal link  */

  --shadow: 0 6px 24px rgba(40, 32, 20, 0.18);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans:  system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  overflow-x: hidden;               /* never scroll sideways */
}

.view { min-height: 100vh; }
[hidden] { display: none !important; }

kbd {
  font-family: var(--sans);
  font-size: 0.82em;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--ink-soft);
  white-space: nowrap;
}

/* ============================ GALLERY ============================ */

.gallery-head {
  max-width: 1000px;
  margin: 0 auto;
  padding: 6vh 24px 2vh;
  text-align: center;
}
.wordmark {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2.6rem, 6vw, 4.4rem);
  letter-spacing: 0.01em;
  margin: 0 0 0.3em;
}
.tagline {
  font-size: clamp(1rem, 1.7vw, 1.35rem);
  line-height: 1.5;
  color: var(--ink-soft);
  max-width: 60ch;
  margin: 0 auto;
}
.tagline strong { color: var(--ink); }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 26px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 3vh 24px;
}
.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.14s ease, box-shadow 0.14s ease, opacity 0.14s ease;
}
.card:hover, .card:focus-within {
  transform: translateY(-4px);
  box-shadow: 0 12px 34px rgba(40, 32, 20, 0.26);
}
/* the clickable body of a card (opens the scene) */
.card-open {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0;
  margin: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.card-open:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }

/* corner hide / restore button */
.card-hide {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(251, 248, 241, 0.92);
  color: var(--ink-soft);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.14s ease, background-color 0.14s ease,
              color 0.14s ease, border-color 0.14s ease;
}
.card:hover .card-hide,
.card:focus-within .card-hide { opacity: 1; }
.card-hide:hover { background: var(--invented); color: #fff; border-color: var(--invented); }
/* touch devices have no hover — keep the control reachable */
@media (hover: none) { .card-hide { opacity: 1; } }

/* a hidden card is removed from the normal gallery; it only reappears,
   dimmed, while the presenter is managing hidden scenes */
.gallery-grid:not(.show-hidden) .card.is-hidden { display: none; }
.card.is-hidden { opacity: 0.5; }
.card.is-hidden .card-hide {
  opacity: 1;
  background: var(--authentic);
  color: #fff;
  border-color: var(--authentic);
}

/* completed badge — a green check on scenes the player has finished (solo) */
.card-done {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--authentic);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  place-items: center;
  box-shadow: var(--shadow);
  display: none;
}
body[data-mode="solo"] .card.is-completed .card-done { display: grid; }
body[data-mode="solo"] .card.is-completed { border-color: var(--authentic); }

/* gallery tools bar (only shown once something is hidden) */
.gallery-tools {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}
.gallery-tools:empty { display: none; }
.tools-status {
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--ink-soft);
}
.gallery-tools .btn { font-size: 0.95rem; padding: 8px 14px; }
.card-thumb {
  aspect-ratio: 3 / 2;
  width: 100%;
  object-fit: cover;
  display: block;
  background: var(--bg-deep);
}
.card-body { padding: 16px 18px 18px; }
.card-index {
  display: inline-block;
  font-family: var(--serif);
  font-size: 0.95rem;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  margin-bottom: 8px;
}
.card-title {
  font-family: var(--serif);
  font-size: 1.5rem;
  margin: 0 0 2px;
  /* card names read as Wikipedia wikilinks: blue, underlined on hover */
  color: var(--wikilink);
  text-decoration: none;
  text-underline-offset: 2px;
}
.card:hover .card-title,
.card-open:focus-visible .card-title { text-decoration: underline; }
.card-date { color: var(--ink-soft); font-size: 1rem; }

.gallery-foot {
  text-align: center;
  color: var(--ink-soft);
  padding: 2vh 24px 6vh;
  font-size: 0.95rem;
}

/* ============================= SCENE ============================= */

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 0;
  height: 100vh;
}

/* --- image side --- */
.canvas-wrap {
  position: relative;
  background: #1c1813;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.canvas {
  position: relative;
  display: inline-block;
  max-width: 100%;
  max-height: 100vh;
  line-height: 0;
}
.scene-img {
  display: block;
  max-width: 100%;
  max-height: 100vh;
  width: auto;
  height: auto;
}

.chip {
  position: absolute;
  top: 18px;
  left: 18px;
  background: rgba(20, 16, 12, 0.72);
  color: #fdfaf3;
  backdrop-filter: blur(4px);
  border-radius: 10px;
  padding: 8px 14px;
  line-height: 1.15;
}
.chip-title { font-family: var(--serif); font-size: 1.5rem; display: block; }
.chip-date  { font-size: 1rem; opacity: 0.85; }

/* --- markers on the image --- */
/* The overlay spans the whole image; keep it click-through so author-mode
   clicks reach the image beneath. Individual markers re-enable clicks. */
.markers { position: absolute; inset: 0; pointer-events: none; }
.marker {
  position: absolute;
  pointer-events: auto;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;          /* center on x,y */
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  background: rgba(30, 24, 18, 0.62);
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.35), 0 3px 10px rgba(0,0,0,0.45);
  cursor: pointer;
  transition: transform 0.16s ease, background-color 0.25s ease, border-color 0.25s ease;
  z-index: 2;
}
.marker:hover { transform: scale(1.12); }
.marker.is-active { transform: scale(1.18); z-index: 3; }
.marker.revealed.v-invented  { background: var(--invented);  border-color: #fff; }
.marker.revealed.v-unlikely  { background: var(--unlikely);  border-color: #fff; }
.marker.revealed.v-disputed  { background: var(--disputed);  border-color: #fff; }
.marker.revealed.v-plausible { background: var(--plausible); border-color: #fff; }
.marker.revealed.v-authentic { background: var(--authentic); border-color: #fff; }
.marker.revealed.v-todo      { background: var(--todo);      border-color: #fff; }

/* --- side panel --- */
.panel {
  background: var(--card);
  border-left: 1px solid var(--line);
  padding: 22px 22px 18px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.prompt {
  font-family: var(--serif);
  font-size: 1.18rem;
  line-height: 1.35;
  margin: 0 0 14px;
  color: var(--ink);
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.item {
  border: 1px solid var(--line);
  border-left: 6px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  padding: 11px 13px;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}
.item:hover { background: var(--bg-deep); }
.item.is-active { box-shadow: 0 0 0 2px var(--ink) inset; }
.item-head {
  display: flex;
  align-items: baseline;
  gap: 9px;
}
.item-num {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.15rem;
  min-width: 1.2em;
}
.item-label {
  font-size: 1.06rem;
  line-height: 1.3;
  flex: 1;
}
.badge {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
  align-self: center;
}
.item-explain {
  font-size: 0.98rem;
  line-height: 1.4;
  color: var(--ink-soft);
  margin: 9px 0 0;
  /* collapsed until revealed */
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease, margin 0.3s ease;
}

.item.revealed { border-left-color: var(--todo); }
.item.revealed .item-explain { max-height: 340px; opacity: 1; margin-top: 9px; }

.item.revealed.v-invented  { border-left-color: var(--invented); }
.item.revealed.v-unlikely  { border-left-color: var(--unlikely); }
.item.revealed.v-disputed  { border-left-color: var(--disputed); }
.item.revealed.v-plausible { border-left-color: var(--plausible); }
.item.revealed.v-authentic { border-left-color: var(--authentic); }
.item.revealed.v-todo      { border-left-color: var(--todo); }
.badge.v-invented  { background: var(--invented); }
.badge.v-unlikely  { background: var(--unlikely); }
.badge.v-disputed  { background: var(--disputed); }
.badge.v-plausible { background: var(--plausible); }
.badge.v-authentic { background: var(--authentic); }
.badge.v-todo      { background: var(--todo); }

/* --- panel footer / controls --- */
.panel-foot { padding-top: 14px; border-top: 1px solid var(--line); margin-top: 12px; }
.counter {
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--ink-soft);
  margin-bottom: 10px;
}
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.btn {
  font: inherit;
  font-size: 1rem;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 9px;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: var(--bg-deep); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary {
  grid-column: 1 / -1;
  background: var(--ink);
  color: var(--card);
  border-color: var(--ink);
  font-weight: 600;
}
.btn-primary:hover { background: #3c352b; }
.hint {
  margin: 12px 0 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
  line-height: 1.7;
}

/* --- reference / compare overlay --- */
/* Shows the real historical image over the AI one so the room can compare.
   Fills the whole dark stage, letterboxing the reference to fit. */
.reference {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: #14100c;
  display: flex;
  flex-direction: column;
  animation: reference-in 0.2s ease;
}
@keyframes reference-in { from { opacity: 0; } to { opacity: 1; } }

.reference-img {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  object-fit: contain;
  background: #14100c;
}
.reference-bar {
  flex: 0 0 auto;
  background: rgba(20, 16, 12, 0.92);
  color: #fdfaf3;
  padding: 12px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.reference-caption {
  font-family: var(--serif);
  font-size: 1.14rem;
  line-height: 1.35;
  margin: 0;
}
.reference-credit {
  font-size: 0.82rem;
  color: #cabfa8;
  text-decoration: underline;
  align-self: flex-start;
}
.reference-credit:hover { color: #fdfaf3; }
.reference-tag {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 1;
  background: var(--authentic);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 5px 13px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.reference-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1;
  font: inherit;
  font-size: 0.95rem;
  color: #fdfaf3;
  background: rgba(20, 16, 12, 0.75);
  border: 1px solid rgba(253, 250, 243, 0.4);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
}
.reference-close:hover { background: rgba(60, 50, 38, 0.9); }
.btn.is-on {
  background: var(--ink);
  color: var(--card);
  border-color: var(--ink);
}

/* --- author mode readout --- */
.author-readout {
  position: absolute;
  bottom: 14px;
  left: 14px;
  background: rgba(20, 16, 12, 0.85);
  color: #9effa0;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem;
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 4;
}
.canvas-wrap.authoring { cursor: crosshair; }
.author-dot {
  position: absolute;
  width: 12px; height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: #9effa0;
  border: 2px solid #12200f;
  z-index: 3;
}

/* ============================ MODE TOGGLE + SCOREBOARD ============================ */

/* In solo mode the presenter reveal controls are out of the way. */
body[data-mode="solo"] .presenter-only { display: none !important; }


.mode-toggle {
  display: inline-flex;
  gap: 4px;
  margin: 22px auto 0;
  padding: 4px;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.mode-btn {
  font: inherit;
  font-size: 0.98rem;
  padding: 7px 20px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.mode-btn:hover { color: var(--ink); }
.mode-btn.is-on {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(40, 32, 20, 0.16);
  font-weight: 600;
}

.scoreboard {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 16px auto 0;
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--ink);
}
.scoreboard-reset {
  font: inherit;
  font-size: 0.82rem;
  font-family: var(--sans);
  color: var(--ink-soft);
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 12px;
  cursor: pointer;
}
.scoreboard-reset:hover { background: var(--bg-deep); color: var(--ink); }

/* ============================ SOLO PLAY ============================ */

.solo-answer { margin-bottom: 4px; }
.solo-question {
  font-family: var(--serif);
  font-size: 1.1rem;
  line-height: 1.35;
  margin: 0 0 12px;
}
.solo-question b { color: var(--ink); }
.solo-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.solo-btn {
  font-size: 1.05rem;
  font-weight: 600;
  padding: 13px 12px;
}
.solo-btn-auth:hover  { background: var(--authentic); color: #fff; border-color: var(--authentic); }
.solo-btn-wrong:hover { background: var(--invented);  color: #fff; border-color: var(--invented); }

.solo-feedback {
  margin: 12px 0 0;
  padding: 11px 13px;
  border-radius: 10px;
  font-size: 1rem;
  line-height: 1.4;
}
.solo-feedback.is-correct {
  background: rgba(47, 125, 79, 0.13);
  border: 1px solid var(--authentic);
  color: var(--authentic);
}
.solo-feedback.is-wrong {
  background: rgba(180, 48, 42, 0.12);
  border: 1px solid var(--invented);
  color: var(--invented);
}
.solo-feedback.is-neutral {
  background: rgba(200, 135, 27, 0.13);
  border: 1px solid var(--disputed);
  color: var(--disputed);
}
.solo-feedback b { font-weight: 700; }

/* thin bar that drains while the next marker auto-loads */
.solo-timer {
  height: 4px;
  margin-top: 12px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.solo-timer-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--ink-soft);
  border-radius: 999px;
}
/* subtle, optional shortcut past the auto-advance wait */
.solo-skip {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 2px;
  background: none;
  border: 0;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.solo-skip:hover { color: var(--ink); }

/* respect reduced-motion: keep the auto-advance, drop the animated bar */
@media (prefers-reduced-motion: reduce) {
  .solo-timer { display: none; }
}

.solo-results { text-align: center; }
.solo-results-score {
  font-family: var(--serif);
  font-size: 1.5rem;
  margin: 0 0 4px;
}
.solo-results-score b { color: var(--authentic); }
.solo-results-session {
  color: var(--ink-soft);
  font-size: 0.98rem;
  margin: 0 0 14px;
}
.solo-results-actions {
  display: grid;
  gap: 8px;
}
.solo-next-scene { width: 100%; }
.solo-results-secondary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* end-of-scene Wikipedia gag */
.wiki-question {
  margin-top: 14px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  text-align: center;
}
.wiki-q-text {
  font-family: var(--serif);
  font-size: 1.15rem;
  margin: 0 0 10px;
}
.wiki-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.wiki-answer {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(51, 102, 204, 0.1);
  border: 1px solid var(--wikilink);
  color: var(--wikilink);
  font-size: 1rem;
  line-height: 1.4;
}

/* per-item correctness marks (solo mode) */
.item-mark {
  margin-left: auto;
  font-weight: 700;
  font-size: 1.05rem;
  align-self: center;
}
.item.answered-correct .item-mark { color: var(--authentic); }
.item.answered-wrong   .item-mark { color: var(--invented); }
.item.solo-current { box-shadow: 0 0 0 2px var(--ink) inset; }

/* ---------------- responsive: narrow screens ---------------- */
@media (max-width: 900px) {
  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    height: auto;
    min-height: 100vh;
  }
  .canvas-wrap { min-height: 46vh; }
  .canvas, .scene-img { max-height: 60vh; }
  .panel { height: auto; max-height: 54vh; }
}
