:root{
  --bg: #0f1115;
  --paper: #fbf6ea; /* już tylko awaryjnie */
  --ink: #1a1a1a;
  --shadow: 0 18px 60px rgba(0,0,0,.55);
  --radius: 18px;
  --page-pad: 26px;
  --page-border: rgba(0,0,0,.08);

  --spread-ar: 4 / 3;

  /* Feather (prostokątny) */
  --feather-y: 40px;
  --feather-x: 40px;
  --feather-boost: 6px;

  /* Jeśli kiedyś wrócisz do MIXED */
  --mixed-img-area: 58%;
  --mixed-gap: 14px;
  --mixed-feather-top: 16px;

  /* Typografia “książkowa” */
  --book-font: "Literata", ui-serif, Georgia, "Times New Roman", serif;

  /* TEXT-ONLY (prawa strona) */
  --text-color: rgba(26, 22, 18, 0.86);
  --text-font-size: 18px;
  --text-line-height: 1.65;
  --text-max-width: 88%;

  /* =========================
     PERGAMIN – ustaw ścieżkę
     ========================= */
  --parchment-url: url("assets/pergamin.jpg");

  /* Rozjaśnianie pergaminu */
  --parchment-wash: 0.75;

  /* Poświata u góry jak wcześniej */
  --parchment-highlight: radial-gradient(140% 120% at 50% 0%, rgba(255,255,255,.40) 0%, rgba(255,255,255,0) 55%);

  /* Delikatna winieta papieru */
  --parchment-vignette: radial-gradient(120% 120% at 50% 50%, rgba(0,0,0,0) 55%, rgba(0,0,0,.05) 100%);
}

*{ box-sizing: border-box; }
html,body{ height:100%; }

body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: radial-gradient(1200px 700px at 50% 15%, #1b2030 0%, var(--bg) 55%, #0b0c10 100%);
  color: #e8e8e8;
}

.app{
  min-height:100%;
  display:flex;
  flex-direction:column;
  gap: 14px;
  padding: 18px;
}

.toolbar{
  display:flex;
  align-items:center;
  justify-content:center;
  gap: 12px;
}

.toolbar button{
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.06);
  color: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
}
.toolbar button:active{ transform: translateY(1px); }

.status{
  min-width: 180px;
  text-align:center;
  font-size: 14px;
  opacity: .9;
}

.stage{
  display:flex;
  align-items:center;
  justify-content:center;
  flex: 1;
}

.book{
  --book-h: min(720px, 78vh);
  height: var(--book-h);
  width: min(calc(var(--book-h) * (4 / 3)), 96vw);

  position: relative;
  perspective: 1400px;
  outline: none;
}

/* Rozkładówka */
.spread{
  position:absolute;
  inset:0;
  display:grid;
  grid-template-columns: 1fr 1fr;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  background: rgba(255,255,255,.06);
}

/* Single-page wrapper (mobile) */
.spread.spread--single{
  grid-template-columns: 1fr;
}

/* Grzbiet */
.spread::after{
  content:"";
  position:absolute;
  top:0; bottom:0;
  left:50%;
  width: 2px;
  transform: translateX(-1px);
  background: rgba(0,0,0,.20);
  mix-blend-mode: multiply;
  pointer-events:none;
}

/* W single-page nie ma grzbietu */
.spread.spread--single::after{ display:none; }

/* Strona */
.page{
  position: relative;
  color: var(--ink);
  border: 1px solid var(--page-border);
  overflow:hidden;

  background:
    var(--parchment-highlight),
    var(--parchment-vignette),
    linear-gradient(rgba(255,255,255,var(--parchment-wash)), rgba(255,255,255,var(--parchment-wash))),
    var(--parchment-url);

  background-size: auto, auto, auto, cover;
  background-position: center, center, center, center;
  background-repeat: no-repeat, no-repeat, no-repeat, no-repeat;
}

.page--left{ border-right: none; }
.page--right{ border-left: none; }

/* Single-page: wyłącz “wewnętrzne” separatory */
.page.page--single{
  border-left: none;
  border-right: none;
}

.page__inner{
  position:absolute;
  inset:0;
  padding: var(--page-pad);
  display:flex;
}

/* Warstwy */
.page__layer{
  position:absolute;
  inset: var(--page-pad);
  display:flex;
  pointer-events:none;
}

