/* Baloo 2 is self-hosted so the game works offline (SIL Open Font License) */
@font-face {
  font-family: 'Baloo 2';
  font-weight: 400 800;
  font-display: swap;
  src: url(../fonts/baloo2.woff2) format('woff2');
}

:root {
  --ink: #1f1c18;
  --paper: #fffdf6;
  --green: #3d7a4a;
  /* One colour per group (up to 12) */
  --g0: #d6452b; --g1: #2f6db5; --g2: #2f8a3e; --g3: #8a4bc4;
  --g4: #c26a0c; --g5: #c2367a; --g6: #14857f; --g7: #6b5a3a;
  --g8: #4a5bd6; --g9: #9a2f2f; --g10: #5c7d18; --g11: #7a4f9e;
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #86b04e; }
button, select, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- The field ---------- */
#field { position: fixed; inset: 0; }
#field canvas { display: block; width: 100%; height: 100%; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.in-setup #labels { visibility: hidden; }

/* Name tag over a sheep's head; stage.js sets translate */
.tag {
  position: absolute; left: 0; top: 0;
  transform: translate(-50%, -100%);
  padding: 0 0.5em;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 4px;
  font-size: clamp(11px, 1vw, 20px); font-weight: 700; line-height: 1.35;
  white-space: nowrap;
}
.tag.picked { background: var(--group); border-color: var(--group); color: #fff; }

/* The card above each pen; names are added as sheep go in */
.pen-card {
  position: absolute; left: 0; top: 0;
  transform: translateY(-100%);
  padding-bottom: 6px;
}
.pen-card.below { transform: none; padding: 6px 0 0; }
.pen-card h3 {
  margin: 0;
  padding: 0 0.4em;
  background: var(--group); color: #fff;
  font-size: clamp(13px, 1.3vw, 24px); line-height: 1.5;
  text-align: center; white-space: nowrap;
}
.pen-card ol {
  margin: 0; padding: 0.2em 0.4em;
  list-style: none;
  background: rgba(255, 253, 246, 0.92);
  border: 2px solid var(--group); border-top: 0;
  column-width: 7em; column-gap: 0.6em;
  font-size: clamp(12px, 1.1vw, 20px); font-weight: 600; line-height: 1.3;
}
.pen-card ol:empty { display: none; }
.pen-card li { break-inside: avoid; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; animation: pop 0.35s; }
@keyframes pop { from { background: var(--group); color: #fff; } }

/* ---------- Toolbar ---------- */
#toolbar {
  position: fixed; left: 12px; bottom: 12px;
  display: flex; gap: 8px;
}
.in-setup #toolbar { display: none; }
#toolbar button, .buttons button, .names-foot button {
  min-height: 44px; padding: 0 14px;
  background: var(--paper); border: 2px solid var(--ink); border-radius: 6px;
  font-weight: 700; cursor: pointer;
}
#toolbar button { display: inline-flex; align-items: center; gap: 6px; }
#toolbar button:hover, .buttons button:hover, .names-foot button:hover { background: #fff3c4; }

/* ---------- Setup and results panels ---------- */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(30, 40, 24, 0.35);
  overflow: auto;
}
.panel {
  width: min(560px, 100%);
  max-height: 100%; overflow: auto;
  padding: 24px 28px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 8px;
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.25);
}
.panel.wide { width: min(1200px, 100%); }
.panel h1, .panel h2 { margin: 0; font-size: 2.4rem; line-height: 1.1; }
.lede { margin: 6px 0 18px; font-size: 1.1rem; color: #4a4540; }
.panel label { display: block; font-weight: 700; }
textarea {
  display: block; width: 100%; margin-top: 4px;
  padding: 8px 10px;
  border: 2px solid var(--ink); border-radius: 6px;
  font-size: 1.05rem; line-height: 1.35; resize: vertical;
}
.names-foot { display: flex; align-items: center; gap: 8px; margin: 8px 0 16px; }
.names-foot span { margin-right: auto; color: #4a4540; }
.names-foot button { min-height: 36px; font-size: 0.95rem; }
.row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.pair { display: flex; gap: 8px; margin-top: 4px; }
.row select, .row input {
  height: 44px; padding: 0 8px;
  border: 2px solid var(--ink); border-radius: 6px; background: #fff;
}
.row label > select { display: block; width: 100%; margin-top: 4px; }
#amount { width: 4.5em; font-weight: 700; }
.pair select { flex: 1; }
#preview { min-height: 1.5em; margin: 14px 0 10px; font-size: 1.15rem; font-weight: 700; color: var(--green); }
#preview.error { color: #b0302a; }
.primary, button.primary {
  display: block; width: 100%;
  min-height: 52px;
  background: var(--green) !important; color: #fff;
  border: 2px solid var(--ink); border-radius: 6px;
  font-size: 1.25rem; font-weight: 800; cursor: pointer;
}
.primary:hover { background: #2f6a3c !important; }
.primary:disabled { opacity: 0.5; cursor: default; }
.small { margin: 10px 0 0; font-size: 0.9rem; color: #6a645c; text-align: center; }

#result-list {
  display: grid; grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)); gap: 14px;
  margin: 16px 0 20px;
}
.result h3 { margin: 0; padding: 2px 10px; background: var(--group); color: #fff; font-size: 1.4rem; }
.result ol {
  margin: 0; padding: 6px 12px 8px;
  list-style: none;
  border: 2px solid var(--group); border-top: 0;
  font-size: clamp(1.1rem, 1.7vw, 1.6rem); font-weight: 700; line-height: 1.3;
}
.buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.buttons .primary { width: auto; padding: 0 22px; }

#loading {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  margin: 0; padding: 10px 20px;
  background: var(--paper); border: 2px solid var(--ink); border-radius: 6px;
  font-size: 1.3rem; font-weight: 700;
}

@media (max-width: 640px) {
  .row { grid-template-columns: 1fr; }
  #result-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #toolbar { flex-wrap: wrap; right: 12px; }
}
