/* Коробки и скотч: крафт, тёмные чернила, оранжевая лента. Один радиус на всё. */
:root {
  --bg: #e9d7b0;
  --card: #f7eeda;
  --line: #c9ae7c;
  --ink: #27211a;
  --muted: #65573f;
  --tape: #e5691c;
  --tape-ink: #1f1408;
  --plus: #24622e;
  --minus: #a8321c;
  --empty: #27211a;
  --tape-hover: #ee7a2f;
  --paper-hover: #f1e3c4;
  --r: 6px;
  --gap: 16px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --head: "Fira Sans Extra Condensed", "Arial Narrow", sans-serif;
  --text: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.5 var(--text);
  font-variant-numeric: tabular-nums;
}
.wrap { width: 100%; max-width: 640px; margin: 0 auto; padding: 0 var(--gap); }
main.wrap { flex: 1; padding-top: 20px; padding-bottom: 32px; outline: none; }
a { color: inherit; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

p, dd, .opt-desc { text-wrap: pretty; }
h1, h2, h3 { margin: 0; font-family: var(--head); font-weight: 800; letter-spacing: 0; text-wrap: balance; }
.title { font-size: clamp(34px, 9vw, 48px); line-height: 1.05; margin: 12px 0 14px; }
.screen-title { font-size: 32px; line-height: 1.15; }
.h2 { font-size: 22px; margin: 28px 0 12px; }
.h3 { font-family: var(--text); font-size: 16px; margin: 20px 0 8px; }
.lede { margin: 0 0 8px; color: var(--muted); max-width: 60ch; }
.kicker { margin: 0; color: var(--muted); font-weight: 500; }
.pos { color: var(--plus); }
.neg { color: var(--minus); }

.tape {
  display: inline-block;
  margin: 0;
  padding: 6px 14px;
  background: var(--tape);
  color: var(--tape-ink);
  font-weight: 700;
  transform: rotate(-1.5deg);
  border-radius: 2px;
}

/* ---------- выбор ниши ---------- */
.niches { display: grid; gap: 12px; }
.niche {
  display: grid;
  gap: 4px;
  text-align: left;
  padding: 16px;
  min-height: 48px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--r);
  cursor: pointer;
  transition: transform .15s var(--ease), border-color .15s;
}
.niche:hover { border-color: var(--ink); }
.niche:active { transform: translateY(1px) scale(.99); }
.niche-name { font-family: var(--head); font-size: 22px; font-weight: 800; line-height: 1.15; }
.niche-pitch { color: var(--muted); }
.niche-meta { font-size: 14px; color: var(--muted); }
.niche-level { justify-self: start; font-size: 13px; font-weight: 700; padding: 2px 8px; border-radius: 2px; border: 1.5px solid var(--ink); }
.lvl-dress { background: var(--ink); color: var(--card); }
.lvl-garland { background: var(--tape); color: var(--tape-ink); border-color: var(--tape); }

