/* ==========================================================================
   TiskParte – rozhraní aplikace
   Rozvržení: vlevo panel s kroky, vpravo „stůl“ s živým náhledem listu.
   Na mobilu jeden sloupec, náhled se otevírá přes celou obrazovku.
   ========================================================================== */

:root {
  /* Barvy – chladná šedá s nádechem fialové (liturgická barva smutku) */
  --bg: #f3f2f6;
  --surface: #ffffff;
  --desk: #e6e4ec;
  --ink: #1d1b24;
  --muted: #615e6d;
  --line: #dcd9e3;
  --accent: #4a3d6e;
  --accent-ink: #ffffff;
  --accent-soft: #ebe7f4;
  --danger: #a3323a;
  --warn: #7a4b00;
  --warn-soft: #fbedd0;
  --shadow-paper: 0 1px 2px rgb(30 25 45 / .08), 0 12px 32px -8px rgb(30 25 45 / .22);

  /* Písma */
  --font-ui: 'Figtree', 'Segoe UI', system-ui, sans-serif;
  --font-display: 'Spectral', Georgia, serif;
  --font-verse: 'EB Garamond', Garamond, Georgia, serif;

  /* Typografická stupnice – spíš větší, web používají i starší lidé */
  --fs-xs: .875rem;
  --fs-sm: .9375rem;
  --fs-md: 1rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.875rem;

  --radius: 10px;
  --topbar-h: 64px;
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16151b;
    --surface: #1e1d24;
    --desk: #0f0e13;
    --ink: #ebe9f2;
    --muted: #a3a0af;
    --line: #34323e;
    --accent: #b8aae2;
    --accent-ink: #17141f;
    --accent-soft: #2a2638;
    --danger: #f08a90;
    --warn: #f3c46b;
    --warn-soft: #3a2e17;
    --shadow-paper: 0 1px 2px rgb(0 0 0 / .4), 0 16px 40px -8px rgb(0 0 0 / .7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16151b;
  --surface: #1e1d24;
  --desk: #0f0e13;
  --ink: #ebe9f2;
  --muted: #a3a0af;
  --line: #34323e;
  --accent: #b8aae2;
  --accent-ink: #17141f;
  --accent-soft: #2a2638;
  --danger: #f08a90;
  --warn: #f3c46b;
  --warn-soft: #3a2e17;
  --shadow-paper: 0 1px 2px rgb(0 0 0 / .4), 0 16px 40px -8px rgb(0 0 0 / .7);
  color-scheme: dark;
}

/* ---------- Základ ---------- */

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

/* Atribut hidden musí vyhrát i nad display u tříd (.btn, .custom-verse …) */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--fs-md)/1.55 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { text-wrap: balance; }

a { color: var(--accent); text-underline-offset: .2em; }

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

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Horní lišta ---------- */

body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 10;
  background: var(--surface);
}

.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar__inner {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  height: var(--topbar-h);
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: .1em;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 500;
  letter-spacing: -.005em;
  text-decoration: none;
}
.brand__cross {
  align-self: center;
  width: .5em;
  height: .72em;
  margin-right: .3em;
  background:
    linear-gradient(currentColor 0 0) 50% 0 / 14% 100% no-repeat,
    linear-gradient(currentColor 0 0) 50% 28% / 100% 13% no-repeat;
}
.brand__tld { color: var(--muted); font-weight: 300; }

.topbar__tag {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.topbar__actions {
  display: flex;
  gap: .5rem;
  margin-left: auto;
}

/* ---------- Tlačítka ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: 44px;
  padding: .5rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: 500 var(--fs-sm)/1.2 var(--font-ui);
  cursor: pointer;
  text-decoration: none;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { border-color: var(--muted); }
.btn svg { width: 1.1em; height: 1.1em; flex: none; }

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

.btn--quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn--quiet:hover { border-color: var(--line); color: var(--ink); }

.btn--danger { border-color: var(--danger); color: var(--danger); }

.btn--wide { width: 100%; min-height: 52px; font-size: var(--fs-md); }

/* ---------- Rozvržení aplikace ---------- */

.app {
  display: grid;
  grid-template-columns: minmax(360px, 500px) minmax(0, 1fr);
  align-items: start;
}

.panel {
  min-width: 0;
  padding-block: 1.5rem 3rem;
  padding-left: var(--gutter-l);
  padding-right: 1.75rem;
  background: var(--surface);
  border-right: 1px solid var(--line);
  min-height: calc(100dvh - var(--topbar-h));
}

.stage {
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + var(--topbar-h));
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top, 0px));
  padding-block: 1.25rem;
  padding-left: 2rem;
  padding-right: var(--gutter-r);
  background: var(--desk);
}

/* ---------- Kroky ---------- */

.stepper {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .375rem;
  margin: 0 0 1.75rem;
  padding: 0;
  list-style: none;
}

