/* 🧪 Game Lab: the Lab screen (#lab), the screen lab games play in (#labgame), and the bits
   games/lab/kit.js gives every game (word boxes, the end-of-round card, confetti).
   Each game's own styles live in games/<id>/<id>.css, every rule under .lab-game-<id>. */
#lab, #labgame {
  --ink: #1d2233;
  --f-display: "Lilita One", "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
  --f-body: "Nunito", -apple-system, "PingFang SC", "Segoe UI", system-ui, sans-serif;
  --f-brush: "Ma Shan Zheng", "Kaiti SC", "STKaiti", "KaiTi", serif;
  font-family: var(--f-body);
  color: var(--ink);
}

/* ---- Home: the pill ---- */
.pill[hidden] { display: none; }
.pill .lab-pill-new {
  min-width: 26px; height: 26px; border-radius: 13px; padding: 0 7px; margin-left: 2px;
  background: #ff3d7f; color: #fff; font-size: 15px; line-height: 26px; text-align: center;
}
.pill .lab-pill-new[hidden] { display: none; }
.pill .lab-pill-icon { font-size: 24px; line-height: 1; }

/* ---- the Lab screen ---- */
#lab {
  background: #f6f1ff;
  background-image: radial-gradient(circle at 20% 0%, #ffe9f3 0, transparent 40%), radial-gradient(circle at 90% 10%, #e3f7ff 0, transparent 40%);
}
#lab .game-head { flex-wrap: wrap; gap: 12px 16px; }
#lab .icon-btn, #labgame .lab-head .icon-btn {
  background: #fff; border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink); border-radius: 50%;
  width: 56px; height: 56px; font-size: 26px; display: grid; place-items: center; padding: 0; flex: none;
}
#lab .icon-btn:active, #labgame .lab-head .icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.lab-title { font-family: var(--f-display); font-weight: 400; font-size: 40px; margin: 0; line-height: 1; }
.lab-sub { font-weight: 800; color: #6b6578; font-size: 17px; flex: 1; min-width: 200px; }
.lab-kid { font-weight: 900; font-size: 18px; background: #fff; border: 3px solid var(--ink); border-radius: 999px; padding: 6px 14px; box-shadow: 0 4px 0 var(--ink); white-space: nowrap; }
.lab-stats-btn { font-family: var(--f-body); font-weight: 900; font-size: 16px; background: #fff; border: 3px solid var(--ink); border-radius: 999px; padding: 8px 14px; box-shadow: 0 4px 0 var(--ink); }
.lab-stats-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.lab-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px max(24px, env(safe-area-inset-right)) 40px max(24px, env(safe-area-inset-left)); }
.lab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 20px; }
.lab-empty { font-size: 22px; font-weight: 800; color: #6b6578; text-align: center; margin-top: 60px; }

.lab-card {
  position: relative; display: flex; flex-direction: column; align-items: stretch; text-align: left; gap: 6px;
  background: #fff; border: 3px solid var(--ink); border-radius: 24px; padding: 10px 10px 14px;
  box-shadow: 0 6px 0 var(--ink); font-family: var(--f-body); color: var(--ink);
  transition: transform .12s, box-shadow .12s;
}
.lab-card:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.lab-card-art {
  position: relative; aspect-ratio: 16 / 10; border-radius: 16px; overflow: hidden;
  background: var(--c); display: grid; place-items: center; border: 3px solid var(--ink);
}
.lab-card-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.lab-card-emoji { font-size: 64px; filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .2)); }
.lab-card-name { font-family: var(--f-display); font-size: 25px; line-height: 1.05; margin: 4px 4px 0; }
.lab-card-name small { font-family: var(--f-body); font-weight: 900; font-size: 16px; color: #6b6578; white-space: nowrap; }
.lab-card-blurb { font-weight: 700; font-size: 15px; line-height: 1.3; color: #4a4f63; margin: 0 4px; }
.lab-card-tag, .lab-card-new, .lab-card-fun, .lab-card-off {
  position: absolute; top: 18px; font-weight: 900; font-size: 14px; border: 2px solid var(--ink); border-radius: 999px; padding: 2px 10px;
}
.lab-card-tag { left: 18px; background: #fff; }
.lab-card-new { right: 18px; background: #ffc22e; transform: rotate(6deg); }
.lab-card-fun { right: 18px; background: #fff; font-size: 22px; padding: 0 6px; }
.lab-card-off { right: 18px; top: auto; bottom: 14px; background: #fff3bf; font-size: 12px; }

/* ---- sheets: was it fun? · grown-ups' stats ---- */
.lab-sheet .sheet-card { border: 3px solid var(--ink); box-shadow: 0 8px 0 var(--ink); font-family: var(--f-body); color: var(--ink); }
.lab-sheet h2 { font-family: var(--f-display); font-weight: 400; font-size: 34px; }
.lab-fun-faces { display: flex; gap: 14px; justify-content: center; margin: 6px 0 18px; }
.lab-fun-faces button {
  display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 150px;
  background: #fff; border: 3px solid var(--ink); border-radius: 22px; padding: 12px 10px; box-shadow: 0 5px 0 var(--ink);
  font-weight: 900; font-size: 17px;
}
.lab-fun-faces button span { font-size: 58px; line-height: 1.1; }
.lab-fun-faces button:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.lab-stats-card { width: min(980px, 100%) !important; }
.lab-stats-scroll { overflow-x: auto; margin-bottom: 14px; }
.lab-stats-table { border-collapse: collapse; width: 100%; font-size: 15px; }
.lab-stats-table th, .lab-stats-table td { border-bottom: 2px solid #eee6f7; padding: 8px 10px; text-align: left; vertical-align: top; }
.lab-stats-table thead th { font-size: 16px; }
.lab-stats-table tbody th { white-space: nowrap; }
.lab-stats-table small { color: #6b6578; font-weight: 700; }
.lab-stats-table .lab-st-none { color: #b9b2c6; }
.lab-stats-note { font-weight: 700; color: #6b6578; font-size: 15px; margin: 0 0 14px; }
/* sortable headings (games/lab/lab.js renderStats) and the admin's Our family / All developer families switch */
.lab-stats-table thead th { padding: 0; white-space: nowrap; vertical-align: bottom; }
.lab-stats-table thead th button {
  all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 4px; width: 100%;
  padding: 8px 10px; cursor: pointer; font-weight: 900;
}
.lab-stats-table thead th.lab-st-num button { justify-content: flex-end; }
.lab-stats-table thead th[aria-sort] button { color: #c2255c; }
.lab-stats-table thead th button:focus-visible { outline: 3px solid #4c8dff; outline-offset: -3px; border-radius: 8px; }
.lab-st-arrow { font-size: 12px; }
.lab-stats-table .lab-st-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lab-stats-table .lab-st-line, .lab-stats-table .lab-st-fun { white-space: nowrap; }
.lab-stats-table .lab-st-cell { font-size: 14px; }
.lab-stats-table .lab-st-where { display: block; }
.lab-stats-views { display: inline-flex; border: 3px solid #1d2233; border-radius: 999px; overflow: hidden; margin: 0 0 12px; }
.lab-stats-views[hidden] { display: none; }
.lab-stats-views button { font-family: inherit; font-weight: 900; font-size: 15px; padding: 7px 14px; background: #fff; color: #1d2233; border: 0; }
.lab-stats-views button[aria-pressed="true"] { background: #1d2233; color: #fff; }
.lab-stats-msg { font-weight: 800; color: #6b6578; font-size: 15px; margin: 0 0 12px; }
.lab-stats-msg[hidden] { display: none; }

/* ---- the game screen ---- */
#labgame { position: relative; background: #fffaf2; overflow: hidden; }
#labgame .lab-head { gap: 14px; padding-bottom: 6px; }
#labgame .lab-head[hidden] { display: none; }
#labgame .lab-head-title { font-family: var(--f-display); font-weight: 400; font-size: 30px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#labgame .lab-head .lab-bar { flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0; }
#labgame .lab-head .lab-bar[hidden] { visibility: hidden; display: flex; }
#labgame .lab-head .progress { border: 2px solid var(--ink); height: 16px; }
#labgame .lab-head .progress-bar { background: var(--lab-color, #2ec27e); }
#labgame .lab-head .counter { color: var(--ink); font-weight: 900; }
#labgame .lab-head .music-toggle { margin-left: auto; }
.lab-root { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* writing boxes (LabKit.writeWord / pad / strokes) */
.lab-word { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; min-height: 0; }
.lab-word-boxes { display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; align-items: center; touch-action: none; }
.lab-word-tools { display: flex; gap: 12px; justify-content: center; }
.lab-word-tools .big-btn { min-height: 56px; font-size: 20px; padding: 10px 16px; }
.box.lab-box { touch-action: none; flex: none; }
.lab-offline { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 8px; border: 0; border-radius: 14px; background: rgba(255, 255, 255, .7); font: inherit; font-size: 16px;
  font-weight: 800; color: #6b6257; text-align: center; cursor: pointer; }
.lab-offline span:last-child { color: var(--accent); }

/* the end-of-round card (LabKit ctx.finish) */
.lab-finish {
  position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px;
  background: rgba(29, 34, 51, .45); animation: lab-fade .2s ease-out;
}
.lab-finish-card {
  width: min(560px, 100%); max-height: 100%; overflow-y: auto; text-align: center;
  background: #fff; border: 3px solid var(--ink); border-radius: 28px; box-shadow: 0 8px 0 var(--ink); padding: 22px 24px;
  animation: lab-pop .3s cubic-bezier(.2, 1.5, .4, 1);
}
.lab-finish-stars { font-size: 52px; letter-spacing: 4px; }
.lab-finish-card h2 { font-family: var(--f-display); font-weight: 400; font-size: 38px; margin: 4px 0 10px; }
.lab-finish-card p { font-size: 20px; font-weight: 800; color: #4a4f63; margin: 6px 0; }
.lab-finish-actions { display: flex; gap: 12px; margin-top: 18px; }
.lab-finish-actions .big-btn { flex: 1; }

/* confetti (LabKit.confetti) */
.lab-confetti { position: fixed; inset: 0; pointer-events: none; z-index: 9000; }
.lab-confetti i {
  position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50% 50% 50% 0;
  animation: lab-burst 1.1s cubic-bezier(.15, .7, .3, 1) both;
}
@keyframes lab-burst {
  0% { transform: translate(0, 0) scale(0); opacity: 1; }
  60% { opacity: 1; }
  100% { transform: translate(var(--x), calc(var(--y) + 120px)) scale(var(--s)) rotate(200deg); opacity: 0; }
}
@keyframes lab-fade { from { opacity: 0; } }
@keyframes lab-pop { from { opacity: 0; transform: scale(.7) translateY(30px); } }

@media (max-width: 820px) {
  .lab-title { font-size: 32px; }
  .lab-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
  .lab-fun-faces button { min-width: 0; flex: 1; }
  #labgame .lab-head-title { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  .lab-finish, .lab-finish-card, .lab-card { animation: none; transition: none; }
}
