:root{
  --bg:#0b0c10;
  --card:#11131a;
  --text:#e9eef5;
  --muted:#9aa6b2;

  /* palette sizing (tuned by JS based on palette mode + pointer type) */
  --swatch-min: 44px;
}

body{
  margin:0;
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  background:var(--bg);
  color:var(--text);

  /* UX: zabránit nechtěnému označování textu */
  -webkit-user-select:none;
  -ms-user-select:none;
  user-select:none;
}

/* Ensure the coloring page grid has a real, fixed height so 1fr can be computed
   and inner scrolling can work reliably across browsers. */
html, body{
  height:100%;
}

/* Layout used on the main coloring page (index.html). */
body.coloring-page{
  height:100dvh;
  min-height:0;
  overflow:hidden;

  /* Fixed layout variables (used to keep content visible under collapsed bars) */
  --top-handle-h: 22px;
  /* levé ouško držíme na stejné tloušťce jako výšku horního ouška */
  --side-handle-w: var(--top-handle-h);

  --top-collapsed-h: var(--top-handle-h);
  --side-collapsed-w: var(--side-handle-w);
  --top-expanded-max: 60dvh;
  /* levá lišta: oproti původnímu návrhu záměrně cca "poloviční" šířka */
  --side-expanded-w: clamp(90px, 18vw, 140px);

  /* horní lišta: užší a zarovnaná doprava, nikdy nesmí překrýt otevřenou levou lištu */
  --top-expanded-w: clamp(280px, 45vw, 560px);

  /* palette sizing depending on layout */
  --palette-bottom-h: clamp(180px, 30dvh, 320px);
  --palette-right-w: clamp(240px, 28vw, 360px);
}

/* --------- Header (shared) --------- */

/* Default header used on non-coloring pages (designer/admin). */
.top{
  padding:16px 18px;
  border-bottom:1px solid #22263a;
  display:flex;
  justify-content:space-between;
  gap:12px;
  align-items:flex-start;
}
.top h1{ margin:0; font-size:18px; }
.top p{ margin:6px 0 0; color:var(--muted); font-size:13px; }

/* --------- Collapsible bars (index.html) --------- */

/* shared toggle button */
body.coloring-page .bar-toggle{
  width:38px;
  height:38px;
  border-radius:12px;
  border:1px solid #2b3262;
  background:#0f1220;
  color:var(--text);
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:18px;
  flex:0 0 auto;
}
body.coloring-page .bar-toggle:hover{ filter:brightness(1.08); }

/* "Ouška" pro sbalení/rozbalení – vždy na hraně panelu */
body.coloring-page .bar-handle{
  position:fixed;
  box-sizing:border-box;
  border:1px solid #2b3262;
  background:#0f1220;
  color:var(--text);
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  padding:0 10px;
  box-shadow:0 10px 24px rgba(0,0,0,0.28);
  user-select:none;
  z-index:80;

  /* aby ouška animovala stejně plynule jako samotné lišty */
  transition:
    top 220ms ease,
    left 220ms ease,
    transform 220ms ease,
    filter 220ms ease;
}
body.coloring-page .bar-handle:hover{ filter:brightness(1.08); }

/* horní lišta – ouško je na spodní hraně */
body.coloring-page .bar-handle--top{
  /* při rozbalení horní lišty se ouško posune na její spodní hranu */
  top:var(--top-handle-top, 0px);
  left:50%;
  width:auto;
  height:var(--top-handle-h);
  border-radius:0 0 12px 12px;
  transform:translateX(-50%);
}

/* levá lišta – ouško je na pravé hraně */
body.coloring-page .bar-handle--side{
  left:var(--side-handle-left, 0px);
  top:50%;
  /* tloušťka ouška = výška horního ouška (22px) */
  width:var(--side-handle-w);
  height:160px;
  border-radius:0 12px 12px 0;
  transform:translateY(-50%);
  padding:8px 0;
  gap:6px;
  flex-direction:column;
}

body.coloring-page .bar-handle .handle-label{
  display:block;
  font-size:11px;
  font-weight:800;
  letter-spacing:.04em;
}

body.coloring-page .bar-handle--side .handle-label{
  writing-mode:vertical-rl;
  text-orientation:mixed;
  transform:rotate(180deg);
}

body.coloring-page .bar-handle .handle-icon{
  font-size:14px;
  line-height:1;
}

/* Top bar: fixed overlay, collapsible */
body.coloring-page .top{
  position:fixed;
  top:0;
  left:0;
  right:0;
  width:auto;
  z-index:50;
  border-bottom:1px solid #22263a;
  background:#0f1220;
  padding:6px 10px;
  display:flex;
  gap:10px;
  align-items:flex-start;
  box-shadow:0 10px 24px rgba(0,0,0,0.28);

  /* default: sbalené – venku zůstane jen ouško (viz .bar-handle--top) */
  transform:translateY(-100%);
  transition:transform 220ms ease;
  will-change:transform;
  overflow:visible;
}

