:root {
  --bg: #14110f;
  --panel: #1f1a17;
  --line: #3a312b;
  --text: #f1e9dd;
  --muted: #a89a88;
  --gold: #d9b26a;
  --gold-ink: #1b1408;
  --danger: #e08a7a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: radial-gradient(120% 80% at 50% 0%, #2a211b 0%, var(--bg) 60%) fixed var(--bg);
  color: var(--text);
  font-family: var(--sans);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
}

.top h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
  margin: 0;
}

.top-right { display: flex; align-items: center; gap: 10px; }

.score {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.9rem;
}

.icon-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--text);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
}

main {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 16px;
}

.screen {
  width: 100%;
  max-width: 460px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.screen[hidden] { display: none; }

.lead {
  font-family: var(--serif);
  font-size: 1.3rem;
  line-height: 1.45;
  margin: 0 0 8px;
  text-wrap: balance;
}

.hint, .status {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
  min-height: 1.3em;
}

.btn {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 13px 22px;
  min-height: 48px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}

.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); }
.btn.big { font-size: 1.15rem; padding: 16px 44px; }
.btn.small { min-height: 40px; padding: 8px 16px; font-weight: 500; font-size: 0.9rem; }
.btn.chosen { border-color: var(--gold); color: var(--gold); }
.btn:disabled { opacity: 0.45; cursor: default; }

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Kruhovy odpocet */
.ring-wrap {
  position: relative;
  width: min(62vw, 240px);
  aspect-ratio: 1;
  cursor: pointer;
  outline: none;
}

