:root {
  --bg: #0f1115;
  --surface: #181b21;
  --surface-2: #22262e;
  --border: #2c313a;
  --text: #e8eaed;
  --muted: #9aa0a8;
  --accent: #4c8dff;
  --fresh: #2fb36d;
  --stale: #e0a526;
  --old: #e5484d;
  --star: #f5b301;
  --radius: 10px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-2: #eceef1;
    --border: #d8dbe0;
    --text: #15181d;
    --muted: #5f6670;
    --accent: #1f6feb;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button { font: inherit; }

/* ---------- Horní lišta ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px 0;
}
.topbar__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.sections { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.sections a { padding: 6px 14px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; }
.sections a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); }

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

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0; scrollbar-width: thin; }
.chips a {
  flex: none;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid transparent;
}
.chips a:hover { border-color: var(--border); }
.chips a[aria-current="page"] { background: var(--accent); color: #fff; }

.icon-btn {
  flex: none;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.is-loading { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Mřížka ---------- */
main { padding: 16px; }

.grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 560px)  { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 860px)  { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1150px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1400px) { .grid { grid-template-columns: repeat(5, 1fr); } }

.section-title { margin: 4px 0 10px; font-size: 15px; font-weight: 700; color: var(--muted); }
#fav-section { margin-bottom: 22px; }
#fav-section .section-title { color: var(--text); }
#fav-section .section-title::before { content: "★ "; color: var(--star); }

.grid > li { position: relative; }

/* ---------- Hvězdička oblíbených ---------- */
.star-icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
[aria-pressed="true"] > .star-icon { fill: var(--star); stroke: var(--star); }

.star {
  position: absolute;
  top: 7px;
  left: 7px;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
}
.star:hover { background: rgba(0, 0, 0, .8); }
.grid > li:hover .star,
.star:focus-visible,
.star[aria-pressed="true"] { opacity: 1; }
@media (hover: none) { .star { opacity: 1; } }    /* na mobilu bez myši je hvězdička vidět vždy */

.star-btn { display: grid; place-items: center; }

.card {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-align: left;
  overflow: hidden;
  cursor: zoom-in;
}
.card:hover { border-color: var(--accent); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Dálniční kamery jsou většinou 16:9, pražské 5:4 (dvojitý obraz levý/pravý) */
.thumb { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; }
.grid--praha .thumb, .viewer--tsk .history .thumb { aspect-ratio: 5 / 4; }
.thumb img { position: relative; display: block; width: 100%; height: 100%; object-fit: contain; }
/* Text pod obrázkem – dokud se snímek nestáhne z uamk.cz, není místo něj jen černá plocha */
.card .thumb::before {
  content: "Načítám snímek…";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #888;
  font-size: 13px;
}
.card .thumb.broken::before { content: none; }
.thumb img:not([src]) { visibility: hidden; }
.thumb .age { position: absolute; right: 6px; bottom: 6px; }
.broken::after {
  content: "Snímek nedostupný";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #888;
  font-size: 13px;
}
.broken img { visibility: hidden; }

.card__body { padding: 8px 10px; }
.card__label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-weight: 600; }
.card__time { flex: none; color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.card__dirs { margin-top: 2px; color: var(--muted); font-size: 13px; }
.card__dirs:empty { display: none; }

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  vertical-align: 1px;
}

/* ---------- Stáří snímku ---------- */
.age {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.age[hidden] { display: none; }
.age::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 50%;
  vertical-align: 1px;
}
.age--fresh::before { background: var(--fresh); }
.age--stale::before { background: var(--stale); }
.age--old { background: var(--old); }
.age--old::before { background: #fff; }

.message { padding: 40px 16px; text-align: center; color: var(--muted); }
.message.is-error { color: var(--old); }

.footer { padding: 8px 16px 24px; text-align: center; color: var(--muted); font-size: 12px; }
.footer a { color: inherit; }

/* ---------- Dialog s detailem ---------- */
.viewer {
  width: min(1100px, 100vw - 32px);
  max-width: none;
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  overflow: auto;
}
.viewer::backdrop { background: rgba(0, 0, 0, .8); }

.viewer__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 12px 14px; }
.viewer__title { margin: 0; font-size: 18px; }
.viewer__actions { display: flex; gap: 8px; flex: none; }
.viewer__dirs { margin-top: 2px; color: var(--muted); font-size: 13px; }
.viewer__dirs:empty { display: none; }

.viewer__stage { position: relative; background: #000; touch-action: pan-y; user-select: none; }
.viewer__stage img { display: block; width: 100%; min-height: 200px; max-height: calc(100dvh - 340px); object-fit: contain; }

.viewer__badges { position: absolute; left: 8px; top: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.viewer__time {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.frame-badge { padding: 2px 8px; border-radius: 999px; background: var(--fresh); color: #fff; font-size: 12px; font-weight: 700; }
.frame-badge.is-history { background: var(--accent); }

.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 64px;
  border: 0;
  border-radius: 8px;
  background: rgba(0, 0, 0, .45);
  color: #fff;
  font-size: 32px;
  cursor: pointer;
}
.nav-btn:hover { background: rgba(0, 0, 0, .7); }
.nav-btn:disabled { display: none; }
.nav-btn--older { left: 8px; }
.nav-btn--newer { right: 8px; }

.history { display: flex; gap: 8px; overflow-x: auto; padding: 10px 14px 4px; scrollbar-width: thin; }
.history button {
  flex: none;
  width: 112px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.history button[aria-pressed="true"] { border-color: var(--accent); color: var(--text); font-weight: 700; }
.history .thumb { border-radius: 4px; overflow: hidden; }
.history .thumb img { object-fit: cover; }

.viewer__foot { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 8px 14px 12px; }
.viewer__pos { color: var(--muted); font-size: 13px; text-align: center; }
.viewer__hint { display: block; font-size: 11px; }
@media (hover: none) { .viewer__hint { display: none; } }

.pager {
  max-width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.pager:hover { border-color: var(--accent); }
.pager:disabled { visibility: hidden; }
.pager--prev { justify-self: start; }
.pager--next { justify-self: end; }

/* ---------- Mobil ---------- */
@media (max-width: 559px) {
  .viewer { width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .viewer[open] { display: flex; flex-direction: column; }
  .viewer__stage { flex: 1; display: flex; align-items: center; }
  .viewer__stage img { max-height: none; }
  .history button { width: 88px; }
  .pager { padding: 8px 10px; font-size: 13px; }
  .sections a { padding: 6px 10px; }
  .status #status-text { display: none; }
}
