:root {
  --bg: #0c0f14;
  --panel: rgba(18, 22, 30, 0.92);
  --line: rgba(255, 255, 255, 0.08);
  --text: #e8e6e1;
  --muted: #8d93a0;
  --accent: #f0a640;
  --good: #7bc47f;
  --bad: #e46a5e;
  --tech: #b48ae6;
  --love: #ef8fb5;
  --panel-w: 360px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; }

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#view.drag { cursor: grabbing; }

#hud { position: fixed; top: 12px; left: 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; pointer-events: none; backdrop-filter: blur(6px); }
.hud-title { font-weight: 700; letter-spacing: .02em; }
.hud-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.hud-era { color: var(--accent); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; margin-top: 2px; }

#minimap { position: fixed; top: 96px; left: 12px; width: 168px; height: 168px; border-radius: 10px;
  border: 1px solid var(--line); background: #0e1218; cursor: crosshair; image-rendering: pixelated; }

#toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column;
  gap: 8px; align-items: center; pointer-events: none; z-index: 5; width: min(520px, calc(100vw - 32px)); }
.toast { background: var(--panel); border: 1px solid rgba(240,166,64,.5); color: var(--text); padding: 10px 16px;
  border-radius: 10px; font-weight: 600; text-align: center; box-shadow: 0 8px 30px rgba(0,0,0,.4);
  animation: toastIn .4s ease-out; transition: opacity .6s, transform .6s; backdrop-filter: blur(6px); }
.toast.tech { border-color: rgba(180,138,230,.6); }
.toast.out { opacity: 0; transform: translateY(-10px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }

#controls { position: fixed; left: 12px; bottom: 12px; display: flex; gap: 6px; }
#controls button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); font-size: 18px; cursor: pointer; }
#controls button:hover { border-color: rgba(255,255,255,.25); }
#btnPanel { display: none; }

#panel { position: fixed; top: 12px; right: 12px; bottom: 12px; width: var(--panel-w); background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; overflow: hidden;
  backdrop-filter: blur(6px); }
#panel section { padding: 12px 14px; border-bottom: 1px solid var(--line); }

.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.stat { text-align: center; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12px; }

.alert { margin: 8px 14px 0; padding: 6px 10px; border-radius: 8px; background: rgba(228,106,94,.15);
  color: var(--bad); font-size: 13px; }

.label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
#rName { font-weight: 600; margin: 2px 0 6px; }
.bar { height: 6px; border-radius: 3px; background: rgba(255,255,255,.08); overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--tech); transition: width .6s; }
.muted { color: var(--muted); }
.small { font-size: 12px; margin-top: 4px; }

#detail h3 { margin: 0 0 2px; font-size: 16px; display: flex; justify-content: space-between; align-items: center; }
#detail .close { background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 18px; }
#detail .row { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0; font-size: 13px; }
#detail .meters { display: grid; grid-template-columns: 70px 1fr; gap: 3px 8px; align-items: center; font-size: 12px; margin: 8px 0; }
#detail .meter { height: 5px; border-radius: 3px; background: rgba(255,255,255,.08); overflow: hidden; }
#detail .meter i { display: block; height: 100%; }
#detail .skills { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; font-size: 12px; }
#detail .skills span { display: flex; justify-content: space-between; }
#detail a { color: var(--accent); cursor: pointer; text-decoration: none; }
#detail .actions { margin-top: 8px; display: flex; gap: 6px; }
#detail .actions button { border: 1px solid var(--line); background: rgba(255,255,255,.05); border-radius: 8px; padding: 4px 10px; cursor: pointer; }
#detail .actions button.on { background: var(--accent); color: #1a1205; border-color: var(--accent); }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: 0; padding: 9px 1px; cursor: pointer; color: var(--muted); font-size: 12px;
  border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tab { flex: 1; overflow-y: auto; padding: 8px 14px 14px; }