body.coloring-page .top.is-open{
  transform:translateY(0);
}

/* Když je levá lišta otevřená, horní lišta se rozepne přes celý zbytek šířky
   tak, aby se oba panely dotýkaly. */
body.coloring-page.side-open .top.is-open{
  left:var(--side-open-w, 0px);
  right:0;
  width:auto;
  max-width:none;
}

/* když je levá lišta zavřená, horní lišta zabírá celou šířku */
body.coloring-page:not(.side-open) .top.is-open{
  left:0;
  right:0;
  width:auto;
}

body.coloring-page .top-content{
  display:flex;
  justify-content:space-between;
  gap:12px;
  align-items:flex-start;
  flex:1 1 auto;
  min-width:0;
}

body.coloring-page .top-title{ min-width:0; }
body.coloring-page .top h1{ margin:0; font-size:15px; line-height:1.2; }
body.coloring-page .top p{ margin:4px 0 0; color:var(--muted); font-size:12px; }

.controls{ display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
.label{ color:var(--muted); font-size:13px; }

/* Language switch */
.lang-switch{ display:flex; gap:8px; }
.lang-btn{
  width:42px;
  height:38px;
  border-radius:12px;
  border:1px solid #2b3262;
  background:#0f1220;
  cursor:pointer;
  font-size:18px;
  display:flex;
  align-items:center;
  justify-content:center;
}
.lang-btn:hover{ filter:brightness(1.08); }
.lang-btn[aria-selected="true"]{
  border-color:#fff;
  box-shadow:0 0 0 2px rgba(255,255,255,0.2);
}

/* Left image bar: fixed overlay, collapsible */
body.coloring-page .image-bar{
  position:fixed;
  top:0;
  left:0;
  bottom:0;
  z-index:40;
  width:var(--side-expanded-w);
  background:#0f1220;
  border-right:1px solid #22263a;
  padding:6px;
  display:flex;
  flex-direction:column;
  gap:10px;
  box-shadow:10px 0 24px rgba(0,0,0,0.28);

  /* default: sbalené – venku zůstane jen ouško (viz .bar-handle--side) */
  transform:translateX(-100%);
  transition:transform 220ms ease;
  will-change:transform;
  overflow:visible;
}

body.coloring-page .image-bar.is-open{
  transform:translateX(0);
}

body.coloring-page .image-bar-content{
  flex:1 1 auto;
  min-height:0;
  overflow:auto;
  padding-right:6px; /* small breathing room when scrollbar is hidden */
}

/* hide scrollbar (still scrollable) */
body.coloring-page .image-bar-content{ scrollbar-width:none; }
body.coloring-page .image-bar-content::-webkit-scrollbar{ width:0; height:0; }

body.coloring-page .image-strip{
  display:flex;
  flex-direction:column;
  gap:12px;
  overflow:visible;
}
body.coloring-page .image-strip--tall{ max-height:100%; }

.image-card-wrap{
  position:relative;
  flex:0 0 auto;
  scroll-snap-align:start;
}
.image-del{
  position:absolute;
  top:4px;
  right:4px;
  width:24px;
  height:24px;
  border-radius:999px;
  border:1px solid #2b3262;
  background:#0c0e14;
  color:#fff;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:16px;
  line-height:0;
  padding:0;
}
.image-del:hover{ filter:brightness(1.1); }


.image-card{
  flex:0 0 auto;
  width:100%;
  padding:6px;
  border-radius:12px;
  border:1px solid #2b3262;
  background:#11131a;
  cursor:pointer;
}
.image-card:hover{ filter:brightness(1.06); }
.image-card[aria-selected="true"]{
  border-color:#fff;
  box-shadow:0 0 0 2px rgba(255,255,255,0.2);
}
.image-thumb{
  width:100%;
  aspect-ratio:1/1;
  border-radius:12px;
  object-fit:cover;
  display:block;
}
.image-label{
  margin-top:6px;
  font-size:11px;
  color:var(--muted);
  line-height:1.2;
  overflow:hidden;
  white-space:nowrap;
  text-overflow:ellipsis;
}

@media (max-width: 700px){
  .image-label{ display:none; }
  .image-strip{ gap:10px; }
}

/* Main app area: no page scrolling. Layout switches based on body classes.
   - default: palette bottom
   - when body.palette-right: palette on the right */
.app{
  position:fixed;
  inset:0;
  z-index:10;
  padding-top:var(--top-collapsed-h);
  padding-left:var(--side-collapsed-w);
  padding-right:12px;
  padding-bottom:12px;
  display:grid;
  gap:12px;
  min-height:0;
}

body.coloring-page.palette-bottom .app,
body.coloring-page:not(.palette-right) .app{
  grid-template-columns: 1fr;
  grid-template-rows: 1fr var(--palette-bottom-h);
}

body.coloring-page.palette-right .app{
  grid-template-columns: 1fr var(--palette-right-w);
  grid-template-rows: 1fr;
}

.panel{
  background:var(--card);
  border:1px solid #22263a;
  border-radius:14px;
  padding:12px;
  min-height:0;
  overflow:auto;
}

/* Paleta: když je panel vyšší než obsah, nechytáme obsah k hornímu okraji,
   ale ke spodnímu (příjemnější na velkých obrazovkách). */
body.coloring-page .app > aside.panel{
  display:flex;
  flex-direction:column;
}
body.coloring-page .app > aside.panel .palette-head{
  margin-top:auto;
}

/* hide scrollbar in the panel (still scrollable if needed) */
.panel{ scrollbar-width:none; }
.panel::-webkit-scrollbar{ width:0; height:0; }
.panel h2{
  margin:0;
  font-size:14px;
  color:var(--muted);
  font-weight:600;
  letter-spacing:.02em;
  text-transform:uppercase;
}

/* Palette head (title + active color + modes) */
.palette-head{ display:flex; flex-direction:column; gap:10px; margin-bottom:10px; }

.palette-title{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}

.active-color{
  width:22px;
  height:22px;
  border-radius:8px;
  border:2px solid rgba(255,255,255,0.6);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25);
}

