/* Games family (minesweeper, solitaire, marble match, dot connect, Secret Santa, bingo, brackets).
   Loaded only on those pages, after webtools.css and before tools-premium.css.
   html.p2g-printing is toggled by p2-games-common.js while a sheet on <body> is printed. */

.tool[data-webtool^="p2-"] { display: grid; gap: 0.75rem; min-width: 0; }
.tool[data-webtool^="p2-"] > * { min-width: 0; }
.tool[data-webtool^="p2-"] [hidden] { display: none !important; }

.p2g-bar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; }
.p2g-bar > label { flex: 1 1 12rem; min-width: 0; margin: 0; }
.p2g-bar select { width: 100%; min-height: 44px; }
.p2g-bar .wt-btns { margin-left: auto; }
.p2g-hint, .p2g-best { margin: 0; color: var(--text-2); font-size: 0.9rem; }
.p2g-sr { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
.p2g-ask p { margin: 0 0 0.6rem; font-weight: 600; }

.tp-stage .tool[data-webtool^="p2-"] .ms-c:focus-visible,
.tp-stage .tool[data-webtool^="p2-"] .kl-card:focus-visible,
.tp-stage .tool[data-webtool^="p2-"] .kl-slot:focus-visible,
.tp-stage .tool[data-webtool^="p2-"] .kl-stock:focus-visible,
.tp-stage .tool[data-webtool^="p2-"] .p2g-piece:focus-visible,
.tp-stage .tool[data-webtool^="p2-"] .ko-side:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: none;
}
.tp-stage .kl-card.is-down:disabled,
.tp-stage .mb-cell.is-empty:disabled { opacity: 1; cursor: default; }

