:root {
    --bg: #fff8ec;
    --panel: #ffffff;
    --ink: #3b2f2f;
    --accent: #ff8a3d;
    --accent-soft: #ffe2cc;
    --shadow: 0 4px 14px rgba(80, 50, 20, .15);
    font-family: "Comic Sans MS", "Segoe UI Rounded", "Segoe UI", system-ui, sans-serif;
    color: var(--ink);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
    margin: 0; height: 100%; background: var(--bg);
    overscroll-behavior: none;            /* žádné "pull to refresh" a pružení na tabletu */
    -webkit-user-select: none; user-select: none;
    -webkit-touch-callout: none;          /* dlouhý stisk neotevře menu (iPad) */
}
button, label { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
img { -webkit-user-drag: none; }

/* ---------- Galerie ---------- */
.gallery-header { text-align: center; padding: 24px 16px 8px; position: relative; }
.back-btn {
    position: absolute; left: 16px; top: 24px;
    font-size: 32px; background: var(--panel); border: 0; border-radius: 16px;
    padding: 6px 14px; box-shadow: var(--shadow);
}
.card.category { border-color: var(--accent-soft); }
.card small { color: #998; font-size: 14px; }
.gallery-header h1 { margin: 0; font-size: clamp(28px, 5vw, 48px); color: var(--accent); }
.gallery-header p { margin: 6px 0 0; font-size: 20px; }

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(220px, 42vw), 1fr));
    gap: 20px;
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
}
.card {
    background: var(--panel);
    border: 4px solid transparent;
    border-radius: 22px;
    box-shadow: var(--shadow);
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: transform .12s, border-color .12s;
}
.card:hover, .card:focus-visible { transform: scale(1.04); border-color: var(--accent); outline: none; }
.card img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; border-radius: 12px; }
.card span { font-size: 18px; }

.message { text-align: center; font-size: 22px; padding: 40px 16px; }
.message.error { color: #c62828; }
.message small { display: block; color: #888; margin: 8px 0 16px; font-size: 14px; word-break: break-word; }
.big-btn { background: var(--accent); color: #fff; border: 0; border-radius: 16px; padding: 12px 24px; font-size: 20px; }

/* ---------- Malování ---------- */
.paint {
    display: grid;
    grid-template-columns: auto 1fr auto;
    height: 100vh;
    height: 100dvh;
    gap: 10px;
    padding: 10px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    overflow: hidden;
    touch-action: none;   /* malovací obrazovka se nikdy neposouvá ani nezoomuje */
}
.toolbar, .palette {
    background: var(--panel);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    touch-action: pan-x pan-y;   /* panely jdou posunout prstem, i když je .paint zamčená */
}
.group { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; border-top: 2px dashed var(--accent-soft); }

.tool {
    display: flex; flex-direction: column; align-items: center;
    background: #f7f3ee; border: 3px solid transparent; border-radius: 14px;
    padding: 6px 8px; min-width: 64px;
}
.tool .ico { font-size: 28px; line-height: 1.1; }
.tool .lbl { font-size: 12px; }
.tool.active { border-color: var(--accent); background: var(--accent-soft); }

/* Na šířku: nástroje ve dvou sloupcích, ať se vše vejde na výšku tabletu bez scrollování */
.tools { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.tools .tool { min-width: 0; padding: 4px 2px; }
.tools .tool .lbl { font-size: 11px; white-space: nowrap; }
.toolbar { width: 150px; }
.tool.back { font-size: 28px; }

.sizes { flex-direction: row; flex-wrap: wrap; justify-content: center; max-width: 110px; }
.size {
    width: 48px; height: 48px; border-radius: 50%;
    border: 3px solid transparent; background: #f7f3ee;
    display: grid; place-items: center; padding: 0;
}
.size span { border-radius: 50%; display: block; border: 1px solid rgba(0,0,0,.2); }
.size.active { border-color: var(--accent); }
.actions { flex-direction: row; flex-wrap: wrap; justify-content: center; max-width: 110px; }
.actions .tool { min-width: 0; width: 48px; height: 48px; padding: 0; justify-content: center; font-size: 24px; }

.palette { display: grid; grid-template-columns: repeat(2, 50px); grid-auto-rows: 50px; gap: 8px; align-content: start; }
.swatch {
    width: 50px; height: 50px; border-radius: 50%;
    border: 3px solid rgba(0,0,0,.12); padding: 0;
    position: relative; display: grid; place-items: center; font-size: 20px; cursor: pointer;
}
.swatch.active { border: 4px solid var(--ink); transform: scale(1.1); }
.swatch.custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }

/* Plocha pro obrázek je "container" – obrázek se do ní vejde celý v jakémkoli rozložení.
   --ar (poměr stran obrázku) nastavuje paint.js. */
.stage { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; container-type: size; overflow: hidden; }
.canvas-wrap {
    position: relative;
    width: min(100cqw, 100cqh * var(--ar, 1));
    box-shadow: var(--shadow);
    border-radius: 8px;
    background: #fff;
}
.layer { display: block; width: 100%; height: auto; }
.layer.stroke { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.layer.top { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.layer.top.fill { cursor: cell; }
.stage .message { position: absolute; }

/* Nízký displej na šířku (tablet s lištou prohlížeče): paleta ve třech sloupcích */
@media (orientation: landscape) and (max-height: 900px) {
    .palette { grid-template-columns: repeat(3, 44px); grid-auto-rows: 44px; gap: 6px; }
    .swatch { width: 44px; height: 44px; }
    .toolbar { gap: 6px; padding: 8px; }
    .group { padding-top: 6px; }
    .tool .ico { font-size: 24px; }
}

/* Tablet na výšku (a telefon): nástroje nahoře, paleta dole, obrázek uprostřed */
@media (orientation: portrait), (max-width: 760px) {
    .paint { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
    /* Lišta se zalomí do více řádků, ať jsou vidět všechny nástroje i tlačítka bez posouvání */
    .toolbar { flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: center; width: auto; overflow: visible; }
    .tools { display: flex; flex-wrap: wrap; justify-content: center; }
    .tools .tool { min-width: 64px; }
    .group { flex-direction: row; border-top: 0; border-left: 2px dashed var(--accent-soft); padding: 0 0 0 10px; }
    .sizes, .actions { max-width: none; flex-wrap: nowrap; }
    .palette { display: flex; flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 8px; overflow: visible; }
    .swatch { width: 44px; height: 44px; }
}
/* Malé tablety / telefony: menší popisky nástrojů */
@media (max-width: 600px) {
    .tool { min-width: 48px; padding: 4px; }
    .tool .lbl { display: none; }
    .swatch { width: 40px; height: 40px; }
}

/* ---------- Blazor ---------- */
#blazor-error-ui {
    background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none; left: 0; padding: .6rem 1.25rem .7rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

.loading-progress { position: absolute; display: block; width: 8rem; height: 8rem; inset: 20vh 0 auto 0; margin: 0 auto; }
.loading-progress circle { fill: none; stroke: #f3e6d8; stroke-width: .6rem; transform-origin: 50% 50%; transform: rotate(-90deg); }
.loading-progress circle:last-child {
    stroke: var(--accent);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray .05s ease-in-out;
}
.loading-progress-text { position: absolute; text-align: center; font-weight: bold; inset: calc(20vh + 3.25rem) 0 auto .2rem; }
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Načítám"); }
