/* barrettis kit: components.css (needs tokens.css first)
   Base elements plus the shared pieces every app uses: header, footer, theme toggle, buttons,
   fields, switch, card, progress bar, copy confirmation, notes. Plain CSS, no build step. */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; background: var(--bg); }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: var(--text-base) / var(--leading-body) var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* While the theme toggle switches, colours glide instead of jumping (theme.js adds the class). */
html.bk-theme-anim, html.bk-theme-anim * {
  transition: background-color var(--dur-slow) var(--ease-out), border-color var(--dur-slow) var(--ease-out),
    color var(--dur-slow) var(--ease-out), fill var(--dur-slow) var(--ease-out) !important;
}

::selection { background: var(--accent-soft); color: var(--ink); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); }

h1, h2, .bk-serif {
  font-family: var(--font-serif);
  font-weight: 500;
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
  margin: 0;
}

a { color: inherit; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
@media (hover: hover) { a:hover { text-decoration-color: var(--accent); } }

code, pre, kbd { font-family: var(--font-mono); font-size: 0.92em; }

/* Page frame ---------------------------------------------------------------------------- */

.bk-page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: max(var(--space-4), env(safe-area-inset-top)) var(--space-5) max(var(--space-8), env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
.bk-page--wide { max-width: var(--page-max-wide); }
.bk-main { flex: 1; }

/* Header: brand on the left, theme toggle on the right. Same in all three apps. */
.bk-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0 var(--space-6);
}
.bk-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--ink);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.bk-brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--ink);
  color: var(--bg);
  display: grid;
  place-items: center;
  font: 600 13px/1 var(--font-serif);
}
.bk-brand-app { color: var(--muted); font-weight: 500; }
.bk-header-end { display: flex; align-items: center; gap: var(--space-1); }

/* Hero: a small caps kicker, the serif title, one line of plain words under it. */
.bk-kicker {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--accent);
  margin: 0 0 var(--space-2);
}
.bk-title { font-size: var(--text-xl); margin: 0 0 var(--space-2); }
.bk-lede { color: var(--muted); margin: 0 0 var(--space-8); max-width: 44ch; }

/* Footer: one quiet line. */
.bk-footer {
  margin-top: var(--space-12);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  color: var(--muted);
  font-size: var(--text-xs);
}
.bk-footer a { color: var(--muted); }

/* Theme toggle: one 44 px button that cycles System -> Light -> Dark. */
.bk-theme {
  inline-size: var(--tap);
  block-size: var(--tap);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  padding: 0;
  transition: background-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
@media (hover: hover) { .bk-theme:hover { background: var(--surface-2); } }
.bk-theme:active { transform: scale(0.92); }
.bk-theme svg { width: 20px; height: 20px; display: none; }
.bk-theme svg { transition: transform var(--dur-slow) var(--ease-spring), opacity var(--dur-base) var(--ease-out); }
.bk-theme[data-mode="system"] .bk-i-system,
.bk-theme[data-mode="light"] .bk-i-light,
.bk-theme[data-mode="dark"] .bk-i-dark { display: block; animation: bk-spin-in var(--dur-slow) var(--ease-spring); }
@keyframes bk-spin-in { from { transform: rotate(-60deg) scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }

/* Buttons ------------------------------------------------------------------------------- */

.bk-btn {
  appearance: none;
  min-height: var(--tap);
  padding: 0 var(--space-5);
  border-radius: var(--radius-md);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font: 500 var(--text-base) / 1 var(--font-sans);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  text-decoration: none;
  box-shadow: var(--shadow-1);
  transition: transform var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) { .bk-btn:hover { border-color: var(--ink-2); } }
.bk-btn:active { transform: scale(0.97); box-shadow: none; }
.bk-btn:disabled, .bk-btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; transform: none; }

.bk-btn--primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
@media (hover: hover) { .bk-btn--primary:hover { border-color: var(--primary); filter: brightness(1.12); } }
.bk-btn--accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.bk-btn--ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--ink-2); }
@media (hover: hover) { .bk-btn--ghost:hover { background: var(--surface-2); border-color: transparent; } }
.bk-btn--block { width: 100%; }
.bk-btn--sm { min-height: 36px; padding: 0 var(--space-3); font-size: var(--text-sm); border-radius: var(--radius-sm); }

/* Busy state: a thin shimmer runs under the label while work is in progress. */
.bk-btn[aria-busy="true"] { position: relative; overflow: hidden; pointer-events: none; }
.bk-btn[aria-busy="true"]::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, currentColor, transparent);
  animation: bk-slide 1s linear infinite;
}
@keyframes bk-slide { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* Copy confirmation: the label flips to a check and "Copied" (the scripts already swap the
   text; adding .is-copied gives the colour and the tick). */
.bk-copied, .is-copied {
  background: var(--good-soft) !important;
  border-color: var(--good) !important;
  color: var(--good) !important;
  animation: bk-pop var(--dur-base) var(--ease-spring);
}
@keyframes bk-pop { 0% { transform: scale(0.94); } 100% { transform: none; } }

/* Fields -------------------------------------------------------------------------------- */

.bk-label {
  display: block;
  margin: var(--space-5) 0 var(--space-2);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink-2);
}

