:root {
  --pair1: #e08a1e;
  --pair2: #3b7fc4;
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #23222a;
  --muted: #6b6977;
  --line: #e2e0da;
  --body: #2a9d8f;
  --target: #7b5ea7;
  --ghost: #d9d4e6;
  --remove: #d1495b;
  --pick: #e9a23b;
  --good: #3a7d44;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

h1 { font-size: 20px; margin: 0; letter-spacing: 0.02em; }
h2 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }

.stats { display: flex; gap: 20px; color: var(--muted); font-size: 14px; flex: 1; }
.player { color: var(--muted); font-size: 13px; }
.stats b { color: var(--ink); font-variant-numeric: tabular-nums; }

main { display: flex; gap: 20px; padding: 20px 24px; align-items: flex-start; }

aside {
  width: 300px;
  flex: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  position: sticky;
  top: 20px;
}

#target { display: block; margin: 0 auto 6px; background: #faf9fc; border-radius: 8px; }
.caption { font-size: 12px; color: var(--muted); line-height: 1.4; margin: 0 0 12px; }

.notice {
  font-size: 13px; line-height: 1.4; margin: 0 0 12px; padding: 8px 10px;
  background: #f3eefb; border-left: 3px solid var(--target); border-radius: 6px;
}

.hint { font-size: 14px; line-height: 1.4; min-height: 40px; margin: 0 0 10px; }

.pairs { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.pairs:empty { display: none; }
.pair {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px;
  font-size: 13px; color: var(--muted);
}
.pair canvas { background: #fafafa; border-radius: 4px; }
.pair .swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.pair .x { margin-left: auto; cursor: pointer; border: none; background: none; color: var(--muted); font-size: 16px; padding: 0 4px; }
.pair.empty { border-style: dashed; justify-content: center; height: 46px; }

.actions { display: flex; gap: 8px; margin-bottom: 12px; }

button {
  font: inherit; font-size: 14px; font-weight: 600;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--ink);
  background: var(--ink); color: white; cursor: pointer;
}
button:disabled { opacity: 0.35; cursor: default; }
button.secondary { background: white; color: var(--ink); }
/* Set apart from My games and New game, so testers notice it without being told (B1). */
.feedback-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--target); border-color: var(--target);
}
button.link {
  background: none; border: none; color: var(--target); padding: 8px;
  font-weight: 600; text-decoration: underline;
}

.toggle { font-size: 13px; color: var(--muted); display: block; margin-bottom: 10px; }
.toggle select { font: inherit; font-size: 13px; margin-left: 4px; }
.help { font-size: 13px; color: var(--muted); line-height: 1.45; }
.help summary { cursor: pointer; }

section { flex: 1; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }

.card {
  position: relative;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.1s, opacity 0.1s;
}
.card canvas { display: block; max-width: 100%; }
.card:hover { border-color: #bdb9b0; }
.card.picked { border-color: var(--ink); border-style: dashed; }
.card.pair1 { border-color: var(--pair1); }
.card.pair2 { border-color: var(--pair2); }
.card.pair1.pair2 { border-color: var(--pair1) var(--pair2) var(--pair2) var(--pair1); }
.card.marked { border-color: var(--remove); opacity: 0.45; }
.card.winner { border-color: var(--good); box-shadow: 0 0 0 3px #3a7d4433; }
.card.inactive { cursor: default; }

.card .badges { position: absolute; top: 6px; left: 6px; display: flex; gap: 3px; }
.card .badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0.05em;
  background: var(--pick); color: white; border-radius: 4px; padding: 1px 5px;
  border: 1.5px solid transparent;
}
.card .badge.child1 { background: var(--pair1); }
.card .badge.child2 { background: var(--pair2); }
.card .badge.parent1 { background: white; color: var(--pair1); border-color: var(--pair1); }
.card .badge.parent2 { background: white; color: var(--pair2); border-color: var(--pair2); }
.card.litter1 { box-shadow: inset 4px 0 0 var(--pair1); }
.card.litter2 { box-shadow: inset 4px 0 0 var(--pair2); }
.card .mark {
  position: absolute; top: 4px; right: 8px;
  color: var(--remove); font-weight: 800; font-size: 18px;
}

.meter { display: flex; align-items: center; gap: 6px; font-size: 13px; font-variant-numeric: tabular-nums; }
.meter .bar { flex: 1; height: 6px; background: #eeece6; border-radius: 3px; position: relative; overflow: hidden; }
.meter .fill { position: absolute; inset: 0 auto 0 0; background: var(--body); }
.meter .line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); opacity: 0.5; }

/* Stacking: cards (positioned) < the phone's pinned moves bar (10) < dialogs (20) < toast (30)
   < the update banner (40), which must show even over a dialog. */
