:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #2b2a27;
  --muted: #6f6b63;
  --line: #e4ded2;
  --brand: #2f7d6d;
  --brand-ink: #ffffff;
  --brand-soft: #e3f1ec;
  --sun: #f3b33d;
  --sun-soft: #fdf1d8;
  --good: #2e8b57;
  --good-soft: #e5f4ea;
  --bad: #c2523c;
  --bad-soft: #fbe9e4;
  --money-in: #2e8b57;
  --money-out: #b8661f;
  --radius: 18px;
  --shadow: 0 2px 10px rgba(60, 50, 30, .08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#app { max-width: 560px; margin: 0 auto; padding: 12px 16px 120px; }
.loading { text-align: center; color: var(--muted); margin-top: 30vh; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 8px; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 12px 0;
}
.card.soft { background: var(--brand-soft); box-shadow: none; }
.card.sun { background: var(--sun-soft); box-shadow: none; }

button, .btn {
  font: inherit;
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  min-height: 48px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button:disabled { opacity: .45; cursor: default; }
button.primary, .btn.primary { background: var(--brand); color: var(--brand-ink); }
button.ghost { background: transparent; color: var(--brand); padding: 8px 10px; min-height: 40px; }
button.danger { background: var(--bad-soft); color: var(--bad); }
button.block { width: 100%; }
button.big { font-size: 20px; min-height: 60px; }
input, select {
  font: inherit;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  min-height: 48px;
  width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--brand); }
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }

/* Шапка партии */
.topbar { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.topbar .title { flex: 1; font-weight: 700; font-size: 18px; }
.code-chip { background: var(--card); border-radius: 999px; padding: 4px 10px; font-size: 14px; box-shadow: var(--shadow); letter-spacing: 1px; }

.phases { display: flex; gap: 4px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.phases::-webkit-scrollbar { display: none; }
.phase {
  flex: 0 0 auto;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #ebe6dc;
  color: var(--muted);
  white-space: nowrap;
}
.phase.done { background: var(--brand-soft); color: var(--brand); }
.phase.now { background: var(--brand); color: #fff; font-weight: 700; }

.players { display: flex; gap: 6px; overflow-x: auto; padding: 6px 0; scrollbar-width: none; }
.players::-webkit-scrollbar { display: none; }
.pchip {
  flex: 0 0 auto;
  background: var(--card);
  border-radius: 999px;
  padding: 6px 12px 6px 6px;
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 6px;
  font-size: 15px; font-weight: 600; color: var(--ink);
  min-height: 40px;
}
.pchip.now { outline: 3px solid var(--sun); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 15px; flex: 0 0 auto;
}

/* Большая картинка события */
.picture { font-size: 72px; text-align: center; line-height: 1.1; margin: 6px 0; }
.headline { font-size: 22px; font-weight: 700; text-align: center; margin: 6px 0 10px; }
.effect { text-align: center; color: var(--muted); }

.bottom {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, rgba(244, 241, 234, 0));
}
.bottom .inner { max-width: 560px; margin: 0 auto; display: flex; gap: 8px; }
button.undo { flex: 0 0 72px; flex-direction: column; gap: 0; font-size: 22px; line-height: 1; padding: 6px 4px; min-height: 60px; background: var(--card); box-shadow: var(--shadow); }
button.undo small { font-size: 11px; font-weight: 600; margin-top: 3px; }

/* Сообщения после действия */
.messages { margin: 10px 0; display: grid; gap: 6px; }
.msg { border-radius: 12px; padding: 10px 12px; background: var(--card); box-shadow: var(--shadow); font-size: 16px; }
.msg.money-in { border-left: 6px solid var(--money-in); }
.msg.money-out { border-left: 6px solid var(--money-out); }
.msg.good { border-left: 6px solid var(--good); }
.msg.warn { border-left: 6px solid var(--bad); background: var(--bad-soft); }
.msg.lesson { border-left: 6px solid var(--sun); background: var(--sun-soft); }

/* Город */
.district { margin: 14px 0 6px; font-weight: 700; color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: .5px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile {
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  padding: 10px 6px; text-align: center; font-size: 13px; font-weight: 600; color: var(--ink);
  min-height: 92px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  position: relative;
}
.tile .ic { font-size: 32px; }
.tile.used { opacity: .45; }
.tile.used::after { content: "✓"; position: absolute; top: 6px; right: 10px; color: var(--good); font-size: 18px; }
.tile.work { outline: 2px dashed var(--brand); }

.action {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: var(--brand-soft); color: var(--ink); font-weight: 600; margin: 6px 0;
  justify-content: flex-start;
}
.action .price { margin-left: auto; color: var(--money-out); white-space: nowrap; }
.action .sub { display: block; font-weight: 400; font-size: 14px; color: var(--muted); }
.action:disabled { opacity: 1; background: #f1eee7; color: var(--muted); }

.tokens { display: inline-flex; gap: 4px; vertical-align: middle; }
.token { width: 18px; height: 18px; border-radius: 50%; background: var(--sun); display: inline-block; border: 2px solid #d79a26; }
.token.duty { background: #b8b2a6; border-color: #9c968a; }
.token.used { background: transparent; border: 2px dashed #c9c2b5; }

.scale-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.scale-row:last-child { border-bottom: 0; }
.scale-row .name { flex: 1; }
.scale-row .val { font-weight: 700; min-width: 72px; text-align: right; }
.up { color: var(--good); }
.down { color: var(--bad); }
.bar { height: 8px; border-radius: 4px; background: #ebe6dc; overflow: hidden; width: 90px; }
.bar i { display: block; height: 100%; background: var(--brand); }

.bill { display: flex; justify-content: space-between; padding: 3px 0; font-size: 15px; }
.bill.total { font-weight: 700; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; }
.pill { display: inline-block; font-size: 13px; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.good { background: var(--good-soft); color: var(--good); }

.dice { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 8px; }
.dice button { font-size: 22px; padding: 0; }

.dream-card { border: 3px solid var(--sun); background: var(--sun-soft); text-align: left; width: 100%; display: block; color: var(--ink); font-weight: 400; padding: 14px; margin: 8px 0; }
.dream-card b { font-size: 19px; }

table.scores { width: 100%; border-collapse: collapse; font-size: 15px; }
table.scores th, table.scores td { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: right; }
table.scores th:first-child, table.scores td:first-child { text-align: left; }

/* Нижний лист */
.sheet {
  position: fixed; inset: 0; background: rgba(30, 25, 15, .45); z-index: 10;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet .panel {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  border-radius: 22px 22px 0 0; padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}
.sheet .close { float: right; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 96px; z-index: 20;
  background: #2b2a27; color: #fff; padding: 12px 16px; border-radius: 14px; max-width: 92vw; font-size: 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.toast.error { background: var(--bad); }

.qr { display: block; margin: 8px auto; width: 200px; height: 200px; background: #fff; border-radius: 12px; padding: 8px; }
.code-big { font-size: 40px; font-weight: 800; letter-spacing: 6px; text-align: center; margin: 4px 0; }

.hero { text-align: center; padding: 24px 0 8px; }
.hero .picture { font-size: 84px; }
.stack { display: grid; gap: 10px; }