/* ---------- шкалы ---------- */
.hud {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: -20px calc(var(--gap) * -1) 16px;
  padding: 10px var(--gap) 12px;
  background: var(--bg);
  border-bottom: 2px solid var(--line);
}
.hud-top { margin: 0 0 6px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.hud-month { font-weight: 700; color: var(--ink); font-size: 16px; }
.gauges { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0; }
.g { min-width: 0; }
.g dt { font-size: 12px; color: var(--muted); }
.g dd { margin: 0; font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g small { display: block; font-size: 12px; color: var(--muted); }
@media (max-width: 420px) {
  .gauges { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 6px; }
}

/* ---------- планёрка ---------- */
.tape-note {
  margin: 20px 0 6px;
  padding: 8px 14px;
  background: var(--tape);
  color: var(--tape-ink);
  font-weight: 500;
  border-radius: 2px;
  transform: rotate(-.6deg);
}
.lead-line { margin: 10px 0 0; }
.block {
  margin: 18px 0 0;
  padding: 14px 16px 16px;
  border: 2px solid var(--line);
  border-radius: var(--r);
  background: var(--card);
  min-width: 0;
}
.block legend { padding: 0 6px; margin-left: -6px; font-weight: 700; font-size: 16px; }
.label { margin: 14px 0 6px; font-weight: 500; }
.opts { display: grid; gap: 8px; }
.opts.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.opts.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 520px) { .opts.three, .opts.two { grid-template-columns: 1fr; } }
.opt { position: relative; display: block; cursor: pointer; }
.opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.opt-body {
  display: grid;
  gap: 2px;
  height: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: var(--r);
  background: var(--bg);
  transition: border-color .15s, background-color .15s;
}
.opt-title { font-weight: 700; }
.opt-desc { font-size: 14px; color: var(--muted); }
.opt:hover .opt-body { border-color: var(--muted); }
.opt input:checked + .opt-body { border-color: var(--ink); background: var(--card); box-shadow: inset 0 0 0 1px var(--ink); }
.opt input:focus-visible + .opt-body { outline: 3px solid var(--ink); outline-offset: 2px; }

.stepper { display: flex; align-items: stretch; gap: 8px; }
.step {
  width: 48px; height: 48px;
  flex: none;
  border: 2px solid var(--ink);
  border-radius: var(--r);
  background: var(--bg);
  font-size: 22px; font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.step:active { transform: translateY(1px); }
.stepper input, .stepper-val {
  width: 140px; height: 48px;
  display: grid; place-items: center;
  text-align: center;
  border: 2px solid var(--line);
  border-radius: var(--r);
  background: var(--bg);
  font-weight: 700; font-size: 18px;
}
.info { margin: 10px 0 0; }
.hint { margin: 8px 0 0; font-size: 14px; color: var(--muted); }
.transit { margin: 10px 0 0; padding-left: 18px; font-size: 14px; color: var(--muted); }

.season { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; height: 64px; align-items: end; }
.season-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 2px; }
.season-col i { display: block; width: 100%; flex: 1; background: var(--line); transform-origin: bottom; border-radius: 2px 2px 0 0; }
.season-col b { font-size: 11px; font-weight: 500; color: var(--muted); }
.season-col.now i { background: var(--tape); }
.season-col.now b { color: var(--ink); font-weight: 700; }

.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; min-height: 44px; }
.check input { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--ink); flex: none; }

.src { margin: 18px 0 0; font-size: 14px; color: var(--muted); }
.src summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 500; color: var(--ink); }
.src summary::after { content: "+"; margin-left: 8px; font-weight: 700; color: var(--ink); }
.src[open] summary::after { content: "−"; }
.src dl { margin: 4px 0 0; }
.src dt { font-weight: 700; color: var(--ink); margin-top: 8px; }
.src dd { margin: 0; }
.src.small { margin-top: 8px; }
.src.small p { margin: 0; }

.actionbar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  margin: 20px calc(var(--gap) * -1) 0;
  padding: 10px var(--gap) calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 2px solid var(--line);
}
.actionbar.two { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.warn { margin: 0 0 8px; font-size: 14px; min-height: 0; }
.warn:empty { display: none; }
.warn.bad { color: var(--minus); font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px;
  padding: 10px 20px;
  border: 2px solid var(--ink);
  border-radius: var(--r);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  transition: transform .12s var(--ease), background-color .15s;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn.primary { width: 100%; background: var(--tape); color: var(--tape-ink); border-color: var(--tape-ink); font-size: 17px; }
.btn.primary:hover { background: var(--tape-hover); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--card); }
.btn.small { min-height: 44px; margin-top: 12px; padding: 8px 16px; font-size: 15px; }
.btn.ghost:disabled { opacity: .45; cursor: not-allowed; transform: none; background: transparent; }

/* ---------- месяц ---------- */
.month-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.day { margin: 0; color: var(--muted); }
.day span { color: var(--ink); font-weight: 700; }
.progress { height: 6px; margin: 12px 0 16px; background: var(--card); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--ink); transform: scaleX(0); transform-origin: left; }
.chart { display: grid; grid-template-columns: repeat(30, 1fr); gap: 2px; height: 140px; align-items: end; padding: 8px; background: var(--card); border: 2px solid var(--line); border-radius: var(--r); }
.chart i { display: block; height: 100%; background: var(--plus); transform: scaleY(0); transform-origin: bottom; border-radius: 1px; transition: transform .25s var(--ease); }
.live { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 16px 0 0; }
.live dt { font-size: 13px; color: var(--muted); }
.live dd { margin: 0; font-family: var(--head); font-size: clamp(22px, 6vw, 28px); font-weight: 800; white-space: nowrap; }
.flash { margin: 14px 0; min-height: 24px; font-weight: 500; }
.flash.bad { color: var(--minus); font-weight: 700; }

