/* Minigames: hub, Capture the Flag, Tower Defense, Trading Post.
   Dark slate cards, lime accent, chunky buttons. Phone first (≈430px), roomier on desktop. */

#screen-minigames, #screen-ctf, #screen-tower-defense, #screen-trading {
  justify-content: flex-start;
  overflow-y: auto;
  padding: 16px 16px 36px;
}

.mg-page {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.mg-page .mg-back { align-self: flex-start; margin: 0 0 -6px; padding: 8px 2px; font-weight: 800; }
.mg-page .mg-back:hover { color: var(--brand); }
.mg-title { font-size: 1.6rem; text-align: center; margin: 0; color: #f6f6e9; }
.mg-page .btn { min-width: 0; }

#ctf-game-area, #td-game-area, #trade-game-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ===== Hub ===== */
.mg-page-head { text-align: left; }
.mg-page-head h2 { font-size: 2rem; margin: 6px 0 4px; text-align: left; color: #f6f6e9; }
.mg-page-head p { color: var(--text-secondary); font-size: .95rem; }

.minigames-grid { display: grid; gap: 14px; width: 100%; }

.mg-card {
  --card-a: #3a4a62; --card-b: #283850; --card-edge: #1a2638;
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "icon info" "play play";
  align-items: center;
  gap: 10px 14px;
  width: 100%;
  padding: 18px;
  border: 2px solid rgba(255, 255, 255, .18);
  border-radius: 22px;
  background: linear-gradient(150deg, var(--card-a), var(--card-b));
  box-shadow: 0 6px 0 var(--card-edge), 0 12px 24px rgba(0, 0, 0, .25);
  color: #fff;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, filter .15s ease;
}
.mg-card:hover { transform: translateY(-3px); filter: brightness(1.06); box-shadow: 0 9px 0 var(--card-edge), 0 16px 28px rgba(0, 0, 0, .3); }
.mg-card:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--card-edge); }
.mg-card-ctf { --card-a: #36c98a; --card-b: #188a5c; --card-edge: #0e5539; }
.mg-card-td { --card-a: #7a6cf0; --card-b: #4a3fc0; --card-edge: #2b2380; }
.mg-card-trade { --card-a: #f7b733; --card-b: #c9851a; --card-edge: #7d500c; color: #2e1d00; }

.mg-card-icon {
  grid-area: icon;
  width: 68px; height: 68px;
  display: grid; place-items: center;
  border-radius: 20px;
  background: rgba(255, 255, 255, .2);
  font-size: 2.3rem;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .2));
}
.mg-card-info { grid-area: info; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.mg-card-title { font: 1.3rem/1.1 var(--font-display); }
.mg-card-goal { font-size: .92rem; font-weight: 700; line-height: 1.35; opacity: .95; }
.mg-card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.mg-card-meta span {
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .2);
  font-size: .74rem;
  font-weight: 800;
}
.mg-card-trade .mg-card-meta span { background: rgba(255, 255, 255, .35); }
.mg-card-play {
  grid-area: play;
  justify-self: stretch;
  padding: 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .92);
  color: #1d2a3c;
  font: 1.05rem var(--font-display);
  text-align: center;
}
.mg-card-locked { filter: saturate(.35); }
.mg-card-locked .mg-card-play { background: rgba(0, 0, 0, .25); color: #fff; }

.mg-no-monster {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px 14px;
  align-items: center;
  padding: 16px;
  border-radius: 20px;
  background: linear-gradient(135deg, #3a2f63, #25304f);
  border: 2px solid #7b68c9;
}
.mg-no-monster-egg { font-size: 2.6rem; animation: mg-wobble 2.2s ease-in-out infinite; }
.mg-no-monster h3 { font-size: 1.1rem; margin-bottom: 2px; }
.mg-no-monster p { color: #d8d4f4; font-size: .88rem; line-height: 1.4; }
.mg-no-monster .btn { grid-column: 1 / -1; width: 100%; }
.mg-nudge { animation: mg-nudge .5s ease; }

/* Friendly empty state inside a game */
.mg-empty {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 32px 20px;
  border-radius: 22px;
  background: var(--surface);
  border: 2px solid var(--border);
  text-align: center;
}
.mg-empty-icon { font-size: 3.4rem; animation: mg-wobble 2.2s ease-in-out infinite; }
.mg-empty h3 { font-size: 1.3rem; }
.mg-empty p { color: var(--text-secondary); max-width: 300px; line-height: 1.45; }
.mg-empty .btn { width: 100%; max-width: 280px; margin-top: 6px; }

/* Shared result card */
.mg-result {
  position: relative;
  overflow: hidden;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 28px 20px 22px;
  border-radius: 24px;
  background: linear-gradient(160deg, #26394f, #1a2638);
  border: 2px solid var(--border);
  text-align: center;
  animation: mg-pop .35s cubic-bezier(.2, 1.4, .4, 1);
}
.mg-result.win { border-color: var(--brand); background: linear-gradient(160deg, #2e5046, #1a2638 70%); }
.mg-result-icon { font-size: 4rem; line-height: 1; animation: mg-bounce 1.4s ease-in-out infinite; }
.mg-result h3 { font-size: 2rem; color: #fff; }
.mg-result.win h3 { color: var(--brand); }
.mg-result-sub { color: #d5e0ea; max-width: 360px; line-height: 1.45; }
.mg-result-score { display: flex; gap: 10px; align-items: center; font: 1.15rem var(--font-display); }
.mg-rewards { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 4px 0; }
.mg-reward {
  padding: 8px 14px;
  border-radius: 999px;
  background: #3b3313;
  border: 2px solid #f7d88f;
  color: #ffe08a;
  font: 1.05rem var(--font-display);
  animation: mg-pop .4s .2s both cubic-bezier(.2, 1.4, .4, 1);
}
.mg-result-actions { display: grid; gap: 10px; width: 100%; max-width: 320px; margin-top: 6px; }
.mg-result-actions .btn-back { margin-top: 0; }
.mg-confetti { position: absolute; inset: 0; pointer-events: none; }
.mg-confetti i {
  position: absolute;
  top: -12px;
  left: calc(var(--i) * 5.5% + 2%);
  width: 8px; height: 14px;
  border-radius: 2px;
  background: hsl(calc(var(--i) * 47), 90%, 62%);
  animation: mg-confetti 2.4s calc(var(--i) * -.13s) linear infinite;
}

/* ===== Capture the Flag ===== */
.ctf-banner {
  padding: 10px 14px;
  border-radius: 14px;
  background: #2f4a44;
  border: 2px solid #48756b;
  color: #e7f6dd;
  font-weight: 700;
  text-align: center;
}
.ctf-banner strong { color: var(--brand); }
.ctf-hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--surface);
  border: 2px solid var(--border);
}
.ctf-hud-side { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ctf-hud-rival { align-items: flex-end; text-align: right; }
.ctf-hud-name { font-weight: 800; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.ctf-hud-you .ctf-hud-name { color: var(--brand); }
.ctf-hud-rival .ctf-hud-name { color: #ff9aa9; }
.ctf-hud-mid { display: flex; flex-direction: column; align-items: center; }
.ctf-hud-mid strong { font: 1rem var(--font-display); }
.ctf-hud-mid span { font-size: .78rem; color: var(--text-secondary); font-weight: 700; }
.ctf-flag-dots { display: flex; gap: 4px; }
.ctf-flag-dot {
  width: 20px; height: 20px;
  border-radius: 6px;
  background: rgba(255, 255, 255, .08);
  border: 2px dashed rgba(255, 255, 255, .25);
}
.ctf-flag-dot.won { border: none; background: #ffd166; box-shadow: 0 0 10px #ffd16688; animation: mg-pop .35s cubic-bezier(.2, 1.4, .4, 1); }
.ctf-flag-dot.won::after { content: ''; display: block; height: 100%; background: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M6.4%203.6H19.6L16%208.2L19.6%2012.8H6.4Z%22%20fill%3D%22%23ff5d6c%22%20stroke%3D%22%231d1433%22%20stroke-width%3D%221.6%22%20stroke-linejoin%3D%22round%22%20stroke-linecap%3D%22round%22%2F%3E%3Cpath%20d%3D%22M5.4%202.8V21.2%22%20fill%3D%22none%22%20stroke%3D%22%231d1433%22%20stroke-width%3D%224.2%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%2F%3E%3Cpath%20d%3D%22M5.4%202.8V21.2%22%20fill%3D%22none%22%20stroke%3D%22%2394a3b8%22%20stroke-width%3D%221.8%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%2F%3E%3Cpath%20d%3D%22M8.2%205.2H13%22%20stroke%3D%22%23f8fafc%22%20stroke-width%3D%221.4%22%20stroke-linecap%3D%22round%22%20opacity%3D%22.55%22%2F%3E%3C%2Fsvg%3E") center / 80% no-repeat; }
.ctf-win-note { text-align: center; font-size: .78rem; color: var(--text-secondary); font-weight: 700; margin-top: -6px; }

.ctf-track {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 20px;
  background: linear-gradient(180deg, #2d6a4f, #1f4d39);
  border: 3px solid #14392a;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .2);
}
.ctf-lane { display: grid; grid-template-columns: 46px 1fr; align-items: center; gap: 8px; }
.ctf-lane-label {
  font: .8rem var(--font-display);
  text-align: center;
  padding: 4px 0;
  border-radius: 8px;
}
.ctf-lane-you .ctf-lane-label { background: var(--brand); color: var(--brand-ink); }
.ctf-lane-rival .ctf-lane-label { background: #ff5d6c; color: #fff; }
.ctf-lane-track {
  --runner: 56px;
  position: relative;
  height: 72px;
  border-radius: 14px;
  background: repeating-linear-gradient(90deg, rgba(255, 255, 255, .07) 0 12px, transparent 12px 24px), rgba(0, 0, 0, .18);
}
.ctf-steps { position: absolute; left: calc(var(--runner) / 2); right: calc(var(--runner) / 2); top: 0; bottom: 0; }
.ctf-step {
  position: absolute;
  bottom: 6px;
  left: calc(var(--p) * 100%);
  transform: translateX(-50%);
  width: 20px; height: 20px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, .15);
  color: rgba(255, 255, 255, .7);
  font-size: .66rem;
  font-weight: 800;
  transition: background .3s ease;
}
.ctf-step-start { width: 6px; height: 40px; bottom: 16px; border-radius: 3px; background: #fff; }
.ctf-lane-you .ctf-step.passed { background: var(--brand); color: var(--brand-ink); }
.ctf-lane-rival .ctf-step.passed { background: #ff5d6c; color: #fff; }
.ctf-goal { position: absolute; right: 4px; top: 4px; width: 40px; height: 60px; pointer-events: none; }
.ctf-pole { position: absolute; left: 6px; top: 0; bottom: 0; width: 4px; border-radius: 2px; background: #e9e4d4; }
.ctf-cloth {
  position: absolute; left: 10px; top: 2px;
  width: 28px; height: 20px;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  animation: ctf-wave 1.2s ease-in-out infinite;
  transform-origin: left center;
}
.ctf-lane-you .ctf-cloth { background: #ff5d6c; }   /* you run for the rival's red flag */
.ctf-lane-rival .ctf-cloth { background: var(--brand); } /* the rival runs for your green flag */
.ctf-runner {
  position: absolute;
  bottom: 12px;
  left: calc(var(--p) * (100% - var(--runner)));
  width: var(--runner);
  height: 56px;
  display: grid; place-items: end center;
  transition: left .6s cubic-bezier(.3, 1.3, .5, 1);
  z-index: 1;
}
.ctf-runner-sprite { transform: scale(.78); transform-origin: bottom center; }
.ctf-runner.hop .ctf-runner-sprite { animation: ctf-hop .6s ease; }
.ctf-runner.captured .ctf-runner-sprite { animation: mg-bounce .8s ease-in-out infinite; }
.ctf-runner::before {
  content: '';
  position: absolute; bottom: -4px; left: 50%;
  width: 44px; height: 10px; margin-left: -22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .35);
  box-shadow: 0 0 0 3px var(--ring);
}
.ctf-lane-you .ctf-runner { --ring: rgba(202, 238, 147, .75); }
.ctf-lane-rival .ctf-runner { --ring: rgba(255, 93, 108, .75); }
.ctf-track-toast {
  position: absolute;
  inset: 50% 12px auto;
  transform: translateY(-50%);
  z-index: 3;
  padding: 14px;
  border-radius: 16px;
  font: 1.2rem var(--font-display);
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  animation: mg-pop .35s cubic-bezier(.2, 1.4, .4, 1);
}
.ctf-track-toast.you { background: var(--brand); color: var(--brand-ink); }
.ctf-track-toast.rival { background: #ff5d6c; color: #fff; }
.ctf-track-toast.none { background: var(--surface-2); color: #fff; }

.ctf-feedback { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; min-height: 36px; }
.ctf-chip {
  padding: 7px 12px;
  border-radius: 999px;
  font-weight: 800;
  font-size: .9rem;
  animation: mg-pop .3s cubic-bezier(.2, 1.4, .4, 1);
}
.ctf-chip.good { background: #1f5140; color: #bff5d9; border: 2px solid var(--good); }
.ctf-chip.bad { background: #4a2029; color: #ffc9cf; border: 2px solid var(--bad); }
.ctf-chip.rival { background: #3a2530; color: #ffb3bd; border: 2px solid #8a4252; }
.ctf-chip.calm { background: var(--surface-2); color: #d5e0ea; border: 2px solid var(--border); }
.ctf-quiz { width: 100%; }
.ctf-question {
  margin-bottom: 12px;
  padding: 16px;
  border-radius: 16px;
  background: var(--surface);
  border: 2px solid var(--border);
  font: 1.15rem/1.35 var(--font-display);
  text-align: center;
}
.ctf-answers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ctf-answers .btn { min-width: 0; }

/* ===== Tower Defense ===== */
.td-setup { display: flex; flex-direction: column; gap: 14px; }
.td-how { list-style: none; display: grid; gap: 8px; }
.td-how li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 2px solid var(--border);
}
.td-how li span { flex: 0 0 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; background: #2f4a44; font-size: 1.35rem; }
.td-how p { line-height: 1.4; color: #e7eef4; font-size: .93rem; }
.td-how strong { color: var(--brand); }
.td-setup-tip { padding: 10px 14px; border-radius: 12px; background: #3b3313; color: #ffe08a; font-weight: 700; font-size: .9rem; }
.td-setup-title { font-size: 1.2rem; margin-top: 4px; }
.td-difficulty { display: grid; gap: 10px; }
.td-diff-btn {
  display: grid; gap: 2px;
  padding: 14px 16px;
  border: 2px solid rgba(255, 255, 255, .2);
  border-radius: 16px;
  color: #fff;
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .35);
  transition: transform .1s ease, box-shadow .1s ease, filter .15s ease;
}
.td-diff-btn:hover { transform: translateY(-2px); filter: brightness(1.08); }
.td-diff-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0, 0, 0, .35); }
.td-diff-btn strong { font: 1.2rem var(--font-display); display: flex; align-items: center; gap: 8px; }
.td-diff-btn em { font: 800 .68rem var(--font-body); font-style: normal; padding: 3px 8px; border-radius: 999px; background: #fff; color: #0e5539; letter-spacing: .04em; }
.td-diff-btn span { font-weight: 800; font-size: .9rem; }
.td-diff-btn small { font-size: .8rem; opacity: .85; }
.td-diff-easy { background: linear-gradient(150deg, #36c98a, #188a5c); }
.td-diff-normal { background: linear-gradient(150deg, #4d9bff, #2b64c9); }
.td-diff-hard { background: linear-gradient(150deg, #ff5d73, #b8233f); }

.td-hud { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.td-hud-item {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 6px;
  border-radius: 14px;
  background: var(--surface);
  border: 2px solid var(--border);
  font-weight: 800;
  font-size: .9rem;
  white-space: nowrap;
}
.td-hud-item strong { font: 1.1rem var(--font-display); }
.td-lives strong { color: #ff8a96; }
.td-score strong { color: #ffd166; }
.td-hint {
  min-height: 42px;
  display: grid; place-items: center;
  padding: 8px 12px;
  border-radius: 12px;
  background: #2f4a44;
  color: #e7f6dd;
  font-weight: 700;
  font-size: .92rem;
  text-align: center;
}
.td-hint:empty { visibility: hidden; }
.td-hint strong { color: var(--brand); }
.td-hint-nudge { animation: mg-nudge .45s ease; }

.td-board { display: grid; grid-template-columns: 30px 1fr 34px; align-items: stretch; gap: 4px; }
.td-end { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-radius: 12px; }
.td-end span { font-size: 1.5rem; }
.td-end small { font-size: .55rem; font-weight: 800; letter-spacing: .04em; color: var(--text-secondary); text-transform: uppercase; }
.td-portal { background: #2b2350; }
.td-portal span { animation: td-spin 3s linear infinite; }
.td-castle { background: #3b3313; }
.td-castle-hit { animation: td-shake .4s ease; background: #6b1f2b; }
.td-field {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #1f4d39;
  border: 3px solid #14392a;
}
.td-field.zapped::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(255, 238, 120, .55), transparent 70%);
  animation: td-flash .6s ease forwards;
  pointer-events: none;
  z-index: 4;
}
.td-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
}
.td-cell {
  position: relative;
  min-width: 0;
  overflow: hidden;
  aspect-ratio: 1;
  min-height: 44px;
  display: grid; place-items: center;
  padding: 0;
  border: none;
  background: #b08a5a;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
  cursor: pointer;
  font: inherit;
  color: #fff;
}
/* Paths look like dirt roads with a grass strip between them. */
.td-cell:nth-child(odd) { background: #b89363; }
.td-grid.placing .td-cell-valid::before {
  content: '';
  position: absolute; inset: 5px;
  border: 3px dashed rgba(255, 255, 255, .85);
  border-radius: 10px;
  background: rgba(202, 238, 147, .25);
  animation: td-glow 1.2s ease-in-out infinite;
}
.td-grid.placing .td-cell-best::before { border-color: var(--brand); background: rgba(202, 238, 147, .4); }
.td-grid.placing .td-cell-valid:hover::before { background: rgba(202, 238, 147, .6); }
.td-cell-tower { background: #6b8f4e !important; }
.td-cell-tower::after {
  content: '';
  position: absolute; inset: 8%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .25), transparent 70%);
}
.td-tower { position: absolute; z-index: 1; left: 50%; top: 50%; width: 60px; height: 60px; margin: -32px 0 0 -30px; transform: scale(.62); display: grid; place-items: end center; }
.td-tower-tag {
  position: absolute; bottom: 1px; left: 50%; transform: translateX(-50%);
  z-index: 2;
  max-width: 96%;
  padding: 0 4px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .55);
  font-size: .52rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.td-cell.firing .td-tower { animation: td-fire .3s ease; }
.td-cell-placed { animation: mg-pop .4s cubic-bezier(.2, 1.4, .4, 1); }

.td-enemy-layer { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.td-enemy {
  position: absolute;
  width: calc(100% / var(--cols));
  height: calc(100% / var(--rows));
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: left .1s linear;
}
.td-enemy-face { font-size: 1.7rem; line-height: 1; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .4)); }
.td-boss .td-enemy-face { font-size: 2.2rem; }
.td-enemy-hp { width: 70%; height: 6px; border-radius: 3px; background: rgba(0, 0, 0, .55); overflow: hidden; }
.td-enemy-hp i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ff5d6c, #ffb03a); transition: width .15s ease; }
.td-boss .td-enemy-hp { width: 90%; height: 8px; }
.td-enemy.hit .td-enemy-face { animation: td-hit .25s ease; }
.td-enemy.defeated { animation: td-pop-out .35s ease forwards; }
.td-float {
  position: absolute;
  transform: translateX(-50%);
  color: #fff;
  font: .9rem var(--font-display);
  text-shadow: 0 2px 0 #000;
  animation: td-float .7s ease-out forwards;
}
.td-shot {
  position: absolute;
  width: 12px; height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: #fff6a8;
  box-shadow: 0 0 10px 3px #ffe066;
  transition: left .22s linear, top .22s linear;
}
.td-shot-fire { background: #ffb36b; box-shadow: 0 0 10px 3px #ff6b35; }
.td-shot-water { background: #a8e6ff; box-shadow: 0 0 10px 3px #00b4d8; }
.td-shot-earth { background: #d6f5a8; box-shadow: 0 0 10px 3px #8cb369; }
.td-shot-cloud { background: #eef0ff; box-shadow: 0 0 10px 3px #b8c0ff; }
.td-shot-dragon, .td-shot-dino { background: #f0c8ff; box-shadow: 0 0 10px 3px #9b4ace; }
.td-shot-crystal { background: #c9f6ff; box-shadow: 0 0 10px 3px #5ad1e6; }
.td-toast {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  padding: 10px 18px;
  border-radius: 14px;
  background: var(--surface-2);
  color: #fff;
  font: 1.15rem var(--font-display);
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  animation: mg-pop .3s cubic-bezier(.2, 1.4, .4, 1);
  pointer-events: none;
}
.td-toast.good { background: var(--brand); color: var(--brand-ink); }

.td-quiz-dock {
  padding: 12px;
  border-radius: 18px;
  background: linear-gradient(160deg, #4a3a10, #2e2610);
  border: 3px solid #ffd166;
  box-shadow: 0 0 0 4px rgba(255, 209, 102, .18), 0 10px 24px rgba(0, 0, 0, .35);
}
.td-quiz-in { animation: td-quiz-in .4s cubic-bezier(.2, 1.4, .4, 1); }
.td-quiz-head { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; }
.td-quiz-prompt { font: 1.25rem var(--font-display); color: #ffd166; animation: mg-bounce 1s ease-in-out infinite; }
.td-quiz-sub { font-size: .8rem; color: #f5e3b0; font-weight: 700; }
.td-quiz-q { margin: 10px 0; text-align: center; font: 1.1rem/1.35 var(--font-display); color: #fff; }
.td-quiz-answers { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.td-quiz-answers .btn { min-width: 0; }
.td-quiz-result { margin-top: 10px; text-align: center; font-weight: 800; }
.td-correct { color: #8ff0c4; }
.td-wrong { color: #ffb3bd; }

.td-dock { display: grid; gap: 10px; }
.td-picker { padding: 10px 12px; border-radius: 16px; background: var(--surface); border: 2px solid var(--border); }
.td-pick-label { font-size: .75rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 8px; }
.td-pick-list { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.td-pick-btn {
  flex: 0 0 auto;
  width: 84px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px 8px;
  border-radius: 14px;
  border: 3px solid var(--border);
  background: var(--surface-2);
  color: #fff;
  font: inherit;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease;
}
.td-pick-btn:hover { transform: translateY(-2px); border-color: #a5cf7f; }
.td-pick-btn.td-pick-selected { border-color: var(--brand); background: #2f4a44; box-shadow: 0 0 0 3px rgba(202, 238, 147, .3); }
.td-pick-sprite { width: 60px; height: 60px; transform: scale(.7); margin: -8px 0 -10px; display: grid; place-items: end center; }
.td-pick-name { font-weight: 800; font-size: .74rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-pick-atk { font-size: .7rem; color: #ffd166; font-weight: 800; }
.td-no-towers { font-size: .88rem; color: #bff5d9; font-weight: 700; }
.td-start { width: 100%; font-size: 1.15rem !important; }
.td-start:not(:disabled) { animation: td-glow-btn 1.6s ease-in-out infinite; }

/* ===== Trading Post ===== */
.trade-header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.trade-chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 2px solid var(--border);
  font-weight: 800;
  font-size: .9rem;
}
.trade-chip strong { font-family: var(--font-display); }
.trade-refresh {
  margin-left: auto;
  padding: 9px 14px !important;
  font-size: .9rem !important;
  background: var(--surface-2);
  border: 2px solid var(--border) !important;
}
.trade-success {
  padding: 12px 14px;
  border-radius: 14px;
  background: #1f5140;
  border: 2px solid var(--good);
  color: #d4fbe7;
  font-weight: 800;
  text-align: center;
  animation: mg-pop .35s cubic-bezier(.2, 1.4, .4, 1);
}
.trade-offers { display: grid; gap: 14px; }
.trade-empty { text-align: center; color: var(--text-secondary); padding: 30px; }
.trade-card {
  --trader: #8b6cf0;
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px;
  border-radius: 22px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-top: 6px solid var(--trader);
}
.trade-card-header { display: flex; align-items: center; gap: 12px; }
.trade-avatar {
  flex: 0 0 56px; height: 56px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--trader) 35%, #1a2638);
  border: 3px solid var(--trader);
  font-size: 1.9rem;
}
.trade-trader-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.trade-trader-name { font: 1.15rem var(--font-display); display: flex; align-items: center; gap: 8px; }
.trade-trader-name .type-badge { font-family: var(--font-body); font-size: .62rem; padding: 2px 8px; }
.trade-quote {
  position: relative;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--surface-2);
  color: #d5e0ea;
  font-size: .85rem;
  font-style: italic;
}
.trade-offer-list { display: grid; gap: 10px; }
.trade-offer {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px;
  border-radius: 16px;
  background: #18233a;
  border: 2px solid #2c3b53;
}
.trade-offer.done { opacity: .75; }
.trade-deal { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 6px; }
.trade-side {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-height: 132px;
  padding: 8px 6px;
  border-radius: 14px;
  text-align: center;
  justify-content: center;
}
.trade-give { background: rgba(255, 93, 108, .12); border: 2px dashed rgba(255, 93, 108, .45); }
.trade-get { background: rgba(54, 211, 153, .12); border: 2px solid rgba(54, 211, 153, .5); }
.trade-side-label { font-size: .66rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--text-secondary); }
.trade-side-name { font-size: .92rem; line-height: 1.2; }
.trade-side-note { font-size: .7rem; color: var(--text-secondary); }
.trade-big-icon { font-size: 2.4rem; line-height: 60px; }
.trade-sprite { width: 60px; height: 60px; margin-top: 16px; display: grid; place-items: end center; }
.trade-badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.trade-badges .rarity-badge, .trade-badges .type-badge { font-size: .6rem; padding: 2px 7px; }
.trade-arrow { font-size: 1.5rem; color: var(--brand); animation: trade-nudge 1.4s ease-in-out infinite; }
.trade-btn { width: 100%; }
.trade-reason { text-align: center; font-weight: 800; font-size: .85rem; color: #ffb3bd; }
.trade-done-stamp { text-align: center; font: 1.1rem var(--font-display); color: var(--good); }

.trade-overlay-wrap {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(8, 12, 20, .78);
  backdrop-filter: blur(4px);
  animation: mg-fade .2s ease;
}
.trade-picker-overlay {
  width: min(100%, 460px);
  max-height: 86vh;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
  padding: 20px;
  border-radius: 24px;
  background: linear-gradient(160deg, #26394f, #1a2638);
  border: 2px solid #48756b;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
  animation: mg-pop .28s cubic-bezier(.2, 1.4, .4, 1);
}
.trade-picker-overlay h3 { font-size: 1.3rem; text-align: center; }
.trade-picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; }
.trade-picker-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 6px;
  border-radius: 16px;
  border: 3px solid var(--border);
  background: var(--surface-2);
  color: #fff;
  font: inherit;
  font-size: .82rem;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease;
}
.trade-picker-card:hover { transform: translateY(-2px); border-color: var(--brand); }
.trade-partner-tag {
  position: absolute; top: -9px; left: 50%; transform: translateX(-50%);
  padding: 1px 8px;
  border-radius: 999px;
  background: #ffd166;
  color: #3a2500;
  font-size: .64rem;
  font-weight: 800;
  white-space: nowrap;
}
.trade-gem-reward { color: #ffd166; font-weight: 800; }
.trade-picker-cancel { width: 100%; margin-top: 0; }
.trade-warnings { list-style: none; display: grid; gap: 6px; }
.trade-warnings li { padding: 9px 12px; border-radius: 12px; background: #3b3313; color: #ffe08a; font-size: .88rem; line-height: 1.4; }
.trade-confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.trade-confirm-actions .btn { margin-top: 0; padding: 13px 10px; }
.trade-yes-danger { background: #ffb03a !important; color: #3a2500 !important; }

/* ===== Animations ===== */
@keyframes mg-pop { from { transform: scale(.7); opacity: 0; } }
@keyframes mg-fade { from { opacity: 0; } }
@keyframes mg-bounce { 50% { transform: translateY(-6px); } }
@keyframes mg-wobble { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
@keyframes mg-nudge { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-3px); } }
@keyframes mg-confetti { from { transform: translateY(0) rotate(0); } to { transform: translateY(520px) rotate(720deg); } }
@keyframes ctf-hop { 40% { transform: scale(.78) translateY(-18px); } }
@keyframes ctf-wave { 50% { transform: scaleX(.8) skewY(6deg); } }
@keyframes td-spin { to { transform: rotate(360deg); } }
@keyframes td-shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
@keyframes td-flash { from { opacity: 1; } to { opacity: 0; } }
@keyframes td-glow { 50% { opacity: .55; } }
@keyframes td-glow-btn { 50% { box-shadow: 0 5px 0 rgba(0, 0, 0, .35), 0 0 0 6px rgba(202, 238, 147, .35); } }
@keyframes td-fire { 50% { translate: 0 -4px; scale: 1.15; } }
@keyframes td-hit { 50% { transform: scale(.8) rotate(-10deg); filter: brightness(2); } }
@keyframes td-pop-out { to { transform: scale(1.6); opacity: 0; } }
@keyframes td-float { from { transform: translate(-50%, 0); opacity: 1; } to { transform: translate(-50%, -26px); opacity: 0; } }
@keyframes td-quiz-in { from { transform: translateY(16px) scale(.96); opacity: 0; } }
@keyframes trade-nudge { 50% { transform: translateX(4px); } }

@media (prefers-reduced-motion: reduce) {
  .mg-no-monster-egg, .mg-empty-icon, .mg-result-icon, .mg-confetti, .ctf-cloth,
  .ctf-runner.captured .ctf-runner-sprite, .td-portal span, .td-start, .td-quiz-prompt,
  .trade-arrow, .td-grid.placing .td-cell-valid::before { animation: none !important; }
  .mg-confetti { display: none; }
  .ctf-runner { transition: none; }
  .ctf-runner.hop .ctf-runner-sprite { animation: none; }
  .td-shot { display: none; }
  .mg-card, .td-diff-btn, .trade-picker-card, .td-pick-btn { transition: none; }
}

/* Very small phones */
@media (max-width: 380px) {
  .ctf-answers, .td-quiz-answers { grid-template-columns: 1fr; }
  .ctf-lane { grid-template-columns: 1fr; }
  .ctf-lane-label { justify-self: start; padding: 2px 10px; }
  .trade-side { min-height: 118px; }
}

/* Desktop: more room for the board and trader cards */
@media (min-width: 900px) {
  #screen-minigames, #screen-ctf, #screen-tower-defense, #screen-trading { padding: 28px 40px 48px; }
  .mg-page { max-width: 880px; gap: 18px; }
  .minigames-grid { grid-template-columns: repeat(3, 1fr); }
  .mg-card { grid-template-columns: 1fr; grid-template-areas: "icon" "info" "play"; align-content: start; padding: 24px; }
  .mg-card-icon { width: 84px; height: 84px; font-size: 2.8rem; }
  .mg-card-play { align-self: end; }
  .mg-no-monster { grid-template-columns: auto 1fr auto; }
  .mg-no-monster .btn { grid-column: auto; width: auto; }
  .ctf-lane-track { height: 88px; --runner: 68px; }
  .ctf-runner { height: 68px; }
  .ctf-runner-sprite { transform: scale(1); }
  .ctf-answers .btn, .td-quiz-answers .btn { min-height: 72px; }
  .td-difficulty { grid-template-columns: repeat(3, 1fr); }
  .td-how { grid-template-columns: 1fr 1fr; }
  .td-board { grid-template-columns: 56px 1fr 60px; gap: 8px; }
  .td-end span { font-size: 2.2rem; }
  .td-tower { transform: scale(.95); }
  .td-tower-tag { font-size: .7rem; }
  .td-enemy-face { font-size: 2.6rem; }
  .td-boss .td-enemy-face { font-size: 3.2rem; }
  .td-dock { grid-template-columns: 1fr 260px; align-items: stretch; }
  .td-start { height: 100%; }
  .trade-offers { grid-template-columns: repeat(2, 1fr); align-items: start; }
}
