/* Shared building blocks for tool and game pages.
   Components (kit-*, game-*) use only shell.css tokens, so they look the same
   on every page in both themes. <body class="kit-page"> adds the tool page
   layout (main width, box-sizing); game pages use the components alone.
   Template: Programy/_szablon/_szablon.html */
body {
  --kit-radius: 12px;
  --kit-radius-sm: 8px;
  --kit-gap: 16px;
  --kit-control-h: 44px;
  --kit-danger: #b93832;
  --kit-mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  --kit-width: 960px;
}
[data-theme="dark"] body { --kit-danger: #ff8f86; }
.kit-page *, .kit-page *::before, .kit-page *::after { box-sizing: border-box; }
.kit-page .sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.kit-page main { max-width: var(--kit-width); margin: 0 auto; padding: 48px 24px 0; }
.kit-page main.kit-wide { --kit-width: 1184px; }
.kit-page main.kit-narrow { --kit-width: 640px; }

/* Page heading: icon chip + title + one-line lead, left aligned like the catalogs. */
.kit-head { display: flex; gap: 18px; align-items: center; margin: 0 0 32px; }
.kit-head-icon {
  display: grid; place-content: center; flex: 0 0 auto;
  width: 56px; height: 56px; border-radius: 14px;
  background: var(--shell-soft); font-size: 28px; line-height: 1;
}
.kit-head h1 {
  margin: 0; font-size: clamp(28px, 4vw, 40px); line-height: 1.1;
  font-weight: 700; letter-spacing: -1px;
}
.kit-head p { margin: 6px 0 0; color: var(--shell-muted); font-size: 15px; }

/* Surfaces */
.kit-card {
  background: var(--shell-card); border: 1px solid var(--shell-border);
  border-radius: var(--kit-radius); padding: 24px;
}
.kit-card + .kit-card { margin-top: var(--kit-gap); }
.kit-card > h2, .kit-section-title {
  margin: 0 0 14px; font-size: 13px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--shell-muted);
}
.kit-grid { display: grid; gap: var(--kit-gap); grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.kit-stack { display: flex; flex-direction: column; gap: var(--kit-gap); }
.kit-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.kit-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: var(--kit-gap); }
.kit-actions.start { justify-content: flex-start; }
.kit-space { margin-top: var(--kit-gap); }
.kit-note { color: var(--shell-muted); font-size: 14px; margin: 12px 0 0; }

/* Stats: big number + small label */
.kit-stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); margin-bottom: var(--kit-gap); }
.kit-stat {
  background: var(--shell-card); border: 1px solid var(--shell-border);
  border-radius: var(--kit-radius); padding: 16px 18px;
}
.kit-stat-value { display: block; font-size: 28px; font-weight: 750; line-height: 1.2; color: var(--shell-accent); font-variant-numeric: tabular-nums; }
.kit-stat-label { display: block; margin-top: 4px; font-size: 12px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase; color: var(--shell-muted); }

/* Buttons */
.kit-btn, .kit-input, .kit-tab, .game-bar, .game-bar * { box-sizing: border-box; }
.kit-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--kit-control-h); padding: 0 18px;
  border: 1px solid var(--shell-border); border-radius: var(--kit-radius-sm);
  background: var(--shell-card); color: var(--shell-text);
  font: inherit; font-size: 14px; font-weight: 650; line-height: 1.2;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
/* display:inline-flex must not defeat the hidden attribute. */
.kit-btn[hidden], .kit-tab[hidden], .game-stat[hidden] { display: none; }
.kit-btn:hover { background: var(--shell-hover); border-color: var(--shell-muted); }
.kit-btn:disabled { opacity: .5; cursor: not-allowed; }
.kit-btn.primary { background: var(--shell-accent); border-color: var(--shell-accent); color: var(--shell-bg); }
.kit-btn.primary:hover { filter: brightness(1.08); }
.kit-btn.danger { color: var(--kit-danger); }
.kit-btn.danger:hover { border-color: var(--kit-danger); }
.kit-btn.ghost { background: transparent; border-color: transparent; }
.kit-btn.ghost:hover { background: var(--shell-soft); }
.kit-btn.block { width: 100%; }
.kit-btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }

/* Form fields */
.kit-field { display: flex; flex-direction: column; gap: 6px; }
.kit-field + .kit-field { margin-top: var(--kit-gap); }
.kit-grid > .kit-field + .kit-field { margin-top: 0; }
.kit-label, .kit-field > label { font-size: 14px; font-weight: 650; }
.kit-label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.kit-input, .kit-page textarea.kit-input, .kit-page select.kit-input {
  width: 100%; min-height: var(--kit-control-h); padding: 10px 14px;
  border: 1px solid var(--shell-border); border-radius: var(--kit-radius-sm);
  background: var(--shell-card); color: var(--shell-text);
  font: inherit; font-size: 15px;
}
.kit-page textarea.kit-input { min-height: 160px; line-height: 1.7; resize: vertical; }
.kit-input:focus { outline: none; border-color: var(--shell-accent); box-shadow: 0 0 0 3px var(--shell-soft); }
.kit-input.mono, .kit-mono { font-family: var(--kit-mono); }
.kit-page input[type="range"] { width: 100%; accent-color: var(--shell-accent); }
.kit-page input[type="color"] {
  width: 100%; height: var(--kit-control-h); padding: 4px;
  border: 1px solid var(--shell-border); border-radius: var(--kit-radius-sm); background: var(--shell-card); cursor: pointer;
}