.palette-modes{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}

.segmented{
  display:flex;
  border:1px solid #2b3262;
  border-radius:12px;
  overflow:hidden;
  background:#0f1220;
}

.seg-btn{
  border:0;
  background:transparent;
  padding:8px 12px;
  color:var(--text);
  cursor:pointer;
  font-weight:700;
  min-width:44px;
}
.seg-btn:hover{ filter:brightness(1.12); }
.seg-btn[aria-selected="true"]{
  background:#1b2040;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}

/* Palette */
.palette{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--swatch-min), 1fr));
  gap:10px;
}
.swatch{
  width:100%;
  aspect-ratio:1/1;
  border-radius:12px;
  border:2px solid transparent;
  cursor:pointer;
  box-shadow:inset 0 0 0 1px rgba(255,255,255,0.08);
}
.swatch[aria-selected="true"]{
  border-color:#fff;
  box-shadow:0 0 0 2px rgba(255,255,255,0.2);
}

/* Bigger tap targets on touch devices (fine-tuned via --swatch-min) */
@media (pointer: coarse){
  .swatch{ min-height:56px; border-radius:16px; }
}

/* Buttons */
.row{ display:flex; gap:10px; flex-wrap:wrap; margin-top:12px; }
button{
  background:#1b2040;
  color:var(--text);
  border:1px solid #2b3262;
  padding:10px 12px;
  border-radius:12px;
  cursor:pointer;
  font-weight:600;
}
button:hover{ filter:brightness(1.08); }
button:disabled{ opacity:0.5; cursor:not-allowed; }
button.danger{ background:#3a1620; border-color:#7a2a3f; }

button.is-active{
  box-shadow:0 0 0 2px rgba(255,255,255,0.3);
}

.hint{
  margin-top:10px;
  color:var(--muted);
  font-size:13px;
  line-height:1.35;
}

/* Stage */
.stage{
  background:#0f1220;
  border:1px solid #22263a;
  border-radius:14px;
  padding:10px;
  min-height:0;
  overflow:hidden;
  display:flex;
}
.stage-inner{
  display:flex;
  justify-content:center;
  align-items:center;
  width:100%;
  height:100%;
  min-height:0;
}

.svg-host{
  width:100%;
  height:100%;
  display:block;
}

.svg-host svg{
  /* Always contain within the stage (no scrolling). */
  width:100%;
  height:100%;
  display:block;
}

button, .cell{
  -webkit-tap-highlight-color: transparent;
}

/* SVG coloring */
.cell{
  fill:#ffffff;
  stroke:#000;
  stroke-width:3;
  vector-effect: non-scaling-stroke;
  cursor:pointer;
}

/* Paint mode */
.paint-mode .cell{
  transition: fill 640ms ease, filter 240ms ease, transform 640ms ease;
  transform-origin: center;
}

.paint-mode .cell:hover{
  filter: brightness(0.95);
}

.paint-mode .cell.painted{
  filter: brightness(0.92);
  transform: scale(1.015);
}

/* Designer mode */
.designer-mode .cell{
  transition: none !important;
  transform-origin: initial !important;
  filter: none !important;
}


/* Link na designér v hlavičce */
.designer-link{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  height:38px;
  padding:0 12px;
  border-radius:12px;
  border:1px solid #2b3262;
  background:#0f1220;
  color:var(--text);
  text-decoration:none;
  font-weight:700;
}
.designer-link:hover{ filter:brightness(1.08); }