/* style.css – čisté světlé UI, fotka je hlavní, ovládání dole (na šířku vpravo). */

:root {
  --bg: #ffffff;
  --stage: #f1f2f4;
  --panel: #ffffff;
  --panel-2: #f4f5f7;
  --line: #e2e4e8;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --accent-text: #ffffff;
  --radius: 12px;
  --touch: 44px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "top" "stage" "panel";
  height: 100dvh;
  overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* --- horní lišta --- */
#top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.spacer { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.btn:disabled { opacity: .4; cursor: default; }
.btn.icon { padding: 0; width: var(--touch); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.big { min-height: 56px; padding: 0 28px; font-size: 18px; }
.btn.on, .btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn:active:not(:disabled) { filter: brightness(0.94); }
.btn svg { flex-shrink: 0; }

#modeSel {
  min-height: var(--touch);
  min-width: 0;
  max-width: 190px;
  flex: 0 1 auto;
  padding: 0 8px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  text-overflow: ellipsis;
}
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex-shrink: 0; }
.seg button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--touch);
  padding: 0 12px;
  border: 0;
  background: var(--panel-2);
  cursor: pointer;
  touch-action: manipulation;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }

/* --- plátno --- */
#stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
  touch-action: none;
  min-height: 0;
  background: var(--stage);
}
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { pointer-events: none; }

#empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  padding: 16px;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }

#busy {
  position: absolute;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .12);
  border: 1px solid var(--line);
  z-index: 5;
  max-width: calc(100% - 32px);
}
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

#dropHint {
  position: absolute; inset: 12px;
  display: flex; align-items: center; justify-content: center;
  border: 3px dashed var(--accent); border-radius: 16px;
  background: rgba(31, 111, 235, .06);
  font-size: 22px; z-index: 6;
}

/* --- spodní panel --- */
#panel {
  grid-area: panel;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  min-width: 0;
}
#panelHead { display: flex; align-items: center; gap: 8px; padding: 6px 8px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs button {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}
.tabs button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#panelToggle svg { transition: transform .2s; }
#panel.collapsed #panelToggle svg { transform: rotate(180deg); }
#panel.collapsed #panelBody { display: none; }

#panelBody {
  max-height: 40dvh;
  overflow-y: auto;
  padding: 2px 12px 12px;
}
.tab > * + * { margin-top: 8px; }
[data-for] > * + * { margin-top: 8px; }

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "label out" "range range";
  align-items: center;
  column-gap: 8px;
}
.row > span { grid-area: label; color: var(--muted); }
.row > output { grid-area: out; font-variant-numeric: tabular-nums; }
.row > input { grid-area: range; }
.grow { flex: 1; min-width: 0; }

input[type="range"] {
  width: 100%;
  height: 36px;
  margin: 0;
  background: transparent;
  accent-color: var(--accent);
  touch-action: pan-y;
}

.btnrow { display: flex; gap: 8px; }
.btnrow > .btn { flex: 1; }
.btnrow.wrap { flex-wrap: wrap; }
.btnrow.wrap > .btn { flex: 1 1 calc(50% - 8px); }
.seg.tools { display: flex; }
.seg.tools button { flex: 1; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

.angle-row { display: flex; gap: 12px; align-items: center; }
.dial {
  width: 56px; height: 56px; flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--panel);
  position: relative;
  touch-action: none;
  cursor: grab;
}
.dial .needle {
  position: absolute; left: 6px; right: 6px; top: 50%;
  height: 3px; margin-top: -1.5px;
  background: var(--accent); border-radius: 2px;
}
.dial .needle::after {
  content: ""; position: absolute; right: -2px; top: -4px;
  border: 5px solid transparent; border-left: 7px solid var(--accent);
  transform: translateX(6px);
}

.presets { display: flex; gap: 8px; flex-wrap: wrap; }
.presets select {
  flex: 1 1 100%;
  min-height: var(--touch);
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  padding: 0 10px;
}
.presets .btn { flex: 1; }

/* --- dialog exportu --- */
dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  padding: 20px;
}
dialog::backdrop { background: rgba(15, 18, 25, .35); }
dialog { box-shadow: 0 12px 40px rgba(0, 0, 0, .18); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
.progress { height: 10px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
#expBar { height: 100%; width: 0; background: var(--accent); transition: width .15s; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: #16181d;
  color: #fff;
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 20;
  max-width: calc(100vw - 32px);
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Úzké telefony: kompaktnější horní lišta */
@media (max-width: 480px) {
  #btnOpen span { display: none; }
  #btnOpen { padding: 0; width: var(--touch); }
  .seg button { padding: 0 9px; }
  #btnBefore, #btnExport { padding: 0; width: var(--touch); }
  #btnBefore .lbl, #btnExport .lbl { display: none; }
  #top { gap: 4px; padding-left: 6px; padding-right: 6px; }
}
@media (max-width: 360px) {
  #btnRedo { display: none; }
}

/* Na šířku (telefon otočený): panel vpravo */
@media (orientation: landscape) and (max-height: 600px) {
  body {
    grid-template-columns: 1fr minmax(260px, 34vw);
    grid-template-rows: auto 1fr;
    grid-template-areas: "top top" "stage panel";
  }
  #panel { border-top: 0; border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
  #panelBody { max-height: none; flex: 1; }
  body.panel-collapsed { grid-template-columns: 1fr auto; }
  #panel.collapsed .tabs { display: none; }
  #panel.collapsed #panelToggle svg { transform: rotate(90deg); }
}