.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(39, 33, 26, 0); transition: background-color .2s; }
.sheet[hidden] { display: none; }
.sheet.open { background: rgba(39, 33, 26, .45); }
.event {
  width: 100%; max-width: 640px;
  max-height: 92dvh; overflow: auto;
  padding: 18px var(--gap) calc(18px + env(safe-area-inset-bottom));
  position: relative;
  background: var(--card);
  border-radius: var(--r) var(--r) 0 0;
  transform: translateY(100%);
  transition: transform .28s var(--ease);
}
.sheet.open .event { transform: none; }
/* полоска скотча поперёк крышки коробки */
.event::before { content: ""; position: absolute; top: 0; left: 50%; width: 112px; height: 14px; margin-left: -56px; background: var(--tape); opacity: .92; }
.timer { height: 4px; margin: 6px 0 12px; background: var(--line); border-radius: 2px; overflow: hidden; }
.timer i { display: block; height: 100%; background: var(--minus); transform-origin: left; animation: drain linear forwards; }
@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.who { margin: 0; font-size: 14px; font-weight: 700; color: var(--muted); }
.ev-title { font-size: 20px; line-height: 1.2; margin: 4px 0 8px; }
.ev-text { margin: 0 0 14px; }
.ev-choice { margin: 0 0 8px; font-weight: 500; }
.choices { display: grid; gap: 8px; }
.choice { justify-content: flex-start; text-align: left; white-space: normal; background: var(--bg); }
.choice:hover { background: var(--paper-hover); }
.secs { margin: 10px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- итог месяца ---------- */
.summary .big, .botbox .big { margin: 6px 0 0; font-family: var(--head); font-size: clamp(40px, 11vw, 56px); font-weight: 800; line-height: 1.05; }
.big-cap { margin: 4px 0 0; color: var(--muted); }
.rows { margin: 18px 0 0; border-top: 2px solid var(--line); }
.rows div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rows dt { color: var(--muted); }
.rows dt small { display: block; margin-top: 2px; font-size: 13px; line-height: 1.4; }
.rows dd { margin: 0; font-weight: 700; text-align: right; white-space: nowrap; }
.note { margin: 14px 0 0; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--card); }
.note.bad { border-color: var(--minus); color: var(--minus); font-weight: 500; }
.botbox { margin: 18px 0 0; padding: 14px 16px; border: 2px solid var(--ink); border-radius: var(--r); background: var(--card); }
.botbox-head { margin: 0; font-weight: 700; }
.botbox p { margin: 6px 0 0; }
.botbox .btn { margin-top: 12px; }
.botbox.fog { border-style: dashed; border-color: var(--muted); }
.fog-text { color: var(--muted); }
.eaters { list-style: none; margin: 10px 0 0; padding: 0; }
.eaters li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-top: 1px dashed var(--line); }
.log { margin: 0; padding-left: 18px; }
.log li { margin: 6px 0; }

