/*
 * Podstawa wszystkich stron i wspólne klocki: pasek, nagłówek strony, rozdzielacz,
 * stopka, przyciski, pola formularzy, okno dialogowe, ramka rysowana tuszem.
 * Wartości wyłącznie z tokens.css. Arkusze stref (home, gallery, panel, lectures)
 * dokładają tylko to, co ich własne.
 */

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

html {
  scroll-padding-top: var(--topbar-height);
  scrollbar-gutter: stable;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  min-height: 100vh;
  padding-top: var(--topbar-height);
  overflow-x: clip;
  font-family: var(--font-serif);
  font-size: var(--fs-body);
  font-weight: var(--weight-regular);
  line-height: var(--lh-body);
  color: var(--color-ink);
  background-color: var(--color-paper);
}

/* Delikatna poświata czerwieni pod całą stroną */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: var(--z-base);
  pointer-events: none;
  background:
    radial-gradient(ellipse at 20% 50%, var(--color-accent-wash) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, var(--color-accent-wash) 0%, transparent 40%);
}

main {
  position: relative;
  z-index: var(--z-content);
  display: block;
}

main:focus { outline: none; }

img, svg { display: block; max-width: 100%; }

/* <picture> tylko wybiera plik — układ i style należą do <img> w środku */
picture { display: contents; }

/* Atrybut hidden ukrywa także element, którego klasa ustawia display (np. .btn) — selektor
   z typem przed atrybutem wygrywa z pojedynczą klasą niezależnie od kolejności arkuszy */
html [hidden] { display: none; }

a { color: inherit; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

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

.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: var(--z-dialog);
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-ui);
  font-size: var(--fs-small);
  color: var(--color-paper);
  background: var(--color-ink);
  transform: translateY(-200%);
}

.skip-link:focus { transform: none; }

/* Etykieta wersalikami — jedyne źródło stylu tekstu pisanego wersalikami */
.label {
  font-family: var(--font-ui);
  font-size: var(--fs-label);
  font-weight: var(--weight-regular);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--color-ink-soft);
}

/* === Pasek === */

.topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: var(--z-topbar);
  height: var(--topbar-height);
  padding: 0 var(--space-5);
  background: var(--color-paper);
}

.topbar-nav,
.topbar-menu {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.topbar-menu { flex: 1; }

.topbar-links,
.lang-switch {
  display: flex;
  align-items: center;
  list-style: none;
}

.topbar-links li + li::before {
  content: '·';
  padding: 0 var(--space-1);
  color: var(--color-ink-faint);
}

.topbar-links li,
.lang-switch li {
  display: flex;
  align-items: center;
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch-target);
  padding: 0 var(--space-2);
  text-decoration: none;
  background: none;
  border: none;
  transition: color var(--dur-fast) ease;
}

.topbar-link:hover { color: var(--color-accent); }

/* Bieżąca strona i bieżący język */
.topbar-link[aria-current] { color: var(--color-accent); }

.topbar-logout { display: contents; }

.topbar-burger {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--touch-target);
  height: var(--touch-target);
  color: var(--color-ink-soft);
  background: none;
  border: none;
}

.topbar-burger:hover { color: var(--color-accent); }

.topbar-burger svg {
  width: var(--space-5);
  height: var(--space-5);
  stroke: currentColor;
}

.topbar-burger .icon-close,
.topbar-burger[aria-expanded="true"] .icon-open { display: none; }

.topbar-burger[aria-expanded="true"] .icon-close { display: block; }

@media (max-width: 40rem) {
  .topbar { padding: 0 var(--space-3); }

  .topbar-burger { display: inline-flex; }

  .topbar-menu {
    position: fixed;
    inset: var(--topbar-height) 0 auto;
    display: none;
    flex-direction: column;
    align-items: stretch;
    height: auto;
    padding: var(--space-2) var(--space-5) var(--space-4);
    background: var(--color-paper);
    border-bottom: var(--line-width) solid var(--color-line);
  }

  .topbar-burger[aria-expanded="true"] + .topbar-menu { display: flex; }

  .topbar-links { flex-direction: column; align-items: stretch; }

  .topbar-links li + li::before { content: none; }

  .lang-switch {
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: var(--line-width) solid var(--color-line);
  }

  .topbar-links .topbar-link { width: 100%; padding: 0; }
}

/* === Nagłówek strony (nazwa pracowni i podtytuł) === */

.masthead {
  padding: var(--space-6) var(--space-6) var(--space-4);
  text-align: center;
}

.masthead-title {
  font-size: var(--fs-display);
  font-weight: var(--weight-light);
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-display);
  text-indent: var(--tracking-display);
  text-transform: lowercase;
}

.masthead--compact { padding-top: var(--space-9); }

.masthead--compact .masthead-title { font-size: var(--fs-display-sm); }

