:root {
  --bg: #f3ece0;
  --panel: #fbf7f0;
  --ink: #2d2418;
  --muted: #7a6b57;
  --line: #e2d6c3;
  --accent: #8a4b1f;
  --accent-ink: #fffaf2;
  --good: #3f7a3a;
  --warn: #b7791f;
  --bad: #a83a2c;
  --bar: #e9dfcf;
  --shadow: 0 1px 2px rgba(60, 40, 10, .08), 0 4px 14px rgba(60, 40, 10, .06);
  --serif: Georgia, "Times New Roman", serif;
  --sans: "Segoe UI", system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1913;
    --panel: #26211a;
    --ink: #eee4d3;
    --muted: #a7977f;
    --line: #3a3227;
    --accent: #d08a4f;
    --accent-ink: #1d1913;
    --good: #7fbf72;
    --warn: #e0a84a;
    --bad: #e2725f;
    --bar: #3a3227;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--sans); }
h1, h2 { font-family: var(--serif); font-weight: 600; margin: 0; }
h2 { font-size: 17px; margin-bottom: 10px; display: flex; align-items: baseline; gap: 8px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

button {
  font: inherit; padding: 6px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.ghost { background: transparent; }
button.tiny { padding: 1px 8px; min-width: 28px; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 8px;
}
textarea { width: 100%; resize: vertical; margin-bottom: 8px; }

/* Старт */
.start { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.start-card { max-width: 760px; width: 100%; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 28px; box-shadow: var(--shadow); }
.start-card h1 { font-size: 34px; }
.lead { color: var(--muted); font-size: 15px; }
.professions { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin: 16px 0; }
.prof { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer; background: var(--bg); }
.prof.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.prof b { display: block; font-family: var(--serif); font-size: 15px; }
.prof span { color: var(--muted); font-size: 12px; }
.professions.big { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.professions.big .prof { padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.professions.big .prof .icon { font-size: 34px; line-height: 1; }
.professions.big .prof b { font-size: 19px; }
.professions.big .prof .flavor { font-size: 13px; font-style: italic; }
.prof .perk { font-size: 13px; color: var(--ink); }
.prof .perk .lbl { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.prof .perk.strong .lbl { color: var(--good); }
.prof .perk.special { color: var(--accent); }
.prof.selected { background: var(--panel); }
.prof.selected b::after { content: " ✓"; color: var(--accent); }
.prof-legend { max-width: 760px; }
.promo-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.promo-row input { text-transform: uppercase; letter-spacing: .08em; width: 140px; }
.promo-row .muted { flex: 1; min-width: 240px; }
.prof-icons { display: flex; gap: 4px; flex-wrap: wrap; }
.prof-icons button { display: flex; flex-direction: column; align-items: center; min-width: 64px; padding: 4px 6px; font-size: 11px; opacity: .6; }
.prof-icons button .icon { font-size: 22px; }
.prof-icons button.selected { opacity: 1; outline: 2px solid var(--accent); }
.worlds { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; margin-bottom: 8px; }
.world { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer; background: var(--bg); }
.world-new { border-style: dashed; margin-bottom: 4px; }
.worlds-title { font-size: 13px; color: var(--muted); font-weight: normal; margin: 10px 0 6px; }
.world.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.world b { font-family: var(--serif); }
.world p { margin: 2px 0 0; color: var(--muted); font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden; }
.start-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; margin: 10px 0; }
.start-row label { display: flex; gap: 8px; align-items: center; }
.start-row input[type=number] { width: 120px; }
.start-actions { display: flex; gap: 10px; margin-top: 16px; }
.note { color: var(--warn); }
.footer { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 10px; }
.world.old { opacity: .7; }
.history-detail { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }

/* Верхня панель */
.topbar { display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: center; padding: 12px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.title { flex: 0 1 320px; min-width: 200px; }
.title h1 { font-size: 22px; }
#date { display: grid; gap: 4px; margin-top: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { cursor: help; white-space: nowrap; }
.chips .chip { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; font-size: 13px; }
.stats { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.stat { cursor: help; }
.stat b { font-variant-numeric: tabular-nums; }
.stat.good b { color: var(--good); } .stat.warn b { color: var(--warn); } .stat.bad b { color: var(--bad); }
.actions { display: flex; gap: 8px; }

/* Екрани гри: вкладки за діяльністю, на екрані — лише його панелі (колонками, як влізуть) */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; box-shadow: var(--shadow); }
.screen-tabs { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px 20px 0; border-bottom: 1px solid var(--line); }
.screen-tabs button { border: 1px solid transparent; border-bottom: none; border-radius: 8px 8px 0 0; background: none;
  padding: 7px 14px; position: relative; }
.screen-tabs button.selected { background: var(--panel); border-color: var(--line); font-weight: 600; margin-bottom: -1px; }
.tab-badge:empty { display: none; }
.tab-badge { display: inline-block; margin-left: 6px; min-width: 16px; padding: 0 4px; border-radius: 8px;
  font-size: 11px; font-weight: 700; line-height: 16px; text-align: center; color: #fff; background: var(--warn); }
.tab-badge.w3 { background: var(--bad); }
.screens { columns: 3 340px; column-gap: 16px; padding: 16px 20px; }
.screens > .panel { break-inside: avoid; margin-bottom: 16px; }
.screens > .panel.hidden { display: none; }
/* «Тиждень» — завжди три колонки (їжа · люди · журнал): у колонках-«газеті» довга панель людей
   на не дуже широкому вікні зсувала все в дві. */
@media (min-width: 900px) {
  .screens[data-screen="week"] { columns: auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) minmax(0, 1fr);
    gap: 16px; align-items: start; }
  .screens[data-screen="week"] > .panel { margin-bottom: 0; }
}
.screens[data-screen="week"] > .panel:not([data-screen="week"]) { display: none; }
.screens[data-screen="economy"] > .panel:not([data-screen="economy"]) { display: none; }
.screens[data-screen="growth"] > .panel:not([data-screen="growth"]) { display: none; }
.screens[data-screen="village"] > .panel:not([data-screen="village"]) { display: none; }
.screens[data-screen="army"] > .panel:not([data-screen="army"]) { display: none; }
.screens[data-screen="map"] > .panel:not([data-screen="map"]) { display: none; }
.screens[data-screen="friends"] > .panel:not([data-screen="friends"]) { display: none; }
.screens[data-screen="more"] > .panel:not([data-screen="more"]) { display: none; }
/* Карта — на весь екран, більші клітинки */
.screens[data-screen="map"] { columns: auto; }
.screens[data-screen="map"] > .panel { max-width: 920px; margin: 0 auto; }
.screens[data-screen="map"] .tile { font-size: 28px; border-radius: 8px; }
.screens[data-screen="map"] .tile .camp, .screens[data-screen="map"] .tile .manor { font-size: 16px; }
.screens[data-screen="map"] .map { gap: 4px; }
@media (max-width: 720px) { .screens { padding: 12px 16px; } .screen-tabs { padding: 8px 16px 0; } .topbar { padding: 12px 16px; } }
/* Телефон: верхня панель липка, тож вона мусить бути низькою — показники й кнопки в один рядок,
   що гортається вбік, замість трьох-чотирьох рядків на третину екрана. Так само вкладки й переходи. */
@media (max-width: 640px) {
  .topbar { gap: 6px; padding: 8px 12px calc(6px); }
  .title { flex: 1 1 100%; min-width: 0; }
  .title h1 { font-size: 18px; }
  #date { display: block; font-size: 13px; }
  #date .chips { display: none; }
  .stats, .actions, .screen-tabs, .jump-bar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .stats::-webkit-scrollbar, .actions::-webkit-scrollbar, .screen-tabs::-webkit-scrollbar, .jump-bar::-webkit-scrollbar { display: none; }
  .stats { flex: 1 1 100%; gap: 4px; }
  .stat { padding: 2px 8px; font-size: 13px; }
  .actions { flex: 1 1 100%; gap: 6px; }
  .actions button { white-space: nowrap; padding: 6px 10px; flex: 0 0 auto; }
  .actions #next-week { flex: 1 0 auto; }
  .screen-tabs { padding: 6px 8px 0; }
  .screen-tabs button { white-space: nowrap; padding: 7px 10px; flex: 0 0 auto; }
  .screens { padding: 10px 8px; }
  .panel { padding: 12px 10px; }
  /* Рядки складу й виробництв: назва з поясненням — на всю ширину, кнопки — під нею справа,
     інакше назва стискалась у вузький стовпчик по слову в рядок. */
  #stock .row, #crafts .row { flex-wrap: wrap; justify-content: flex-end; row-gap: 4px; }
  #stock .row > .grow, #crafts .row > .grow { flex: 1 1 100%; }
  /* Вікна (події, підсумки) — не вищі за екран, щоб кнопки вибору внизу були досяжні. */
  .overlay { padding: 8px; }
  .modal { max-height: calc(100dvh - 16px); overflow-y: auto; padding: 16px 14px; }
}

/* Стартовий екран: одна велика «Продовжити» */
.resume { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: left;
  padding: 14px 18px; font-size: 16px; }
.resume-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; opacity: .85; }
.resume-sub { font-size: 12px; opacity: .85; }
.other-saves, .start-advanced { margin: 10px 0; }
.other-saves > summary, .start-advanced > summary { cursor: pointer; color: var(--muted); font-size: 14px; }

/* Рядки */
.row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .num { font-variant-numeric: tabular-nums; min-width: 26px; text-align: center; font-weight: 600; }
.row .sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.stepper { display: flex; align-items: center; gap: 4px; }
.sell input { width: 60px; }
.panel.foldable > h2 { cursor: pointer; user-select: none; }
.panel.foldable > h2::before { content: "▾ "; color: var(--muted); }
.panel.foldable.folded > h2::before { content: "▸ "; }
.panel.foldable.folded > h2 { margin-bottom: 0; }
.panel.foldable.folded > :not(h2) { display: none; }
select.policy { width: 2.6em; padding: 1px 2px; cursor: pointer; }
input.keep { width: 46px; }
.badge { font-size: 11px; padding: 0 6px; border-radius: 999px; background: var(--bar); color: var(--muted); }
.payoff, .hint-hover { cursor: help; }
.craft-group + .craft-group { margin-top: 6px; }
/* --topbar-h ставить app.js: верхня панель липка, і без відступу рядок переходів і група ховались би під нею */
.jump-bar { position: sticky; top: var(--topbar-h, 0px); z-index: 2; display: flex; flex-wrap: wrap; gap: 4px; padding: 4px 0 6px;
  background: var(--panel); }
.jump-bar button { font-size: 12px; }
.friend-more > summary { cursor: pointer; color: var(--muted); margin-top: 4px; }
.star { font-size: 15px; line-height: 1; padding: 0 4px 0 0; color: var(--muted); text-decoration: none; }
.star.on { color: #c9971c; }
.cart { font-size: 13px; line-height: 1; padding: 0 4px 0 0; text-decoration: none; filter: grayscale(1); opacity: .45; }
.cart.on { filter: none; opacity: 1; }
.sub .cart, #autobuy .cart { filter: none; opacity: 1; text-decoration: underline dotted; }
#stock .craft-group, #crafts .craft-group, #stock .row { scroll-margin-top: calc(var(--topbar-h, 0px) + 44px); }
a.goto { color: inherit; text-decoration: underline dotted; cursor: pointer; }
a.goto:hover { color: var(--accent); }
.row.flash { animation: row-flash 1.6s ease-out; }
@keyframes row-flash { from { background: color-mix(in srgb, var(--accent) 30%, transparent); } to { background: transparent; } }
.craft-group-head { font-family: var(--serif); font-weight: 600; cursor: pointer; user-select: none;
  padding: 4px 0; border-bottom: 1px solid var(--line); }
.craft-group-head::before { content: "▾ "; color: var(--muted); }
.craft-group.folded .craft-group-head::before { content: "▸ "; }
.craft-group.folded > :not(.craft-group-head) { display: none; }
.payoff { white-space: nowrap; }
.debt-row { display: flex; gap: 8px; align-items: center; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.debt-row span { flex: 1; }
.debt-row input { width: 90px; }

/* Ідея і вердикт */
.verdict { margin-top: 12px; border-left: 3px solid var(--accent); padding: 8px 12px; background: var(--bg); border-radius: 0 8px 8px 0; }
.verdict.accepted { border-color: var(--good); }
.verdict.too_advanced { border-color: var(--warn); }
.verdict.not_possible, .verdict.already_known { border-color: var(--muted); }
.verdict h3 { margin: 0 0 4px; font-size: 14px; }
.verdict ul { margin: 4px 0; padding-left: 18px; }
.verdict details { margin-top: 6px; }
.verdict summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.trace { font-family: ui-monospace, Consolas, monospace; font-size: 11px; color: var(--muted); margin: 4px 0 0; padding-left: 18px; }

/* Дослідження */
.research { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.research:last-child { border-bottom: 0; }
.research.active { }
.research-head { display: flex; align-items: center; gap: 8px; }
.research-head b { flex: 1; }
.progress { height: 8px; border-radius: 4px; background: var(--bar); overflow: hidden; margin: 6px 0 4px; }
.progress div { height: 100%; background: var(--accent); }
.tag-active { color: var(--good); font-size: 12px; font-weight: 600; }

/* Журнал */
.week { margin-bottom: 8px; }
.week b { font-size: 12px; color: var(--muted); }
.week ul { margin: 2px 0; padding-left: 16px; }
.week li.alert { color: var(--bad); }
.week li.win { color: var(--good); font-weight: 600; }
.log li { margin-bottom: 3px; }

/* Герой */
.knowledge { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 13px; margin-top: 8px; }
.k-clear { color: var(--good); } .k-vague { color: var(--warn); } .k-none { color: var(--muted); }

/* Модальні вікна */
.overlay { position: fixed; inset: 0; background: rgba(20, 14, 6, .55); display: flex; align-items: center;
  justify-content: center; padding: 16px; z-index: 20; }
.modal { background: var(--panel); border-radius: 12px; max-width: 520px; width: 100%; padding: 22px; box-shadow: var(--shadow); }
.modal h2 { font-size: 22px; }
.choices { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.choices button { text-align: left; padding: 10px 12px; }

/* Їжа */
.food-now { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; margin-bottom: 8px; }
.food-now b { font-variant-numeric: tabular-nums; }
.forecast { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 6px 0 10px; }
.season { border: 1px solid var(--line); border-radius: 8px; padding: 6px; text-align: center; background: var(--bg); }
.season.current { border-color: var(--accent); }
.season .name { font-size: 12px; color: var(--muted); }
.season .bal { font-weight: 700; font-variant-numeric: tabular-nums; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.chart { width: 100%; height: 70px; display: block; }
.chart .line-food { stroke: var(--accent); fill: none; stroke-width: 2; }
.chart .line-pop { stroke: var(--good); fill: none; stroke-width: 1.5; stroke-dasharray: 3 3; }
.chart .zero { stroke: var(--line); }
.legend { display: flex; gap: 12px; font-size: 11px; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 4px; }
.job-head { font-size: 12px; color: var(--muted); margin-top: 8px; text-transform: uppercase; letter-spacing: .04em; }
.job-head:first-child { margin-top: 0; }
.nonfood b { font-weight: 500; }
.row.dormant { opacity: .6; }
.suggest-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 13px; }
.suggest-head span { flex: 1; color: var(--muted); }
.idea-card { display: block; width: 100%; text-align: left; margin-bottom: 6px; padding: 8px 10px; background: var(--bg); }
.idea-card b { display: block; }
.idea-card span { font-size: 12px; color: var(--muted); }
.hint { font-size: 12px; color: var(--warn); margin-top: 2px; }
.hint b { color: var(--ink); }
.tools-line { font-size: 11px; color: var(--good); margin: 2px 0 0; }
.stock-badge { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.factors { display: flex; gap: 8px; font-size: 11px; color: var(--muted); margin-top: 1px; }
.factors .cur { color: var(--ink); font-weight: 600; }
.factors .word { display: none; }
body.kids .factors { flex-wrap: wrap; font-size: 13px; gap: 4px 12px; }
body.kids .factors .num { display: none; }
body.kids .factors .word { display: inline; }
body.kids .factors > span { cursor: help; text-decoration: underline dotted; text-underline-offset: 3px; }
body.kids .factors > span.show .num { display: inline; margin-right: 4px; }
.badge.vit { color: var(--good); }
button.link { border: 0; background: transparent; color: var(--muted); text-decoration: underline; padding: 0 4px; font-size: 11px; }
button.link:hover { color: var(--accent); }
a.link { color: var(--muted); font-size: 11px; padding: 0 4px; }
.ai-sources { margin-top: 4px; }
.ai-sources label { display: block; margin: 2px 0; }
.ai-sources summary { cursor: pointer; color: var(--muted); }
.archive { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; }
.archive summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.archive .row { opacity: .75; }
.badge.off { background: transparent; border: 1px dashed var(--muted); }

/* Дитячий режим: менше цифр, більші кнопки, ховаємо деталі для дорослих */
body.kids .kids-hide, body.kids #meta-panel .tokens, body.kids .tools-line,
body.kids .stock-badge + .sub, body.kids .chart, body.kids .legend { display: none !important; }
body.kids { font-size: 15px; }
body.kids button { padding: 8px 14px; }
body.kids button.tiny { padding: 4px 10px; min-width: 34px; }
#autoassign-btn { margin-bottom: 8px; }
body.kids #autoassign-btn { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Мапа */
.map { display: grid; gap: 3px; margin-bottom: 8px; }
.tile { aspect-ratio: 1; border-radius: 6px; display: flex; align-items: center; justify-content: center;
  font-size: 18px; cursor: pointer; border: 2px solid transparent; position: relative; user-select: none; }
.tile.fog { background: var(--bar) !important; color: var(--muted); font-size: 13px; }
.tile.developed { border-color: var(--accent); }
/* Розвідана, але не освоєна — бліда, щоб не плутати з освоєною (гравцю здавалось, що освоєння зникає). */
.tile:not(.developed):not(.fog) { opacity: .5; filter: saturate(.6); }
.tile.can:not(.developed) { border-style: dashed; border-color: var(--muted); opacity: .8; }
.tile.building:not(.developed) { opacity: .9; border-style: dotted; border-color: var(--accent); }
.tile.selected { outline: 2px solid var(--ink); }
.tile .camp { position: absolute; right: 1px; bottom: -2px; font-size: 12px; }
.tile .manor { position: absolute; left: 1px; top: -2px; font-size: 12px; }
.t-field { background: #e8d68f; } .t-forest { background: #8fb27f; } .t-water { background: #8fb6d6; }
.t-marsh { background: #a9b58c; } .t-hills { background: #c4b19a; } .t-meadow { background: #bcd69a; }
.t-village { background: #e9c9a0; }
@media (prefers-color-scheme: dark) {
  .t-field { background: #6e6230; } .t-forest { background: #3d5a35; } .t-water { background: #33536e; }
  .t-marsh { background: #4c5638; } .t-hills { background: #5d4f40; } .t-meadow { background: #4f6436; }
  .t-village { background: #6d5236; }
}
.map-legend { font-size: 11px; color: var(--muted); }

/* Військо */
.power { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.power .metric { flex: 1; min-width: 90px; }
.mil-block { border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 8px; }
.mil-block h3 { font-size: 13px; margin: 0 0 4px; font-family: var(--serif); }
.camp { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.camp .grow { flex: 1; min-width: 0; }
.neighbor { padding: 6px 0 6px 8px; border-left: 3px solid var(--line); margin: 6px 0; }
.neighbor.hostile { border-left-color: var(--bad); }
.neighbor.conquered { opacity: 0.75; }
.neighbor .actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.liege { background: var(--bg); border-left: 3px solid var(--warn); padding: 8px 10px; border-radius: 0 8px 8px 0; margin-top: 8px; }
.liege .actions { display: flex; gap: 6px; margin-top: 6px; }
.choices .detail { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Аналіз */
.modal.wide { max-width: 680px; max-height: calc(100vh - 32px); overflow-y: auto; }
.status { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.status.victory { color: var(--good); } .status.defeat { color: var(--bad); }
.factor { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.factor .mark { font-weight: 700; width: 18px; flex: none; text-align: center; }
.factor.positive .mark { color: var(--good); } .factor.negative .mark { color: var(--bad); }
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; margin: 10px 0; }
.metric { background: var(--bg); border-radius: 8px; padding: 6px 10px; font-size: 12px; color: var(--muted); }
.metric b { display: block; font-size: 16px; color: var(--ink); }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
/* Хрестик, що лишається видимим під час прокрутки довгої модалки */
.modal-x { position: sticky; top: 0; float: right; margin: -8px -8px 0 8px; z-index: 1; width: 34px; height: 34px; padding: 0;
  border-radius: 50%; font-size: 16px; line-height: 1; }
.modal h3 { font-family: var(--serif); margin: 14px 0 4px; }

/* Завантаження і повідомлення */
.loading { position: fixed; inset: 0; background: rgba(20, 14, 6, .35); display: flex; align-items: center;
  justify-content: center; gap: 12px; color: #fff; font-size: 16px; z-index: 30; }
.spinner { width: 26px; height: 26px; border: 3px solid rgba(255, 255, 255, .3); border-top-color: #fff;
  border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 40; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); }
.feedback-btn { position: fixed; left: 16px; bottom: 16px; z-index: 39; border-radius: 999px; box-shadow: var(--shadow); }
.fun-scale { display: flex; gap: 6px; margin-top: 4px; }
.fun-scale button { font-size: 24px; padding: 4px 10px; opacity: .55; }
.fun-scale button.selected { opacity: 1; outline: 2px solid var(--accent, #a0672a); }
#feedback .field { display: block; margin-top: 10px; }
#feedback textarea { width: 100%; box-sizing: border-box; margin-top: 4px; font: inherit; }
.toast.error { background: var(--bad); color: #fff; }
.toast.sticky { cursor: pointer; padding-right: 30px; position: relative; }
.toast.sticky::after { content: "✕"; position: absolute; top: 8px; right: 10px; opacity: .7; }

/* Гра на кількох */
.mode-tabs { display: flex; gap: 8px; margin: 14px 0 4px; flex-wrap: wrap; }
.mode-tabs .mode { flex: 1; min-width: 160px; }
.mode-tabs .mode.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }
.player-row { display: grid; grid-template-columns: 28px 1fr 1fr; gap: 8px; align-items: center; margin: 10px 0 14px; }
.player-row .prof-icons { grid-column: 2 / -1; flex-wrap: nowrap; overflow-x: auto; }
.player-row .num { font-family: var(--serif); font-weight: 700; color: var(--accent); }
@media (max-width: 640px) { .player-row { grid-template-columns: 1fr; } .player-row .num { display: none; } .player-row .prof-icons { grid-column: auto; } }
.hotseat-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.turn-player { font-family: var(--serif); font-weight: 700; font-size: 16px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; padding: 4px 10px; border-radius: 8px; background: var(--bar); min-width: 64px; text-align: center; }
.timer.low { background: var(--bad); color: var(--accent-ink); animation: pulse 1s infinite; }
.timer.paused { opacity: .6; }
@keyframes pulse { 50% { opacity: .55; } }
.curtain { background: var(--bg); }
.hs-modes { margin: 8px 0; }
.room-join-row { align-items: center; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.room-join-row input { width: 9em; text-transform: uppercase; }
.room-code { font-size: 32px; letter-spacing: 4px; font-weight: 700; margin: 4px 0 8px; user-select: all; }
.room-share { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: center; margin: 8px 0; }
.room-share .qr { width: 140px; height: 140px; background: #fff; border-radius: 6px; padding: 4px; }
.room-share code { word-break: break-all; user-select: all; }
.room-players { list-style: none; padding: 0; margin: 12px 0; text-align: left; }
.room-players li { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; }
.room-players li.free { border-style: dashed; color: var(--muted); }
.room-form { display: flex; flex-direction: column; gap: 10px; text-align: left; max-width: 720px; margin: 12px auto; }
.room-form input, .room-form select { width: 100%; }
.hs-modes .mode { font-size: 13px; }
.waiting { flex-basis: 100%; }
body.readonly .waiting { color: var(--good); font-weight: 600; }
.player-links { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; text-align: left; }
.player-link { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px 10px; border: 1px solid var(--line);
               border-radius: 8px; background: var(--panel); }
.player-link code { font-size: 13px; user-select: all; word-break: break-all; }
.player-link .qr { width: 112px; height: 112px; background: #fff; border-radius: 6px; padding: 4px; }
.player-link .ready { color: var(--good); font-weight: 600; }
.curtain .big { font-family: var(--serif); font-size: 30px; margin: 4px 0 2px; }
.standings { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 14px; }
.standings th, .standings td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.standings tr.me td { background: var(--bar); font-weight: 600; }
.standings .place { font-size: 18px; width: 32px; }
.round-report { max-height: 220px; overflow-y: auto; font-size: 13px; padding-left: 18px; }
.friend { padding: 8px 0 8px 8px; border-left: 3px solid var(--good); margin: 6px 0; }
.friend-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.friend-row .qty { width: 58px; }
.friend-row select { max-width: 150px; }
.offer { font-size: 13px; margin-top: 6px; padding: 4px 8px; border-radius: 6px; background: var(--bar); }
.offer.in { border-left: 3px solid var(--warn); }
.round-report.inbox { font-weight: 600; }
.horde { border: 2px solid var(--bad); border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; background: var(--bg); }
.duels-open { font-weight: 600; color: var(--bad); margin: 6px 0; }
.nominations { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; margin: 12px 0; }
.nomination { background: var(--bar); border-radius: 8px; padding: 8px 10px; }
.nomination b { display: block; font-size: 13px; }
.nomination span { font-size: 13px; color: var(--muted); }

/* Як грати */
.guide { z-index: 60; }
.guide .modal { max-width: 720px; }
.guide details { border-top: 1px solid var(--line); padding: 8px 0; }
.guide summary { cursor: pointer; font-family: var(--serif); font-size: 17px; font-weight: 700; padding: 4px 0; }
.guide li { margin: 5px 0; line-height: 1.45; }
.guide ol, .guide ul { padding-left: 22px; }

/* Що нового */
.cl-old { position: relative; margin-top: 18px; }
.cl-old-inner { max-height: 160px; overflow: hidden; filter: blur(3px); opacity: .45; pointer-events: none; user-select: none;
  -webkit-mask-image: linear-gradient(#000, transparent); mask-image: linear-gradient(#000, transparent); }
.cl-old.open .cl-old-inner { max-height: none; filter: none; opacity: 1; pointer-events: auto; user-select: auto;
  -webkit-mask-image: none; mask-image: none; }
.cl-more { position: absolute; left: 50%; top: 50px; transform: translateX(-50%); }
#changelog h3 { font-family: var(--serif); margin: 18px 0 4px; border-top: 1px solid var(--line); padding-top: 12px; }
#changelog h4 { margin: 10px 0 2px; font-size: 14px; color: var(--accent); }
#changelog li { margin: 5px 0; line-height: 1.45; font-size: 14px; }
#changelog code { background: var(--bar); padding: 0 4px; border-radius: 4px; }

/* Наступний тиждень у панелі їжі */
.next-week { padding: 8px 10px; border-radius: 8px; margin-bottom: 8px; border-left: 4px solid var(--good); background: var(--bg); }
.next-week.bad { border-left-color: var(--bad); }
.next-week .small { margin-top: 3px; }

/* Що зараз важливо */
.priorities { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px 0; }
.priority { display: flex; gap: 6px; align-items: center; text-align: left; font-size: 13px; padding: 6px 10px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--panel); max-width: 420px; }
.priority .icon { font-size: 16px; }
.priority.w3 { border-color: var(--bad); box-shadow: inset 3px 0 0 var(--bad); }
.priority.w2 { border-color: var(--warn); box-shadow: inset 3px 0 0 var(--warn); }
.priority.w0 { color: var(--muted); }
.advisor { display: flex; align-items: flex-end; flex: none; }
.advisor-face { display: block; border-radius: 50%; background: var(--line); }
.advisor-line { display: inline-flex; align-items: center; gap: 6px; }
/* Замовлення */
.contract { padding: 8px 0 8px 8px; border-left: 3px solid var(--line); margin: 6px 0; }
.contract.offer { border-left-color: var(--accent); }
.contract.urgent { border-left-color: var(--bad); }
.contract .actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.contract .bar { height: 6px; background: var(--bar); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.contract .bar div { height: 100%; background: var(--good); }

/* AI думає у фоні */
.thinking { font-size: 13px; padding: 6px 10px; margin: 6px 0; border-radius: 8px; background: var(--bar);
  border-left: 3px solid var(--accent); animation: pulse 1.6s infinite; }

/* Попит на ринку біля ціни на складі */
.demand.falling { color: var(--warn, #b7791f); }
.demand.saturated { color: var(--bad, #c0392b); }

/* Верхня панель: кнопка «ще N» для плашок, які зараз не горять; характер світу в рядку дати */
.stat.idle-stat { cursor: pointer; font: inherit; color: inherit; }
.stat.critical { cursor: pointer; font: inherit; color: var(--bad); border-color: var(--bad); box-shadow: inset 3px 0 0 var(--bad); }
.stat.more-stats { cursor: pointer; color: var(--muted); border-style: dashed; font: inherit; }
.temperament.warlike { color: var(--bad); }
.temperament.peaceful { color: var(--good); }

/* Найм нагорі «Людей на джерелах» */
.hiring { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 6px 8px; margin-bottom: 8px; border-radius: 8px; background: var(--bg); }
.hire-group { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }

/* Стрілка руху товару за тиждень біля джерела */
.flow { font-size: 0.85em; white-space: nowrap; cursor: help; }

/* Досліди минулого тижня — нагорі панелі «Дослідження» */
.research-week { margin-bottom: 8px; padding: 6px 8px; background: var(--bg); border-radius: 8px; display: grid; gap: 2px; }

/* Журнал розвідки */
.scout-log { margin: 6px 0; display: grid; gap: 3px; }
.scout-log .when { color: var(--muted); white-space: nowrap; margin-right: 4px; }
.gear-row { margin-top: 3px; }
.nowrap { white-space: nowrap; }
#room-resume .resume { margin-bottom: 12px; }
.professions.guide .prof { cursor: default; }
.professions.guide .prof.selected { border-color: var(--line); box-shadow: none; background: var(--bg); }
.professions.guide .prof.selected b::after { content: ""; }
