/* ==========================================================================
   Base — reset, type, and the handful of controls both pages share.
   Everything here is used by the shelf or the reader; nothing is speculative.
   ========================================================================== */

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

/* The `hidden` attribute only carries the UA stylesheet's `display: none`,
   which any author rule such as `.tools { display: flex }` outranks. Without
   this, hiding a panel silently stops working. */
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--t-body);
  line-height: 1.6;
  color: var(--text);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img, svg, video, canvas { display: block; max-width: 100%; height: auto; }
input, button, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

:where(a, button, input, textarea, select, summary, [tabindex]):focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  border-radius: var(--r-2);
}

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

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: 1.18;
  letter-spacing: -0.012em;
  text-wrap: balance;
  color: var(--text);
}

p { text-wrap: pretty; }
code, kbd, .mono { font-family: var(--font-mono); font-size: 0.92em; }

/* Bangla gets its own serif and a little more leading — the conjuncts need it. */
:lang(bn), .bn { font-family: var(--font-bn); line-height: 1.75; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: fixed;
  top: var(--s-3);
  inset-inline-start: var(--s-3);
  z-index: 200;
  padding: var(--s-3) var(--s-5);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--r-2);
  font-weight: 600;
  transform: translateY(-160%);
  transition: transform var(--d-2) var(--ease-out);
}
.skip-link:focus-visible { transform: none; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 0.55rem 1rem;
  min-height: 2.4rem;                /* 44px targets on touch, see below */
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  background: var(--surface);
  color: var(--text-1);
  font-size: var(--t-sm);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  transition: background var(--d-2), border-color var(--d-2), color var(--d-2);
}
.btn svg { width: 1rem; height: 1rem; flex: none; }
.btn:hover { background: var(--surface-3); border-color: var(--line-strong); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }

.btn--primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
  font-weight: 600;
}
.btn--primary:hover { background: color-mix(in oklab, var(--accent) 86%, #000); color: var(--accent-ink); }

.btn--sm { padding: 0.35rem 0.7rem; min-height: 2rem; font-size: var(--t-xs); }
.btn--lg { padding: 0.7rem 1.3rem; min-height: 2.8rem; font-size: var(--t-body); }

@media (pointer: coarse) {
  .btn { min-height: 2.75rem; }
  .btn--sm { min-height: 2.4rem; }
}

/* --- Chip ----------------------------------------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.12em 0.6em;
  border: 1px solid var(--line);
  border-radius: var(--r-1);
  background: var(--surface-2);
  font-size: var(--t-micro);
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
}
.chip--accent { background: var(--accent-soft); border-color: var(--accent-line); color: var(--text); }

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

.field {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  background: var(--surface);
  transition: border-color var(--d-2), box-shadow var(--d-2);
}
.field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field svg { width: 1rem; height: 1rem; color: var(--text-3); flex: none; }
.field input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  outline: none;
  font-size: var(--t-sm);
}
.field input::placeholder { color: var(--text-3); }

/* --- Spinner + toasts ------------------------------------------------------ */

.spinner {
  width: 1.05rem; height: 1.05rem;
  border: 2px solid color-mix(in oklab, currentColor 25%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(1turn); } }

.toast-stack {
  position: fixed;
  inset-block-end: var(--s-5);
  inset-inline: 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  pointer-events: none;
}
.toast {
  max-width: min(92vw, 32rem);
  padding: 0.6rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  font-family: var(--font-bn);
  font-size: var(--t-sm);
  color: var(--text-1);
  animation: toast-in var(--d-3) var(--ease-out) both;
}
.toast[data-tone="ok"] { border-inline-start: 3px solid var(--ok); }
.toast[data-tone="bad"] { border-inline-start: 3px solid var(--bad); }
.toast[data-leaving="true"] { animation: toast-out var(--d-2) var(--ease-in-out) both; }

@keyframes toast-in { from { opacity: 0; transform: translateY(0.6rem); } }
@keyframes toast-out { to { opacity: 0; } }

/* --- Motion preference ------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