.masthead-subtitle {
  margin-top: var(--space-3);
  font-size: var(--fs-body);
  letter-spacing: var(--tracking-airy);
  text-indent: var(--tracking-airy);
  color: var(--color-ink-soft);
}

@media (max-width: 40rem) {
  .masthead-title {
    font-size: var(--fs-display-phone);
    letter-spacing: var(--tracking-display-narrow);
    text-indent: var(--tracking-display-narrow);
  }
}

/* === Rozdzielacz: kreska, kropka, kreska === */

.divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-5);
  padding: var(--space-7) 0;
}

.divider::before,
.divider::after {
  content: '';
  width: var(--space-9);
  height: var(--line-width);
  background: var(--color-ink-faint);
}

.divider-dot {
  width: var(--space-1);
  height: var(--space-1);
  border-radius: 50%;
  background: var(--color-accent);
}

/* === Nagłówek sekcji: numer, tytuł, kreska === */

.section-heading {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.section-number {
  min-width: var(--space-5);
  font-family: var(--font-jp);
  font-size: var(--fs-label);
  color: var(--color-accent);
}

.section-title {
  font-size: var(--fs-small);
  font-weight: var(--weight-regular);
  letter-spacing: var(--tracking-airy);
  text-transform: uppercase;
  color: var(--color-ink-soft);
}

.section-line {
  flex: 1;
  height: var(--line-width);
  background: linear-gradient(to right, var(--color-ink-faint), transparent);
}

/* === Stopka === */

.footer {
  position: relative;
  z-index: var(--z-content);
  padding: var(--space-8) var(--space-6) var(--space-9);
  text-align: center;
}

.footer-mark {
  position: relative;
  width: var(--space-6);
  height: var(--space-6);
  margin: 0 auto var(--space-5);
  border-radius: 50%;
  background: var(--color-accent);
  opacity: 0.7;
}

.footer-mark::after {
  content: '';
  position: absolute;
  inset: var(--space-1);
  border-radius: 50%;
  border: var(--line-width) solid var(--color-seal-ring);
}

.footer-text { letter-spacing: var(--tracking-wide); text-indent: var(--tracking-wide); }

/* === Przyciski === */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: var(--space-3) var(--space-7);
  font-family: var(--font-ui);
  font-size: var(--fs-label);
  font-weight: var(--weight-regular);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  text-decoration: none;
  /* Napis w dwóch wierszach (wąski telefon) wyśrodkowany także w linku — <button> robi to sam. */
  text-align: center;
  color: var(--color-paper);
  background: var(--color-ink);
  border: var(--line-width) solid var(--color-ink);
  transition: background-color var(--dur-fast) ease, border-color var(--dur-fast) ease, color var(--dur-fast) ease;
}

.btn:hover {
  background: var(--color-accent);
  border-color: var(--color-accent);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  cursor: default;
  color: var(--color-ink-soft);
  background: var(--color-paper-warm);
  border-color: var(--color-line-strong);
}

.btn--quiet {
  color: var(--color-ink-soft);
  background: none;
  border-color: var(--color-field-border);
}

.btn--quiet:hover {
  color: var(--color-accent);
  background: none;
  border-color: var(--color-accent);
}

/* === Pola formularzy === */

.form-fields {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.field-label {
  display: block;
  margin-bottom: var(--space-2);
}

.field-input {
  display: block;
  width: 100%;
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-serif);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  background: transparent;
  border: var(--line-width) solid var(--color-field-border);
  border-radius: 0;
  appearance: none;
  transition: border-color var(--dur-fast) ease;
}

.field-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: inset 0 0 0 var(--line-width) var(--color-accent);
}

textarea.field-input { min-height: 8rem; resize: vertical; }

select.field-input {
  padding-right: var(--space-7);
  background-image: linear-gradient(45deg, transparent 50%, var(--color-ink-soft) 50%), linear-gradient(135deg, var(--color-ink-soft) 50%, transparent 50%);
  background-position: calc(100% - var(--space-5)) 50%, calc(100% - var(--space-4)) 50%;
  background-size: var(--space-2) var(--space-2);
  background-repeat: no-repeat;
}

.field-input[aria-invalid="true"] { border-color: var(--color-accent); }

.field-errors {
  margin-top: var(--space-2);
  list-style: none;
  font-family: var(--font-ui);
  font-size: var(--fs-small);
  color: var(--color-accent);
}

.form-errors { margin: 0 0 var(--space-4); text-align: center; }

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin-top: var(--space-6);
}

.form-actions--start { justify-content: flex-start; }

/* === Przełącznik (widoczność tagu w panelu, „Pokaż zmiany” w oknie poprawki): stan wyłącznie z aria-pressed === */
.switch {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: 0 var(--space-2);
  font-family: var(--font-ui);
  font-size: var(--fs-label);
  color: var(--color-ink-soft);
  background: none;
  border: none;
}

