/* ============================================================
   Ant-Man · Lesson 7 — Detective Case Board  (v2 chalkboard)
   A teacher's crime wall: slate chalkboard, pinned evidence
   Polaroids, red yarn, chalk-written labels.
   Namespaced under .dx-detective. Self-contained.
   Tuned for a 10-year-old: alive but calm, big payoff on success.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Gaegu:wght@400;700&family=Patrick+Hand&display=swap');

.dx-detective,
.dx-detective * { box-sizing: border-box; }

.dx-detective {
  --board:      #2b3a34;
  --board-2:    #243029;
  --chalk:      #f4f1e8;
  --chalk-dim:  #c8cabf;
  --chalk-yel:  #ffe08a;
  --yarn:       #d94f4f;
  --wood:       #6b4d35;
  --wood-2:     #543c29;
  --ok:         #7fdca4;
  --bad:        #ff8a7a;
  --paper:      #f5efe0;
  --font-chalk: 'Gaegu', 'Patrick Hand', "PingFang SC", "Microsoft YaHei", cursive;
  --font-hand:  'Patrick Hand', 'Gaegu', "PingFang SC", sans-serif;
}

/* ---------- Launch button ---------- */
.dx-detective-launch {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 14px 22px; font-size: 17px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, #3a4d44 0%, #243029 100%);
  border: none; border-radius: 14px; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.3); transition: transform .12s ease, box-shadow .12s ease;
  font-family: inherit;
}
.dx-detective-launch:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(0,0,0,.4); }
.dx-detective-launch .ico { font-size: 22px; }
.dx-detective-launch .sub { font-size: 13px; font-weight: 500; opacity: .85; }

