/* ==========================================================
   PF generátor – jedna responzivní aplikace (PC, tablet, mobil)
   ========================================================== */
:root {
    --red: #B3000C;
    --red-hover: #d90013;
    --green: #0F4928;
    --green-hover: #1a6a3e;
    --gold: #D4AF37;
    --gold-hover: #e6c04a;
    --cream: #fdfaf0;
    --stage: #efe9d6;
    --ink: #2b2b2b;
    --muted: #6d6a60;
    --line: #e4ddc8;
    --surface: #ffffff;
    --radius: 8px;
    --radius-sm: 6px;
    --shadow: 0 6px 22px rgba(15, 73, 40, .14);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, .10);
    --head-h: 58px;
    --ease: cubic-bezier(.2, .7, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: var(--cream);
    color: var(--ink);
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.ic {
    width: 20px; height: 20px; flex: none;
    fill: none; stroke: currentColor; stroke-width: 1.8;
    stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Rozložení aplikace ---------- */
.app {
    display: grid;
    grid-template-rows: var(--head-h) minmax(0, 1fr);
    height: 100vh; height: 100dvh;
    min-height: 600px;
}
.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 450px;
    min-height: 0;
}

/* ---------- Horní lišta ---------- */
.topbar {
    position: sticky; top: 0; z-index: 60;   /* hlavička zůstává vždy na očích, i když se stránka posune */
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 0 1rem;
    background: linear-gradient(180deg, #14603a 0%, var(--green) 100%);
    color: #fff;
    border-bottom: 2px solid var(--gold);
    overflow: hidden;
    z-index: 5;
}
.snow { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.brand { position: relative; display: flex; align-items: center; gap: .7rem; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.top-actions { flex: 0 0 auto; }
.brand-ic { width: 28px; height: 28px; color: var(--gold); fill: currentColor; stroke: none; }
.brand-text h1 {
    font-family: 'Merriweather', serif; font-weight: 700;
    font-size: 1.2rem; line-height: 1.2; white-space: nowrap;
}
.brand-text h1 span { color: var(--gold); }
.brand-text p { font-size: .78rem; opacity: .82; line-height: 1.2; white-space: nowrap; }
.top-actions { position: relative; display: flex; align-items: center; gap: .35rem; }

.tbtn {
    display: grid; place-items: center;
    width: 40px; height: 40px;
    background: transparent; color: #fff;
    border: 0; border-radius: var(--radius);
    transition: background .2s, opacity .2s;
}
.tbtn:hover:not(:disabled) { background: rgba(255, 255, 255, .14); }
.tbtn:disabled { opacity: .35; cursor: default; }

/* ---------- Tlačítka ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    min-height: 42px; padding: 0 1rem;
    border: 1.5px solid transparent; border-radius: var(--radius);
    font-weight: 500; font-size: .95rem; line-height: 1.2; text-align: center;
    transition: background .2s, transform .15s var(--ease), box-shadow .2s, border-color .2s;
    user-select: none; -webkit-user-select: none;
}
@media (hover: hover) { .btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); } }
.btn:active { transform: translateY(0) scale(.98); box-shadow: none; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-hover); }
.btn-gold { background: var(--gold); color: #2b2b2b; font-weight: 700; }
.btn-gold:hover { background: var(--gold-hover); }
.btn-outline { background: #fff; color: var(--green); border-color: var(--green); }
.btn-outline:hover { background: #f2f7f4; }
.btn-ghost { background: #f4f0e2; color: var(--ink); }
.btn-ghost:hover { background: #ece6d2; }
.btn-danger { background: #fff; color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: #fdf0f1; }
.btn-block { display: flex; width: 100%; margin-top: .5rem; }
.row { display: flex; gap: .5rem; }
.row > .btn { flex: 1; min-width: 0; }
.row-tight { align-items: center; flex-wrap: wrap; margin-top: .6rem; }

.mini-btn {
    display: grid; place-items: center; width: 32px; height: 32px;
    background: transparent; border: 0; border-radius: var(--radius-sm); color: var(--muted);
    transition: background .2s, color .2s;
}
.mini-btn:hover { background: #f1ecda; color: var(--red); }
.mini-btn .ic { width: 18px; height: 18px; }

.link-btn {
    display: inline-flex; align-items: center; gap: .4rem;
    background: none; border: 0; padding: .3rem .2rem;
    color: var(--red); font-size: .92rem; text-decoration: underline; text-underline-offset: 3px;
}
.link-btn:hover { color: var(--red-hover); }
.link-btn .ic { width: 18px; height: 18px; }

/* ---------- Plátno (stage) ---------- */
.stage {
    position: relative; min-width: 0; min-height: 0;
    display: grid; place-items: center;
    padding: 20px;
    background:
        radial-gradient(1200px 500px at 50% -10%, rgba(255, 255, 255, .6), transparent 70%),
        var(--stage);
    overflow: hidden;
}
.canvas-holder {
    position: relative;
    box-shadow: 0 10px 36px rgba(15, 40, 25, .28), 0 0 0 1px rgba(0, 0, 0, .06);
    background: #fff;
}
#pf-canvas {
    display: block; width: 100%; height: 100%;
    touch-action: none; user-select: none; -webkit-user-select: none;
    cursor: default;
}
.canvas-holder.dragover { outline: 3px dashed var(--gold); outline-offset: 6px; }

/* Úvodní karta */
.welcome {
    position: absolute; inset: 0; overflow: hidden auto;
    display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 28px 32px;
    background:
        radial-gradient(120% 80% at 0% 0%, rgba(212, 175, 55, .16), transparent 55%),
        linear-gradient(180deg, #f6f1e0 0%, #ebe6d3 100%);
    animation: fadeIn .45s var(--ease);
}
.welcome::before {
    content: ''; position: absolute; inset: 12px; pointer-events: none;
    border: 1px solid rgba(212, 175, 55, .55); border-radius: 3px;
}
.welcome-card {
    position: relative; display: flex; flex-direction: column; align-items: stretch; gap: .7rem;
    width: min(900px, 100%); text-align: left;
}
.welcome-card h2 {
    display: flex; align-items: center; gap: .6rem;
    font-family: 'Merriweather', serif; font-size: 1.7rem; line-height: 1.2; color: var(--green);
}
.welcome-card h2 .ic { width: 26px; height: 26px; color: var(--red); }
.welcome-card p { font-size: .98rem; color: var(--muted); max-width: 52ch; }
.welcome-card { margin: auto; }
.welcome-card .w-actions { max-width: 460px; }
.w-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; margin-top: .4rem; }
.w-actions .btn { min-height: 48px; }
.welcome-card .w-sub {
    display: flex; align-items: center; gap: .5rem; margin-top: 1.4rem;
    font-family: 'Merriweather', serif; font-size: 1.02rem; color: var(--green);
}
.welcome-card .w-sub .ic { width: 18px; height: 18px; color: var(--gold-hover, #b8941f); }
.w-slider { position: relative; margin: 0 -4px; }
.w-cards {
    display: flex; gap: .7rem; padding: 4px 4px 6px;
    overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding: 0 4px; overscroll-behavior-x: contain;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.w-cards::-webkit-scrollbar { display: none; }
.w-cards .w-card { flex: 0 0 auto; scroll-snap-align: start; }
.w-nav {
    position: absolute; top: calc(50% - 22px); z-index: 2; display: grid; place-items: center;
    width: 34px; height: 34px; padding: 0; border: 0; border-radius: 50%;
    background: rgba(255, 255, 255, .94); color: var(--green); box-shadow: 0 2px 10px rgba(15, 73, 40, .3);
    transition: opacity .2s, transform .2s;
}
.w-nav .ic { width: 20px; height: 20px; }
.w-prev { left: 6px; } .w-prev .ic { transform: rotate(90deg); }
.w-next { right: 6px; } .w-next .ic { transform: rotate(-90deg); }
.w-nav[disabled] { opacity: 0; pointer-events: none; }
@media (hover: none) { .w-nav { display: none; } }
.w-card {
    display: flex; flex-direction: column; gap: .4rem; min-width: 0; padding: 0;
    background: transparent; border: 0; color: var(--green); font-size: .82rem; font-weight: 500; text-align: left;
}
.w-card img {
    display: block; width: auto; max-width: none; height: clamp(150px, 24vh, 240px); border-radius: 3px;
    border: 1px solid rgba(212, 175, 55, .7); box-shadow: 0 6px 14px rgba(15, 73, 40, .2);
    transition: transform .35s var(--ease), box-shadow .25s;
}
@media (hover: hover) { .w-card:hover img { transform: translateY(-3px); box-shadow: 0 12px 22px rgba(15, 73, 40, .3); } }
.welcome-card .link-btn { align-self: flex-start; margin-top: .5rem; }
.welcome-card .w-skip { align-self: flex-start; margin-top: .6rem; min-height: 46px; }
@media (max-width: 640px) {
    .welcome { padding: 22px 0 18px; }
    .welcome-card .w-actions { max-width: none; }
    .welcome::before { display: none; }
    .welcome-card { gap: .7rem; width: 100%; }
    .welcome-card h2, .welcome-card .w-actions, .welcome-card .w-sub, .welcome-card .link-btn, .welcome-card .w-skip { margin-left: 14px; margin-right: 14px; }
    .welcome-card .w-skip { align-self: stretch; }
    .welcome-card h2 { font-size: 1.3rem; }
    .welcome-card p { font-size: .9rem; margin: 0 14px; max-width: none; }
    .welcome-card .w-sub { margin-top: 1rem; }
    .w-slider { margin: 0; }
    .w-cards { padding: 4px 14px 6px; scroll-padding: 0 14px; gap: .6rem; }
    .w-card img { height: 128px; }
    .w-card span { font-size: .76rem; }
    .w-card img { border-radius: 3px; }
}

.panel-bar { display: none; }
.panel-handle { display: none; place-items: center; width: 100%; height: 26px; background: #fff; border: 0; border-bottom: 1px solid var(--line); color: var(--muted); }
.panel-handle .ic { width: 20px; height: 20px; transition: transform .25s var(--ease); }

/* Panel nástrojů pro vybraný prvek */
.ctx-bar {
    position: absolute; left: 50%; bottom: 14px;
    display: flex; gap: 2px; padding: 4px;
    background: rgba(15, 73, 40, .95); border-radius: var(--radius);
    box-shadow: var(--shadow);
    opacity: 0; pointer-events: none;
    transform: translate(-50%, 10px);
    transition: opacity .2s, transform .25s var(--ease);
    z-index: 3;
}
.ctx-bar.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.ctx-bar button {
    display: grid; place-items: center; width: 42px; height: 40px;
    background: transparent; border: 0; border-radius: var(--radius-sm); color: #fff;
    transition: background .15s;
}
.ctx-bar button:hover { background: rgba(255, 255, 255, .16); }
.ctx-bar .ctx-ok { background: var(--gold); color: #2b2b2b; margin-left: 4px; }
.ctx-bar .ctx-ok:hover { background: var(--gold-hover); }

/* Přímá editace textu */
#inline-editor {
    position: absolute; z-index: 4; left: 0; top: 0;
    margin: 0; padding: 0; resize: none; overflow: hidden;
    background: rgba(0, 0, 0, .22);
    border: 0; outline: 2px dashed rgba(255, 255, 255, .9); outline-offset: 6px;
    caret-color: #fff; white-space: pre-wrap;
    transform-origin: 0 0;
}

/* ---------- Panel s nástroji ---------- */
.panel {
    display: flex; flex-direction: column; min-height: 0;
    background: var(--surface);
    border-left: 1px solid var(--line);
    box-shadow: -6px 0 22px rgba(15, 73, 40, .06);
}
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tab {
    position: relative; flex: 1; min-width: 0;
    display: flex; align-items: center; justify-content: center; gap: .4rem;
    height: 50px; padding: 0 .3rem;
    background: transparent; border: 0;
    color: var(--muted); font-size: .88rem; font-weight: 500;
    transition: color .2s, background .2s;
}
.tab::after {
    content: ''; position: absolute; left: 12%; right: 12%; bottom: -1px; height: 3px;
    background: var(--red); border-radius: 3px 3px 0 0;
    transform: scaleX(0); transition: transform .3s var(--ease);
}
@media (hover: hover) { .tab:hover { background: #faf7ec; color: var(--ink); } }
.tab[aria-selected="true"] { color: var(--red); }
.tab[aria-selected="true"]::after { transform: scaleX(1); }
.tab .ic { width: 19px; height: 19px; }

.panel-body {
    flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
    padding: 1rem 1.1rem 1.5rem;
    scrollbar-width: thin;
}
.pane { animation: paneIn .25s var(--ease); }
.pane-title {
    display: flex; align-items: center; gap: .5rem;
    font-family: 'Merriweather', serif; font-size: 1.25rem; font-weight: 700; color: var(--green);
    margin: 0 0 .8rem;
}
.pane-title .ic { color: var(--red); }
.pane h3 {
    font-family: 'Merriweather', serif; font-size: .98rem; font-weight: 700; color: var(--green);
    margin: 1.4rem 0 .5rem;
}
.pane h3.first { margin-top: 0; }
.hint { font-size: .85rem; color: var(--muted); margin: .2rem 0 .6rem; }

/* ---------- Formulářové prvky ---------- */
.field { margin: .55rem 0; }
.field > label, .label-row label {
    display: flex; justify-content: space-between; align-items: baseline; gap: .5rem;
    font-size: .88rem; font-weight: 500; margin-bottom: .25rem;
}
.field output { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 400; }
.label-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: .1rem; }
.label-row label { margin: 0; }

textarea, select {
    width: 100%; padding: .6rem .7rem;
    background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius);
    transition: border-color .2s, box-shadow .2s;
}
textarea { resize: vertical; min-height: 74px; line-height: 1.4; }
textarea:focus, select:focus { outline: 0; border-color: var(--green); box-shadow: 0 0 0 3px rgba(15, 73, 40, .12); }

input[type="range"] {
    --p: 0%;
    -webkit-appearance: none; appearance: none;
    width: 100%; height: 26px; margin: 0; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
    height: 5px; border-radius: 5px;
    background: linear-gradient(to right, var(--red) var(--p), #e4ddc8 var(--p));
}
input[type="range"]::-moz-range-track { height: 5px; border-radius: 5px; background: #e4ddc8; }
input[type="range"]::-moz-range-progress { height: 5px; border-radius: 5px; background: var(--red); }
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8.5px;
    background: #fff; border: 2px solid var(--red); border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .25); transition: transform .15s;
}
input[type="range"]::-moz-range-thumb {
    width: 18px; height: 18px; background: #fff; border: 2px solid var(--red); border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.15); }

.swatches { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; }
.sw {
    width: 36px; height: 36px; padding: 0;
    border: 1px solid rgba(0, 0, 0, .18); border-radius: var(--radius-sm);
    transition: transform .15s var(--ease);
}
.sw:hover { transform: scale(1.08); }
.sw[aria-pressed="true"] { outline: 2px solid var(--green); outline-offset: 2px; }
.sw-color {
    width: 36px; height: 36px; padding: 2px; cursor: pointer;
    border: 1px solid rgba(0, 0, 0, .18); border-radius: var(--radius-sm); background: #fff;
}

.color-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem; margin: .4rem 0 .5rem; }
.cfield { display: grid; gap: .25rem; font-size: .8rem; font-weight: 500; color: var(--muted); }
.cfield input[type="color"] { width: 56px; height: 38px; padding: 2px; cursor: pointer; border: 1px solid rgba(0, 0, 0, .18); border-radius: var(--radius-sm); background: #fff; }
.presets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .45rem; margin-bottom: .6rem; }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .1rem; }
.chip {
    display: inline-flex; align-items: center; gap: .35rem;
    min-height: 36px; padding: 0 .75rem;
    background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
    font-size: .88rem;
    transition: border-color .2s, background .2s, color .2s;
}
.chip:hover { border-color: var(--green); }
.chip .ic { width: 16px; height: 16px; }
.chip-toggle[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: #fff; }

.seg {
    display: inline-flex; background: #f4f0e2; border-radius: var(--radius); padding: 3px; gap: 2px;
}
.seg button {
    display: grid; place-items: center; min-width: 38px; height: 32px; padding: 0 .6rem;
    background: transparent; border: 0; border-radius: var(--radius-sm); color: var(--ink);
    font-size: .9rem; transition: background .2s, color .2s;
}
.seg button[aria-pressed="true"] { background: var(--green); color: #fff; }
.seg-wide { display: flex; margin: 0 0 .8rem; }
.seg-wide button { flex: 1; height: 38px; }

.toggle { display: flex; align-items: center; gap: .65rem; cursor: pointer; font-size: .92rem; margin: .3rem 0 .4rem; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track {
    position: relative; flex: none; width: 42px; height: 24px; border-radius: 12px;
    background: #cfc8b0; transition: background .25s;
}
.toggle-track::after {
    content: ''; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px;
    background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
    transition: transform .25s var(--ease);
}
.toggle input:checked + .toggle-track { background: var(--green); }
.toggle input:checked + .toggle-track::after { transform: translateX(18px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--gold); outline-offset: 2px; }

.symbols { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: .4rem; }
.symbols button {
    height: 44px; background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
    font-size: 1.3rem; line-height: 1; font-family: 'Roboto', 'Segoe UI Symbol', sans-serif;
    transition: border-color .2s, transform .15s var(--ease), background .2s;
}
.symbols button:hover { border-color: var(--green); background: #f6faf7; transform: translateY(-1px); }
.symbols button.wide { grid-column: span 3; font-size: 1rem; }

.decor { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; margin-bottom: .7rem; }
.decor button {
    aspect-ratio: 1; padding: 10px;
    background: var(--green); border: 0; border-radius: var(--radius);
    transition: transform .2s var(--ease), box-shadow .2s;
}
.decor button:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.decor.lines { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.decor.lines button { aspect-ratio: 4 / 1; padding: 8px 12px; }
.decor img { display: block; width: 100%; height: 100%; object-fit: contain; }

.formats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem; }
.fmt {
    display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: .5rem;
    padding: .7rem .3rem; min-height: 112px;
    background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius);
    font-size: .8rem; line-height: 1.25; text-align: center; color: var(--muted);
    transition: border-color .2s, background .2s, color .2s, transform .15s var(--ease);
}
.fmt i {
    display: block; height: 42px; max-width: 100%;
    background: linear-gradient(160deg, #cfe3d6, #e9efe6);
    border: 2px solid var(--green); border-radius: 3px;
}
.fmt:hover { border-color: var(--green); transform: translateY(-1px); }
.fmt[aria-pressed="true"] { border-color: var(--red); background: #fff7f7; color: var(--ink); }
.fmt[aria-pressed="true"] i { border-color: var(--red); }

/* ---------- Dialogy ---------- */
dialog.sheet {
    width: min(940px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
    padding: 0; border: 0; border-radius: 12px;
    background: #fff; color: var(--ink);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}
dialog.sheet-narrow { width: min(640px, calc(100vw - 24px)); }
dialog.sheet[open] { display: flex; animation: pop .3s var(--ease); }
dialog.sheet::backdrop { background: rgba(10, 30, 20, .58); backdrop-filter: blur(2px); animation: fadeIn .25s; }
.dlg-body { display: flex; flex-direction: column; width: 100%; max-height: calc(100dvh - 24px); padding: 1rem 1.1rem 1.1rem; min-height: 0; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .8rem; }
.dlg-head h2 {
    display: flex; align-items: center; gap: .5rem;
    font-family: 'Merriweather', serif; font-size: 1.3rem; color: var(--green);
}
.dlg-head h2 .ic { color: var(--red); }
.dlg-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-right: 4px; scrollbar-gutter: stable; }
#gallery-dlg[open] { height: min(780px, calc(100dvh - 24px)); }
.dlg-scroll h3 { font-family: 'Merriweather', serif; font-size: 1rem; color: var(--green); margin: 1.3rem 0 .5rem; }
.dlg-scroll h3:first-child { margin-top: .2rem; }

.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.gal-item {
    aspect-ratio: 1; padding: 0; overflow: hidden;
    background: conic-gradient(#ececec 25%, #fff 0 50%, #ececec 0 75%, #fff 0) 0 0 / 16px 16px;
    border: 2px solid transparent; border-radius: var(--radius-sm);
    transition: transform .2s var(--ease), border-color .2s, box-shadow .2s;
}
.gal-item:hover { border-color: var(--green); box-shadow: var(--shadow); }
.gal-item img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .25s var(--ease); }
@media (hover: hover) { .gal-item:hover img { transform: scale(1.06); } }
.gal-contain .gal-item img { object-fit: contain; }
.gal-empty { color: var(--muted); padding: 1rem 0; }

.qr-content { text-align: center; padding: .5rem 0 .5rem; }
.qr-content p { margin: .8rem 0; }
.qr-content img { max-width: min(320px, 100%); height: auto; border: 4px solid var(--gold); border-radius: var(--radius); }

/* ---------- Toast & cookies ---------- */
.toast {
    position: fixed; left: 50%; bottom: 24px; z-index: 1300;
    max-width: calc(100vw - 32px); padding: .7rem 1.1rem;
    background: #2b2b2b; color: #fff; border-radius: var(--radius); font-size: .92rem;
    box-shadow: var(--shadow); opacity: 0; pointer-events: none;
    transform: translate(-50%, 14px); transition: opacity .25s, transform .3s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

#cookie-consent {
    position: fixed; left: 12px; bottom: 12px; z-index: 1200;
    display: flex; flex-direction: column; gap: .7rem;
    width: min(440px, calc(100vw - 24px)); padding: 1rem;
    background: #fff; border: 1px solid var(--line); border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
    animation: slideUp .5s var(--ease);
}
#cookie-consent p { font-size: .9rem; }
.cookie-actions { display: flex; gap: .5rem; }
.cookie-actions .btn { flex: 1; min-height: 40px; font-size: .88rem; }

/* ---------- Animace ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes paneIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: none; } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }

/* ---------- Větší obrazovky ---------- */
@media (min-width: 1500px) {
    .workspace { grid-template-columns: minmax(0, 1fr) 500px; }
    .stage { padding: 28px; }
}

/* ---------- Tablet a mobil: plátno nahoře, nástroje dole ---------- */
@media (max-width: 899px) {
    :root { --head-h: 52px; }
    .app { min-height: 0; }
    .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
    .stage { padding: 10px; }
    .panel { border-left: 0; border-top: 1px solid var(--line); box-shadow: 0 -6px 22px rgba(15, 73, 40, .08); }
    .panel-body { flex: none; height: 34vh; height: min(34dvh, 330px); min-height: 150px; padding: .8rem .9rem 1.2rem; }
    .app:has(#welcome:not([hidden])) .panel { display: none; }   /* na úvodní obrazovce celou výšku dostane nabídka, nástroje se ukážou po výběru */
    .panel-bar { display: flex; align-items: center; background: #e6efe8; border-bottom: 1px solid #c4d6c8; }
    .panel-bar .tbtn { width: 44px; height: 36px; flex: none; border-radius: 0; background: transparent; color: var(--green); display: grid; place-items: center; border: 0; }
    .panel-bar .tbtn:hover:not(:disabled) { background: #d5e5d9; }
    .panel-handle { flex: 1; display: flex; align-items: center; justify-content: center; gap: .45rem; height: 36px; background: transparent; border: 0; color: var(--green); font: 700 .86rem/1 inherit; cursor: pointer; }
    .panel-handle .ic { width: 26px; height: 26px; stroke-width: 2.6; }
    .panel-handle::after { content: 'Skrýt nástroje'; }
    .panel.collapsed .panel-handle::after { content: 'Zobrazit nástroje'; }
    .panel-handle:active { background: #d5e5d9; }
    .panel.collapsed .panel-handle .ic { transform: rotate(180deg); }
    .panel.collapsed .panel-body { display: none; }
    .tab { height: 48px; }
    .tab span { display: none; }
    .tab .ic { width: 22px; height: 22px; }
    .pane-title { font-size: 1.1rem; margin-bottom: .6rem; }
    .brand-text p { display: none; }
    .brand-text h1 { font-size: 1.02rem; }
    .brand-ic { width: 24px; height: 24px; }
    .topbar { padding: 0 .5rem 0 .8rem; gap: .5rem; }
    .tbtn { width: 38px; height: 38px; }
    #download-btn { min-height: 38px; padding: 0 .8rem; }
    .ctx-bar { bottom: 8px; }
    .ctx-bar button { width: 44px; height: 42px; }
    /* 16px zabrání automatickému přiblížení na iOS při psaní */
    textarea, select { font-size: 16px; }
    .toast { bottom: 90px; }
    #cookie-consent { left: 8px; right: 8px; bottom: 8px; width: auto; }

    dialog.sheet {
        width: 100%; max-width: 100%; margin: auto 0 0; max-height: 90dvh;
        border-radius: 16px 16px 0 0;
    }
    dialog.sheet[open] { animation: sheetUp .35s var(--ease); }
    #gallery-dlg[open] { height: 90dvh; }
    .dlg-body { max-height: 90dvh; padding-bottom: calc(1.1rem + env(safe-area-inset-bottom)); }
    .gal-grid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); }
}

@media (max-width: 520px) {
    #redo-btn, #help-btn { display: none; }
    .top-actions { gap: .1rem; }
    .tbtn { width: 36px; height: 36px; }
}
@media (max-width: 420px) {
    #download-btn span { display: none; }
    #download-btn { width: 40px; padding: 0; }
    .brand-text h1 { font-size: .95rem; }
}

/* Telefon na šířku: nástroje vedle plátna */
@media (max-width: 899px) and (max-height: 520px) and (orientation: landscape) {
    :root { --head-h: 46px; }
    .workspace { grid-template-columns: minmax(0, 1fr) 330px; grid-template-rows: minmax(0, 1fr); }
    .panel { border-top: 0; border-left: 1px solid var(--line); }
    .panel-body { flex: 1; max-height: none; }
    .panel.collapsed .panel-body { display: block; }
    .stage { padding: 6px; }
    .tbtn { width: 34px; height: 34px; }
    .tab { height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Rychlé texty: na PC kompaktně v jednom řádku */
@media (min-width: 900px) {
    #quick-texts { flex-wrap: wrap; gap: .3rem; }
    #quick-texts .chip { min-height: 28px; padding: 0 .5rem; font-size: .76rem; white-space: nowrap; flex: 0 1 auto; }
}
@media (min-width: 900px) and (max-width: 1499px) {
    #quick-texts .chip { padding: 0 .38rem; font-size: .7rem; }
}

/* ---------- PDF k tisku ---------- */
.pdf-info { margin: .8rem 0 1rem; padding: .7rem .85rem; background: #f6f2e3; border-radius: var(--radius-sm); font-size: .9rem; color: var(--ink); }
.pdf-info[data-quality="ok"] { background: #e8f0eb; color: var(--green); }
.pdf-info[data-quality="low"] { background: #f7ece3; }
#pdf-dlg select { width: 100%; }

/* iOS Safari: pole s menším písmem než 16 px přibližují stránku při zaostření */
@media (max-width: 899px), (hover: none) {
    textarea, select, input[type="text"], input[type="search"], input[type="number"], input[type="email"], input:not([type]) { font-size: 16px; }
}
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }


/* Reklamní plocha v panelu Pozadí (zatím prázdný rámeček) */
.ad-slot { margin-top: .8rem; }
.ad-label { display: block; margin-bottom: .2rem; font-size: .62rem; line-height: 1; letter-spacing: .04em; color: var(--muted, #6b695f); }
.ad-box { width: 100%; height: clamp(84px, 15vh, 140px); background: #ecebe7; border: 1px solid #d8d6cf; border-radius: 6px; }
@media (max-height: 760px) { .ad-box { height: 72px; } }
