/* Self-hosted (SIL Open Font License), latin subset. */
@font-face {
  font-family: "Nunito";
  font-weight: 600 900;
  font-display: swap;
  src: url(fonts/nunito.woff2) format("woff2");
}
@font-face {
  font-family: "Press Start 2P";
  font-display: swap;
  src: url(fonts/press-start-2p.woff2) format("woff2");
}

:root {
  --bg: #f6f1e4;
  --dot: #e7dfcb;
  --ink: #262626;
  --muted: #6b6457;
  --card: #fffdf8;
  --red: #e3350d;
  --red-dark: #a8260a;
  --line: #262626;
  --radius: 14px;

  --normal: #a8a77a;
  --fire: #ee8130;
  --water: #6390f0;
  --electric: #f7d02c;
  --grass: #7ac74c;
  --ice: #96d9d6;
  --fighting: #c22e28;
  --poison: #a33ea1;
  --ground: #e2bf65;
  --flying: #a98ff3;
  --psychic: #f95587;
  --bug: #a6b91a;
  --rock: #b6a136;
  --ghost: #735797;
  --dragon: #6f35fc;
  --dark: #705746;
  --steel: #b7b7ce;
  --fairy: #d685ad;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1b18;
    --dot: #2a2722;
    --ink: #f3eee3;
    --muted: #a59e90;
    --card: #2b2824;
    --line: #0d0c0b;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Nunito", system-ui, sans-serif;
  font-weight: 600;
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1.5px, transparent 1.5px);
  background-size: 18px 18px;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ---------- header & tabs ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--red);
  border-bottom: 4px solid var(--line);
  box-shadow: inset 0 -6px 0 var(--red-dark);
}

.logo {
  margin: 0;
  font-family: "Press Start 2P", monospace;
  font-size: clamp(15px, 4.6vw, 26px);
  line-height: 1.35;
  white-space: nowrap;
  text-align: center;
  color: #fff;
  text-shadow: 3px 3px 0 var(--line);
  letter-spacing: 1px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid var(--line);
  background: #fff;
  color: #262626;
  font-weight: 900;
  font-size: 18px;
  box-shadow: 0 3px 0 var(--line);
}
.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--line);
}

.tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 12px 12px 0;
}
.tabs button {
  padding: 8px 14px;
  border: 3px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-weight: 800;
  box-shadow: 0 3px 0 var(--line);
}
.tabs button[aria-selected="true"] {
  background: var(--ink);
  color: var(--bg);
}

/* ---------- ad placeholders ---------- */

.ad-slot {
  max-width: 728px;
  margin: 12px auto;
  border: 2px dashed var(--muted);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  opacity: 0.6;
}
.ad-top {
  height: 50px;
  line-height: 46px;
  width: calc(100% - 24px);
}
.ad-bottom {
  width: 300px;
  height: 250px;
  line-height: 246px;
}
@media (min-width: 760px) {
  .ad-top {
    height: 90px;
    line-height: 86px;
  }
}

/* ---------- layout ---------- */

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 12px;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.puzzle-title {
  margin: 8px 0;
  font-size: 22px;
  font-weight: 900;
}
.puzzle-title small {
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
  margin-left: 4px;
}

.segmented {
  display: inline-flex;
  border: 3px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: 0 3px 0 var(--line);
}
.segmented button {
  border: 0;
  padding: 6px 14px;
  background: var(--card);
  font-weight: 800;
}
.segmented button[aria-checked="true"] {
  background: var(--red);
  color: #fff;
}

.meta {
  display: flex;
  gap: 16px;
  align-items: center;
  color: var(--muted);
  margin: 4px 0 12px;
}
.meta b {
  color: var(--ink);
}

.balls {
  display: inline-flex;
  gap: 6px;
}
.ball {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: linear-gradient(var(--red) 0 44%, var(--line) 44% 56%, #fff 56%);
  position: relative;
}
.ball::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--line);
}
.ball.spent {
  filter: grayscale(1);
  opacity: 0.35;
}

/* ---------- cards ---------- */

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 112px;
  padding: 0 6px 8px;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 4px 0 var(--line);
  overflow: hidden;
}
.card img {
  width: 80px;
  height: 80px;
  image-rendering: pixelated;
  margin-top: 4px;
}
.card .name {
  font-size: 13px;
  font-weight: 900;
  line-height: 1.1;
  min-height: 2.2em;
  display: flex;
  align-items: center;
  text-align: center;
}
.card .pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 3px;
  margin-top: 4px;
  max-width: 100%;
}

