:root {
  --bg: #faf6ef;
  --card: #ffffff;
  --ink: #241d19;
  --muted: #7b6f66;
  --line: #eadfce;
  --brand: #d6401f;
  --brand-2: #f06b2a;
  --brand-ink: #ffffff;
  --ok: #2b7a4b;
  --ok-bg: #e3f3e9;
  --warn: #9a5b00;
  --warn-bg: #fff0d6;
  --err: #b3261e;
  --err-bg: #fde7e4;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(60, 30, 10, 0.06), 0 8px 24px rgba(60, 30, 10, 0.07);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15110e;
    --card: #211b17;
    --ink: #f5ede5;
    --muted: #a99c90;
    --line: #36291f;
    --brand: #ff6a45;
    --brand-2: #ff9a3c;
    --brand-ink: #1a0d07;
    --ok: #6fd39a;
    --ok-bg: #173324;
    --warn: #ffc468;
    --warn-bg: #3a2a10;
    --err: #ff8b80;
    --err-bg: #3b1a17;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}
#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
main { flex: 1; padding: 20px 16px 110px; }
h1 { font-size: 26px; line-height: 1.15; margin: 4px 0 6px; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin: 24px 0 10px; letter-spacing: -0.01em; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
a { color: var(--brand); }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; letter-spacing: -0.02em; }
.logo { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); display: grid; place-items: center; color: #fff; font-weight: 800; }
.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.points {
  background: linear-gradient(140deg, var(--brand), var(--brand-2));
  color: #fff;
  border: 0;
  position: relative;
  overflow: hidden;
}
.points .venue { font-weight: 700; opacity: 0.95; }
.points .big { font-size: 56px; font-weight: 800; line-height: 1; letter-spacing: -0.04em; margin: 10px 0 2px; }
.points .sub { opacity: 0.9; font-size: 14px; margin-bottom: 14px; }
.points::after { content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; background: rgba(255, 255, 255, 0.12); }
.points .btn { background: rgba(255, 255, 255, 0.22); color: #fff; box-shadow: none; }
.points .btn.solid { background: #fff; color: var(--brand); }
@media (prefers-color-scheme: dark) { .points .btn.solid { color: #7a2410; } }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; }
.stack > * + * { margin-top: 12px; }

label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 14px; padding: 13px 14px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
input.code { font-size: 28px; letter-spacing: 0.35em; text-align: center; font-weight: 700; }
input.upper { text-transform: uppercase; }

.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 700;
  padding: 14px 18px; border-radius: 14px; background: var(--brand); color: var(--brand-ink);
  min-height: 48px; text-align: center; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(0.98); }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--brand); border: 1.5px solid var(--line); }
.btn.soft { background: color-mix(in srgb, var(--brand) 12%, var(--card)); color: var(--brand); }
.btn[disabled] { opacity: 0.55; pointer-events: none; }

.seg { display: flex; background: color-mix(in srgb, var(--ink) 7%, var(--bg)); border-radius: 14px; padding: 4px; gap: 4px; margin-bottom: 16px; }
.seg button { flex: 1; border: 0; background: transparent; font: inherit; font-weight: 600; font-size: 14px; padding: 10px 6px; border-radius: 11px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs nav { max-width: 480px; margin: 0 auto; display: flex; }
.tabs a { flex: 1; text-align: center; padding: 10px 4px 12px; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 600; }
.tabs a.on { color: var(--brand); }
.tabs svg { display: block; margin: 0 auto 3px; width: 24px; height: 24px; }

.chip { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.err { background: var(--err-bg); color: var(--err); }

.notice { border-radius: 14px; padding: 12px 14px; font-size: 14px; margin: 12px 0; background: var(--warn-bg); color: var(--warn); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.err { background: var(--err-bg); color: var(--err); }

.qrbox { background: #fff; border-radius: 22px; padding: 14px; box-shadow: var(--shadow); width: min(100%, 320px); margin: 10px auto 14px; }
.qrbox svg { display: block; width: 100%; height: auto; }
.codeText { font: 700 26px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.12em; text-align: center; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.plus { color: var(--ok); font-weight: 700; }
.minus { color: var(--err); font-weight: 700; }

.gift {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; text-decoration: none; color: inherit;
}
.gift .val { font-size: 28px; font-weight: 800; letter-spacing: -0.03em; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.stat b { display: block; font-size: 26px; letter-spacing: -0.03em; }
.stat span { color: var(--muted); font-size: 13px; }

.result { text-align: center; padding: 26px 16px; }
.result .tick { width: 64px; height: 64px; border-radius: 50%; background: var(--ok-bg); color: var(--ok); display: grid; place-items: center; margin: 0 auto 12px; font-size: 32px; font-weight: 800; }
.result .num { font-size: 44px; font-weight: 800; letter-spacing: -0.03em; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 14px; max-width: min(92vw, 440px); font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
}
.toast.err { background: var(--err); color: #fff; }

.scanner { position: fixed; inset: 0; z-index: 60; background: #000; display: flex; flex-direction: column; }
.scanner video { flex: 1; width: 100%; object-fit: cover; }
.scanner .bar { padding: 14px; display: flex; gap: 10px; align-items: center; color: #fff; background: #000; }
.scanner .bar span { flex: 1; font-size: 14px; }
.scanner .frame { position: absolute; inset: 22% 14% auto; aspect-ratio: 1; border: 3px solid rgba(255, 255, 255, 0.85); border-radius: 22px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.45); pointer-events: none; }

.hero { padding: 40px 0 8px; }
.hero .logo { width: 56px; height: 56px; border-radius: 16px; font-size: 28px; margin-bottom: 18px; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.points .expiry { font-size: 13px; opacity: 0.9; margin: -8px 0 14px; }
.points .expiry.soon { opacity: 1; font-weight: 700; background: rgba(255, 255, 255, 0.22); display: inline-block; padding: 3px 10px; border-radius: 99px; }

.doc h1 { font-size: 28px; }
.doc h2 { font-size: 19px; margin: 28px 0 8px; }
.doc ol, .doc ul { padding-left: 22px; margin: 0 0 12px; }
.doc li { margin-bottom: 6px; }
.todo { background: var(--warn-bg); color: var(--warn); padding: 1px 6px; border-radius: 6px; font-weight: 600; font-size: 0.92em; }

/* ---- okazje i obracana karta ---- */
.mini { flex: none; width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 24px; background: linear-gradient(135deg, var(--c1), var(--c2)); }
.flip { perspective: 1000px; width: min(100%, 340px); aspect-ratio: 4 / 5; margin: 14px auto 0; cursor: pointer; text-align: left; -webkit-tap-highlight-color: transparent; }
.flip:focus-visible { outline: 3px solid var(--brand); outline-offset: 4px; border-radius: 26px; }
.flip-in { position: relative; width: 100%; height: 100%; transition: transform 0.7s cubic-bezier(0.3, 0.7, 0.2, 1); transform-style: preserve-3d; }
.flip.flipped .flip-in { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; border-radius: 26px; backface-visibility: hidden; -webkit-backface-visibility: hidden; box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 22px; text-align: center; }
.face.front { background: linear-gradient(145deg, var(--c1), var(--c2)); color: #fff; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.28); }
.face.back { background: #fff; color: #241d19; transform: rotateY(180deg); gap: 12px; }
.confetti { position: absolute; inset: 0; opacity: 0.22; pointer-events: none;
  background-image: radial-gradient(circle, #fff 3px, transparent 4px), radial-gradient(circle, #fff 2px, transparent 3px), radial-gradient(circle, #fff 5px, transparent 6px);
  background-size: 70px 70px, 46px 46px, 110px 110px; background-position: 0 0, 20px 30px, 50px 10px; }
.face .emoji { font-size: 84px; line-height: 1; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.25)); position: relative; }
.face .occ { font-size: 22px; font-weight: 800; margin-top: 10px; position: relative; }
.face .amt { font-size: 46px; font-weight: 800; letter-spacing: -0.03em; margin-top: 6px; position: relative; }
.face .meta { font-size: 13px; opacity: 0.95; margin-top: 4px; position: relative; }
.face .tap { position: absolute; bottom: 14px; left: 0; right: 0; font-size: 12px; opacity: 0.9; text-shadow: none; }
.face .tap.dark { color: #6b5f56; }
.qrwrap { width: 100%; max-width: 240px; }
.qrwrap svg { display: block; width: 100%; height: auto; }
@media (prefers-reduced-motion: reduce) { .flip-in { transition: none; } }

.occs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.occ-btn { appearance: none; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; padding: 9px 12px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); min-height: 44px; }
.occ-btn.on { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 14%, var(--card)); color: var(--brand); }
.occprev { margin-top: 10px; border-radius: 16px; padding: 14px; display: flex; align-items: center; gap: 12px; font-weight: 800; color: #fff; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.28); background: linear-gradient(135deg, var(--c1), var(--c2)); }
.occprev .emoji { font-size: 34px; }

.badge { position: absolute; top: 14px; left: 14px; z-index: 1; background: #fff; color: #7a2410; font-size: 11px; font-weight: 800; letter-spacing: 0.08em; padding: 4px 9px; border-radius: 999px; text-shadow: none; }
.face.has-img { justify-content: flex-end; padding-bottom: 44px; }
.face.has-img .emoji { display: none; }
.mini { background-size: cover; background-position: center; }
.occ-btn .thumb { width: 22px; height: 22px; border-radius: 6px; background-size: cover; background-position: center; display: inline-block; }
.occrow { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.occrow .btn { min-height: 40px; padding: 8px 12px; }
.occprev { background-size: cover; background-position: center; min-height: 64px; }
input[type="color"] { width: 64px; height: 44px; padding: 2px; border-radius: 10px; }
input[type="file"] { width: 100%; }

.cond { font-size: 15px; font-weight: 600; margin-top: 6px; position: relative; padding: 0 6px; }
.list-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row > span:first-child { flex: 1 1 150px; }
.btn.sm { min-height: 38px; padding: 6px 12px; font-size: 14px; border-radius: 12px; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 600; }
.check input { width: 20px; height: 20px; }
.seg button { padding-left: 6px; padding-right: 6px; }

/* ---- wydruk kuponów (A4) ---- */
#print-area { display: none; }
@media print {
  @page { size: A4; margin: 8mm; }
  body > *:not(#print-area) { display: none !important; }
  body { background: #fff !important; }
  #print-area { display: block; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet { display: grid; width: 194mm; height: 281mm; page-break-after: always; break-after: page; }
  .sheet:last-child { page-break-after: auto; break-after: auto; }
  .pc { border: 0.3mm dashed #777; padding: 3mm; display: flex; flex-direction: column; gap: 1.5mm; overflow: hidden; font-family: system-ui, Arial, sans-serif; text-align: center; }
  .pc-art { width: 100%; flex: 0 0 auto; height: 12mm; border-radius: 3mm; display: grid; place-items: center; font-size: 7mm; line-height: 1; background: linear-gradient(135deg, var(--c1), var(--c2)); }
  .pc-art.has-img { background-size: cover; background-position: center; height: 24mm; }
  #print-area, #print-area * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pc-main { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 1.5mm; }
  .pc-text { display: flex; flex-direction: column; gap: 1mm; align-items: center; }
  .pc-title { font-weight: 800; font-size: 4.6mm; line-height: 1.1; }
  .pc-cond { font-size: 3.2mm; line-height: 1.15; }
  .pc-qr { width: min(100%, 34mm); flex: none; }
  .pc-qr svg { display: block; width: 100%; height: auto; }
  .pc-code { font: 700 3.4mm ui-monospace, Consolas, monospace; letter-spacing: 0.08em; }
  .pc-meta { font-size: 2.7mm; line-height: 1.25; color: #333; }
  /* 8 i 10 na stronie: kupon szeroki i niski, więc QR po lewej, tekst po prawej */
  .wide .pc-art { height: 9mm; font-size: 5.5mm; }
  .wide .pc-art.has-img { height: 17mm; }
  .wide .pc-main { flex-direction: row; align-items: center; justify-content: flex-start; gap: 4mm; }
  .wide .pc-text { align-items: flex-start; text-align: left; }
  .wide .pc-qr { width: 29mm; }
  .wide .pc-title { font-size: 4.2mm; }
  /* 12 i 16 na stronie: wąski kupon, układ pionowy, mniejsze elementy */
  .dense .pc { padding: 2mm; gap: 1mm; }
  .dense .pc-art { height: 8mm; font-size: 5mm; }
  .dense .pc-art.has-img { height: 14mm; }
  .dense .pc-title { font-size: 3.6mm; }
  .dense .pc-cond { font-size: 2.6mm; }
  .dense .pc-qr { width: min(100%, 25mm); }
  .dense .pc-code { font-size: 2.8mm; }
  .dense .pc-meta { font-size: 2.2mm; }
}
a.occ-btn { text-decoration: none; }

/* Panel właściciela: zwijane grupy sekcji */
details.grp { margin-top: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); padding: 0 14px; }
details.grp > summary { list-style: none; cursor: pointer; padding: 14px 0; display: flex; flex-direction: column; gap: 2px; font-weight: 700; font-size: 17px; }
details.grp > summary::-webkit-details-marker { display: none; }
details.grp > summary::after { content: "▾"; position: absolute; right: 14px; color: var(--muted); }
details.grp > summary { position: relative; padding-right: 24px; }
details.grp[open] > summary::after { content: "▴"; }
details.grp[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: 4px; }
details.grp > summary small { font-weight: 400; font-size: 12px; }
details.grp > h2:first-of-type { margin-top: 10px; }
details.grp { padding-bottom: 6px; }