.stepper__btn {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  width: 100%;
  padding: .6rem .7rem .65rem;
  border: 0;
  border-top: 3px solid var(--line);
  background: none;
  color: var(--muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.stepper__btn:hover { color: var(--ink); }
.stepper__btn[aria-selected="true"] { border-top-color: var(--accent); color: var(--ink); }

.stepper__label {
  font-size: var(--fs-sm);
  font-weight: 600;
}
.stepper__label b {
  font-weight: 600;
  color: var(--accent);
  margin-right: .3em;
  font-variant-numeric: tabular-nums;
}
.stepper__summary {
  overflow: hidden;
  font-size: var(--fs-xs);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.step {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.step__title {
  margin: 0 0 .35rem;
  padding: 0;
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 500;
  line-height: 1.15;
}
.step__hint {
  max-width: 52ch;
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.step__group + .step__group { margin-top: 2rem; }
.step__group-title {
  margin: 0 0 .75rem;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel__nav {
  display: flex;
  gap: .75rem;
  justify-content: space-between;
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}
.panel__nav [data-nav="next"] { margin-left: auto; }

/* ---------- Pole formuláře ---------- */

.fields { display: flex; flex-direction: column; gap: 1.35rem; }

.field { display: flex; flex-direction: column; gap: .4rem; }

.field__label {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: var(--fs-sm);
  font-weight: 600;
}
.field__opt { color: var(--muted); font-weight: 400; }

.field__hint { margin: 0; color: var(--muted); font-size: var(--fs-xs); }

.field__error {
  margin: 0;
  color: var(--danger);
  font-size: var(--fs-xs);
  font-weight: 500;
}

.input {
  width: 100%;
  min-height: 46px;
  padding: .65rem .8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  line-height: 1.45;
  transition: border-color .15s, background-color .15s;
}
.input::placeholder { color: var(--muted); opacity: .75; }
.input:hover { border-color: var(--muted); }
.input:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"] { border-color: var(--danger); }

textarea.input { resize: vertical; field-sizing: content; min-height: 4.6em; }
.input--name { font-family: var(--font-verse); font-size: 1.375rem; }

/* Návrhy běžných formulací */
.suggest {
  display: flex;
  flex-wrap: wrap;
  gap: .375rem;
}
.suggest__label { width: 100%; color: var(--muted); font-size: var(--fs-xs); }
.chip {
  max-width: 100%;
  padding: .3rem .7rem;
  border: 1px dashed var(--line);
  border-radius: 999px;
  background: none;
  color: var(--ink);
  font: var(--fs-xs)/1.35 var(--font-ui);
  text-align: left;
  cursor: pointer;
}
.chip:hover { border-style: solid; border-color: var(--accent); color: var(--accent); }

/* Přepínač zesnulý / zesnulá */
.segmented {
  display: inline-flex;
  align-self: flex-start;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
}
.segmented label {
  position: relative;
  padding: .4rem 1rem;
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Volby (motiv, verš, rámeček, písmo, formát) ---------- */

.choices {
  display: grid;
  gap: .625rem;
  margin: 0;
  padding: 0;
  border: 0;
}
.choices--motiv  { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.choices--ramecek { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
.choices--pismo,
.choices--format { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.choices--vers   { grid-template-columns: 1fr; }

.choice { position: relative; display: block; min-width: 0; }
.choice__input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.choice__card {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  height: 100%;
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color .15s, background-color .15s, box-shadow .15s;
  pointer-events: none;
}
.choice:hover .choice__card { border-color: var(--muted); }
.choice__input:checked + .choice__card {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.choice__input:focus-visible + .choice__card { outline: 2px solid var(--accent); outline-offset: 2px; }

.choice__name { font-size: var(--fs-xs); font-weight: 500; line-height: 1.3; }
.choice__desc { color: var(--muted); font-size: var(--fs-xs); line-height: 1.35; }

/* Motiv: obrázek na „papíře“ */
.choices--motiv .choice__card { align-items: center; text-align: center; padding: .5rem .5rem .6rem; }
.choice__img {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  background: var(--paper);
}
.choice__img img {
  position: absolute;
  inset: 14%;
  width: 72%;
  height: 72%;
  object-fit: contain;
}
.choice__img--none::before {
  content: "";
  width: 46%;
  aspect-ratio: 1;
  border: 1px dashed var(--paper-hint);
  border-radius: 4px;
}

/* Rámeček: zmenšený list se stejnými třídami jako náhled */
.choices--ramecek .choice__card { align-items: center; text-align: center; }
.choice__sheet { display: block; width: 62%; box-shadow: 0 0 0 1px var(--line); }

/* Písmo: ukázka jména */
.choice__sample {
  font-size: 1.6rem;
  line-height: 1.1;
  color: var(--ink);
}

/* Verš */
.choices--vers .choice__card { gap: .35rem; padding: .85rem 1rem; }
.choice__verse {
  font-family: var(--font-verse);
  font-size: 1.0625rem;
  font-style: italic;
  line-height: 1.4;
  white-space: pre-line;
}
.choice__author { color: var(--muted); font-size: var(--fs-xs); letter-spacing: .04em; }
.choice__name--option { font-size: var(--fs-sm); }

.custom-verse {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  margin-top: .75rem;
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--bg);
}

/* ---------- Dokončení ---------- */

.finish {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  margin-top: 2rem;
  padding: 1.25rem;
  border-radius: var(--radius);
  background: var(--accent-soft);
}
.finish__title { margin: 0; font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 500; }
.finish__text { margin: 0; color: var(--muted); font-size: var(--fs-sm); }
.finish__note {
  margin: 0;
  padding: .75rem .9rem;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  font-size: var(--fs-sm);
}

.saved-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem .75rem;
  margin-top: 1.5rem;
  color: var(--muted);
  font-size: var(--fs-xs);
}

/* ---------- Náhled ---------- */

.stage__bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  min-height: 36px;
  margin-bottom: 1rem;
  color: var(--muted);
  font-size: var(--fs-sm);
}
.stage__title { margin: 0; font-size: var(--fs-sm); font-weight: 600; color: var(--ink); }
.stage__actions { display: none; }
.stage__warn {
  padding: .2rem .6rem;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: var(--fs-xs);
  font-weight: 500;
}

.stage__sheet {
  display: flex;
  flex: 1;
  min-height: 0;
  align-items: flex-start;
  justify-content: center;
}

.stage .parte {
  width: min(100%, calc((100dvh - var(--topbar-h) - 7rem) * 210 / 297));
  box-shadow: var(--shadow-paper);
}

/* A5 2× na A4: naznačit polovinu listu */
.stage__sheet[data-format="a5x2"] .parte { width: min(100%, calc((100dvh - var(--topbar-h) - 7rem) * 210 / 297 * .82)); }

/* ---------- Patička ---------- */

.footer {
  padding-block: 2.5rem;
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
  border-top: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  font-size: var(--fs-sm);
}
.footer__inner {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 2rem;
  max-width: 1100px;
}
.footer h2 {
  margin: 0 0 .5rem;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink);
}
.footer ol, .footer ul { margin: 0; padding-left: 1.1rem; }
.footer li + li { margin-top: .3rem; }
.footer__copy { margin: 0; }

/* ---------- Mobilní lišta s náhledem ---------- */

.mobilebar { display: none; }

@media (max-width: 860px) {
  :root {
    --topbar-h: 56px;
    /* Na mobilu ještě o stupeň větší písmo */
    --fs-xs: .9375rem;
    --fs-sm: 1rem;
    --fs-md: 1.0625rem;
    --fs-xl: 1.75rem;
  }

  .topbar__tag { display: none; }
  .brand { font-size: 1.4rem; }

  .app { grid-template-columns: minmax(0, 1fr); }

  .panel {
    padding-block: 1.25rem 2rem;
    padding-right: var(--gutter-r);
    border-right: 0;
    min-height: 0;
  }

  .stepper { gap: .25rem; }
  .stepper__btn { padding-inline: .2rem; }
  .stepper__summary { display: none; }

  /* Náhled jako vrstva přes celou obrazovku */
  .stage {
    position: fixed;
    inset: 0;
    z-index: 20;
    height: auto;
    padding-top: calc(env(safe-area-inset-top, 0px) + .75rem);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
    padding-left: var(--gutter-l);
    overflow-y: auto;
  }
  .stage:not(.is-open) { display: none; }
  .stage__actions {
    position: sticky;
    bottom: 0;
    display: flex;
    gap: .5rem;
    margin-top: 1rem;
    padding-block: .6rem calc(env(safe-area-inset-bottom, 0px) + .6rem);
    background: var(--desk);
  }
  .stage__actions .btn { flex: 1; }
  .stage .parte,
  .stage__sheet[data-format="a5x2"] .parte { width: min(100%, 560px); }

  .mobilebar {
    position: sticky;
    bottom: 0;
    z-index: 4;
    display: flex;
    gap: .5rem;
    padding-block: .6rem calc(env(safe-area-inset-bottom, 0px) + .6rem);
    padding-left: var(--gutter-l);
    padding-right: var(--gutter-r);
    background: var(--surface);
    border-top: 1px solid var(--line);
  }
  .mobilebar .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- Tisk přímo z prohlížeče ---------- */

@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  body::before, .topbar, .panel, .footer, .mobilebar, .stage__bar { display: none !important; }
  .app { display: block; }
  .stage { position: static; display: block !important; height: auto; padding: 0; background: none; }
  .stage .parte { width: 210mm !important; box-shadow: none; }
}

/* ---------- Samostatná zpráva (chybová stránka) ---------- */

.message {
  max-width: 36rem;
  margin: 0 auto;
  padding-block: 4rem;
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
}