/* The ribbon across the top of a chain card names the link to the previous card. */
.ribbon {
  display: block;
  width: calc(100% + 12px);
  padding: 3px 4px;
  border-bottom: 3px solid var(--line);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
}
.ribbon i {
  font-style: normal;
  opacity: 0.8;
}
.ribbon-blind {
  background: var(--muted);
  color: #fff;
  text-shadow: none;
}
.ribbon-start {
  background: var(--ink);
  color: var(--bg);
  font-family: "Press Start 2P", monospace;
  font-size: 8px;
  padding: 5px 4px;
  text-shadow: none;
}

.chip-trait {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 5px;
  border: 2px solid var(--line);
  font-size: 9px;
  font-weight: 900;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
}

.kind-gen { background: #5b6b7f; }
.kind-family { background: #3b82c4; }
.kind-mega { background: linear-gradient(135deg, #6d28d9, #db2777); }
.kind-gmax { background: linear-gradient(135deg, #e11d48, #f97316); }
.kind-legend { background: linear-gradient(135deg, #b8860b, #f5c518); }
.kind-regional { background: #0f9488; }
.kind-starter { background: #16a34a; }
.kind-baby { background: #f472b6; }
.kind-step { background: linear-gradient(90deg, #5b6b7f, #2f3b4a); }

.chip-trait.chip-big {
  font-size: 12px;
  padding: 2px 10px;
}

.toggles {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.stats-toggle {
  display: flex;
  justify-content: center;
  margin: 8px 0;
}

.pill {
  display: inline-block;
  min-width: 38px;
  padding: 2px 4px;
  border-radius: 999px;
  border: 2px solid var(--line);
  font-size: 9px;
  letter-spacing: -0.2px;
  font-weight: 900;
  text-transform: uppercase;
  text-align: center;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
}
.pill-hidden {
  background: var(--muted);
}

.badge-undo {
  position: absolute;
  top: 26px;
  right: 6px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--bg);
  font-size: 12px;
}

.chain {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
  padding: 14px 8px;
  border: 3px dashed var(--muted);
  border-radius: 20px;
  min-height: 180px;
}

.chain-card[disabled] {
  cursor: default;
  color: inherit;
}
.chain-card.anchor {
  outline: 3px solid var(--electric);
  outline-offset: 2px;
}
.chain-card.undoable:hover {
  transform: translateY(-2px);
}

.slot {
  min-height: 166px;
  justify-content: center;
  gap: 6px;
  border-style: dashed;
  box-shadow: none;
  background: transparent;
}
.slot-q {
  font-family: "Press Start 2P", monospace;
  font-size: 28px;
  color: var(--muted);
}
.slot-label {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}
.slot-label b {
  color: var(--ink);
}

.instructions {
  text-align: center;
  margin: 16px 0 10px;
  color: var(--muted);
}

.tray {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 12px;
  justify-items: center;
}
.tray-card {
  transition: transform 0.08s;
}
.tray-card:hover {
  transform: translateY(-3px);
}
.tray-card:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--line);
}

.actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0;
}

.btn {
  padding: 10px 18px;
  border: 3px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-weight: 900;
  box-shadow: 0 4px 0 var(--line);
}
.btn:active:not([disabled]) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--line);
}
.btn[disabled] {
  opacity: 0.45;
  cursor: default;
}
.btn-primary {
  background: var(--red);
  color: #fff;
}

/* ---------- type colours ---------- */

.type-normal { background: var(--normal); }
.type-fire { background: var(--fire); }
.type-water { background: var(--water); }
.type-electric { background: var(--electric); }
.type-grass { background: var(--grass); }
.type-ice { background: var(--ice); }
.type-fighting { background: var(--fighting); }
.type-poison { background: var(--poison); }
.type-ground { background: var(--ground); }
.type-flying { background: var(--flying); }
.type-psychic { background: var(--psychic); }
.type-bug { background: var(--bug); }
.type-rock { background: var(--rock); }
.type-ghost { background: var(--ghost); }
.type-dragon { background: var(--dragon); }
.type-dark { background: var(--dark); }
.type-steel { background: var(--steel); }
.type-fairy { background: var(--fairy); }

.type-text-normal { color: var(--normal); }
.type-text-fire { color: var(--fire); }
.type-text-water { color: var(--water); }
.type-text-electric { color: #c9a400; }
.type-text-grass { color: #4f9a2b; }
.type-text-ice { color: #3aa9a4; }
.type-text-fighting { color: var(--fighting); }
.type-text-poison { color: var(--poison); }
.type-text-ground { color: #b8912a; }
.type-text-flying { color: var(--flying); }
.type-text-psychic { color: var(--psychic); }
.type-text-bug { color: #869612; }
.type-text-rock { color: var(--rock); }
.type-text-ghost { color: var(--ghost); }
.type-text-dragon { color: var(--dragon); }
.type-text-dark { color: var(--dark); }
.type-text-steel { color: #8a8aa8; }
.type-text-fairy { color: var(--fairy); }

/* ---------- archive ---------- */

.archive {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
  display: grid;
  gap: 8px;
}
.archive-row {
  display: grid;
  grid-template-columns: 48px 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 3px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 3px 0 var(--line);
}
.archive-num {
  font-family: "Press Start 2P", monospace;
  font-size: 11px;
}
.archive-date em {
  font-style: normal;
  font-size: 11px;
  background: var(--red);
  color: #fff;
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 4px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-weight: 800;
  font-size: 13px;
}
.status {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
}
.status-won { background: var(--grass); color: #fff; }
.status-lost { background: var(--fighting); color: #fff; }
.status-none { color: var(--muted); }

/* ---------- modal ---------- */

dialog {
  width: min(460px, calc(100% - 24px));
  padding: 20px;
  border: 4px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 8px 0 var(--line);
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
}
.modal-close button {
  border: 0;
  background: none;
  font-size: 18px;
}
.modal-title {
  margin: 0 0 4px;
  font-family: "Press Start 2P", monospace;
  font-size: 15px;
  line-height: 1.5;
}
.modal-sub {
  margin: 0 0 14px;
  color: var(--muted);
}
.stats-h {
  margin: 16px 0 6px;
}
.stat-row {
  display: flex;
  justify-content: space-around;
  gap: 8px;
  margin: 10px 0;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.stat b {
  font-size: 22px;
  font-weight: 900;
}
.stat span {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
}
.share-preview {
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px;
  font-size: 13px;
}
.help-chain {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 6px;
  margin: 12px 0;
}
.card.mini {
  width: 92px;
}
.card.mini img {
  width: 56px;
  height: 56px;
}
.card.mini .ribbon {
  font-size: 7px;
  padding: 4px 2px;
  letter-spacing: -0.2px;
}
.card.mini .ribbon i {
  display: none;
}
.help-kinds {
  line-height: 2;
}
.links-detail {
  margin: 8px 0;
  font-size: 14px;
}
.links-detail summary {
  cursor: pointer;
  font-weight: 800;
}
.links-detail ul {
  padding-left: 18px;
  margin: 6px 0 0;
  line-height: 1.5;
}
.help-list {
  padding-left: 18px;
  line-height: 1.5;
}

/* ---------- toast & motion ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  border: 3px solid var(--line);
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s;
  z-index: 10;
}
#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.shake {
  animation: shake 0.35s;
}
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.chain .chain-card:last-of-type:not(.anchor) {
  animation: pop 0.2s ease-out;
}
@keyframes pop {
  from { transform: scale(0.85); }
}

.hop {
  animation: hop 0.5s ease-out both !important;
}
@keyframes hop {
  40% { transform: translateY(-14px); }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 420px) {
  .card {
    width: 108px;
    padding: 0 4px 8px;
  }
  .ribbon {
    width: calc(100% + 8px);
    font-size: 9px;
  }
  .pill {
    min-width: 0;
    font-size: 8.5px;
  }
  .chip-trait {
    font-size: 8px;
    padding: 1px 3px;
  }
  .chain {
    gap: 8px;
    padding: 12px 4px;
  }
  .card.mini {
    width: 76px;
  }
  .card img {
    width: 68px;
    height: 68px;
  }
  .tray {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }
}

.footer {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}
.footer a {
  color: inherit;
}

/* ---------- privacy page ---------- */

.prose {
  max-width: 640px;
  line-height: 1.6;
}
.prose a:not(.btn) {
  color: inherit;
}
.prose .btn {
  display: inline-block;
  text-decoration: none;
  margin-top: 8px;
}
.back-btn {
  display: grid;
  place-items: center;
  text-decoration: none;
}
.spacer {
  visibility: hidden;
}