/* ---------- Overlay = chalkboard ---------- */
.dx-detective {
  position: fixed; inset: 0; z-index: 9999; display: none;
  flex-direction: column; overflow-y: auto;
  color: var(--chalk); font-family: var(--font-hand);
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255,255,255,.05), transparent 60%),
    radial-gradient(60% 50% at 18% 30%, rgba(255,255,255,.035), transparent 70%),
    radial-gradient(50% 45% at 82% 70%, rgba(255,255,255,.03), transparent 70%),
    radial-gradient(140% 120% at 50% 50%, transparent 55%, rgba(0,0,0,.45) 100%),
    var(--board);
}
.dx-detective.open { display: flex; animation: dxd-fadein .35s ease;
  cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'><circle cx='13' cy='13' r='8' fill='none' stroke='%23ffe08a' stroke-width='2.5'/><line x1='19' y1='19' x2='28' y2='28' stroke='%23ffe08a' stroke-width='3' stroke-linecap='round'/></svg>") 6 6, auto; }
@keyframes dxd-fadein { from { opacity: 0; } to { opacity: 1; } }

.dx-detective::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    repeating-linear-gradient(0deg, rgba(255,255,255,.014) 0 1px, transparent 1px 38px),
    repeating-linear-gradient(90deg, rgba(255,255,255,.014) 0 1px, transparent 1px 38px);
  -webkit-mask-image: radial-gradient(120% 100% at 50% 40%, #000 50%, transparent 90%);
          mask-image: radial-gradient(120% 100% at 50% 40%, #000 50%, transparent 90%);
}

/* chalk dust */
.dx-detective .dxd-dust { position: fixed; inset: 0; pointer-events: none; z-index: 1; overflow: hidden; }
.dx-detective .dxd-dust i {
  position: absolute; top: -10px; width: 3px; height: 3px; border-radius: 50%;
  background: rgba(244,241,232,.5); opacity: 0; animation: dxd-fall linear infinite;
}
@keyframes dxd-fall {
  0% { transform: translateY(-10px) translateX(0); opacity: 0; }
  10% { opacity: .55; } 90% { opacity: .4; }
  100% { transform: translateY(102vh) translateX(24px); opacity: 0; }
}

/* ---------- Top bar / chalk tray ---------- */
.dx-detective .dxd-topbar {
  position: sticky; top: 0; z-index: 6;
  display: flex; align-items: center; justify-content: space-between; padding: 12px 22px;
  background: linear-gradient(180deg, var(--wood) 0%, var(--wood-2) 100%);
  box-shadow: 0 4px 14px rgba(0,0,0,.4), inset 0 2px 0 rgba(255,255,255,.08);
}
.dx-detective .dxd-title { display: flex; flex-direction: column; line-height: 1.1; }
.dx-detective .dxd-title b { font-family: var(--font-chalk); font-size: 24px; letter-spacing: .5px; color: var(--chalk); }
.dx-detective .dxd-title span { font-size: 13px; opacity: .8; color: #e9dcc7; }
.dx-detective .dxd-topbar-right { display: flex; align-items: center; gap: 14px; }
.dx-detective .dxd-score {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-chalk); font-size: 18px; font-weight: 700;
  color: #1f2a24; background: var(--chalk-yel); padding: 6px 16px; border-radius: 10px;
  transform: rotate(-2deg); box-shadow: 0 3px 8px rgba(0,0,0,.3);
}
.dx-detective .dxd-stars { letter-spacing: 2px; font-size: 16px; }
.dx-detective .dxd-close {
  background: rgba(255,255,255,.12); color: #f4ead8; border: none;
  width: 40px; height: 40px; border-radius: 10px; font-size: 22px; cursor: pointer;
  transition: background .12s, transform .12s;
}
.dx-detective .dxd-close:hover { background: rgba(255,255,255,.25); transform: rotate(90deg); }

/* ---------- Banner ---------- */
.dx-detective .dxd-banner {
  position: relative; z-index: 2; margin: 22px auto 4px; max-width: 1000px;
  font-family: var(--font-chalk); font-size: 17px; line-height: 1.5;
  color: var(--chalk); text-align: center; padding: 6px 18px;
}
.dx-detective .dxd-banner b { color: var(--chalk-yel); }
.dx-detective .dxd-banner .cn { display: block; font-size: 15px; color: var(--chalk-dim); margin-top: 2px; }

/* ---------- Board ---------- */
.dx-detective .dxd-board-wrap { position: relative; z-index: 2; flex: 1 1 auto; width: calc(100% - 264px); min-width: 560px; max-width: none; margin: 0; padding: 8px 0 0; }
.dx-detective .dxd-board { position: relative; width: 100%; aspect-ratio: 16 / 10; min-height: 460px; }
.dx-detective .dxd-strings { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; overflow: visible; }
.dx-detective .dxd-strings line { stroke-linecap: round; }
.dx-detective .dxd-strings line.committed { filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); }

/* ---------- Evidence photo ---------- */
.dx-detective .dxd-card {
  position: absolute; width: 150px;
  transform: translate(-50%, -50%) rotate(var(--tilt, -2deg));
  background: #fdfbf4; padding: 10px 10px 14px; border-radius: 3px;
  box-shadow: 0 10px 22px rgba(0,0,0,.45), 0 2px 4px rgba(0,0,0,.3);
  z-index: 2; text-align: center; user-select: none;
  animation: dxd-sway var(--sway, 7s) ease-in-out infinite;
  transition: box-shadow .18s, filter .18s;
}
.dx-detective .dxd-card.center {
  z-index: 3; width: 168px;
  box-shadow: 0 14px 30px rgba(217,79,79,.4), 0 3px 6px rgba(0,0,0,.4); animation-duration: 9s;
}
.dx-detective .dxd-card[data-id="hank"] { left: 50%; top: 20%; }
.dx-detective .dxd-card[data-id="scott"] { left: 17%; top: 22%; }
.dx-detective .dxd-card[data-id="hope"] { left: 83%; top: 22%; }
.dx-detective .dxd-card[data-id="maggie"] { left: 50%; top: 66%; }
.dx-detective .dxd-card[data-id="cassie"] { left: 17%; top: 68%; }
.dx-detective .dxd-card[data-id="darren"] { left: 83%; top: 68%; }
.dx-detective .dxd-card:hover { box-shadow: 0 16px 34px rgba(0,0,0,.55); }
@keyframes dxd-sway {
  0%, 100% { transform: translate(-50%, -50%) rotate(var(--tilt, -2deg)); }
  50%      { transform: translate(-50%, calc(-50% - 5px)) rotate(calc(var(--tilt, -2deg) + 1.2deg)); }
}
.dx-detective .dxd-card .pin {
  position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
  width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #ff8a7e, var(--yarn) 65%, #9e2b2b 100%);
  box-shadow: 0 4px 6px rgba(0,0,0,.5), inset 0 -2px 3px rgba(0,0,0,.3); z-index: 4;
}
.dx-detective .dxd-card .pin::after {
  content: ""; position: absolute; top: 5px; left: 6px; width: 5px; height: 5px;
  border-radius: 50%; background: rgba(255,255,255,.7);
}
.dx-detective .dxd-photo {
  width: 100%; aspect-ratio: 1; border-radius: 2px; object-fit: cover;
  background: #ece4d4; display: block; filter: saturate(1.02) contrast(1.02);
}
.dx-detective .dxd-photo-fallback {
  width: 100%; aspect-ratio: 1; border-radius: 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; color: #fff; position: relative; overflow: hidden;
}
.dx-detective .dxd-photo-fallback::after {
  content: "EVIDENCE PENDING"; position: absolute; bottom: 8px;
  font-family: var(--font-hand); font-size: 9px; letter-spacing: 1px; opacity: .85;
}
.dx-detective .dxd-photo-fallback .fb-initials { font-family: var(--font-chalk); font-size: 40px; font-weight: 700; }
.dx-detective .dxd-name { margin-top: 8px; font-family: var(--font-chalk); font-size: 17px; font-weight: 700; color: #23201a; }
.dx-detective .dxd-name .cn { font-weight: 700; color: #6b5a44; font-size: 14px; }
.dx-detective .dxd-role { font-family: var(--font-hand); font-size: 12px; color: #7a6a52; margin-top: 1px; line-height: 1.25; }
.dx-detective .dxd-handle {
  position: absolute; right: -10px; bottom: -10px; width: 30px; height: 30px; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #ff8a7e, var(--yarn) 70%); color: #fff;
  border: 2px solid #fdfbf4; display: flex; align-items: center; justify-content: center;
  font-size: 14px; cursor: grab; z-index: 5; box-shadow: 0 3px 8px rgba(0,0,0,.4);
  animation: dxd-pulse 2.4s ease-in-out infinite;
}
@keyframes dxd-pulse {
  0%, 100% { box-shadow: 0 3px 8px rgba(0,0,0,.4), 0 0 0 0 rgba(217,79,79,.5); }
  50%      { box-shadow: 0 3px 8px rgba(0,0,0,.4), 0 0 0 9px rgba(217,79,79,0); }
}
.dx-detective .dxd-handle:active { cursor: grabbing; }
.dx-detective .dxd-card.droppable { outline: 3px dashed var(--chalk-yel); outline-offset: 4px; }
.dx-detective .dxd-card.linked { box-shadow: 0 12px 26px rgba(127,220,164,.5), 0 2px 6px rgba(0,0,0,.35); }
.dx-detective .dxd-card.just-linked { animation: dxd-snap .5s ease; }
@keyframes dxd-snap {
  0% { transform: translate(-50%, -50%) rotate(var(--tilt,-2deg)) scale(1); }
  35% { transform: translate(-50%, -50%) rotate(var(--tilt,-2deg)) scale(1.06); }
  100% { transform: translate(-50%, -50%) rotate(var(--tilt,-2deg)) scale(1); }
}
.dx-detective .dxd-card .reltag {
  margin-top: 7px; font-family: var(--font-hand); font-size: 12px; font-weight: 700;
  color: #0f6e56; background: #e6f7ee; border-radius: 6px; padding: 3px 7px; display: none;
}
.dx-detective .dxd-card.linked .reltag { display: inline-block; }
.dx-detective .dxd-card .chalk-check {
  position: absolute; top: -6px; right: -6px; font-family: var(--font-chalk);
  font-size: 30px; color: var(--ok); text-shadow: 0 0 8px rgba(127,220,164,.6);
  opacity: 0; transform: scale(.3) rotate(-20deg); z-index: 6;
}
.dx-detective .dxd-card.linked .chalk-check { animation: dxd-check .5s .1s forwards ease; }
@keyframes dxd-check { to { opacity: 1; transform: scale(1) rotate(-8deg); } }

/* ---------- Relationship popover ---------- */
.dx-detective .dxd-rel-pop {
  position: absolute; z-index: 30; width: 260px; display: none;
  background: var(--paper); color: #2c2218; border-radius: 10px; padding: 14px;
  box-shadow: 0 16px 40px rgba(0,0,0,.5); border: 1px solid #e0d6bf;
}
.dx-detective .dxd-rel-pop.open { display: block; animation: dxd-pop .22s ease; }
.dx-detective .dxd-rel-pop h4 { margin: 0 0 10px; font-family: var(--font-chalk); font-size: 16px; color: var(--yarn); }
.dx-detective .dxd-rel-pop button {
  display: block; width: 100%; text-align: left; margin: 6px 0; padding: 9px 11px;
  font-family: var(--font-hand); font-size: 14px; border: 1px solid #e0d6bf;
  border-radius: 8px; background: #fff; cursor: pointer; transition: background .1s, transform .08s;
}
.dx-detective .dxd-rel-pop button:hover { background: #f3ead4; transform: translateX(2px); }
.dx-detective .dxd-rel-pop button .cn { color: #998; }

/* ---------- Case files ---------- */
.dx-detective .dxd-files { position: relative; z-index: 2; max-width: 1000px; margin: 30px auto; padding: 0 18px 50px; }
.dx-detective .dxd-files h3 { font-family: var(--font-chalk); color: var(--chalk); font-size: 22px; margin: 6px 0 4px; display: flex; align-items: center; gap: 8px; }
.dx-detective .dxd-files .sub { font-family: var(--font-hand); color: var(--chalk-dim); font-size: 14px; margin-bottom: 16px; }
.dx-detective .dxd-clue {
  position: relative; background: var(--paper); color: #2c2218; border-radius: 4px;
  padding: 16px 18px 14px; margin-bottom: 18px; box-shadow: 0 8px 18px rgba(0,0,0,.35);
  transform: rotate(var(--ctilt, -.5deg)); border-left: 4px solid var(--yarn);
}
.dx-detective .dxd-clue::before {
  content: ""; position: absolute; top: -9px; left: 50%; transform: translateX(-50%) rotate(-2deg);
  width: 64px; height: 18px; background: rgba(255,224,138,.55); border-radius: 2px; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.dx-detective .dxd-clue .tag {
  display: inline-block; font-family: var(--font-hand); font-size: 12px; font-weight: 700;
  background: #fce4e1; color: var(--yarn); padding: 3px 11px; border-radius: 6px; margin-bottom: 9px;
}
.dx-detective .dxd-clue .quote { font-size: 18px; line-height: 1.6; color: #2c2218; font-family: var(--font-hand); }
.dx-detective .dxd-clue .cn { font-size: 14px; color: #7a6a52; margin-top: 4px; }
.dx-detective .dxd-blank {
  display: inline-block; min-width: 96px; text-align: center; border-bottom: 2px solid #2E75B6;
  color: #2E75B6; font-weight: 700; padding: 0 6px; font-family: var(--font-chalk); font-size: 19px;
}
.dx-detective .dxd-blank.filled { border-bottom-color: #1D9E75; color: #1D9E75; }
.dx-detective .dxd-opts { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 12px; }
.dx-detective .dxd-opts button {
  font-family: var(--font-hand); font-size: 15px; padding: 8px 18px; border: 1px solid #d8cdb4;
  border-radius: 8px; background: #fff; cursor: pointer; transition: background .12s, transform .08s;
}
.dx-detective .dxd-opts button:hover { background: #f3ead4; }
.dx-detective .dxd-opts button:active { transform: scale(.96); }
.dx-detective .dxd-opts button.correct { background: #e6f7ee; border-color: #1D9E75; color: #0f6e56; }
.dx-detective .dxd-opts button.wrong { background: #fcecec; border-color: var(--yarn); color: #A32D2D; }
.dx-detective .dxd-opts button:disabled { cursor: default; }
.dx-detective .dxd-fb { font-family: var(--font-hand); font-size: 13px; margin-top: 9px; min-height: 1em; }

/* ---------- Student evidence notebook ---------- */
.dx-detective .dxd-linebook {
  position: relative; z-index: 2; max-width: 1000px; margin: -10px auto 34px; padding: 0 18px;
}
.dx-detective .dxd-linebook h3 {
  font-family: var(--font-chalk); color: var(--chalk); font-size: 22px;
  margin: 6px 0 4px; display: flex; align-items: center; gap: 8px;
}
.dx-detective .dxd-linebook .sub {
  font-family: var(--font-hand); color: var(--chalk-dim); font-size: 14px; margin-bottom: 16px;
}
.dx-detective .dxd-line-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px;
}
.dx-detective .dxd-line-card {
  position: relative; background: rgba(245,239,224,.96); color: #2c2218;
  border-left: 5px solid var(--accent, var(--yarn)); border-radius: 5px;
  padding: 14px; box-shadow: 0 8px 18px rgba(0,0,0,.35);
}
.dx-detective .dxd-line-card::before {
  content: ""; position: absolute; top: -8px; right: 22px; width: 58px; height: 16px;
  background: rgba(255,224,138,.5); transform: rotate(2deg); border-radius: 2px;
}
.dx-detective .dxd-line-card.complete {
  box-shadow: 0 10px 22px rgba(127,220,164,.34), 0 4px 10px rgba(0,0,0,.28);
}
.dx-detective .dxd-line-card.complete::after {
  content: "PROFILE BUILT"; position: absolute; top: 12px; right: 12px;
  font-family: var(--font-chalk); font-size: 12px; color: #0f6e56;
  border: 2px solid #1D9E75; border-radius: 5px; padding: 2px 6px;
  transform: rotate(5deg); opacity: .9;
}
.dx-detective .dxd-line-head {
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; margin-bottom: 8px;
}
.dx-detective .line-dot { width: 12px; height: 12px; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.dx-detective .line-name { font-family: var(--font-chalk); font-size: 18px; font-weight: 700; color: #23201a; }
.dx-detective .line-name .cn { font-size: 14px; color: #6b5a44; }
.dx-detective .line-count {
  font-family: var(--font-chalk); font-weight: 700; font-size: 15px; color: #0f6e56;
  background: #e6f7ee; border-radius: 999px; padding: 3px 8px;
}
.dx-detective .line-prompt {
  font-size: 13px; line-height: 1.35; color: #62533f; margin-bottom: 9px; padding-right: 70px;
}
.dx-detective .line-prompt span { color: #8a765c; }
.dx-detective .dxd-line-input {
  width: 100%; resize: vertical; min-height: 56px; max-height: 120px;
  border: 1.5px dashed #cbbd9f; border-radius: 8px; background: #fffdf8; color: #2c2218;
  padding: 9px 10px; font-family: var(--font-hand); font-size: 15px; line-height: 1.35; outline: none;
}
.dx-detective .dxd-line-input:focus {
  border-color: var(--accent, var(--yarn)); box-shadow: 0 0 0 3px rgba(255,224,138,.25);
}
.dx-detective .dxd-line-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 9px; }
.dx-detective .dxd-line-actions button,
.dx-detective .line-example,
.dx-detective .line-remove {
  font-family: var(--font-hand); cursor: pointer;
}
.dx-detective .dxd-line-actions button {
  border: 1px solid #d8cdb4; border-radius: 8px; padding: 7px 10px; font-size: 13px; background: #fff;
  color: #2c2218; transition: transform .08s, background .12s;
}
.dx-detective .dxd-line-actions button:hover { background: #f3ead4; transform: translateY(-1px); }
.dx-detective .dxd-line-actions .pin-line { background: #e6f7ee; color: #0f6e56; border-color: rgba(29,158,117,.35); font-weight: 700; }
.dx-detective .dxd-line-hints { display: none; gap: 7px; flex-direction: column; margin-top: 9px; }
.dx-detective .dxd-line-card.show-hints .dxd-line-hints { display: flex; }
.dx-detective .line-example {
  text-align: left; border: 1px solid rgba(217,79,79,.22); background: #fff8f3; color: #5f4932;
  border-radius: 8px; padding: 7px 9px; font-size: 13px; line-height: 1.3;
}
.dx-detective .line-example:hover { background: #fcefe7; }
.dx-detective .line-feedback { min-height: 1em; margin-top: 8px; font-size: 12px; color: #7a6a52; }
.dx-detective .line-feedback.ok { color: #0f6e56; }
.dx-detective .line-feedback.warn { color: #A32D2D; }
.dx-detective .dxd-line-list { display: flex; flex-direction: column; gap: 7px; margin-top: 9px; }
.dx-detective .line-note {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start;
  background: #fffaf0; border: 1px solid #e7dcc5; border-radius: 8px; padding: 8px 8px 8px 10px;
}
.dx-detective .line-note-text { font-size: 14px; line-height: 1.35; color: #2c2218; }
.dx-detective .line-remove {
  width: 24px; height: 24px; border: none; border-radius: 7px; background: #fce4e1; color: #A32D2D;
  font-size: 16px; line-height: 1;
}
.dx-detective .line-remove:hover { background: #f6cac5; }
@media (max-width: 760px) {
  .dx-detective .dxd-line-grid { grid-template-columns: 1fr; }
  .dx-detective .line-prompt { padding-right: 0; }
  .dx-detective .dxd-line-card.complete::after {
    position: static; display: inline-block; margin: 2px 0 8px 20px;
  }
}

/* ---------- Win ---------- */
.dx-detective .dxd-win {
  position: relative; z-index: 3; display: none; max-width: 1000px; margin: 0 auto 36px;
  background: linear-gradient(135deg, #2f5e4a, #1d4636); color: #fff; border-radius: 16px;
  padding: 26px; text-align: center; box-shadow: 0 12px 30px rgba(0,0,0,.5); border: 2px dashed var(--chalk-yel);
}
.dx-detective .dxd-win.show { display: block; animation: dxd-pop .45s ease; }
.dx-detective .dxd-win h2 { font-family: var(--font-chalk); margin: 0 0 6px; font-size: 30px; color: var(--chalk-yel); }
.dx-detective .dxd-win p { margin: 0; opacity: .94; font-size: 16px; font-family: var(--font-hand); }
.dx-detective .dxd-win .replay {
  margin-top: 16px; background: var(--chalk-yel); color: #1f2a24; border: none; padding: 11px 26px;
  border-radius: 999px; font-family: var(--font-chalk); font-weight: 700; font-size: 17px; cursor: pointer;
}
@keyframes dxd-pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.dx-detective .dxd-confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; display: none; }
.dx-detective .dxd-confetti.show { display: block; }
.dx-detective .dxd-confetti i {
  position: absolute; top: -12px; width: 8px; height: 8px; border-radius: 1px; opacity: .9;
  animation: dxd-confetti-fall 2.2s ease-in forwards;
}
@keyframes dxd-confetti-fall { to { transform: translateY(105vh) rotate(540deg); opacity: 0; } }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  .dx-detective .dxd-board { aspect-ratio: auto; min-height: 0; display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; padding-top: 8px; }
  .dx-detective .dxd-card { position: static; transform: rotate(var(--tilt,-2deg)); width: 44%; animation: none; }
  .dx-detective .dxd-card.center { width: 60%; }
  .dx-detective .dxd-strings, .dx-detective .dxd-handle { display: none; }
  .dx-detective .dxd-title b { font-size: 20px; }
}
.dx-detective .dxd-mobile-link { display: none; }
@media (max-width: 720px) {
  .dx-detective .dxd-mobile-link {
    display: inline-flex; align-items: center; justify-content: center;
    width: 100%; margin-top: 8px; padding: 7px 8px;
    border: 1px dashed rgba(39, 174, 148, .45); border-radius: 7px;
    background: #eef8f1; color: #0f6e56;
    font-family: var(--font-hand); font-size: 13px; font-weight: 700;
    cursor: pointer;
  }
  .dx-detective .dxd-card.just-linked { animation: dxd-mobile-snap .45s ease; }
  .dx-detective .dxd-card.shake { animation: dxd-mobile-shake .45s ease; }
  @keyframes dxd-mobile-snap {
    0% { transform: rotate(var(--tilt,-2deg)) scale(1); }
    35% { transform: rotate(var(--tilt,-2deg)) scale(1.04); }
    100% { transform: rotate(var(--tilt,-2deg)) scale(1); }
  }
  @keyframes dxd-mobile-shake {
    0%,100% { transform: rotate(var(--tilt,-2deg)) translateX(0); }
    20% { transform: rotate(var(--tilt,-2deg)) translateX(-6px); }
    40% { transform: rotate(var(--tilt,-2deg)) translateX(6px); }
    60% { transform: rotate(var(--tilt,-2deg)) translateX(-4px); }
    80% { transform: rotate(var(--tilt,-2deg)) translateX(4px); }
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .dx-detective, .dx-detective * { animation: none !important; transition: none !important; }
}

/* ---------- Main: left panel + board ---------- */
.dx-detective .dxd-main { position: relative; z-index: 2; display: flex; gap: 14px; max-width: 1180px; margin: 0 auto; padding: 22px 18px 0; align-items: flex-start; }
.dx-detective .dxd-leftpanel { flex: 0 0 250px; position: sticky; top: 78px; min-height: 320px; }
.dx-detective .dxd-leftpanel-hint {
  display: flex; align-items: center; gap: 10px; padding: 14px;
  background: rgba(255,255,255,.06); border: 1px dashed rgba(255,224,138,.4);
  border-radius: 12px; color: var(--chalk);
}
.dx-detective .dxd-leftpanel.choosing .dxd-leftpanel-hint { display: none; }
.dx-detective .lp-badgeicon { font-size: 26px; }
.dx-detective .lp-hint-text b { font-family: var(--font-chalk); font-size: 16px; display:block; }
.dx-detective .lp-hint-text span { font-size: 12px; opacity: .8; }
.dx-detective .dxd-board-wrap { flex: 1 1 auto; width: calc(100% - 264px); min-width: 560px; max-width: none; margin: 0; padding: 8px 0 0; }
.dx-detective .dxd-board {
  aspect-ratio: auto;
  height: clamp(700px, 48vw, 780px);
  min-height: 700px;
  max-height: none;
  margin: 0 auto;
  overflow: visible;
}
@media (max-width: 980px) {
  .dx-detective .dxd-main { flex-direction: column; }
  .dx-detective .dxd-leftpanel { position: static; flex-basis: auto; width: 100%; min-height: 0; }
  .dx-detective .dxd-board-wrap { width: 100%; max-width: 720px; margin: 0 auto; }
  .dx-detective .dxd-board {
    aspect-ratio: auto;
    height: auto;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(150px, 1fr));
    gap: 22px 18px;
    justify-items: center;
    align-items: start;
    padding: 14px 6px 34px;
    overflow: visible;
  }
  .dx-detective .dxd-card,
  .dx-detective .dxd-card.center {
    position: relative;
    left: auto !important;
    top: auto !important;
    width: min(190px, 100%);
    transform: rotate(var(--tilt,-2deg));
    animation: none;
  }
  .dx-detective .dxd-strings,
  .dx-detective .dxd-handle { display: none; }
  .dx-detective .dxd-mobile-link {
    display: inline-flex; align-items: center; justify-content: center;
    width: 100%; margin-top: 8px; padding: 7px 8px;
    border: 1px dashed rgba(39, 174, 148, .45); border-radius: 7px;
    background: #eef8f1; color: #0f6e56;
    font-family: var(--font-hand); font-size: 13px; font-weight: 700;
    cursor: pointer;
  }
  .dx-detective .dxd-card.just-linked { animation: dxd-mobile-snap .45s ease; }
  .dx-detective .dxd-card.shake { animation: dxd-mobile-shake .45s ease; }
}
@keyframes dxd-mobile-snap {
  0% { transform: rotate(var(--tilt,-2deg)) scale(1); }
  35% { transform: rotate(var(--tilt,-2deg)) scale(1.04); }
  100% { transform: rotate(var(--tilt,-2deg)) scale(1); }
}
@keyframes dxd-mobile-shake {
  0%,100% { transform: rotate(var(--tilt,-2deg)) translateX(0); }
  20% { transform: rotate(var(--tilt,-2deg)) translateX(-6px); }
  40% { transform: rotate(var(--tilt,-2deg)) translateX(6px); }
  60% { transform: rotate(var(--tilt,-2deg)) translateX(-4px); }
  80% { transform: rotate(var(--tilt,-2deg)) translateX(4px); }
}
@media (max-width: 420px) {
  .dx-detective .dxd-board {
    grid-template-columns: 1fr;
    max-width: 240px;
  }
}

/* ---------- Chalk arrow (popover → active card) ---------- */
.dx-detective .dxd-arrow { position: fixed; inset: 0; pointer-events: none; z-index: 25; opacity: 0; transition: opacity .2s; }
.dx-detective .dxd-arrow.show { opacity: 1; }

/* ---------- Card shake (invalid link) ---------- */
.dx-detective .dxd-card.shake { animation: dxd-shake .45s ease; }
@keyframes dxd-shake {
  0%,100% { transform: translate(-50%,-50%) rotate(var(--tilt,-2deg)); }
  20% { transform: translate(calc(-50% - 6px),-50%) rotate(var(--tilt,-2deg)); }
  40% { transform: translate(calc(-50% + 6px),-50%) rotate(var(--tilt,-2deg)); }
  60% { transform: translate(calc(-50% - 4px),-50%) rotate(var(--tilt,-2deg)); }
  80% { transform: translate(calc(-50% + 4px),-50%) rotate(var(--tilt,-2deg)); }
}

/* wrong flash on chooser question */
.dx-detective .dxd-rel-pop h4.wrongflash { animation: dxd-wrongflash .6s ease; }
@keyframes dxd-wrongflash { 0%,100%{ color: var(--yarn);} 50%{ color:#fff; background:var(--yarn); border-radius:6px; } }

/* relationship popover now lives in-flow inside the left panel.
   Self-contained: own paper background + capped height with internal scroll so it
   can never overlap the case-files section below, even when the panel is sticky. */
.dx-detective .dxd-rel-pop {
  position: relative; width: 100%;
  max-height: calc(100vh - 110px); overflow-y: auto;
  background: var(--paper); color: #2c2218;
  border-radius: 12px; padding: 14px; border: 1px solid #e0d6bf;
  box-shadow: 0 12px 30px rgba(0,0,0,.45);
}
.dx-detective .dxd-rel-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  margin-bottom: 8px;
}
.dx-detective .dxd-rel-head h4 { margin: 0; flex: 1 1 auto; }
.dx-detective .dxd-rel-cancel {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 8px; border: none;
  background: var(--yarn); color: #fff; font-size: 16px; line-height: 1; cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.3); transition: background .12s, transform .12s;
}
.dx-detective .dxd-rel-cancel:hover { background: #b83b3b; transform: rotate(90deg); }
.dx-detective .dxd-rel-pop button .note { color: #8a7a5e; font-size: 12px; }

/* ---------- CASE CLOSED rubber stamp ---------- */
.dx-detective .dxd-stamp {
  position: absolute; top: 14px; right: 18px; font-family: var(--font-chalk);
  font-weight: 700; font-size: 26px; line-height: .95; text-align: center;
  color: #d94f4f; border: 4px solid #d94f4f; border-radius: 8px; padding: 6px 12px;
  transform: rotate(-16deg) scale(2); opacity: 0;
  text-shadow: 0 1px 0 rgba(0,0,0,.15); letter-spacing: 1px;
  box-shadow: inset 0 0 0 2px rgba(217,79,79,.3);
}
.dx-detective .dxd-stamp.show { animation: dxd-stamp .45s cubic-bezier(.3,1.4,.5,1) forwards; }
@keyframes dxd-stamp {
  0% { opacity: 0; transform: rotate(-16deg) scale(2.4); }
  60% { opacity: 1; transform: rotate(-16deg) scale(.92); }
  100% { opacity: .92; transform: rotate(-16deg) scale(1); }
}

/* ---------- Badge unlock ---------- */
.dx-detective .dxd-badge {
  display: flex; align-items: center; gap: 12px; justify-content: center;
  margin: 16px auto 4px; padding: 12px 18px; max-width: 320px;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,224,138,.5);
  border-radius: 14px; opacity: 0; transform: translateY(10px) scale(.9);
}
.dx-detective .dxd-badge.show { animation: dxd-badge .6s cubic-bezier(.2,1.3,.4,1) forwards; }
@keyframes dxd-badge { to { opacity: 1; transform: translateY(0) scale(1); } }
.dx-detective .badge-medal { font-size: 40px; animation: dxd-medal-spin 1.2s ease; }
@keyframes dxd-medal-spin { 0%{ transform: rotate(0) scale(.4);} 70%{ transform: rotate(380deg) scale(1.15);} 100%{ transform: rotate(360deg) scale(1);} }
.dx-detective .badge-label { font-family: var(--font-chalk); font-size: 18px; color: var(--chalk-yel); text-align: left; line-height: 1.15; }
.dx-detective .badge-label span { font-family: var(--font-hand); font-size: 12px; color: var(--chalk-dim); }

/* ---------- Exit confirm (child-proof) ---------- */
.dx-detective .dxd-exit-ask {
  position: fixed; inset: 0; z-index: 60; display: none;
  align-items: center; justify-content: center; background: rgba(0,0,0,.55);
}
.dx-detective .dxd-exit-ask.show { display: flex; animation: dxd-fadein .2s ease; }
.dx-detective .dxd-exit-ask .ask-box {
  background: var(--paper); color: #2c2218; border-radius: 16px; padding: 24px 26px;
  max-width: 360px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.5);
}
.dx-detective .dxd-exit-ask h3 { font-family: var(--font-chalk); margin: 0 0 8px; font-size: 22px; color: var(--yarn); }
.dx-detective .dxd-exit-ask p { font-family: var(--font-hand); margin: 0 0 16px; font-size: 15px; }
.dx-detective .dxd-exit-ask .ask-row { display: flex; gap: 10px; justify-content: center; }
.dx-detective .dxd-exit-ask button { font-family: var(--font-chalk); font-size: 16px; padding: 9px 18px; border-radius: 10px; cursor: pointer; border: none; }
.dx-detective .dxd-exit-ask .ask-stay { background: #2f5e4a; color: #fff; }
.dx-detective .dxd-exit-ask .ask-go { background: var(--yarn); color: #fff; }

/* make the top-right close button more obvious for kids */
.dx-detective .dxd-close { background: var(--yarn); color: #fff; box-shadow: 0 3px 8px rgba(0,0,0,.35); }
.dx-detective .dxd-close:hover { background: #b83b3b; transform: rotate(90deg); }

/* personalized name highlight */
.dx-detective .dxd-name-hl { color: var(--chalk-yel); text-decoration: underline wavy var(--chalk-yel); text-underline-offset: 3px; }

/* win box: relative for stamp. Do NOT clip content (was cutting off the
   trophy / "Case solved!" line); give the stamp room with right padding instead. */
.dx-detective .dxd-win {
  position: relative; overflow: visible;
  width: min(1000px, calc(100% - 36px));
  margin: 18px auto 64px;
  padding: 30px 180px 26px 28px;
  scroll-margin-block: 130px;
}
@media (max-width: 760px) {
  .dx-detective .dxd-win { padding: 88px 22px 24px; }
  .dx-detective .dxd-stamp { top: 16px; right: 50%; transform: translateX(50%) rotate(-10deg) scale(2); font-size: 22px; }
  @keyframes dxd-stamp {
    0% { opacity: 0; transform: translateX(50%) rotate(-10deg) scale(2.4); }
    60% { opacity: 1; transform: translateX(50%) rotate(-10deg) scale(.92); }
    100% { opacity: .92; transform: translateX(50%) rotate(-10deg) scale(1); }
  }
}
