:root {
  --wood-dark: #2c2418;
  --wood-mid: #3a2f22;
  --wood-light: #4a3b28;
  --parchment: #f2e6c9;
  --parchment-line: rgba(139, 105, 20, 0.08);
  --ink: #4a2e1a;
  --ink-soft: #6b5638;
  --border: #6b4423;
  --error: #8a1f11;
  --sand: #c9a24b;
}

* {
  box-sizing: border-box;
}

body.quest-body {
  margin: 0;
  min-height: 100vh;
  font-family: Georgia, 'Times New Roman', serif;
  background: radial-gradient(circle at 20% 20%, var(--wood-light), var(--wood-dark) 70%);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.quest-screen {
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.parchment {
  width: 100%;
  background-color: var(--parchment);
  background-image: repeating-linear-gradient(
    0deg,
    var(--parchment-line) 0,
    var(--parchment-line) 1px,
    transparent 1px,
    transparent 28px
  );
  border: 3px solid var(--border);
  border-radius: 8px;
  padding: 28px 32px;
  text-align: center;
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.35);
}

.quest-reveal {
  max-width: 640px;
}

body.quest-body--about {
  background-color: var(--wood-dark);
  background-image:
    linear-gradient(rgba(15, 12, 8, 0.5), rgba(15, 12, 8, 0.6)),
    url('/assets/img/about-bg.jpg');
  background-position: center;
  background-repeat: no-repeat;
  /* contain (not cover) so the whole poster stays visible instead of
     being cropped/zoomed to fill a wide viewport - the portrait image
     would otherwise lose its top/bottom on a landscape screen. */
  background-size: contain;
  /* No background-attachment: fixed - unsupported on many mobile
     browsers (notably iOS Safari), where it can fail to render the
     background at all instead of just losing the parallax effect. */
}

.quest-body--about .parchment {
  background-color: rgba(242, 230, 201, 0.88);
  backdrop-filter: blur(3px);
}

.quest-about {
  text-align: left;
}

.quest-about-heading {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-soft);
  border-bottom: 1px dashed var(--border);
  padding-bottom: 6px;
  margin: 22px 0 10px;
}

.quest-about-heading:first-of-type {
  margin-top: 4px;
}

.quest-other-sites {
  margin: 0 0 14px;
  padding-left: 20px;
}

.quest-other-sites li {
  margin-bottom: 6px;
  line-height: 1.4;
}

.quest-label {
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 18px;
}

.field-row {
  text-align: left;
  margin-bottom: 14px;
}

.field-tag {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.quest-input {
  width: 100%;
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.5);
}

.quest-input:focus {
  outline: none;
  border-style: solid;
  background: rgba(255, 255, 255, 0.8);
}

.quest-btn {
  display: inline-block;
  margin-top: 8px;
  background: var(--border);
  color: var(--parchment);
  border: none;
  border-radius: 4px;
  padding: 10px 28px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  text-decoration: none;
}

.quest-btn:hover {
  background: #543318;
}

.quest-error {
  color: var(--error);
  font-size: 0.85rem;
  margin: 0 0 14px;
}

.countdown-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 10px;
}

.hourglass {
  flex-shrink: 0;
  width: 56px;
  height: 84px;
  position: relative;
}

.hourglass-bulb {
  position: absolute;
  left: 0;
  width: 100%;
  height: 42px;
  overflow: hidden;
  border: 2px solid var(--border);
  background: rgba(255, 255, 255, 0.15);
}

