:root {
  --ink: #1d2433;
  --muted: #5d6677;
  --line: #d9dde5;
  --paper: #ffffff;
  --desk: #e9ecf1;
  --panel: #f8f9fb;
  --accent: #1f3a5f;
  --accent-soft: #dfe8f3;
  --error: #b3261e;
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sheet-font: "Helvetica Neue", Helvetica, Arial, "Liberation Sans", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font: 15px/1.45 var(--ui-font);
  color: var(--ink);
  background: var(--desk);
}

[hidden] { display: none !important; }

/* ---------- rozvržení aplikace ---------- */

.app {
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  min-height: 100vh;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 22px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; gap: 12px; align-items: flex-start; }
.brand h1 { font-size: 19px; margin: 0; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.brand-mark {
  flex: none;
  width: 34px;
  height: 34px;
  margin-top: 2px;
  background:
    conic-gradient(var(--accent) 25%, transparent 0 50%, var(--accent) 0 75%, transparent 0) 0 0 / 50% 50%;
  border: 2px solid var(--accent);
  border-radius: 4px;
}

form { display: flex; flex-direction: column; gap: 16px; }

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend {
  padding: 0;
  margin-bottom: 7px;
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.hint { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }
.hint.error { color: var(--error); }

.seg {
  display: flex;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 600;
  padding: 7px 4px;
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
}
.seg button:hover:not(:disabled) { background: var(--accent-soft); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.seg button:disabled { color: #b5bbc6; cursor: not-allowed; }

.motifs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 7px;
}
.motif {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 7px 5px 5px;
  font: inherit;
  font-size: 12.5px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
  color: var(--ink);
}
.motif:hover { border-color: #9fb1c8; }
.motif[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }
.thumb { width: 46px; height: 46px; display: grid; place-items: center; }
.thumb svg { width: 100%; height: 100%; }
.thumb .lines { stroke: #e3e6ec; }
.dice {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 2px dashed #9fb1c8;
  border-radius: 6px;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.row input { width: 80px; }

input[type="number"], input[type="text"] {
  font: inherit;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.check { display: flex; align-items: center; gap: 9px; padding: 3px 0; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; }

.code-row { display: flex; gap: 6px; }
.code-row input { flex: 1; min-width: 0; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 14px; }

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}
.btn:hover { border-color: #9fb1c8; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-size: 16px; padding: 11px 14px; }
.btn.primary:hover { background: #172d4a; }

.print-box { margin-top: auto; padding-top: 6px; border-top: 1px solid var(--line); }
.print-box .btn { margin-top: 12px; }

/* ---------- náhled ---------- */

.panel, .preview { min-width: 0; }
.preview-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--muted);
  background: color-mix(in srgb, var(--desk) 88%, transparent);
  backdrop-filter: blur(6px);
}

.pages {
  --s: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 4px 16px 40px;
}
.frame {
  width: calc(210mm * var(--s));
  height: calc(297mm * var(--s));
  flex: none;
}
.frame .page {
  transform: scale(var(--s));
  transform-origin: 0 0;
  box-shadow: 0 1px 3px rgb(20 30 50 / 0.12), 0 8px 24px rgb(20 30 50 / 0.08);
}

/* ---------- list A4 ---------- */

.page {
  position: relative;
  width: 210mm;
  height: 297mm;
  overflow: hidden;
  background: var(--paper);
  color: #000;
  font-family: var(--sheet-font);
  font-variant-numeric: tabular-nums;
}

.sheet-head {
  position: absolute;
  top: 13mm;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8mm;
}
.sheet-head h2 { margin: 0; font-size: 16pt; line-height: 1.15; font-weight: 700; }
.sheet-head .topic { margin: 1.2mm 0 0; font-size: 10.5pt; }
.name { display: flex; align-items: flex-end; gap: 2mm; font-size: 10pt; padding-top: 2.5mm; }
.name-line { display: inline-block; width: 52mm; border-bottom: 0.3mm solid #444; height: 4.5mm; }

.steps { position: absolute; top: 28.5mm; margin: 0; font-size: 9pt; color: #333; }

.examples { position: absolute; display: grid; grid-auto-flow: column; column-gap: 3mm; }
.ex { white-space: nowrap; display: flex; align-items: center; }
.ex b { font-weight: 700; }

.divider { position: absolute; height: 0; border-top: 0.25mm solid #cfcfcf; }

.grid text { font-family: var(--sheet-font); font-weight: 700; fill: #000; }
.grid .lines { fill: none; stroke: #8c8c8c; stroke-linecap: square; }
.grid .fill { fill: #1a1a1a; }

.code-tag {
  position: absolute;
  right: 16mm;
  bottom: 6mm;
  font-size: 7.5pt;
  color: #888;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

.sol-grid {
  position: absolute;
  top: 34mm;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  row-gap: 8mm;
  column-gap: 10mm;
  justify-items: center;
}
.sol-grid figure { margin: 0; }
.sol-grid figcaption { display: flex; justify-content: space-between; gap: 4mm; font-size: 9.5pt; margin: 0 0 1.5mm; }
.sol-grid figcaption span { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 8pt; color: #666; }

/* ---------- mobil ---------- */

@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .panel { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .print-box { margin-top: 0; }
}

/* ---------- tisk ---------- */

@page { size: A4; margin: 0; }

@media print {
  html, body { background: #fff; }
  .panel, .preview-bar { display: none !important; }
  .app { display: block; min-height: 0; }
  .pages { display: block; padding: 0; gap: 0; }
  .frame { width: auto; height: auto; }
  .frame .page { transform: none; box-shadow: none; }
  .page { height: 296.8mm; break-after: page; page-break-after: always; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .frame:last-child .page { break-after: auto; page-break-after: auto; }
}
