/* ============ Barvy a základ ============ */
:root {
  --bg: #f6f3ef;
  --surface: #ffffff;
  --surface-2: #eeeae4;
  --text: #1f1c1a;
  --muted: #706a63;
  --line: #e2ddd6;
  --accent: #cf5236;
  --accent-ink: #ffffff;
  --accent-soft: #fae3dc;
  --ok: #2e8b57;
  --ok-soft: #d9efe2;
  --danger: #c23b3b;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(40, 30, 20, .05), 0 4px 16px rgba(40, 30, 20, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151413;
    --surface: #1f1d1c;
    --surface-2: #2b2927;
    --text: #f2eee9;
    --muted: #a69f97;
    --line: #34312e;
    --accent: #f2775b;
    --accent-ink: #1c0e0a;
    --accent-soft: #3b231d;
    --ok: #5cc48a;
    --ok-soft: #1c3326;
    --danger: #ff7070;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151413;
    --surface: #1f1d1c;
    --surface-2: #2b2927;
    --text: #f2eee9;
    --muted: #a69f97;
    --line: #34312e;
    --accent: #f2775b;
    --accent-ink: #1c0e0a;
    --accent-soft: #3b231d;
    --ok: #5cc48a;
    --ok-soft: #1c3326;
    --danger: #ff7070;
    --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { line-height: 1.2; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px calc(104px + env(safe-area-inset-bottom));
}

/* ============ Hlavička ============ */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 4px;
  margin: 0 -16px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  min-height: 64px;
}
.top h1 {
  flex: 1; margin: 0;
  font-size: 22px; font-weight: 750;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.top .icon-btn:first-child { margin-left: -10px; }

/* ============ Ikony a tlačítka ============ */
.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 44px; height: 44px;
  border: 0; border-radius: 12px;
  background: transparent; color: inherit; text-decoration: none;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:disabled { opacity: .22; cursor: default; }
.icon-btn.sm { width: 38px; height: 38px; }
.icon-btn.sm svg { width: 20px; height: 20px; }
.icon-btn:active:not(:disabled) { background: var(--surface-2); }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 20px;
  border: 0; border-radius: 14px;
  background: var(--surface-2); color: var(--text);
  font-weight: 650; text-decoration: none; text-align: center;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.block { width: 100%; margin: 12px 0; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1.5px dashed var(--line); }
.btn.danger-ghost { background: transparent; color: var(--danger); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:active:not(:disabled) { transform: scale(.98); }

.link {
  border: 0; background: none; padding: 8px 4px;
  color: var(--accent); font-weight: 650;
}
.link.muted { color: var(--muted); }

/* ============ Formuláře ============ */
input, textarea {
  width: 100%; min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font: inherit;
}
textarea { resize: vertical; line-height: 1.4; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
input.c { text-align: center; font-size: 18px; font-weight: 650; padding: 10px 4px; }

.field { display: block; margin: 12px 0; }
.field > span { display: block; margin: 0 0 6px 2px; font-size: 13px; font-weight: 650; color: var(--muted); }

.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid3 .field { margin: 0; }

.seg { display: flex; gap: 4px; padding: 4px; margin: 0 0 12px; border-radius: 12px; background: var(--surface-2); }
.seg > * {
  flex: 1; padding: 10px 6px;
  border: 0; border-radius: 9px; background: transparent;
  color: var(--muted); font-weight: 650; text-align: center; text-decoration: none;
}
.seg .on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ============ Domovská obrazovka ============ */
.hero {
  display: flex; flex-direction: column; gap: 2px;
  margin: 4px 0 12px; padding: 20px;
  border-radius: 20px; background: var(--surface); box-shadow: var(--shadow);
  color: inherit; text-decoration: none;
}
.hero.active { outline: 2px solid var(--accent); }
.eyebrow { font-size: 12px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.hero strong { font-size: 28px; line-height: 1.15; margin: 4px 0 2px; overflow-wrap: anywhere; }
.hero .btn { margin-top: 16px; }

.banner {
  display: flex; align-items: center; gap: 12px; width: 100%;
  margin: 8px 0; padding: 12px 14px;
  border: 0; border-radius: 14px;
  background: var(--accent-soft); color: var(--text);
  font-size: 14px; text-align: left; text-decoration: none;
}
.banner svg { width: 22px; height: 22px; flex: none; color: var(--accent); }

.empty { text-align: center; padding: 32px 12px; }
.empty > svg { width: 64px; height: 64px; color: var(--accent); }
.empty h2 { margin: 12px 0 6px; font-size: 22px; }
.empty p { margin: 0 0 20px; color: var(--muted); }
.empty .btn { width: 100%; margin: 8px 0; }

/* ============ Seznamy ============ */
.section {
  margin: 26px 4px 8px;
  font-size: 13px; font-weight: 750; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted);
}
.list {
  list-style: none; margin: 0; padding: 0; overflow: hidden;
  border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
}
.list li + li { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: 12px;
  min-height: 64px; padding: 10px 14px;
  color: inherit; text-decoration: none;
}
.grow { flex: 1; min-width: 0; }
.grow strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); }
.grow .muted { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.small { font-size: 13px; }
.pad { padding: 8px 4px; }

.ex-row { padding: 8px 4px 8px 12px; }
.row-link { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.reorder { display: flex; flex-direction: column; }

.badge {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--surface-2); font-weight: 750;
}
.pill {
  flex: none; padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 750;
}
.chev { width: 20px; height: 20px; flex: none; color: var(--muted); }

.thumb {
  display: grid; place-items: center; flex: none;
  width: 52px; height: 52px; border-radius: 12px;
  background: var(--surface-2); color: var(--muted);
  object-fit: cover;
}
.thumb svg { width: 24px; height: 24px; }

.card {
  margin: 12px 0; padding: 14px;
  border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
}
.card.row { padding: 8px 8px 8px 16px; min-height: 56px; }

/* ============ Fotky ============ */
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ph { position: relative; aspect-ratio: 1; overflow: hidden; border-radius: 14px; background: var(--surface-2); }
.ph-img { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: none; }
.ph-img img { display: block; width: 100%; height: 100%; object-fit: cover; }
.ph-del {
  position: absolute; top: 6px; right: 6px;
  display: grid; place-items: center;
  width: 32px; height: 32px; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .55); color: #fff;
}
.ph-del svg { width: 18px; height: 18px; }
.ph.add {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 1.5px dashed var(--line); background: transparent;
  color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer;
}
.ph.add svg { width: 28px; height: 28px; }
img.missing { visibility: hidden; }

/* ============ Série ============ */
.set-head, .set, .eset {
  display: grid; grid-template-columns: 26px 1fr 1fr 48px; gap: 8px; align-items: center;
}
.set-head { margin-bottom: 6px; font-size: 12px; font-weight: 650; text-align: center; color: var(--muted); }
.set, .eset { margin-bottom: 8px; }
.si { font-weight: 750; text-align: center; color: var(--muted); }

.check {
  display: grid; place-items: center;
  width: 48px; height: 48px;
  border: 2px solid var(--line); border-radius: 14px;
  background: transparent; color: transparent;
  transition: background .15s, border-color .15s;
}
.check svg { width: 26px; height: 26px; }
.set.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.set.done input { background: var(--ok-soft); border-color: transparent; }

/* ============ Trénink ============ */
.progress { display: flex; align-items: center; gap: 10px; margin: 0 0 4px; font-size: 14px; font-weight: 750; color: var(--muted); }
.bar { flex: 1; height: 8px; overflow: hidden; border-radius: 8px; background: var(--surface-2); }
.bar i { display: block; height: 100%; background: var(--ok); transition: width .25s; }

.wex.complete { outline: 2px solid var(--ok); }
.wex-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.wex-head h3 { margin: 0 0 2px; font-size: 18px; overflow-wrap: anywhere; }
.wthumb {
  position: relative; flex: none; overflow: hidden;
  width: 68px; height: 68px; padding: 0;
  border: 0; border-radius: 12px; background: var(--surface-2);
}
.wthumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.wthumb .count {
  position: absolute; right: 4px; bottom: 4px;
  padding: 1px 6px; border-radius: 8px;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 11px; font-weight: 750;
}
.note {
  margin: 0 0 12px; padding: 8px 12px;
  border-radius: 10px; background: var(--surface-2);
  font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.wex-foot { display: flex; gap: 16px; }

/* ============ Historie ============ */
.date { flex: none; width: 44px; text-align: center; }
.date b { display: block; font-size: 20px; line-height: 1.1; }
.date span { font-size: 11px; font-weight: 650; text-transform: uppercase; color: var(--muted); }
.stat { display: flex; gap: 10px; margin: 12px 0; }
.stat > div { flex: 1; padding: 12px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 13px; color: var(--muted); }

.chart { display: block; width: 100%; height: auto; }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; }

.sets-list { margin: 6px 0 0; padding: 0; list-style: none; font-size: 15px; }
.sets-list li { display: flex; gap: 10px; padding: 3px 0; }
.sets-list li.skip { color: var(--muted); text-decoration: line-through; }

/* ============ Spodní menu ============ */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--surface);
}
#nav a {
  flex: 1; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; border-radius: 12px;
  color: var(--muted); font-size: 12px; font-weight: 650; text-decoration: none;
}
#nav a.on { color: var(--accent); }
#nav svg { width: 24px; height: 24px; }