/* ---------- итог года ---------- */
.squares { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; margin: 18px 0 6px; }
.sq { aspect-ratio: 1; display: grid; place-items: end center; border-radius: 3px; padding-bottom: 2px; }
.sq b { font-size: 11px; color: #fff; font-weight: 700; }
.sq-plus { background: var(--plus); }
.sq-minus { background: var(--minus); }
.sq-empty { background: var(--empty); }
.sq-none { background: transparent; border: 2px dashed var(--line); }
.sq-none b { color: var(--muted); }
.legend { margin: 0; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sq-key { width: 12px; height: 12px; border-radius: 2px; display: inline-block; margin-left: 6px; }
.sq-key:first-child { margin-left: 0; }

.fall { list-style: none; margin: 10px 0 0; padding: 0; }
.fall-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "k v" "t t"; column-gap: 10px; row-gap: 3px; padding: 5px 0; font-size: 14px; }
.fall-k { grid-area: k; }
.fall-v { grid-area: v; text-align: right; white-space: nowrap; font-weight: 500; }
.fall-track { grid-area: t; position: relative; height: 12px; }
.fall-bar { position: absolute; top: 0; bottom: 0; border-radius: 2px; }
.fall-bar.rev { background: var(--plus); }
.fall-bar.cost { background: var(--minus); }
.fall-row.total { border-top: 2px solid var(--ink); margin-top: 4px; padding-top: 8px; font-weight: 700; }

.botbox.real { border-color: var(--tape); border-width: 3px; }
/* карточка для чата оформлена как наклейка на коробку: пунктир линии отреза и скотч сверху */
.share-card { margin: 18px 0 0; }
.share-card canvas { display: block; width: 100%; height: auto; aspect-ratio: 1; border-radius: var(--r); box-shadow: 0 6px 18px rgb(39 33 26 / .18); }
.back { margin-top: 16px; }

/* ---------- прочее ---------- */
.foot { padding-top: 16px; padding-bottom: 24px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
.foot p { margin: 0; max-width: 58ch; }
.toast {
  position: fixed; left: 50%; bottom: 90px; z-index: 60;
  padding: 10px 16px;
  background: var(--ink); color: var(--card);
  border-radius: var(--r);
  font-weight: 500;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity .2s, transform .2s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- звук и движение на игровых моментах ---------- */
.snd { margin-left: auto; display: inline-flex; gap: 6px; position: relative; }
.snd-row { margin: 0 0 10px; display: flex; justify-content: flex-end; }
.snd-btn {
  position: relative; min-height: 32px; padding: 4px 10px;
  border: 1.5px solid var(--line); border-radius: var(--r);
  background: transparent; color: var(--ink);
  font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
}
.snd-btn::after { content: ""; position: absolute; inset: -6px -2px; }
.snd-btn[data-off] { color: var(--muted); text-decoration: line-through; }
.snd-btn[aria-expanded="true"] { background: var(--card); border-color: var(--ink); }
.snd-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.snd-pop {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 40;
  display: grid; grid-template-columns: auto 150px; gap: 10px 12px; align-items: center;
  padding: 12px 14px;
  background: var(--card); border: 2px solid var(--ink); border-radius: var(--r);
  box-shadow: 0 6px 18px rgb(60 40 20 / .18);
  color: var(--ink); font-size: 14px; font-weight: 600;
  animation: rise .18s var(--ease) both;
}
.snd-pop[hidden] { display: none; }
.snd-pop input[type="range"] { width: 100%; height: 32px; margin: 0; accent-color: var(--tape); cursor: pointer; touch-action: none; }
.snd-pop input[type="range"]:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* карточки ниш выкладываются по одной */
.niche { animation: rise .35s var(--ease) both; }
.niche:nth-child(2) { animation-delay: 70ms; }
.niche:nth-child(3) { animation-delay: 140ms; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* партия приехала: строка падает сверху, как коробка на склад */
.flash.drop { animation: drop .45s var(--ease) .25s both; }
@keyframes drop { from { opacity: 0; transform: translateY(-14px); } }
/* полка опустела, исход пожара плохой: короткая встряска */
.flash.thud, .event.lost { animation: shake .4s ease-out; }
@keyframes shake { 20% { transform: translateX(-6px); } 45% { transform: translateX(5px); } 70% { transform: translateX(-3px); } }
.event.won { animation: nod .35s var(--ease); }
@keyframes nod { from { transform: scale(.97); } }
/* последние секунды пожара */
.event.urgent .secs { color: var(--minus); font-weight: 700; }
.event.urgent .timer { animation: pulse .5s ease-in-out infinite alternate; }
@keyframes pulse { to { transform: scaleY(2); } }

/* кредит и конец игры ложатся штампом */
.note.stamp { animation: stamp .35s cubic-bezier(.2, 1.5, .4, 1) .5s both; }
@keyframes stamp { from { opacity: 0; transform: scale(1.3) rotate(-2deg); } }

/* цифра на шкале поменялась */
.g dd.bump { transform-origin: left center; animation: bump .45s var(--ease); }
@keyframes bump { from { transform: scale(1.18); } }

/* водопад итога года растёт столбик за столбиком */
.fall-bar { transition: transform .5s var(--ease) calc(var(--i, 0) * 70ms); }
.fall-bar.rev { transform-origin: left; }
.fall-bar.cost { transform-origin: right; }
.fall:not(.in) .fall-bar { transform: scaleX(0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; animation-delay: 0s !important; transition-delay: 0s !important; }
  .timer i { animation: none; }
  .tape, .tape-note { transform: none; }
}