/* Domyślny “dymek” */
.page__textBox{
  pointer-events:auto;
  max-width: 92%;
  max-height: 92%;
  overflow:auto;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(255,255,255,.72);
  box-shadow: 0 10px 30px rgba(0,0,0,.08);
}

.page__textBox p{
  margin: 0 0 10px 0;
  line-height: 1.45;
  font-size: 18px;
}
.page__textBox p:last-child{ margin-bottom: 0; }

/* Obraz */
.page__img{
  pointer-events:auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  object-fit: contain;

  -webkit-mask-image:
    linear-gradient(to bottom, rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--feather-y) + var(--feather-boost))),
    linear-gradient(to top,    rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--feather-y) + var(--feather-boost))),
    linear-gradient(to right,  rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--feather-x) + var(--feather-boost))),
    linear-gradient(to left,   rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--feather-x) + var(--feather-boost)));
  -webkit-mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;

  mask-image:
    linear-gradient(to bottom, rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--feather-y) + var(--feather-boost))),
    linear-gradient(to top,    rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--feather-y) + var(--feather-boost))),
    linear-gradient(to right,  rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--feather-x) + var(--feather-boost))),
    linear-gradient(to left,   rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--feather-x) + var(--feather-boost)));
  mask-size: 100% 100%;
  mask-repeat: no-repeat;
  mask-position: center;
  mask-composite: intersect;
}

/* PRAWA STRONA: TEXT-ONLY (czysto) */
.page--right[data-has-text="1"][data-has-image="0"] .page__textBox{
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  padding: 0;

  max-height: none;
  overflow: visible;

  max-width: var(--text-max-width);
  color: var(--text-color);
  font-family: var(--book-font);
  font-weight: 500;
}

.page--right[data-has-text="1"][data-has-image="0"] .page__textBox p{
  font-size: var(--text-font-size);
  line-height: var(--text-line-height);
  margin: 0 0 12px 0;
}
.page--right[data-has-text="1"][data-has-image="0"] .page__textBox p:last-child{
  margin-bottom: 0;
}

/* MIXED (na przyszłość) */
.page--right[data-has-text="1"][data-has-image="1"] .page__inner{
  display: grid;
  grid-template-rows: minmax(0, var(--mixed-img-area)) auto;
  row-gap: var(--mixed-gap);
  align-content: start;
}
.page--right[data-has-text="1"][data-has-image="1"] .page__layer{
  position: relative;
  inset: auto;
  width: 100%;
  pointer-events: none;
}
.page--right[data-has-text="1"][data-has-image="1"] .page__layer--img{
  grid-row: 1;
  min-height: 0;
  align-items: flex-start !important;
  justify-content: center !important;
}
.page--right[data-has-text="1"][data-has-image="1"] .page__layer--text{
  grid-row: 2;
  align-items: flex-start !important;
  justify-content: center !important;
}
.page--right[data-has-text="1"][data-has-image="1"] .page__textBox{
  max-height: none;
  overflow: visible;
  font-family: var(--book-font);
}
.page--right[data-has-text="1"][data-has-image="1"] .page__layer--img .page__img{
  -webkit-mask-image:
    linear-gradient(to bottom, rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--mixed-feather-top) + var(--feather-boost))),
    linear-gradient(to top,    rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--feather-y) + var(--feather-boost))),
    linear-gradient(to right,  rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--feather-x) + var(--feather-boost))),
    linear-gradient(to left,   rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--feather-x) + var(--feather-boost)));

  mask-image:
    linear-gradient(to bottom, rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--mixed-feather-top) + var(--feather-boost))),
    linear-gradient(to top,    rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--feather-y) + var(--feather-boost))),
    linear-gradient(to right,  rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--feather-x) + var(--feather-boost))),
    linear-gradient(to left,   rgba(0,0,0,0) 0, rgba(0,0,0,1) calc(var(--feather-x) + var(--feather-boost)));
}

/* Klikalne strefy */
.page__hotspot{
  position:absolute;
  inset:0;
  cursor: pointer;
  background: transparent;
}

.hint{
  text-align:center;
  font-size: 12px;
  opacity: .75;
}

/* =========================
   COPYRIGHT (desktop / non-mobile)
   ========================= */