.bk-field {
  width: 100%;
  min-height: var(--tap);
  padding: 10px var(--space-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  font: var(--text-base) / 1.4 var(--font-sans);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.bk-field::placeholder { color: var(--muted); opacity: 1; }
@media (hover: hover) { .bk-field:hover { border-color: var(--ink-2); } }
.bk-field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.bk-field { resize: vertical; min-height: 112px; }
select.bk-field {
  appearance: none;
  padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
}
.bk-hint { font-size: var(--text-sm); color: var(--muted); margin: var(--space-2) 0 0; }
.bk-error { font-size: var(--text-sm); color: var(--bad); margin: var(--space-3) 0 0; min-height: 1em; }
.bk-error:empty { display: none; }

/* Segmented control: a choice of 2 to 4 options that are all visible. */
.bk-seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
}
.bk-seg button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: 500 var(--text-sm) / 1 var(--font-sans);
  cursor: pointer;
  transition: background-color var(--dur-base) var(--ease-out), color var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}
.bk-seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* Switch: on/off with a sprung thumb. Markup: <label class="bk-switch"><input type="checkbox"><span></span></label> */
.bk-switch { position: relative; display: inline-block; width: 46px; height: 28px; flex: none; }
.bk-switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.bk-switch span {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-pill);
  background: var(--line-strong);
  transition: background-color var(--dur-base) var(--ease-out);
}
.bk-switch span::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.25);
  transition: transform var(--dur-base) var(--ease-spring);
}
.bk-switch input:checked + span { background: var(--accent); }
.bk-switch input:checked + span::before { transform: translateX(18px); }
.bk-switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Card ---------------------------------------------------------------------------------- */

.bk-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-1);
}
.bk-card + .bk-card { margin-top: var(--space-3); }
.bk-card-enter { animation: bk-rise var(--dur-slow) var(--ease-out) both; }
@keyframes bk-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.bk-divider { height: 1px; background: var(--line); border: 0; margin: var(--space-5) 0; }

/* Progress: determinate (set --p from 0 to 1, or the width of the inner <i>) and indeterminate. */
.bk-progress { height: 6px; border-radius: var(--radius-pill); background: var(--surface-2); overflow: hidden; }
.bk-progress > i { display: block; height: 100%; width: calc(var(--p, 0) * 100%); background: var(--accent); border-radius: inherit; transition: width var(--dur-base) var(--ease-out); }
.bk-progress.is-indeterminate > i { width: 35%; animation: bk-indet 1.1s var(--ease-out) infinite alternate; }
@keyframes bk-indet { from { margin-left: 0; } to { margin-left: 65%; } }

/* Badge / meter --------------------------------------------------------------------------- */

.bk-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--text-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.bk-badge--warn { background: var(--bad-soft); color: var(--bad); }
.bk-good { color: var(--good); }
.bk-bad { color: var(--bad); }
.bk-muted { color: var(--muted); }

/* Value row: a read-only value with its copy button (share reader, share link). */
.bk-value {
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
}
.bk-value > code, .bk-value > input {
  flex: 1;
  min-width: 0;
  min-height: var(--tap);
  padding: 11px var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font: var(--text-sm) / 1.45 var(--font-mono);
  word-break: break-all;
  white-space: pre-wrap;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0ms !important; animation-iteration-count: 1 !important; transition-duration: 0ms !important; }
  .bk-progress.is-indeterminate > i { animation: none; width: 100%; opacity: 0.5; }
}

/* Mobile ----------------------------------------------------------------------------------- */

/* Notch and home indicator: with viewport-fit=cover the page keeps clear of both, in portrait
   and in landscape (left and right insets). */
.bk-page {
  padding-left: max(var(--space-4), env(safe-area-inset-left));
  padding-right: max(var(--space-4), env(safe-area-inset-right));
}
@media (min-width: 480px) {
  .bk-page {
    padding-left: max(var(--space-5), env(safe-area-inset-left));
    padding-right: max(var(--space-5), env(safe-area-inset-right));
  }
}

/* No double-tap zoom delay on controls, and no grey flash on tap. */
button, a, label, select, summary, input[type="checkbox"], input[type="range"], [role="button"] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* iOS zooms into any field under 16 px: every text field stays at 16 px or more. */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]), select, textarea {
  font-size: max(16px, 1em);
}

/* Dock: the main action of a screen, kept in the thumb zone. On phones it sticks to the bottom
   edge above the home indicator; from 640 px it sits in the flow like any button. */
.bk-dock {
  position: sticky;
  bottom: max(var(--space-3), env(safe-area-inset-bottom));
  z-index: 5;
}
@media (min-width: 640px) {
  .bk-dock { position: static; }
}

/* Range sliders: a 28 px thumb on a 6 px track, easy to grab with a thumb. */
input[type="range"].bk-range, .bk-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: var(--tap);
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.bk-range::-webkit-slider-runnable-track { height: 6px; border-radius: var(--radius-pill); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); }
.bk-range::-moz-range-track { height: 6px; border-radius: var(--radius-pill); background: var(--surface-2); }
.bk-range::-moz-range-progress { height: 6px; border-radius: var(--radius-pill); background: var(--accent); }
.bk-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -11px;
  border-radius: 50%;
  border: 0;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line-strong), var(--shadow-2);
  transition: transform var(--dur-fast) var(--ease-out);
}
.bk-range::-moz-range-thumb { width: 28px; height: 28px; border-radius: 50%; border: 0; background: var(--surface); box-shadow: 0 0 0 1px var(--line-strong), var(--shadow-2); }
.bk-range:active::-webkit-slider-thumb { transform: scale(1.12); }

/* Things that only make sense with a keyboard or a mouse. */
@media (hover: none) and (pointer: coarse) {
  .bk-desktop-only { display: none !important; }
}