.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 5; }
.ring-bg { stroke: var(--line); }
.ring-fg {
  stroke: var(--gold);
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 0;
}
.ring-wrap.waiting .ring-fg { stroke: var(--muted); }

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.ring-num {
  font-family: var(--serif);
  font-size: 3.4rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.ring-label {
  color: var(--muted);
  font-size: 0.85rem;
  max-width: 70%;
}

/* Odpoved */
.photo {
  width: min(48vw, 190px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: var(--panel);
  overflow: hidden;
  display: grid;
  place-items: center;
  position: relative;
}

.photo span {
  font-family: var(--serif);
  font-size: 3.2rem;
  color: var(--gold);
}

.photo img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 22%;
}

.composer {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.8rem;
  margin: 4px 0 0;
  text-wrap: balance;
}

.years { margin: -10px 0 0; color: var(--muted); font-size: 0.95rem; }

.work {
  font-family: var(--serif);
  font-size: 1.25rem;
  line-height: 1.35;
  margin: 6px 0 0;
  color: var(--gold);
  text-wrap: balance;
}

.part { margin: -8px 0 0; color: var(--text); font-size: 1rem; min-height: 1.2em; }

.from { margin: -8px 0 0; font-family: var(--serif); font-style: italic; font-size: 1.05rem; }
.from[hidden], .part[hidden] { display: none; }
.meta { margin: -6px 0 0; color: var(--muted); font-size: 0.78rem; line-height: 1.4; text-wrap: balance; }

.judge { margin: 4px 0; }

#screenAnswer > * { animation: rise 0.35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { #screenAnswer > * { animation: none; } }

footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.72rem;
  padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

/* Nastaveni */
dialog {
  border: none;
  padding: 0;
  background: transparent;
  color: var(--text);
  width: 100%;
  max-width: 480px;
  max-height: 100dvh;
  margin: auto auto 0;
}

@media (min-width: 560px) { dialog { margin: auto; } }

dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.sheet {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  padding: 18px 18px max(22px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: 92dvh;
  overflow-y: auto;
}

@media (min-width: 560px) { .sheet { border-radius: 20px; } }

.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-family: var(--serif); font-weight: 500; margin: 0; font-size: 1.3rem; }

.field { border: none; padding: 0; margin: 0; display: block; min-width: 0; }
.field legend, .field-top { font-size: 0.9rem; color: var(--muted); padding: 0; margin-bottom: 8px; }
.field legend { width: 100%; display: flex; justify-content: space-between; }
.field-top { display: flex; justify-content: space-between; }
.field output { color: var(--text); font-variant-numeric: tabular-nums; }
.field[hidden] { display: none; }

input[type="range"] { width: 100%; accent-color: var(--gold); height: 28px; margin: 0; }

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.seg input, .chips input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 12px 8px; cursor: pointer; }
.seg input:checked + span { background: var(--gold); color: var(--gold-ink); font-weight: 600; }
.seg input:focus-visible + span, .chips input:focus-visible + span { outline: 2px solid var(--text); outline-offset: -2px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips span {
  display: block;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.9rem;
  color: var(--muted);
  cursor: pointer;
}
.chips input:checked + span { border-color: var(--gold); color: var(--gold); }
.chips .empty span { opacity: 0.4; border-style: dashed; }
.field-note { margin: 8px 0 0; font-size: 0.78rem; color: var(--muted); }

.link {
  background: none;
  border: none;
  color: var(--gold);
  font: inherit;
  font-size: 0.85rem;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link.danger { color: var(--danger); align-self: flex-start; }

.row.left { justify-content: flex-start; }

/* Prehravac cele skladby */
#player, #library { max-width: 560px; }
.pl-title { min-width: 0; text-align: left; }
.pl-title h2 { font-family: var(--serif); font-weight: 500; font-size: 1.25rem; margin: 2px 0 0; color: var(--gold); line-height: 1.3; }
.pl-composer { margin: 0; color: var(--muted); font-size: 0.85rem; }
.pl-part { margin: 2px 0 0; font-size: 0.95rem; }
.pl-part:empty { display: none; }
.pl-cr { margin: -8px 0 0; color: var(--muted); font-size: 0.85rem; }
#plVersions[hidden] { display: none; }

.tl {
  position: relative;
  height: 44px;
  cursor: pointer;
  touch-action: none;
  outline: none;
}
.tl:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; border-radius: 6px; }
.tl-track, .tl-buffer {
  position: absolute;
  left: 0;
  top: 19px;
  height: 6px;
  border-radius: 3px;
}
.tl-track { right: 0; background: var(--line); }
.tl-buffer { width: 0; background: #4d4239; }
.tl-mark, .tl-clip, .tl-pending {
  position: absolute;
  top: 10px;
  height: 24px;
  border-radius: 4px;
  z-index: 1;
}
.tl-mark { background: rgba(217, 178, 106, 0.38); border: 1px dashed rgba(217, 178, 106, 0.8); }
.tl-mark.own { border-style: solid; background: rgba(217, 178, 106, 0.5); }
.tl-clip { background: rgba(241, 233, 221, 0.18); border: 2px solid var(--text); top: 7px; height: 30px; z-index: 2; }
.tl-pending { background: rgba(224, 138, 122, 0.4); border: 1px solid var(--danger); }
.tl-clip[hidden], .tl-pending[hidden] { display: none; }
.tl-head {
  position: absolute;
  top: 4px;
  width: 2px;
  height: 36px;
  margin-left: -1px;
  background: var(--gold);
  border-radius: 1px;
  z-index: 3;
  pointer-events: none;
}
.tl-head::after {
  content: "";
  position: absolute;
  top: -4px;
  left: -5px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gold);
}
.tl-times {
  display: flex;
  justify-content: space-between;
  margin-top: -12px;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
.tl-legend { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 0.78rem; margin-top: -8px; }
.tl-legend span[hidden] { display: none; }
.tl-legend i { display: inline-block; width: 14px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.lg-mark { background: rgba(217, 178, 106, 0.5); border: 1px solid var(--gold); }
.lg-clip { border: 2px solid var(--text); }

#player .row .btn[hidden] { display: none; }
#plStatus { text-align: center; }
.pl-list h3, .lib h3 { font-family: var(--serif); font-weight: 500; font-size: 1.05rem; margin: 6px 0 4px; }
.pl-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.pl-src { color: var(--muted); font-size: 0.8rem; flex: 1; }

/* Seznam skladeb */
.search {
  font: inherit;
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}
.search:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.lib h3 { margin-top: 14px; color: var(--gold); }
.lib-work { margin: 10px 0 2px; font-size: 0.95rem; }
.lib-part {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: none;
  border: none;
  border-top: 1px solid var(--line);
  padding: 10px 2px 10px 12px;
  cursor: pointer;
}
.lib-part:hover, .lib-part:focus-visible { background: rgba(217, 178, 106, 0.08); outline: none; }
.lib-info { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