.switch-track {
  position: relative;
  width: var(--space-7);
  height: var(--space-5);
  border-radius: var(--space-5);
  background: var(--color-field-border);
  transition: background-color var(--dur-fast) ease;
}

.switch-track::after {
  content: '';
  position: absolute;
  top: var(--space-1);
  left: var(--space-1);
  width: var(--space-4);
  height: var(--space-4);
  border-radius: 50%;
  background: var(--color-paper);
  transition: transform var(--dur-fast) ease;
}

.switch[aria-pressed="true"] { color: var(--color-ink); }

.switch[aria-pressed="true"] .switch-track { background: var(--color-accent); }

.switch[aria-pressed="true"] .switch-track::after { transform: translateX(var(--space-4)); }

/* === Okno dialogowe (natywny <dialog>) === */

.dialog {
  width: calc(100% - var(--space-6));
  max-width: var(--width-dialog);
  max-height: calc(100dvh - var(--space-6));
  margin: auto;
  padding: var(--space-7);
  color: var(--color-ink);
  background: var(--color-paper);
  border: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Strona pod otwartym oknem stoi — przewija się tylko treść okna */
html:has(dialog[open]) { overflow: hidden; }

/* Okno dostaje fokus samo (P.openDialog); obrys pokazują dopiero kontrolki w środku */
dialog:focus { outline: none; }

.dialog::backdrop {
  background: var(--color-backdrop);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.dialog-close {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-target);
  height: var(--touch-target);
  color: var(--color-ink-soft);
  background: none;
  border: none;
  transition: color var(--dur-fast) ease;
}

.dialog-close:hover { color: var(--color-accent); }

/* Zamknięcie okna na ciemnym tle (podgląd pracy) */
.dialog-close--on-night { color: var(--color-night-soft); }

.dialog-close--on-night:hover { color: var(--color-paper); }

.dialog-close svg {
  width: var(--space-5);
  height: var(--space-5);
  stroke: currentColor;
}

.dialog-title {
  margin-bottom: var(--space-6);
  font-size: var(--fs-title);
  font-weight: var(--weight-light);
  letter-spacing: var(--tracking-label);
  text-align: center;
}

@media (max-width: 40rem) {
  .dialog { padding: var(--space-6) var(--space-5); }

  /* Okno z formularzem do pisania (opis pracy, poprawka tekstu) na całym ekranie telefonu. */
  .dialog--full {
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: none;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .dialog[open] { animation: rise var(--dur-medium) ease-out both; }
}

/* === Komunikat o wyniku akcji (panel, poprawianie tekstów na stronie wykładu): pasek tuszu u dołu ekranu === */

.action-status {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  z-index: var(--z-action-status);
  width: max-content;
  max-width: calc(100% - var(--space-6));
  transform: translateX(-50%);
}

.action-message {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  font-family: var(--font-ui);
  font-size: var(--fs-small);
  line-height: var(--lh-tight);
  color: var(--color-paper);
  background: var(--color-ink);
  box-shadow: 0 var(--space-2) var(--space-5) var(--color-backdrop);
  cursor: pointer;
}

.action-message::before {
  content: '';
  flex: none;
  width: var(--space-2);
  height: var(--space-2);
  border-radius: 50%;
  background: var(--color-accent);
}

.action-message[data-error] { background: var(--color-accent); }

.action-message[data-error]::before { background: var(--color-paper); }

@media (prefers-reduced-motion: no-preference) {
  .action-message { animation: rise var(--dur-fast) ease-out both; }
}

/* === Kontakt: podstrona z danymi i formularzem === */

.contact-page {
  max-width: var(--width-dialog);
  margin: 0 auto;
  padding: 0 var(--space-5) var(--space-8);
}

.contact { padding: var(--space-7) var(--space-6); }

.contact-info,
.contact-offer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  text-align: center;
}

.contact-info { margin-bottom: var(--space-5); }

.contact-info dt { margin-bottom: var(--space-1); }

.contact-link {
  text-decoration: none;
  transition: color var(--dur-fast) ease;
}

.contact-link:hover { color: var(--color-accent); }

.contact-offer > div { max-width: 18rem; }

.contact-offer dd { color: var(--color-ink-soft); line-height: var(--lh-body); }

.contact-rule {
  width: var(--space-7);
  height: var(--line-width);
  margin: var(--space-6) auto;
  background: var(--color-ink-faint);
}

.honeypot {
  position: absolute;
  left: -100vw;
}

.contact-sent {
  padding: var(--space-8) var(--space-4);
  text-align: center;
}

.contact-sent-text {
  margin-bottom: var(--space-7);
  font-size: var(--fs-lead);
  line-height: var(--lh-loose);
  color: var(--color-ink-soft);
}

@media (max-width: 40rem) {
  .contact { padding: var(--space-6) var(--space-4); }
}

/* === Ramka rysowana tuszem z czerwoną pieczęcią (behavior „ink-frame”) ===
   Skrypt dokłada <svg class="ink-frame-svg"> o wymiarach ramki; kreska rysuje się,
   a pieczęć odbija się w dolnej krawędzi. */

.ink-frame { position: relative; }

.ink-frame-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.ink-frame-line {
  fill: none;
  stroke: var(--color-line-strong);
  stroke-width: var(--line-width);
  stroke-linecap: round;
}

.ink-frame-seal { fill: var(--color-accent); opacity: 0.85; }

.ink-frame-seal-ring {
  fill: none;
  stroke: var(--color-seal-ring);
  stroke-width: 0.8;
}

.ink-frame-stamp,
.ink-frame-pulse { transform-origin: var(--seal-x) var(--seal-y); }

@media (prefers-reduced-motion: no-preference) {
  .ink-frame-line {
    stroke-dasharray: var(--path-length);
    animation: draw-line 6s ease-in-out 1s both;
  }

  .ink-frame-stamp { animation: stamp 1s var(--ease-stamp) 0.3s both; }

  .ink-frame-pulse { animation: pulse-scale 4s ease-in-out 1.5s infinite; }
}

/* === Ramka ze strony głównej: passe-partout, kreska tuszem z przerwą, czerwona pieczęć ===
   Rysunek ramki (_components/hero_frame.html, skala 600 × 240) leży nad oknem `.hero-window`:
   strona główna wstawia w nie tryptyk prac, wykłady — nazwę strefy. */

.hero {
  display: flex;
  justify-content: center;
  padding: var(--space-10) var(--space-6) var(--space-6);
}

.hero-frame {
  position: relative;
  width: min(37.5rem, 100%);
  aspect-ratio: 600 / 240;
}

/* Okno passe-partout: margines 40/600 × 40/240 */
.hero-window {
  position: absolute;
  inset: 16.667% 6.667%;
}

.hero-logo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.hero-mat { fill: var(--color-paper); }

.hero-edge {
  --path-length: 1473;
  fill: none;
  stroke: var(--color-line-strong);
  stroke-width: 0.75;
  stroke-linecap: round;
}

.hero-seal-link { pointer-events: auto; }

.hero-seal-target { fill: transparent; }

.hero-seal-dot {
  fill: var(--color-accent);
  opacity: 0.85;
  transition: opacity var(--dur-fast) ease;
}

.hero-seal-link:hover .hero-seal-dot,
.hero-seal-link:focus-visible .hero-seal-dot { opacity: 1; }

.hero-seal-ring {
  fill: none;
  stroke: var(--color-seal-ring);
  stroke-width: 0.8;
}

.hero-seal-stamp,
.hero-seal-pulse { transform-origin: 508px 220px; }

/* Nagłówek strony w oknie ramki (_components/framed_masthead.html) — stopień tytułu z szerokości okna
   (jednostki kontenera): ten sam układ na komputerze i na najwęższym telefonie */
.hero-name {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  text-align: center;
}

.hero-name .masthead-title { font-size: var(--fs-frame-title); }

.hero-name .masthead-subtitle { margin-top: 0; }

@media (prefers-reduced-motion: no-preference) {
  .hero-edge {
    stroke-dasharray: var(--path-length);
    animation: draw-line 3s ease-in-out 1s both;
  }

  .hero-seal-stamp { animation: stamp var(--dur-medium) var(--ease-stamp) 0.3s both; }

  .hero-seal-pulse { animation: pulse-scale 3s ease-in-out 1s infinite; }

  .hero-name .masthead-title { animation: rise 1.2s ease-out 0.3s both; }

  .hero-name .masthead-subtitle { animation: rise 1.2s ease-out 0.6s both; }
}

@media (max-width: 40rem) {
  .hero { padding: var(--space-8) var(--space-5) var(--space-4); }
}

/* === Ruch: animacje wyłącznie, gdy system nie prosi o ograniczenie ruchu === */

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(var(--space-5)); }
  to { opacity: 1; transform: none; }
}

@keyframes draw-line {
  from { stroke-dashoffset: var(--path-length); }
  to { stroke-dashoffset: 0; }
}

@keyframes stamp {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes pulse-scale {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.3); }
}

/* === Strony błędów (404, 403, 400, wygasły formularz, 500) === */

.error-page {
  max-width: var(--width-text);
  margin: 0 auto;
  padding: var(--space-4) var(--space-5) var(--space-9);
  text-align: center;
}

.error-detail { color: var(--color-ink-soft); }

.error-actions {
  display: flex;
  justify-content: center;
  margin-top: var(--space-7);
}

/* Strona błędu serwera nie ma paska — bez miejsca na niego */
.error-standalone { padding-top: 0; }
