:root {
  color-scheme: dark;
  --bg: #0f0d09;
  --surface: #1a1710;
  --surface-2: #252016;
  --line: #3a3224;
  --text: #f5efe2;
  --muted: #b0a58f;
  --gold: #e8bd5a;
  --gold-strong: #f5d27f;
  --on-gold: #1c1503;
  --danger: #ff8d7d;
  --ok: #8fd694;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p { margin: 0; }
a { color: var(--gold-strong); overflow-wrap: anywhere; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold-strong); outline-offset: 2px; }

.splash {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  color: var(--gold);
  font-size: 1.6rem;
  font-weight: 700;
}

/* ochrana obsahu */
.watermark {
  position: fixed;
  inset: 0;
  z-index: 30;
  background-repeat: repeat;
  background-size: 320px 320px;
  pointer-events: none;
}
body.protected { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.protected input,
body.protected textarea,
body.protected .code { -webkit-user-select: text; user-select: text; }
body.app-hidden #app,
body.app-hidden dialog { visibility: hidden; }
@media print {
  body > * { display: none !important; }
  body::before { content: "Tisk aplikace je zakázaný."; color: #000; }
}

/* pozadí nastavené vedením */
.backdrop { position: fixed; inset: 0; z-index: -1; overflow: hidden; background: var(--bg); }
.backdrop img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .62; }

body.has-bg { --surface: rgb(26 23 16 / .7); --surface-2: rgb(37 32 22 / .78); }
body.has-bg dialog { --surface: #1a1710; --surface-2: #252016; }
body.has-bg .card { -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
body.has-bg .topbar { background: rgb(15 13 9 / .68); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
body.has-bg .tabbar { background: rgb(20 17 12 / .74); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
body.has-bg .brand h1,
body.has-bg .brand p,
body.has-bg .section-title,
body.has-bg .content > p,
body.has-bg .content > div > p { color: var(--text); text-shadow: 0 1px 4px rgb(0 0 0 / .9); }

.bg-preview { width: 100%; aspect-ratio: 16 / 10; border-radius: 10px; object-fit: cover; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; }

/* rozložení */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: calc(56px + var(--safe-top));
  padding: var(--safe-top) 16px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; min-width: 0; font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content {
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(92px + var(--safe-bottom));
}
.content > div { display: grid; gap: 12px; min-width: 0; }

.tabbar {
  position: fixed;
  inset: auto 0 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tab {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  max-width: 160px;
  display: grid;
  justify-items: center;
  gap: 3px;
  padding: 9px 2px 7px;
  color: var(--muted);
  font-size: .7rem;
  text-decoration: none;
}
.tab-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--gold-strong); font-weight: 600; }
.count {
  position: absolute;
  top: 4px;
  left: calc(50% + 7px);
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--gold);
  color: var(--on-gold);
  font-size: .68rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

/* přihlášení */
.auth {
  display: grid;
  align-content: center;
  gap: 16px;
  width: 100%;
  max-width: 420px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(24px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
}
.brand { display: grid; justify-items: center; gap: 6px; text-align: center; }
.brand img { width: 76px; height: 76px; border-radius: 18px; }
.brand h1 { font-size: 1.8rem; }

.segments { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface); }
.segments button { min-height: 44px; padding: 4px; border: 0; border-radius: 9px; background: none; color: var(--muted); font-size: .88rem; cursor: pointer; }
.segments button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); font-weight: 600; }

/* karty */
.card {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
a.card { color: inherit; text-decoration: none; }
.card.unread { border-color: var(--gold); }
.card.notice { background: var(--surface-2); }
.card h2 { font-size: 1.05rem; line-height: 1.3; overflow-wrap: anywhere; }
.row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.name { font-weight: 600; overflow-wrap: anywhere; }
.body { white-space: pre-wrap; overflow-wrap: anywhere; }
.preview { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 3; color: var(--muted); overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.center { text-align: center; }
.code { font: 700 1.35rem/1.3 ui-monospace, Consolas, monospace; letter-spacing: .06em; color: var(--gold-strong); overflow-wrap: anywhere; }
.steps { margin: 0; padding-left: 20px; }
.steps li + li { margin-top: 4px; }
.number { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); color: var(--gold-strong); font-weight: 700; line-height: 28px; text-align: center; }

.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .74rem; white-space: nowrap; }
.chip.gold { background: var(--gold); color: var(--on-gold); font-weight: 600; }
.chip.ok { color: var(--ok); }
.chip.warn { color: var(--danger); }

/* další sekce */
.content > .more-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.more-item { position: relative; justify-items: center; gap: 8px; min-height: 104px; align-content: center; text-align: center; }
.more-item svg { width: 28px; height: 28px; color: var(--gold-strong); }
.more-item .count { top: 10px; right: 10px; left: auto; }

/* chat */
.chat-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 220px;
  max-height: calc(100dvh - 340px - var(--safe-top) - var(--safe-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
}
.msg { justify-self: start; display: grid; gap: 2px; width: fit-content; min-width: 55%; max-width: 88%; padding: 8px 10px; border-radius: 12px; background: var(--surface-2); }
.msg.mine { justify-self: end; background: rgb(232 189 90 / .24); }
.msg-delete { width: 28px; height: 28px; margin: -4px -6px -4px 0; border: 0; background: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; }
.chat-form { display: flex; align-items: flex-end; gap: 8px; }
textarea.chat-input { flex: 1; min-width: 0; min-height: 46px; height: 46px; max-height: 120px; }

/* galerie */
select { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font-size: 16px; }
.photo-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.photo-grid button, .photo-grid a { display: block; aspect-ratio: 1; padding: 0; overflow: hidden; border: 0; border-radius: 6px; background: var(--surface); cursor: pointer; }
.photo-grid img { display: block; width: 100%; height: 100%; object-fit: cover; }
.viewer { display: block; width: 100%; max-height: 68dvh; border-radius: 8px; object-fit: contain; }

/* logo */
.topbar-logo { flex: none; width: 30px; height: 30px; border-radius: 8px; object-fit: cover; }

/* hlasování */
.poll-option { display: grid; gap: 4px; overflow-wrap: anywhere; }
.poll-bar { width: 100%; height: 8px; accent-color: var(--gold); }

/* narozeniny, nápady, rok a informace */
.line-row { padding-top: 8px; border-top: 1px solid var(--line); color: inherit; text-decoration: none; }
h2 + .line-row { padding-top: 0; border-top: 0; }
.section-row { margin-top: 8px; }
.section-row .section-title { margin-top: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { display: grid; justify-items: center; gap: 2px; padding: 10px 4px; border-radius: 10px; background: var(--surface-2); text-align: center; }
.stat strong { color: var(--gold-strong); font-size: 1.4rem; line-height: 1.2; }
textarea.short { min-height: 90px; }
.install-big { min-height: 58px; font-size: 1.08rem; }
.link-card { position: relative; }
.card-cover { position: absolute; inset: 0; border-radius: inherit; }
.reaction-row { position: relative; z-index: 1; display: flex; gap: 8px; }
.reaction { min-width: 64px; min-height: 44px; padding: 4px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); font-size: .95rem; cursor: pointer; }
.reaction[aria-pressed="true"] { border-color: var(--gold); color: var(--gold-strong); font-weight: 700; }
.reaction:disabled { opacity: .6; cursor: default; }
.welcome-icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--surface-2); color: var(--gold-strong); }
.welcome-icon svg { display: block; width: 30px; height: 30px; }
.mark-stage { position: relative; overflow: hidden; border-radius: 8px; }
.mark-stage canvas { display: block; width: 100%; height: auto; cursor: crosshair; }
.mark-dot { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border: 2px solid var(--gold-strong); border-radius: 50%; background: rgb(232 189 90 / .35); pointer-events: none; }

/* hierarchie */
.card h2.rank-title { color: var(--gold-strong); }

/* kalendář */
.stack { display: grid; gap: 12px; min-width: 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.cal-week { color: var(--muted); font-size: .74rem; font-weight: 600; text-align: center; }
.cal-day {
  position: relative;
  min-height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 9px;
  background: none;
  font-size: .92rem;
  cursor: pointer;
}
.cal-day.today { border-color: var(--gold); color: var(--gold-strong); font-weight: 700; }
.cal-day.selected { border-color: var(--gold); background: var(--gold); color: var(--on-gold); font-weight: 700; }
.cal-dot { position: absolute; left: 50%; bottom: 5px; width: 6px; height: 6px; border-radius: 50%; background: var(--gold); transform: translateX(-50%); }
.cal-day.selected .cal-dot { background: var(--on-gold); }

/* formuláře a tlačítka */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 5px; font-size: .9rem; font-weight: 600; }
.field small { color: var(--muted); font-weight: 400; }
input:not([type="checkbox"]), textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-size: 16px;
  font-weight: 400;
}
.invite-row { padding-top: 8px; border-top: 1px solid var(--line); }
input[type="date"],
input[type="datetime-local"] { display: block; min-width: 0; -webkit-appearance: none; appearance: none; }
textarea { min-height: 170px; resize: vertical; }
.check { display: flex; align-items: flex-start; gap: 10px; min-height: 44px; padding: 8px 0; font-size: .92rem; }
.check input { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--gold); }
.form-error { color: var(--danger); font-size: .92rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.btn.primary { border-color: var(--gold); background: var(--gold); color: var(--on-gold); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { min-height: 44px; padding: 4px 12px; font-size: .86rem; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { flex: none; width: 44px; height: 44px; border: 0; border-radius: 10px; background: none; color: var(--text); font-size: 1.3rem; line-height: 1; text-decoration: none; display: grid; place-items: center; cursor: pointer; }
.icon-btn:disabled { opacity: .3; }

.section-title { margin-top: 8px; color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

details summary { min-height: 32px; cursor: pointer; color: var(--gold-strong); font-weight: 600; }

dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .65); }
.dialog-body { display: grid; gap: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-bottom));
  z-index: 20;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: .9rem;
  font-weight: 600;
  transform: translateX(-50%);
}