/* Checkbox/radio option tiles */
.kit-options { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.kit-option {
  display: flex; align-items: center; gap: 10px; min-height: var(--kit-control-h); padding: 8px 14px;
  border: 1px solid var(--shell-border); border-radius: var(--kit-radius-sm); background: var(--shell-card); cursor: pointer;
}
.kit-option:hover { border-color: var(--shell-muted); }
.kit-option input { width: 18px; height: 18px; margin: 0; accent-color: var(--shell-accent); }

/* Output box with a copy button */
.kit-output { display: flex; gap: 10px; align-items: stretch; }
.kit-output .kit-input { font-family: var(--kit-mono); font-size: 18px; text-align: center; }

/* Segmented tabs */
.kit-tabs { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; border: 1px solid var(--shell-border); border-radius: 10px; background: var(--shell-card); }
.kit-tab { min-height: 36px; padding: 0 14px; border: 0; border-radius: 7px; background: transparent; color: var(--shell-muted); font: inherit; font-size: 14px; font-weight: 650; cursor: pointer; }
.kit-tab:hover { color: var(--shell-text); }
.kit-tab[aria-selected="true"], .kit-tab.active { background: var(--shell-soft); color: var(--shell-text); }

/* Toast (Kit.toast) */
.kit-toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 1000; transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: 10px;
  background: var(--shell-text); color: var(--shell-bg); font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.kit-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Game pages ─────────────────────────────────────────────────────────────
   <div class="game-bar">
     <div class="game-title"><h1>Snake</h1><p>Strzałki: ruch · P: pauza</p></div>
     <div class="game-stats"><div class="game-stat"><span>Wynik</span><b id="score">0</b></div>…</div>
     <div class="game-buttons"><button class="kit-btn small primary">Nowa gra</button>…</div>
   </div>
   <div class="game-stage">…board/canvas…</div>
   <p class="game-status" role="status">…</p>
   Boards keep their own colors; only the frame around them is shared. */
.game-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px;
  width: 100%; max-width: var(--game-width, 760px); margin: 0 auto 16px; padding: 0;
  color: var(--shell-text); font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.game-title { flex: 1 1 200px; min-width: 0; }
.game-title h1 { margin: 0; font-size: clamp(22px, 3vw, 30px); line-height: 1.15; font-weight: 750; letter-spacing: -.5px; color: var(--shell-text); }
.game-title p { margin: 4px 0 0; font-size: 13px; line-height: 1.4; color: var(--shell-muted); }
.game-stats { display: flex; flex-wrap: wrap; gap: 8px; }
.game-stat {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 68px; min-height: 48px; padding: 4px 12px;
  border: 1px solid var(--shell-border); border-radius: 10px; background: var(--shell-card);
}
.game-stat > span { font-size: 10px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--shell-muted); line-height: 1.3; }
.game-stat > b { font-size: 18px; font-weight: 750; line-height: 1.2; color: var(--shell-accent); font-variant-numeric: tabular-nums; }
.game-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.game-stage { display: flex; justify-content: center; width: 100%; max-width: var(--game-width, 760px); margin: 0 auto; }
.game-status { max-width: var(--game-width, 760px); margin: 12px auto 0; text-align: center; font: 14px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--shell-muted); }
.game-shell .kit-btn { font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
/* On-screen arrows for touch devices: <div class="game-pad">4 buttons</div> */
.game-pad { display: none; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(2, 56px); gap: 8px; justify-content: center; margin: 16px auto 0; }
.game-pad .kit-btn { min-height: 56px; padding: 0; font-size: 20px; }
.game-pad .up { grid-column: 2; }
.game-pad .left { grid-column: 1; grid-row: 2; }
.game-pad .down { grid-column: 2; grid-row: 2; }
.game-pad .right { grid-column: 3; grid-row: 2; }
@media (hover: none), (max-width: 700px) { .game-pad { display: grid; } }
@media (max-width: 560px) {
  .game-bar { gap: 10px; }
  .game-title { flex-basis: 100%; }
  .game-stat { min-width: 60px; }
}

@media (max-width: 700px) {
  .kit-page main { padding: 28px 16px 0; }
  .kit-grid { grid-template-columns: minmax(0, 1fr); }
  .kit-head { gap: 14px; margin-bottom: 24px; }
  .kit-head-icon { width: 46px; height: 46px; font-size: 23px; border-radius: 12px; }
  .kit-card { padding: 18px; }
  .kit-actions .kit-btn { flex: 1 1 auto; }
  .kit-output { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  .kit-toast, .kit-btn { transition: none; }
}