/* ---------- minesweeper ---------- */
.ms-wrap { max-width: 100%; overflow: auto; border-radius: 8px; }
.ms-wrap.is-scroll { box-shadow: inset -12px 0 10px -12px color-mix(in srgb, var(--text) 35%, transparent); }
.ms-board { width: max-content; user-select: none; touch-action: manipulation; border-radius: 8px; }
.ms-board.is-won { box-shadow: 0 0 0 3px var(--ok); }
.ms-board.is-lost { box-shadow: 0 0 0 3px var(--bad); }
.ms-row { display: flex; }
.ms-c {
  position: relative;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  width: var(--ms-s, 32px);
  height: var(--ms-s, 32px);
  font-size: calc(var(--ms-s, 32px) * 0.52);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  background: color-mix(in srgb, var(--text) 10%, var(--bg-2));
  box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 50%, transparent), inset 0 -2px 0 color-mix(in srgb, var(--text) 22%, transparent);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ms-c.is-open {
  background: var(--bg);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 12%, transparent);
  cursor: default;
}
.ms-c.is-press { background: color-mix(in srgb, var(--accent) 22%, var(--bg)); }
.ms-c.is-hint { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 1; }
.ms-c.n1 { color: #3b82f6; }
.ms-c.n2 { color: #16a34a; }
.ms-c.n3 { color: #ef4444; }
.ms-c.n4 { color: #7c3aed; }
.ms-c.n5 { color: #ea580c; }
.ms-c.n6 { color: #0891b2; }
.ms-c.n7 { color: var(--text); }
.ms-c.n8 { color: var(--text-2); }
.ms-c.is-flag::after,
.ms-c.is-mine::after {
  content: "";
  width: 58%;
  height: 58%;
  background: center / contain no-repeat;
}
.ms-c.is-flag::after {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='%23111' d='M4 1h1.4v14H4z'/><path fill='%23c4283c' d='M5.4 2l8 3.2-8 3.2z'/></svg>");
}
.ms-c.is-wrong::before {
  content: "";
  position: absolute;
  inset: 18%;
  background:
    linear-gradient(to top right, transparent 44%, var(--bad) 44% 56%, transparent 56%),
    linear-gradient(to bottom right, transparent 44%, var(--bad) 44% 56%, transparent 56%);
  z-index: 1;
}
.ms-c.is-mine::after {
  border-radius: 50%;
  background: #111;
  box-shadow:
    0 -0.42em 0 -0.28em #111, 0 0.42em 0 -0.28em #111,
    -0.42em 0 0 -0.28em #111, 0.42em 0 0 -0.28em #111;
}
.ms-c.is-boom { background: var(--bad); }
.ms-c.is-boom.is-mine::after { background: #fff; box-shadow: 0 -0.42em 0 -0.28em #fff, 0 0.42em 0 -0.28em #fff, -0.42em 0 0 -0.28em #fff, 0.42em 0 0 -0.28em #fff; }
.tool.is-flagging .ms-c:not(.is-open) { cursor: crosshair; }

/* ---------- solitaire ---------- */
.kl-table {
  --kl-w: clamp(2.05rem, 9.6vw, 4.5rem);
  overflow-x: auto;
  padding-bottom: 0.25rem;
  touch-action: manipulation;
  user-select: none;
}
.kl-top { display: flex; flex-wrap: wrap; gap: 0.45rem 0.6rem; align-items: flex-start; }
.kl-waste { display: flex; align-items: flex-start; min-height: calc(var(--kl-w) * 1.4); }
.kl-waste .kl-card + .kl-card { margin-left: calc(var(--kl-w) * -0.52); }
.kl-founds { display: grid; grid-template-columns: repeat(4, var(--kl-w)); gap: 0.3rem; margin-left: auto; }
.kl-card, .kl-slot, .kl-stock {
  box-sizing: border-box;
  width: var(--kl-w);
  height: calc(var(--kl-w) * 1.4);
  border-radius: 0.4rem;
  flex: 0 0 auto;
}
.kl-card, .kl-slot, .kl-stock {
  padding: 0.15rem 0.22rem;
  border: 1px solid color-mix(in srgb, var(--text) 22%, #fff);
  background: #fff;
  color: #161616;
  font: inherit;
  font-size: clamp(0.68rem, 2.5vw, 1rem);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.kl-card { display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; text-align: left; }
.kl-card.is-red { color: #c4283c; }
.kl-suit { align-self: flex-end; font-size: 1.15em; }
.kl-card.is-down {
  background: repeating-linear-gradient(135deg, #1d4f8f 0 6px, #163f73 6px 12px);
  color: transparent;
  border-color: #163f73;
}
.kl-stock { display: grid; place-items: center; background: #1d4f8f; color: #fff; border-color: #163f73; font-size: 1rem; }
.kl-slot { background: transparent; border-style: dashed; color: transparent; }
.kl-card.is-sel, .kl-slot.is-hot, .kl-card.is-hot { outline: 2px solid var(--accent); outline-offset: 1px; }
.kl-slot.is-hot { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.kl-tabs {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.22rem;
  margin-top: 0.7rem;
}
.kl-pile { display: flex; flex-direction: column; align-items: stretch; min-width: 0; }
.kl-pile .kl-card, .kl-pile .kl-slot { width: 100%; height: auto; aspect-ratio: 5 / 7; }
.kl-pile > * + * { margin-top: -1.55rem; }
@supports (width: 1cqw) {
  .kl-pile { container-type: inline-size; }
  .kl-pile > * + * { margin-top: -92cqw; }
  .kl-pile > .is-down + .is-down { margin-top: -112cqw; }
}
.kl-ghost {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  width: var(--kl-w, 3.2rem);
}
.kl-ghost .kl-card { width: 100%; }
.kl-ghost .kl-card + .kl-card { margin-top: -1.5rem; }
@media (max-width: 520px) {
  .kl-founds { margin-left: 0; }
}

/* ---------- marble match and dot connect ---------- */
.p2g-board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 8), minmax(0, 1fr));
  gap: clamp(0.2rem, 1.2vw, 0.45rem);
  width: min(100%, 28rem);
  margin-inline: auto;
  touch-action: manipulation;
  user-select: none;
}
.p2g-piece {
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  font: inherit;
  font-weight: 750;
  font-size: clamp(0.75rem, 3.4vw, 1.05rem);
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.p2g-piece.c1 { background: #e11d48; }
.p2g-piece.c2 { background: #2563eb; }
.p2g-piece.c3 { background: #16a34a; }
.p2g-piece.c4 { background: #eab308; color: #1a1404; }
.p2g-piece.c5 { background: #7c3aed; }
.mb-cell.is-empty { background: transparent; box-shadow: inset 0 0 0 1px var(--border); }
.mb-cell.is-hot { box-shadow: 0 0 0 3px var(--text); transform: scale(1.04); }
.dt-cell { position: relative; }
.dt-cell.is-path { box-shadow: inset 0 0 0 3px #fff, 0 0 0 2px var(--text); }
.dt-n {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 0.62em;
  font-weight: 700;
  line-height: 1;
}

/* ---------- secret santa ---------- */
.ss-one { margin: 0; min-height: 1.4em; font-size: 1.2rem; font-weight: 650; }
.ss-list { list-style: none; margin: 0; padding: 0; }
.ss-list li { display: flex; justify-content: space-between; gap: 1rem; padding: 0.45rem 0; border-bottom: 1px solid var(--border); }
.ss-list strong { font-variant-numeric: tabular-nums; }
.ss-slips { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.ss-slip { border: 1px dashed currentColor; padding: 0.75rem 0.85rem; break-inside: avoid; }
.ss-kicker { margin: 0; font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase; }
.ss-from, .ss-to { margin: 0.2rem 0; }
.ss-to { font-size: 1.35rem; font-weight: 750; }

/* ---------- bingo ---------- */
.bn-call { margin: 0; min-height: 1.2em; text-align: center; font-size: clamp(1.6rem, 6vw, 2.4rem); font-weight: 750; font-variant-numeric: tabular-nums; }
.bn-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.35rem; }
.bn-let { text-align: center; font-weight: 750; }
.bn-nums { display: flex; flex-direction: column; gap: 2px; }
.bn-n {
  display: grid;
  place-items: center;
  min-height: 1.35rem;
  border-radius: 0.2rem;
  background: var(--bg-2);
  color: var(--text-2);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}
.bn-n.is-on { background: color-mix(in srgb, var(--accent) 28%, var(--bg)); color: var(--text); font-weight: 700; }
.bn-n.is-now { outline: 2px solid var(--accent); color: var(--text); font-weight: 750; }
.bn-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 0.85rem; }
.bn-card { border: 1px solid var(--border); border-radius: 0.6rem; padding: 0.65rem 0.7rem; background: var(--bg); break-inside: avoid; }
.bn-title { margin: 0; font-weight: 750; text-align: center; }
.bn-sub { margin: 0.1rem 0 0.4rem; text-align: center; color: var(--text-2); font-size: 0.85rem; }
.bn-table { width: 100%; border-collapse: collapse; text-align: center; font-variant-numeric: tabular-nums; }
.bn-table th, .bn-table td { border: 1px solid var(--border); padding: 0.35rem 0.2rem; }
.bn-table th { font-weight: 750; }
.bn-table .is-free { font-size: 0.75rem; font-weight: 750; }

/* ---------- bracket ---------- */
.ko-board { display: flex; gap: 0.75rem; overflow-x: auto; padding-bottom: 0.35rem; }
.ko-round { flex: 1 1 11rem; min-width: 11rem; }
.ko-round h3, .rr-round h3 { margin: 0 0 0.35rem; font-size: 0.95rem; }
.ko-match { display: grid; gap: 0.25rem; margin: 0 0 0.5rem; padding: 0.3rem; border: 1px solid var(--border); border-radius: 0.5rem; background: var(--bg); }
.ko-side {
  min-height: 44px;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.ko-side.is-win { background: color-mix(in srgb, var(--ok) 20%, var(--bg)); border-color: var(--ok); font-weight: 750; }
.ko-bye, .ko-wait { margin: 0; padding: 0.45rem 0.5rem; color: var(--text-2); }
.rr-round { margin: 0 0 1rem; }
.rr-game { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto minmax(0, 1fr); gap: 0.35rem; align-items: center; margin: 0.35rem 0; }
.rr-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rr-game .rr-name:last-child { text-align: right; }
.rr-game input { width: 3.4rem; min-height: 44px; text-align: center; font: inherit; }
.rr-vs { color: var(--text-2); }
.rr-scroll { overflow-x: auto; }
.rr-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rr-table th, .rr-table td { padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.rr-table th:first-child, .rr-table td:first-child, .rr-table th[scope="row"] { text-align: left; }
@media (max-width: 640px) {
  .ko-board { flex-direction: column; overflow-x: visible; }
  .ko-round { min-width: 0; }
}

/* ---------- print sheet (appended to body) ---------- */
html.p2g-printing body > *:not(.p2g-print) { display: none !important; }
html.p2g-printing .p2g-print { display: block !important; }
.p2g-print { padding: 0.5rem; }
html.p2g-printing .p2g-print,
html.p2g-printing .p2g-print * {
  color: #111 !important;
  background: #fff !important;
  box-shadow: none !important;
}
html.p2g-printing .bn-table th,
html.p2g-printing .bn-table td,
html.p2g-printing .ss-slip { border-color: #111 !important; }
.br-print h2, .br-print h3 { margin: 0.8rem 0 0.25rem; }
.br-print ul { margin: 0 0 0.4rem; }