.copyright{
  margin: 2px 0 0 0;
  text-align: center;
  font-size: 12px;
  line-height: 1.35;
  opacity: .65;
  color: rgba(232,232,232,.82);
}

/* UNDER-REVEAL / PREMIUM FLIP (desktop) */
.under-reveal{
  position:absolute;
  top:0; bottom:0;
  width:50%;
  overflow:hidden;
  z-index: 10;
  pointer-events:none;
}
.under-reveal--next{ left:50%; }
.under-reveal--prev{ left:0; }
.under-reveal--next{ border-radius: 0 var(--radius) var(--radius) 0; }
.under-reveal--prev{ border-radius: var(--radius) 0 0 var(--radius); }
.under-reveal .page{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  border: none;
}
.under-reveal .page__hotspot{ display:none; }

.flip-layer{
  position:absolute;
  top:0; bottom:0;
  width:50%;
  transform-style: preserve-3d;
  z-index: 50;
  pointer-events:none;
  will-change: transform;
}
.flip-layer--next{ left:50%; transform-origin: left center; }
.flip-layer--prev{ left:0;  transform-origin: right center; }

.flip-face{
  position:absolute;
  inset:0;
  backface-visibility:hidden;
  overflow:hidden;
  background:
    radial-gradient(140% 120% at 50% 0%, rgba(255,255,255,.55) 0%, rgba(255,255,255,0) 55%),
    var(--paper);
  border: 1px solid rgba(0,0,0,.10);
}
.flip-layer--next .flip-face{
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.flip-layer--prev .flip-face{
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
}
.flip-front{ transform: rotateY(0deg); }
.flip-back{ transform: rotateY(180deg); }

.flip-face .page{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  border: none;
}
.flip-face .page__hotspot{ display:none; }

.flip-shading{ position:absolute; inset:0; pointer-events:none; }
.flip-fold-shadow{ position:absolute; inset:0; opacity: var(--foldShadow, 0); }
.flip-glare{ position:absolute; inset:0; opacity: var(--glare, 0); mix-blend-mode: screen; }
.flip-cast{ position:absolute; inset:0; opacity: var(--castShadow, 0); pointer-events:none; }

.flip-layer--next .flip-fold-shadow{
  background: linear-gradient(to left, rgba(0,0,0,.36), rgba(0,0,0,0) 60%);
}
.flip-layer--prev .flip-fold-shadow{
  background: linear-gradient(to right, rgba(0,0,0,.36), rgba(0,0,0,0) 60%);
}
.flip-layer--next .flip-glare{
  background: linear-gradient(to left, rgba(255,255,255,.60), rgba(255,255,255,0) 55%);
}
.flip-layer--prev .flip-glare{
  background: linear-gradient(to right, rgba(255,255,255,.60), rgba(255,255,255,0) 55%);
}
.flip-layer--next .flip-cast{
  background: linear-gradient(to left, rgba(0,0,0,.30), rgba(0,0,0,0) 65%);
}
.flip-layer--prev .flip-cast{
  background: linear-gradient(to right, rgba(0,0,0,.30), rgba(0,0,0,0) 65%);
}

/* WYŁĄCZ FLIP KLIKNIĘCIEM + POZWÓL ZAZNACZAĆ TEKST */
.page, .page *{
  user-select: text;
  -webkit-user-select: text;
}
.page__hotspot{
  pointer-events: none;
  cursor: default;
}

/* =========================
   MOBILE single-page styling
   ========================= */
@media (max-width: 820px) and (orientation: portrait){
  :root{
    --page-pad: 18px;
    --radius: 16px;

    /* delikatniejszy feather na małym ekranie */
    --feather-y: 26px;
    --feather-x: 26px;

    /* tekst na mobile */
    --text-font-size: 17px;
    --text-line-height: 1.7;
    --text-max-width: 94%;
  }

  .app{ padding: 12px; gap: 10px; }

  .book{
    width: 96vw;
    height: min(84vh, 820px);
    perspective: 900px;
  }

  .spread{
    border-radius: 16px;
    box-shadow: 0 14px 40px rgba(0,0,0,.55);
  }

  .hint{ font-size: 12px; opacity: .7; }

  /* COPYRIGHT (mobile) */
  .copyright{
    font-size: 12px;
    line-height: 1.35;
    opacity: .62;
    margin-top: 0;
    padding-bottom: 4px;
  }
}