/* «Макулатура», прототип: панели интерфейса поверх холста. Палитра — из макета питча. */
:root {
  --floor: #DDE3E8;
  --text: #2B303A;
  --muted: #6B7688;
  --faint: #9AA4B2;
  --panel: #F7F8FA;
  --panel-edge: #C6CED8;
  --chip: #E6EBF1;
  --blue: #4A78C2;
  --green: #5AA469;
  --ok: #4E9B5D;
  --warn: #E7A23B;
  --bad: #D9543F;
  --calm: #8DA2BF;          /* «запас полон»: сделал сколько влезло и ждёт */
  --type: #7B5EA7;          /* литеры и наборная — узкое место эпохи */
  --type-light: #B9A6D6;
  --idle: #B4BDC9;
  --wood: #A87B52;
  --shadow: 0 4px 14px rgba(28, 38, 56, 0.18);
  --ui: "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --book: "Old Standard TT", Georgia, serif;
  --side-w: 262px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #C3CBD4;
  color: var(--text);
  font: 13px/1.35 var(--ui);
  -webkit-font-smoothing: antialiased;
}

#world {
  position: fixed;
  inset: 0;
  display: block;
  cursor: default;
  touch-action: none;
}

button { font: inherit; color: inherit; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.kicker {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  position: fixed;
  left: 0; right: 0; top: 0;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 14px;
  background: rgba(247, 248, 250, 0.97);
  border-bottom: 1px solid var(--panel-edge);
  box-shadow: 0 2px 0 rgba(28, 38, 56, 0.06);
  z-index: 5;
  white-space: nowrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 1.5px;
  padding-right: 16px;
  border-right: 1px solid var(--panel-edge);
}
.spines { display: inline-flex; align-items: flex-end; gap: 1px; height: 16px; }
.spines i { display: block; width: 4px; border-radius: 1px; }
.spines i:nth-child(1) { height: 13px; background: #D9543F; }
.spines i:nth-child(2) { height: 16px; background: #4A78C2; }
.spines i:nth-child(3) { height: 13px; background: #E7A23B; }

.res { display: flex; align-items: center; gap: 7px; color: var(--muted); font-weight: 500; }
.res b { font: 700 13px var(--mono); color: var(--text); }
.res-icon { width: 20px; height: 20px; border-radius: 5px; background: var(--chip); position: relative; flex: none; }
.res-paper::after { content: ""; position: absolute; left: 5px; top: 3px; width: 10px; height: 13px; background: #fff; border: 1px solid #9AA5B5; border-radius: 1px; }
.res-ink::after { content: ""; position: absolute; left: 5px; top: 5px; width: 10px; height: 11px; background: #23262D; border-top: 3px solid #5B6270; border-radius: 2px; }
.res-type::after { content: ""; position: absolute; left: 4px; top: 4px; width: 12px; height: 11px; background: repeating-linear-gradient(90deg, #7C8391 0 3px, transparent 3px 4.5px); border-bottom: 2px solid #4A505C; }
.res-books::after { content: ""; position: absolute; left: 4px; top: 4px; width: 12px; height: 13px; background: linear-gradient(90deg, #A8433A 0 3.5px, transparent 3.5px 4.5px, #2F4A7A 4.5px 8px, transparent 8px 9px, #C8963E 9px 12px); border-radius: 1px; }

.spacer { flex: 1; }

.era { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.era-badge { background: #2B303A; color: #fff; border-radius: 9px; padding: 2px 9px; font-size: 11px; font-weight: 700; letter-spacing: 0.8px; }

.btn {
  border: 1px solid var(--panel-edge);
  background: #fff;
  border-radius: 8px;
  padding: 5px 12px;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { border-color: #9FB0C6; }
.btn:focus-visible, .seg button:focus-visible, .tool:focus-visible, .link:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.btn-accent { background: #2B303A; color: #fff; border-color: #2B303A; }
.btn-accent:hover { background: #3A4250; }

.link { border: 0; background: none; padding: 2px 4px; cursor: pointer; color: var(--blue); font-weight: 600; }
.link.danger { color: #B2483B; }

/* ---------------------------------------------------------------- right column */

.side {
  position: fixed;
  right: 10px;
  top: 54px;
  bottom: 10px;
  width: var(--side-w);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 4;
  overflow-y: auto;          /* on a short window the column scrolls instead of squeezing the list to nothing */
  scrollbar-width: thin;
}

.stage {
  flex: 1;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  padding: 12px 14px 12px;
}
.stage-head { display: flex; align-items: baseline; justify-content: space-between; margin-top: 2px; }
.stage-head h2 { margin: 0; font-size: 19px; font-weight: 700; }
.count { font: 700 14px var(--mono); }
.progress { height: 6px; border-radius: 3px; background: #E1E6EC; margin: 8px 0 10px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--green); border-radius: 3px; }

.shelf { width: 100%; height: 72px; display: block; flex: none; }

.books {
  list-style: none;
  margin: 10px -6px 0 0;
  padding: 8px 6px 0 0;
  border-top: 1px solid var(--panel-edge);
  overflow-y: auto;
  flex: 1;
  min-height: 60px;
  scrollbar-width: thin;
}
.books li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px;
  border-radius: 5px;
  color: var(--muted);
  min-height: 21px;
  transition: background 2.4s ease;
}
.books li .dot {
  width: 13px; height: 13px; border-radius: 50%; flex: none;
  border: 1.5px solid #B4BDC9;
  position: relative;
}
.books li.got { color: var(--text); font-weight: 500; }
.books li.got .dot { background: var(--green); border-color: var(--green); }
.books li.got .dot::after {
  content: ""; position: absolute; left: 3.5px; top: 1px; width: 3px; height: 6px;
  border: solid #fff; border-width: 0 1.8px 1.8px 0; transform: rotate(45deg);
}
.books li { cursor: pointer; }
.books li:hover:not(.got) { background: #EDF1F6; }
.books li.got { cursor: default; }
.books li .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.books li .tag { font-size: 10px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; color: #fff; background: var(--blue); border-radius: 4px; padding: 1px 5px; }
.books li .tag.print { background: var(--bad); }
.books li .tag.next { background: #fff; color: var(--type); box-shadow: inset 0 0 0 1px var(--type); }
.books li.fresh { background: rgba(90, 164, 105, 0.28); transition: none; }

.stage-foot { border-top: 1px solid var(--panel-edge); padding-top: 9px; margin-top: 8px; flex: none; }
.reward { font-weight: 600; margin-top: 3px; }
.colophon { font: italic 14px/1.4 var(--book); color: var(--text); margin-top: 4px; }
.done-title { font: 700 16px var(--book); }

.press { flex: none; padding: 11px 14px 12px; }
.press-body { margin-top: 7px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.press-row { display: flex; align-items: center; gap: 8px; min-height: 18px; min-width: 0; }
.press-row .lbl { width: 72px; flex: none; color: var(--muted); font-size: 12px; }
.press-row .val { flex: 1; min-width: 0; font-weight: 500; line-height: 1.25; }
/* second line under a row: title may be cut, the numbers never are */
.press-sub { margin: -4px 0 0 97px; min-width: 0; line-height: 1.3; }
.press-sub .title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--book); font-size: 13px; }
.press-sub .nums { display: block; font: 500 11px var(--mono); color: var(--muted); }
.press-body .press-sub + .press-row { margin-top: 2px; }
.sdot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--warn); }
.sdot.ok { background: var(--ok); }
.sdot.warn { background: var(--warn); }
.sdot.bad { background: var(--bad); }
.sdot.calm { background: var(--calm); }
.sdot.type { background: var(--type); box-shadow: 0 0 0 2px rgba(123, 94, 167, 0.25); }
.sdot.idle { background: var(--idle); }
.bar { height: 5px; border-radius: 3px; background: #E1E6EC; overflow: hidden; margin: -1px 0 2px 97px; }
.bar i { display: block; height: 100%; background: var(--type); }
.bar.dist i { background: var(--type-light); }
.cases { display: grid; grid-template-columns: repeat(20, minmax(0, 1fr)); gap: 2px; flex: 1; min-width: 0; }
.cases i { height: 7px; border-radius: 1.5px; background: #D5DCE4; }
.cases i.on { background: var(--type); }
.cases i.on.p2 { background: var(--type-light); }
.press-note { font-size: 12px; color: var(--muted); }
.press-note b { font: 700 12px var(--mono); color: var(--text); }

/* ---------------------------------------------------------------- bottom: toolbar and controls */

.bottom {
  position: fixed;
  left: 12px;
  right: calc(var(--side-w) + 22px);
  bottom: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 4;
  pointer-events: none;
}
/* the toolbar and the controls share a row; on a narrow window the controls wrap under the toolbar */
.bottom-row { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; gap: 8px 10px; max-width: 100%; }
.bottom-row > * { pointer-events: auto; }

.toolbar { display: flex; gap: 5px; padding: 5px; }
.tool {
  position: relative;
  width: 44px; height: 44px;
  border: 1px solid #D5DCE4;
  background: #EEF1F5;
  border-radius: 7px;
  padding: 0;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.tool:hover { border-color: #9FB0C6; }
.tool.on { background: #E4ECF9; border: 2px solid var(--blue); }
.tool .key { position: absolute; left: 4px; top: 2px; font: 700 10px var(--mono); color: var(--faint); }
.tool.on .key { color: var(--blue); }
.tool canvas { margin-top: 6px; }
.tool-sep { width: 1px; background: var(--panel-edge); margin: 4px 2px; }

.controls { display: flex; align-items: center; gap: 8px; padding: 8px 10px; height: 56px; }
.btn.icon { width: 34px; height: 30px; padding: 0; display: flex; align-items: center; justify-content: center; }
.ico-pause { width: 10px; height: 12px; border-left: 3.5px solid var(--text); border-right: 3.5px solid var(--text); }
.ico-play { width: 0; height: 0; border-left: 11px solid var(--text); border-top: 7px solid transparent; border-bottom: 7px solid transparent; margin-left: 3px; }
.seg { display: flex; border: 1px solid var(--panel-edge); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: 5px 9px; cursor: pointer; font: 600 12px var(--mono); color: var(--muted); }
.seg button + button { border-left: 1px solid var(--panel-edge); }
.seg button.on { background: #E4ECF9; color: var(--blue); }
.clock { font: 700 13px var(--mono); min-width: 44px; text-align: right; }
.paused .clock { color: var(--bad); }

.tool-hint {
  max-width: 100%;
  text-align: center;
  pointer-events: none;
}
.tool-hint span {
  display: inline-block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  background: rgba(33, 38, 48, 0.9);
  color: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
}
.tool-hint:empty { display: none; }

/* ---------------------------------------------------------------- help, tooltip, toast */

/* Top of the map area between the left edge and the right column: the help card, then toasts.
   The card keeps to the right, so the raw-material zones on the left (where the first building goes)
   stay open at any window width; toasts are centred. */
.top-stack {
  position: fixed;
  top: 54px;
  left: 12px;
  right: calc(var(--side-w) + 22px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 6;
  pointer-events: none;
}
.help {
  align-self: flex-end;
  width: min(560px, calc(100% - 170px));
  padding: 9px 13px 7px;
  font-size: 12px;
  pointer-events: auto;
}
.help p { margin: 6px 0; }
.help .keys { color: var(--muted); }
.help-head { display: flex; justify-content: space-between; align-items: center; }
.help[hidden] { display: none; }

.tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  background: rgba(33, 38, 48, 0.94);
  color: #fff;
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 12px;
  max-width: 300px;
  display: none;
  box-shadow: var(--shadow);
}
.tooltip b { font-weight: 700; }
.tooltip .m { color: #B9C3D1; }
.tooltip .st-ok { color: #9FD8A8; }
.tooltip .st-warn { color: #F4C77A; }
.tooltip .st-bad { color: #F19A8B; }
.tooltip .st-calm { color: #C3D0E2; }
.tooltip .st-type { color: #CDB8EE; }
.tooltip .st-idle { color: #B9C3D1; }

.toast {
  max-width: 100%;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 7px 14px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; }
.toast .book-title { font-family: var(--book); font-size: 15px; font-weight: 700; }

/* ---------------------------------------------------------------- frame counter and error */

.perf {
  position: fixed;
  left: 12px;
  top: 54px;
  z-index: 7;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(33, 38, 48, 0.86);
  color: #D8F0DC;
  font: 500 11.5px var(--mono);
  pointer-events: none;
}
.perf[hidden] { display: none; }

.error-banner {
  position: fixed;
  left: 50%;
  top: 54px;
  transform: translateX(-50%);
  z-index: 9;
  max-width: min(640px, calc(100% - 24px));
  padding: 9px 13px;
  border-color: var(--bad);
  font-size: 12.5px;
}
.error-banner .msg { font: 500 12px var(--mono); color: #9B2F22; }
.error-banner .m { color: var(--muted); margin-top: 3px; }
.error-banner[hidden] { display: none; }

/* ---------------------------------------------------------------- narrow windows */

@media (max-width: 1180px) {
  .res--books { display: none; }
  .era-name { display: none; }
  .topbar { gap: 14px; }
}
@media (max-width: 1060px) {
  .tool { width: 40px; height: 40px; }
  .tool canvas { margin-top: 4px; }
  .controls { height: 46px; padding: 6px 8px; }
}