/* ============ Dialogy, prohlížeč fotek, toast ============ */
.modal-back {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, .45);
  animation: fade .15s ease-out;
}
.modal {
  width: 100%; max-width: 480px; padding: 20px;
  border-radius: 20px; background: var(--surface);
  animation: rise .2s ease-out;
}
.modal p { margin: 0 0 18px; font-size: 17px; }
.modal .actions { display: flex; gap: 10px; }
.modal .btn { flex: 1; }

.viewer {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: #000;
  touch-action: pan-y;
}
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; }
.viewer .icon-btn { position: absolute; background: rgba(255, 255, 255, .14); color: #fff; }
.v-close { top: calc(12px + env(safe-area-inset-top)); right: 12px; }
.v-prev { top: 50%; left: 10px; transform: translateY(-50%); }
.v-next { top: 50%; right: 10px; transform: translateY(-50%); }
.v-count { position: absolute; bottom: calc(22px + env(safe-area-inset-bottom)); color: #fff; font-size: 14px; font-weight: 650; }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 70;
  padding: 10px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 650; white-space: nowrap;
  opacity: 0; pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

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

/* ============ Potvrzení na místě, pokyny, cíl ============ */
.confirm {
  margin: 12px 0; padding: 16px;
  border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
  animation: rise .18s ease-out;
}
.confirm p { margin: 0 0 14px; font-size: 16px; }
.confirm .actions { display: flex; gap: 10px; }
.confirm .btn { flex: 1; }
.photos + .confirm { margin-top: 12px; }

.target { display: block; color: var(--accent); font-weight: 650; }
.plan-note { margin: 0 0 12px; }
.plan-note summary {
  padding: 10px 14px; border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow);
  font-weight: 650; cursor: pointer;
}
.plan-note .note { margin-top: 8px; }
[hidden] { display: none !important; }
.confirm { scroll-margin-bottom: calc(100px + env(safe-area-inset-bottom)); }