.end {
  position: fixed; inset: 0; z-index: 20; background: #23222a88;
  display: flex; align-items: center; justify-content: center;
}
.end-card {
  background: var(--panel); border-radius: 14px; padding: 24px 28px; text-align: center;
  max-width: 360px;
}
.end-card h2 { font-size: 22px; color: var(--ink); }
.end-card canvas { display: block; margin: 8px auto; background: #faf9fc; border-radius: 8px; }
.end-card .actions { justify-content: center; flex-wrap: wrap; }
.end-card .legend { font-size: 12px; color: var(--muted); }

.hidden { display: none; }

.toast {
  position: fixed; z-index: 30; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--remove); color: white; padding: 10px 16px; border-radius: 8px; font-size: 14px;
}

.newcomers { margin-bottom: 12px; }
.seg-label { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.muted { color: var(--muted); font-weight: 400; }
.seg { display: flex; gap: 0; margin-bottom: 6px; }
.seg button {
  flex: 1; border-radius: 0; background: white; color: var(--ink); border-color: var(--line);
  padding: 6px 0;
}
.seg button:first-child { border-radius: 8px 0 0 8px; }
.seg button:last-child { border-radius: 0 8px 8px 0; }
.seg button.on { background: var(--ink); color: white; border-color: var(--ink); }
.card .badge.wild { background: var(--good); }
.card .badge.wild-old { background: white; color: var(--good); border-color: var(--good); }

.games-card { max-width: 480px; width: calc(100% - 32px); text-align: left; }
.games-list { display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow-y: auto; margin: 12px 0; }
.game-row {
  display: flex; align-items: center; gap: 12px; text-align: left; font-weight: 400;
  border-color: var(--line); padding: 6px 10px; min-height: 44px;
}
.game-row.current { border-color: var(--ink); }
/* margin: 0 overrides .end-card canvas, whose auto margins would center the thumbnail. */
.game-row canvas { flex: none; margin: 0; background: #faf9fc; border-radius: 6px; }
.game-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.game-text b { font-weight: 600; font-size: 14px; }
.game-text span { color: var(--muted); }

.feedback-card { max-width: 440px; width: calc(100% - 32px); text-align: left; }
.feedback-card textarea {
  display: block; width: 100%; margin: 4px 0 12px; padding: 8px 10px; resize: vertical;
  font: inherit; font-size: 14px; border: 1px solid var(--line); border-radius: 8px;
}
.toast.ok { background: var(--good); }

.update {
  /* Centered with auto margins, not left: 50%, which would leave it half the
     screen to wrap in on a phone. */
  position: fixed; z-index: 40; top: 12px; left: 0; right: 0; margin: 0 auto;
  width: fit-content; max-width: calc(100% - 24px);
  display: flex; align-items: center; gap: 12px;
  padding: 8px 8px 8px 14px; border-radius: 10px; font-size: 14px;
  background: var(--ink); color: white; box-shadow: 0 4px 16px #23222a44;
}
.update button { background: white; color: var(--ink); border-color: white; flex: none; }
.update.hidden { display: none; }

.invite-card { max-width: 420px; width: calc(100% - 32px); text-align: left; }
.invite-card h3 { font-size: 15px; margin: 16px 0 8px; }
.invite-card label { display: block; font-size: 13px; font-weight: 600; margin: 8px 0 4px; }
.invite-card input {
  display: block; width: 100%; padding: 8px 10px; min-height: 40px;
  font: inherit; font-size: 16px; border: 1px solid var(--line); border-radius: 8px;
}
.invite-card .caption { margin: 4px 0 0; }
.invite-card .actions { margin: 14px 0 0; justify-content: flex-start; }
/* Off-screen rather than display: none, which some bots skip. */
.trap { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* Phones (4.4): one column, a header that wraps instead of scrolling sideways,
   Breed / Next generation pinned to the bottom so they're in reach from the
   grid, and touch targets of at least 44 px. */
@media (max-width: 720px) {
  header { flex-wrap: wrap; gap: 8px 12px; padding: 10px 12px; }
  h1 { flex: 1; }
  .player { order: 1; }
  .stats { order: 2; flex-basis: 100%; gap: 14px; font-size: 13px; }
  .stats span { white-space: nowrap; }
  header button { order: 3; flex: 1; padding: 8px 6px; white-space: nowrap; }
  button { min-height: 44px; }

  main { flex-direction: column; align-items: stretch; gap: 12px; padding: 12px 12px 84px; }
  aside { width: auto; position: static; }
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }

  #moves {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; margin: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: var(--panel); border-top: 1px solid var(--line);
  }
  #moves button { flex: 1; }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); max-width: calc(100% - 24px); }

  .pair .x { min-width: 44px; min-height: 44px; }
  .seg button { min-height: 44px; }
  .toggle select { min-height: 44px; }
  .help summary { padding: 12px 0; min-height: 44px; }
  /* 16 px or more, or iOS zooms the page in when the box is focused. */
  .toggle select, .feedback-card textarea { font-size: 16px; }
  .end-card { padding: 20px; max-width: calc(100% - 24px); }
}

/* No hover on a touch screen, so don't tell people to hover. */
@media (hover: none) {
  #hover-help { display: none; }
}