.hourglass-top {
  top: 0;
  border-bottom: none;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.hourglass-bottom {
  bottom: 0;
  border-top: none;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.hourglass-sand {
  position: absolute;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--sand);
}

.hourglass-sand-top {
  bottom: 0;
  transform-origin: bottom;
  animation: hourglass-empty 4s linear infinite;
}

.hourglass-sand-bottom {
  bottom: 0;
  transform-origin: bottom;
  transform: scaleY(0);
  animation: hourglass-fill 4s linear infinite;
}

.hourglass-stream {
  position: absolute;
  top: 41px;
  left: 50%;
  width: 2px;
  height: 6px;
  background: var(--sand);
  transform: translateX(-50%);
  animation: hourglass-stream 0.4s linear infinite;
}

@keyframes hourglass-empty {
  0% { transform: scaleY(1); }
  95%, 100% { transform: scaleY(0); }
}

@keyframes hourglass-fill {
  0%, 5% { transform: scaleY(0); }
  100% { transform: scaleY(1); }
}

@keyframes hourglass-stream {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.quest-countdown {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 1px;
  margin: 0;
}

.quest-music-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}

.quest-music-btn {
  background: none;
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 0.75rem;
  color: var(--ink-soft);
  cursor: pointer;
}

.quest-music-btn:hover {
  background: rgba(201, 162, 75, 0.2);
}

.quest-music-playing {
  font-size: 0.9rem;
  opacity: 0.85;
  animation: quest-music-pulse 1.4s ease-in-out infinite;
}

@keyframes quest-music-pulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.15); }
}

.quest-progress {
  width: 100%;
  height: 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.3);
  overflow: hidden;
  margin-bottom: 18px;
}

.quest-progress-fill {
  height: 100%;
  background: var(--sand);
  transition: width 0.3s ease;
}

.quest-notice {
  color: var(--ink);
  background: rgba(201, 162, 75, 0.25);
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 0.85rem;
  margin: 0 0 16px;
}

.quest-riddle-images {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 16px;
}

.quest-riddle-images img {
  max-width: 100%;
  max-height: 240px;
  width: auto;
  height: auto;
  object-fit: contain;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.35);
}

.quest-question {
  font-style: italic;
  margin: 0 0 18px;
  line-height: 1.4;
}

.quest-choice {
  display: block;
  text-align: left;
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  margin-bottom: 10px;
  cursor: pointer;
}

.quest-choice input {
  margin-right: 8px;
}

.quest-win-gif {
  margin-bottom: 20px;
  text-align: center;
}

.quest-win-gif img {
  max-width: 100%;
  max-height: 220px;
  border: 2px solid var(--border);
  border-radius: 4px;
}

.quest-message {
  line-height: 1.6;
  margin-bottom: 20px;
  white-space: pre-line;
}

.quest-summary {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  text-align: left;
}

.quest-summary-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px dashed rgba(107, 68, 35, 0.3);
  font-size: 0.85rem;
  line-height: 1.4;
}

.quest-summary-item:last-child {
  border-bottom: none;
}

.quest-summary-icon {
  flex-shrink: 0;
}

.quest-summary-item.is-wrong {
  color: var(--ink-soft);
}

.quest-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.quest-gallery img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border: 2px solid var(--border);
  border-radius: 4px;
}

.quest-video {
  margin-bottom: 20px;
}

.quest-video video {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 4px;
}

.quest-mcq-set-item {
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px dashed rgba(107, 68, 35, 0.3);
}

.quest-mcq-set-item:last-of-type {
  border-bottom: none;
  margin-bottom: 4px;
}

.quest-diff-counter {
  font-weight: 700;
  margin: 0 0 12px;
}

.quest-diff-images {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.diff-image-wrap {
  position: relative;
  border: 2px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  cursor: crosshair;
  line-height: 0;
}

.diff-image-wrap img {
  width: 100%;
  height: auto;
  display: block;
  pointer-events: none;
  user-select: none;
}

.diff-marker {
  position: absolute;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  margin-top: -11px;
  border: 3px solid var(--sand);
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.quest-puzzle-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  max-width: 320px;
  margin: 0 auto 18px;
  border: 3px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  transition: box-shadow 0.3s ease;
}

.quest-puzzle-grid.solved {
  box-shadow: 0 0 0 3px var(--sand);
}

.puzzle-slot {
  position: relative;
  aspect-ratio: 1;
  background: var(--parchment);
}

.puzzle-piece {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
  /* background-size is set inline by puzzle.js, scaled to GRID_SIZE - it
     must not be hardcoded here, that mismatch is what caused pieces to
     visibly overlap/duplicate image content on the 4x4 grid. */
  cursor: grab;
  touch-action: none;
}

.puzzle-piece.dragging {
  cursor: grabbing;
  z-index: 10;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}

@media (max-width: 480px) {
  .parchment {
    padding: 22px 18px;
  }

  .quest-countdown {
    font-size: 1.3rem;
  }
}