.ev { padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.ev .when { color: var(--muted); font-size: 11px; display: block; }
.ev.big { color: var(--accent); font-weight: 600; }
.ev.tech { color: var(--tech); }
.ev.birth { color: var(--good); }
.ev.death, .ev.bad { color: var(--bad); }
.ev.love { color: var(--love); }
.ev.season, .ev.year { color: var(--muted); }

.person { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line);
  cursor: pointer; font-size: 13px; }
.person:hover { color: var(--accent); }
.person .doing { color: var(--muted); font-size: 12px; text-align: right; }

.era-h { margin: 12px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.tk { padding: 4px 8px; margin: 3px 0; border-radius: 6px; border: 1px solid var(--line); font-size: 13px; opacity: .5; }
.tk.known { opacity: 1; border-color: rgba(180,138,230,.5); background: rgba(180,138,230,.08); }
.tk.current { opacity: 1; border-color: var(--accent); }
.tk small { display: block; color: var(--muted); font-size: 11px; }

#graph { width: 100%; height: 180px; display: block; margin-top: 6px; }

#loading { position: fixed; inset: 0; display: grid; place-items: center; font-size: 18px; color: var(--muted); background: var(--bg); }
.join-box { max-width: 460px; padding: 24px; text-align: center; color: var(--text); font-size: 15px; }
.join-box h1 { margin: 0 0 12px; font-size: 30px; color: var(--accent); }
.join-box .muted { font-size: 13px; }
.join-btn { display: inline-block; margin-top: 14px; padding: 10px 20px; border-radius: 10px; background: var(--accent); color: #1a1205;
  font-weight: 700; text-decoration: none; }
#loading.gone { display: none; }

@media (max-width: 760px) {
  #btnPanel { display: block; }
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 55vh; border-radius: 14px 14px 0 0;
    transform: translateY(100%); transition: transform .25s; }
  body.panel-open #panel { transform: none; }
  body.panel-open #controls { bottom: calc(55vh + 12px); }
  #hud { top: 8px; left: 8px; padding: 6px 10px; }
  #minimap { top: auto; bottom: 60px; left: 8px; width: 110px; height: 110px; }
  body.panel-open #minimap { display: none; }
  #toasts { top: 86px; }
  #controls { left: 8px; bottom: 8px; }
}

