:root {
  --accent: #720546;
  --accent-2: #9b0b62;
  --bg: #f3f2f5;
  --panel: #ffffff;
  --ink: #1b1b22;
  --muted: #6b6a75;
  --line: #e2e0e6;
  --stage: #2a2a33;
  --radius: 10px;
  --top-h: 52px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.fatal { padding: 40px; text-align: center; color: var(--muted); }

/* ---------------------------------------------------------------- górny pasek */
.topbar {
  height: var(--top-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 14px;
  background: #16161d; color: #fff;
}
.topbar .brand { font-weight: 800; letter-spacing: .02em; }
.topbar .title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .btn.ghost { color: #fff; border-color: #ffffff40; }

/* ---------------------------------------------------------------- przyciski */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fff; cursor: pointer; text-decoration: none; color: var(--ink);
  white-space: nowrap; user-select: none;
}
.btn:hover:not(:disabled) { border-color: #c8c5cf; background: #faf9fb; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: #b00020; }
.btn.small { min-height: 30px; padding: 3px 10px; font-size: 13px; }
.btn.big { min-height: 46px; padding: 8px 18px; font-size: 16px; }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.btnrow .muted { flex: 1 1 100%; }

/* ---------------------------------------------------------------- strona główna */
.home { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.home h1 { font-size: 22px; margin: 6px 0 16px; }
.tgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.tcard {
  display: flex; flex-direction: column; text-decoration: none; color: inherit;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  transition: transform .12s, box-shadow .12s;
}
.tcard:hover { transform: translateY(-2px); box-shadow: 0 8px 22px #0000001a; }
.tcard .thumb { aspect-ratio: 4 / 5; background: #ddd; display: grid; place-items: center; overflow: hidden; }
.tcard .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tcard .tname { font-weight: 700; padding: 10px 12px 2px; }
.tcard .tmeta { font-size: 13px; color: var(--muted); padding: 0 12px 12px; }
.banner { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; }
.banner.warn { background: #fff4d6; border: 1px solid #f0d58a; }

/* ---------------------------------------------------------------- edytor – układ */
.editor {
  display: grid;
  grid-template-columns: minmax(340px, 420px) 1fr;
  grid-template-areas: "panel preview";
  height: calc(100dvh - var(--top-h));
}
.panel { grid-area: panel; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 4px 14px 40px; }
.preview {
  grid-area: preview; overflow: auto; background: var(--stage); color: #eee;
  display: flex; flex-direction: column; align-items: stretch; gap: 10px; padding: 12px 16px 16px;
}

/* ---------------------------------------------------------------- panel */
.sec { padding: 12px 0 6px; border-bottom: 1px solid var(--line); }
.sec:last-child { border-bottom: 0; }
.sec h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span { font-size: 13px; font-weight: 600; }
.field input, .field textarea, .field select {
  width: 100%; min-height: 40px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
  font-size: 16px; /* 16px = iOS nie powiększa strony przy pisaniu */
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field textarea:focus, .field select:focus, .num:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field .note { color: var(--muted); }
.field.compact { margin-bottom: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; background: #fff; transition: border-color .15s, box-shadow .15s; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px #72054626; }
.card.drop { border-style: dashed; border-color: var(--accent); background: #fbf3f8; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head strong { flex: 1; }
.badge { font-size: 11px; font-weight: 700; letter-spacing: .04em; background: #efe9f0; color: var(--accent); border-radius: 99px; padding: 2px 8px; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; background: #f1eff3; padding: 3px; border-radius: 9px; margin-bottom: 8px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; min-height: 32px; }
.seg button.on { background: #fff; box-shadow: 0 1px 3px #0000002a; font-weight: 600; color: var(--accent); }

.filerow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }

details.group { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 6px; }
details.group > summary { cursor: pointer; font-size: 13px; font-weight: 700; color: var(--muted); padding: 4px 0; list-style-position: inside; }

.slider { display: grid; grid-template-columns: 1fr 76px; grid-template-areas: "lab lab" "rng num"; align-items: center; column-gap: 10px; margin: 6px 0 8px; }
.slider .lab { grid-area: lab; font-size: 13px; cursor: default; user-select: none; }
.slider .lab small { color: var(--muted); }
.slider input[type=range] { grid-area: rng; width: 100%; accent-color: var(--accent); height: 28px; margin: 0; touch-action: pan-y; }
.slider .num { grid-area: num; width: 100%; min-height: 34px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 7px; font-size: 15px; text-align: right; }

.check { display: inline-flex; align-items: center; gap: 8px; margin: 6px 12px 6px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.color { display: inline-flex; align-items: center; gap: 8px; margin: 6px 12px 6px 0; cursor: pointer; }
.color input { width: 42px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 7px; background: #fff; cursor: pointer; }
.subrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.subrow .seg { margin-bottom: 0; }

/* ---------------------------------------------------------------- podgląd */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.tabs button {
  border: 1px solid #ffffff2e; background: transparent; color: #ddd; border-radius: 99px;
  padding: 5px 14px; cursor: pointer; min-height: 32px;
}
.tabs button.on { background: #fff; color: var(--ink); border-color: #fff; font-weight: 600; }

.preview > * { flex-shrink: 0; }
.chips { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center; font-size: 13px; }
.chips:empty { display: none; }
.chips .muted { color: #aaa; }
.chips button { border: 1px solid #ffffff33; background: #ffffff10; color: #eee; border-radius: 99px; padding: 3px 11px; cursor: pointer; min-height: 28px; }
.chips button.on { background: #ffd400; color: #111; border-color: #ffd400; font-weight: 600; }

.canvases { flex: 1 1 auto; display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; align-items: flex-start; }
.pv-card { margin: 0; display: flex; flex-direction: column; gap: 6px; max-width: 100%; }
.pv-card figcaption { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; font-weight: 700; letter-spacing: .05em; color: #bbb; }
.pv-card figcaption .btn { background: #ffffff14; color: #eee; border-color: #ffffff30; }
.pv-card.active figcaption > span { color: #ffd400; }
.cv-wrap { position: relative; line-height: 0; }
.cv {
  display: block; width: auto; height: auto; max-width: 100%;
  max-height: calc(100dvh - var(--top-h) - 190px);
  min-width: 120px; min-height: 120px;
  background: #3a3a44; border-radius: 4px; box-shadow: 0 6px 30px #0000005c;
  touch-action: none; cursor: grab; -webkit-user-select: none; user-select: none;
}
.cv:active { cursor: grabbing; }
.cv.drop { outline: 3px dashed #ffd400; outline-offset: 4px; }
.canvases.n3 .cv, .canvases.carousel:not(.n1) .cv { max-height: 44dvh; }
.cv-msg { position: absolute; inset: 0; display: grid; place-items: center; line-height: 1.3; color: #ccc; pointer-events: none; font-size: 14px; }
.cv-msg:empty { display: none; }
.hint { margin: 0; text-align: center; font-size: 12.5px; color: #a9a8b2; }
.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px);
  background: #16161d; color: #fff; padding: 10px 16px; border-radius: 10px; max-width: min(92vw, 520px);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- telefon / wąski ekran */
@media (max-width: 899px) {
  .editor { display: block; height: auto; }
  .preview {
    position: sticky; top: 0; z-index: 10;
    padding: 8px 10px 8px; gap: 6px; overflow: visible;
    box-shadow: 0 4px 14px #00000040;
  }
  .cv { max-height: 35dvh; min-width: 80px; min-height: 80px; }
  .canvases { gap: 10px; flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; }
  .canvases.n1 { justify-content: center; }
  .canvases.n1 figcaption { display: none; }
  .canvases:not(.n1) .cv { max-height: 32dvh; }
  .pv-card figcaption { font-size: 11px; }
  .pv-card figcaption .btn { display: none; }
  .tabs button { padding: 3px 12px; min-height: 30px; font-size: 14px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; scrollbar-width: none; }
  .chips > * { flex: 0 0 auto; }
  .hint { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .actions {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: #16161df2; backdrop-filter: blur(6px);
  }
  .actions .btn.big { flex: 1 1 0; min-height: 46px; font-size: 15px; padding: 6px 10px; white-space: normal; text-align: center; line-height: 1.15; }
  .panel { border-right: 0; padding: 4px 12px calc(96px + env(safe-area-inset-bottom)); overflow: visible; }
  .topbar { padding: 0 10px; }
}
@media (max-width: 899px) and (max-height: 560px) {
  /* telefon poziomo – podgląd nie przyklejony, żeby dało się przewijać */
  .preview { position: static; }
  .cv { max-height: 70dvh; }
}