.town { padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.town:hover .town-h b { color: var(--accent); }
.town-h { display: flex; justify-content: space-between; gap: 8px; }
.town .small { margin-top: 3px; }
.ev.move { color: #7fb8e0; }

.stats2 { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 0 14px 8px; font-size: 12px; color: var(--muted); }
.stats2:empty { display: none; }
.stats2 b { color: var(--text); font-variant-numeric: tabular-nums; }
.res-gold b { color: #e8c040; }
.res-silver b { color: #d0d4dc; }
.res-coins b { color: #f0c070; }
.ev.trade { color: #e0c070; }
.ev.heal { color: #9fd8a8; }

.thought { margin: 4px 0; padding: 6px 10px; border-radius: 10px; background: rgba(255,255,255,.06); font-style: italic; font-size: 13px; }
.coin { color: #f0c070; font-size: 12px; }
.ev.invest { color: #7fd0c0; }
.tabs { flex-wrap: wrap; }
.tabs button { flex: 1 0 auto; padding: 8px 4px; font-size: 11.5px; }

.ev.map { color: #7fd8c8; }

.paper { background: #efe6d2; color: #2a2218; border-radius: 6px; padding: 10px 12px; margin: 10px 0; font-family: Georgia, 'Times New Roman', serif; }
.paper-h { display: flex; justify-content: space-between; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; border-bottom: 2px solid #2a2218; padding-bottom: 4px; font-weight: 700; }
.paper h4 { margin: 8px 0 6px; font-size: 16px; line-height: 1.25; }
.paper p { margin: 3px 0; font-size: 13px; }
.paper-w { font-style: italic; color: #6a5a40; margin-top: 6px !important; }
.ev.social { color: #d8b0e8; }
.ev.vote { color: #f0a640; }
.bio { margin-top: 8px; font-size: 12px; }
.bio summary { cursor: pointer; color: var(--accent); }
.bio div { padding: 2px 0; }

.ev.diplo { color: #8fc8f0; }
.ev.war { color: #ff6a5a; font-weight: 600; }

.tk.find { cursor: pointer; border-color: rgba(255,214,120,.45); background: rgba(255,214,120,.07); }
.ev.edu { color: #9ac0f8; }

.pr { display: flex; justify-content: space-between; font-size: 13px; margin-top: 4px; }
#rName .bar { margin: 3px 0 2px; }
#rName .bar > div { height: 100%; background: var(--tech); }

/* --- kultura, víra, příroda --- */
.ev.crime { color: #e0a080; }
.ev.faith { color: #e8d08a; }
.ev.disaster { color: #ff8a60; font-weight: 600; }
a.lnk, .lnk { color: var(--accent); cursor: pointer; text-decoration: none; }
a.lnk:hover { text-decoration: underline; }
.bar.goal { margin-top: 3px; height: 5px; }
.bar.goal > div { background: var(--accent); }
.faith { padding: 8px 0; border-bottom: 1px solid var(--line); }
.faith-h { font-size: 14px; display: flex; gap: 6px; align-items: center; }
.faith-sym { font-size: 18px; }
.taboo { color: #e0a080; }
.myth { font-size: 12px; font-style: italic; margin: 3px 0 0 8px; color: #d8d0c0; }
.myth .muted { font-style: normal; }
.town-c { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.climate { display: flex; align-items: flex-end; gap: 1px; height: 30px; margin: 6px 0 2px; }
.climate i { flex: 1; min-width: 2px; border-radius: 1px 1px 0 0; }

/* --- okna --- */
#modal { position: fixed; inset: 0; background: rgba(5,8,12,.72); z-index: 20; display: grid; place-items: center; padding: 16px; backdrop-filter: blur(3px); }
#modal[hidden] { display: none; }
.modal-box { position: relative; width: min(1100px, 100%); max-height: calc(100vh - 32px); background: #141922; border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.6); display: flex; flex-direction: column; overflow: hidden; }
#modalBody { overflow: auto; padding: 18px 22px 22px; }
#modalBody h2 { margin: 0 34px 4px 0; font-size: 20px; }
#modalBody h3 { margin: 16px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.modal-x { position: absolute; top: 8px; right: 10px; background: none; border: 0; color: var(--muted); font-size: 26px; cursor: pointer; z-index: 2; }
.modal-x:hover { color: var(--text); }
.modal-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.modal-actions button, .book-nav button { border: 1px solid var(--line); background: rgba(255,255,255,.05); border-radius: 8px; padding: 5px 10px; cursor: pointer; }
.modal-actions button:hover, .book-nav button:hover:not([disabled]) { border-color: var(--accent); }
.scrollx { overflow-x: auto; padding-bottom: 8px; scrollbar-color: rgba(255,255,255,.25) transparent; }
#modalBody { scrollbar-color: rgba(255,255,255,.25) transparent; }

/* kartička člověka */
.fc { display: inline-flex; flex-direction: column; gap: 1px; min-width: 128px; max-width: 170px; padding: 6px 9px; border-radius: 9px; font-size: 11.5px;
  background: rgba(255,255,255,.05); border: 1px solid var(--line); cursor: pointer; text-align: left; vertical-align: top; line-height: 1.3; }
.fc b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fc span { color: var(--muted); }
.fc.alive { border-color: rgba(123,196,127,.55); }
.fc.alive.fem { background: rgba(239,143,181,.08); }
.fc.alive.mal { background: rgba(110,160,230,.08); }
.fc.dead { opacity: .78; background: rgba(255,255,255,.03); border-style: dashed; }
.fc.me { border: 2px solid var(--accent); }
.fc.sp { margin-left: 4px; }
.fc .fc-c { color: #d8c08a; }
.fc .fc-d { color: #d88a80; }
.fc .fc-t { color: #b8a0e0; }
.fc.unknown { opacity: .4; cursor: default; justify-content: center; min-height: 40px; }
.fc.more { cursor: default; opacity: .6; min-width: 0; }
.fc:hover:not(.unknown):not(.more) { border-color: var(--accent); }
.row-cards { display: flex; flex-wrap: wrap; gap: 6px; }

/* předci: zleva člověk, doprava rodiče, prarodiče... */
.ped { display: flex; align-items: center; }
.ped-me { position: relative; padding: 3px 0; }
.ped-par { display: flex; flex-direction: column; justify-content: center; margin-left: 22px; position: relative; }
.ped-par::before { content: ''; position: absolute; left: -22px; top: 50%; width: 11px; border-top: 2px solid rgba(255,255,255,.18); }
.ped-par > .ped { position: relative; }
.ped-par > .ped::before { content: ''; position: absolute; left: -11px; width: 11px; top: 50%; border-top: 2px solid rgba(255,255,255,.18); }
.ped-par > .ped::after { content: ''; position: absolute; left: -11px; border-left: 2px solid rgba(255,255,255,.18); }
.ped-par > .ped:first-child::after { top: 50%; bottom: 0; }
.ped-par > .ped:last-child::after { top: 0; height: 50%; }

/* potomci: klasický strom shora dolů */
.tree, .tree ul { padding: 0; margin: 0; display: flex; justify-content: center; list-style: none; }
.tree ul { padding-top: 18px; position: relative; }
.tree li { position: relative; padding: 18px 5px 0; display: flex; flex-direction: column; align-items: center; }
.tree > li { padding-top: 0; }
.tree li::before, .tree li::after { content: ''; position: absolute; top: 0; width: 50%; height: 18px; border-top: 2px solid rgba(255,255,255,.18); }
.tree li::before { right: 50%; }
.tree li::after { left: 50%; border-left: 2px solid rgba(255,255,255,.18); }
.tree li:only-child::before, .tree li:only-child::after { border-top: 0; }
.tree li:first-child::before, .tree li:last-child::after { border-top: 0; }
.tree li:last-child::before { border-right: 2px solid rgba(255,255,255,.18); border-radius: 0 6px 0 0; }
.tree li:first-child::after { border-radius: 6px 0 0 0; }
.tree > li::before, .tree > li::after { display: none; }
.tree ul::before { content: ''; position: absolute; top: 0; left: 50%; height: 18px; border-left: 2px solid rgba(255,255,255,.18); }
.couple { display: flex; align-items: flex-start; white-space: nowrap; }

.clan { padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; margin: 6px 0; cursor: pointer; }
.clan:hover { border-color: var(--accent); }
.clan.extinct { opacity: .65; border-style: dashed; }

/* kronika jako kniha */
.book { display: grid; grid-template-columns: 1fr 260px; grid-template-areas: 'h h' 'nav nav' 'pages side'; gap: 10px 18px; }
.book-h { grid-area: h; }
.book-nav { grid-area: nav; display: flex; gap: 8px; align-items: center; }
.book-nav select { background: #1c222c; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font: inherit; }
.book-nav button[disabled] { opacity: .35; cursor: default; }
.pages { grid-area: pages; background: #efe6d2; color: #2a2218; border-radius: 8px; padding: 16px 20px; font-family: Georgia, 'Times New Roman', serif;
  box-shadow: inset 0 0 40px rgba(120,90,40,.25); min-height: 200px; }
.entry { padding: 6px 0 8px; border-bottom: 1px dashed rgba(60,40,20,.25); }
.entry:last-child { border-bottom: 0; }
.entry-h { font-size: 12px; font-weight: 700; color: #7a5a30; text-transform: uppercase; letter-spacing: .05em; }
.entry-h span { text-transform: none; font-weight: 400; font-style: italic; letter-spacing: 0; }
.entry p { margin: 3px 0 0; font-size: 14px; line-height: 1.5; }
.entry.imp p { font-weight: 600; }
.book-side { grid-area: side; font-size: 12px; }
.book-side h3 { margin-top: 4px !important; }
.oral { color: #e8c88a; margin-top: 6px; }
@media (max-width: 760px) {
  .book { grid-template-columns: 1fr; grid-template-areas: 'h' 'nav' 'pages' 'side'; }
  #modal { padding: 6px; }
  #modalBody { padding: 14px; }
}
