/* ---------- шрифты (свои файлы, см. fonts/README.md) ---------- */

@font-face {
  font-family: "Onest";
  src: url("./fonts/onest-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Onest";
  src: url("./fonts/onest-cyrillic.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("./fonts/jetbrains-mono-latin.woff2") format("woff2");
  font-weight: 100 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("./fonts/jetbrains-mono-cyrillic.woff2") format("woff2");
  font-weight: 100 800;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

/* ---------- цвета и размеры ----------
   Чернила – то, чем управляет пользователь. Фиолетовый Monad – только то, что делает сеть:
   блоки, стадии, ожидающие клетки. Цвета взяты из слайдов презентации части 1. */

:root {
  --ink: #0e091c;
  --ink-2: #5a566a;
  --ink-3: #a9a4b8;
  --line: #e6e3ee;
  --line-strong: #c9c4d8;
  --paper: #fff;
  --tint: #f1eeff;
  --chain: #6e54ff;
  --error: #b3261e;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --canvas: 768px; /* уточняется из JS по размеру окна */
  --composition: calc(var(--canvas) + 440px);
  --gutter: max(24px, calc((100vw - var(--composition)) / 2));
}

* {
  box-sizing: border-box;
}

/* hidden должен прятать и элементы, которым в стилях задан display */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 14px/20px "Onest", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}

.mono,
kbd {
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

h2,
h3 {
  margin: 0;
}

a {
  color: inherit;
}

button {
  font: 500 14px/20px "Onest", system-ui, sans-serif;
  padding: 8px 16px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: background 120ms, color 120ms;
}

button.primary {
  background: var(--ink);
  color: var(--paper);
}

button:hover:not(:disabled) {
  background: var(--ink);
  color: var(--paper);
}

button.primary:hover:not(:disabled) {
  background: var(--ink-2);
  border-color: var(--ink-2);
}

button.text-button {
  border-color: transparent;
  background: none;
  color: var(--ink-2);
}

button.text-button:hover:not(:disabled) {
  background: none;
  color: var(--ink);
  text-decoration: underline;
}

button:disabled {
  border-color: var(--line);
  background: var(--paper);
  color: var(--ink-3);
  cursor: default;
}

button.text-button:disabled {
  border-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

input {
  font: 400 13px/18px "JetBrains Mono", ui-monospace, monospace;
  width: 104px;
  padding: 6px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: var(--ink);
}

input:focus {
  border-color: var(--ink);
  outline: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.section-label {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}

.section-label .count {
  margin-left: 4px;
  color: var(--ink-3);
}

/* ---------- шапка ---------- */

.top-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  height: 56px;
  padding: 0 var(--gutter);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.wordmark {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.network-switcher {
  display: flex;
  gap: 16px;
  font-size: 13px;
  font-weight: 500;
}

.network-switcher a {
  color: var(--ink-2);
  text-decoration: none;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
}

.network-switcher a:hover {
  color: var(--ink);
}

.network-switcher [aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

.block-ticker {
  display: flex;
  align-items: center;
  gap: 10px;
}

.block-number {
  min-width: 112px;
  font: 400 13px/20px "JetBrains Mono", ui-monospace, monospace;
}

.block-number.offline {
  color: var(--error);
}

/* Ширина – ровно под 16 блоков, чтобы шапка не сдвигалась; новые блоки появляются справа. */
.block-strip {
  display: flex;
  justify-content: flex-end;
  width: calc(16 * 6px + 15 * 3px);
  gap: 3px;
  transition: opacity 300ms;
}

.block-strip.offline {
  opacity: 0.3;
}

.block-strip span {
  width: 6px;
  height: 6px;
  background: var(--line-strong);
  animation: block-in 200ms var(--ease-out);
}

.block-strip span.event {
  background: var(--chain);
}

.contract-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  text-decoration: none;
}

.contract-link:hover {
  color: var(--ink);
}

.wallet-status {
  position: relative;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.wallet-status .balance {
  color: var(--ink-2);
}

/* «владелец» – переключатель вида: нажат – страница как у обычного игрока. */
.wallet-status .owner-badge {
  padding: 2px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: none;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
}

.wallet-status .owner-badge:hover:not(:disabled) {
  border-color: var(--ink);
  background: none;
  color: var(--ink);
}

.wallet-status .owner-badge[aria-pressed="true"] {
  border-style: dashed;
}

.wallet-status a.install {
  padding: 8px 16px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  font-weight: 500;
  text-decoration: none;
}

.wallet-icon {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 4px;
}

.wallet-icon.blank {
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.wallet-badge,
.wallet-badge:hover:not(:disabled) {
  display: flex;
  padding: 2px;
  border-color: transparent;
  background: none;
}

.wallet-badge:hover:not(:disabled) {
  border-color: var(--line-strong);
}

/* Выбор кошелька – список под кнопкой в шапке. */
.wallet-picker {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: 260px;
  padding: 6px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  animation: enter 140ms var(--ease-out);
}

.wallet-option,
.wallet-option:disabled {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  text-align: left;
}

.wallet-option:hover:not(:disabled) {
  background: rgb(14 9 28 / 0.06);
  color: var(--ink);
}

.wallet-option:disabled .wallet-icon {
  opacity: 0.4;
}

.wallet-option .note {
  margin-left: auto;
  font-size: 12px;
  font-weight: 400;
}

.wallet-picker a.install {
  margin-top: 6px;
  text-align: center;
}

button.nudge {
  animation: nudge 300ms var(--ease-out) 2;
}

/* ---------- игровой ключ ---------- */

.game-key {
  padding: 12px 0 16px;
  border-top: 1px solid var(--line);
}

/* Переключатель: дорожка 28 × 16 с бегунком; включен – чернильный. */
.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.switch input {
  appearance: none;
  border: 0;
  padding: 0;
  position: relative;
  flex: none;
  width: 28px;
  height: 16px;
  margin: 0;
  border-radius: 8px;
  background: var(--line-strong);
  cursor: pointer;
  transition: background 160ms;
}

/* Бегунок по вертикали – строго по центру дорожки, в обоих положениях. */
.switch input::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--paper);
  transform: translateY(-50%);
  transition: transform 160ms var(--ease-out);
}

.switch input:checked {
  background: var(--ink);
}

.switch input:checked::after {
  transform: translate(12px, -50%);
}

.switch input:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.game-key-details {
  margin-top: 8px;
  animation: enter 160ms var(--ease-out);
}

.game-key-details .note {
  margin-bottom: 8px;
}

.game-key-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  font-size: 13px;
  white-space: nowrap;
}

.game-key-row a {
  color: var(--ink);
}

.game-key-balance {
  margin-left: auto;
  color: var(--ink-2);
}

.game-key-row .field {
  margin-left: 0;
}

.game-key-row input {
  width: 72px;
  padding: 3px 8px;
  font-size: 13px;
}

.game-key-row .suffix {
  width: auto;
}

.game-key-row button {
  padding: 3px 10px;
  font-size: 12px;
}

.game-key-row button[type="submit"] {
  margin-left: auto;
}

/* Кто платит за пачку, бомбу и щит: кошелек или игровой ключ. */
.payer {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--ink-2);
}

/* Цена бомбы и щита – заметно, но не крупнее всего остального. */
.price-value {
  margin: 4px 0 8px;
  font: 500 22px/28px "JetBrains Mono", ui-monospace, monospace;
}

.price-value.quiet {
  font: 400 14px/28px "Onest", system-ui, sans-serif;
  color: var(--ink-2);
}

/* ---------- палитра, холст, правая колонка ---------- */

.stage {
  display: grid;
  grid-template-columns: 32px var(--canvas) 1fr;
  column-gap: 8px;
  width: var(--composition);
  margin: 24px auto;
}

.palette {
  display: flex;
  flex-direction: column;
  height: var(--canvas);
}

.swatch {
  flex: 1;
  width: 32px;
  padding: 0;
  border: none;
  border-radius: 0;
  box-shadow: inset 0 0 0 1px rgb(14 9 28 / 0.12);
  transition: transform 140ms var(--ease-out);
}

/* Просвет между группами оттенков: глаз сначала находит группу, потом цвет в ней. */
.swatch.group-start {
  margin-top: 6px;
}

.swatch:hover:not(:disabled) {
  transform: translateX(-3px);
}

/* Белое кольцо внутри и чернильное снаружи – видно и на черном, и на белом цвете. */
.swatch[aria-checked="true"] {
  position: relative;
  transform: translateX(-6px);
  box-shadow: inset 0 0 0 2px var(--paper), 0 0 0 1px var(--ink);
}

.swatch.pop {
  animation: pop 180ms var(--ease-out);
}

.board {
  position: relative;
  width: var(--canvas);
  height: var(--canvas);
  outline: 1px solid var(--ink);
  overflow: hidden;
  background: #fafafc;
}

.board.shake {
  animation: board-shake 220ms var(--ease-out);
}

/* Кнопки приближения – в правом нижнем углу поля. */
.zoom-controls {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 3;
  display: flex;
  gap: 4px;
}

.icon-button {
  display: flex;
  padding: 6px;
  border-color: var(--line-strong);
  background: rgb(255 255 255 / 0.92);
}

.icon-button .icon {
  width: 18px;
  height: 18px;
}

.board-hint {
  position: absolute;
  left: 50%;
  top: 14px;
  z-index: 3;
  margin: 0;
  padding: 8px 14px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
  animation: enter 240ms var(--ease-out);
}

.board canvas {
  position: absolute;
  inset: 0;
  display: block;
  image-rendering: pixelated;
}

#canvas {
  cursor: crosshair;
  touch-action: none;
  transition: filter 300ms, opacity 300ms;
}

.canvas-overlay {
  pointer-events: none;
}

#canvas.panning {
  cursor: grabbing;
}

.board.offline #canvas {
  filter: grayscale(1);
  opacity: 0.5;
}

.banner {
  position: absolute;
  pointer-events: none;
}

.banner[data-kind="band"] {
  inset: 0 0 auto;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  color: var(--paper);
  font-weight: 500;
}

.banner[data-kind="state"] {
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgb(255 255 255 / 0.6);
}

.banner[data-kind="band"] .title {
  font-size: 13px;
  font-weight: 500;
}

.banner .title {
  font-size: 22px;
  font-weight: 700;
}

.banner .hint {
  color: var(--ink-2);
}

.cell-tag {
  position: absolute;
  z-index: 2;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  font: 400 12px/18px "JetBrains Mono", ui-monospace, monospace;
  pointer-events: none;
  white-space: nowrap;
}

.cell-tag .name {
  color: rgb(255 255 255 / 0.65);
}

.chip {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  box-shadow: inset 0 0 0 1px rgb(14 9 28 / 0.2);
}

.side {
  display: flex;
  flex-direction: column;
  height: var(--canvas);
  min-height: 0;
  margin-left: 32px; /* вместе с column-gap – 40 px от холста */
}

/* Переключатель инструментов: три сегмента и ползущий черный индикатор. */
/* Инструменты: пять сегментов, значок над названием; выбранный – чернильный. */
.tools {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  margin: 0;
  padding: 0;
  border: 1px solid var(--ink);
  border-radius: 6px;
  overflow: hidden;
}

.tools label {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 56px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 160ms, color 160ms;
}

.tools label + label {
  border-left: 1px solid var(--line);
}

.tools label:hover {
  background: rgb(14 9 28 / 0.05);
}

.tools input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.tools label:has(input:checked) {
  background: var(--ink);
  color: var(--paper);
}

.tools label:has(input:focus-visible) {
  outline: 2px solid var(--chain);
  outline-offset: -4px;
}

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Высота – под самую длинную панель (пачка с кнопками), чтобы колонка не прыгала при смене инструмента. */
.tool-body {
  height: 204px;
  padding-top: 20px;
}

.tool-panel {
  display: none;
}

.side:has(input[value="brush"]:checked) .brush-panel,
.side:has(input[value="batch"]:checked) .batch-panel,
.side:has(input[value="bomb"]:checked) .bomb-panel,
.side:has(input[value="shield"]:checked) .shield-panel,
.side:has(input[value="pipette"]:checked) .pipette-panel {
  display: block;
}

.caption {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--ink-2);
}

.big-value {
  margin: 0 0 12px;
  font: 500 40px/44px "JetBrains Mono", ui-monospace, monospace;
  letter-spacing: -0.02em;
}

.big-value.quiet {
  font: 400 14px/44px "Onest", system-ui, sans-serif;
  letter-spacing: 0;
  color: var(--ink-2);
}

.big-value.ready {
  font: 500 22px/44px "Onest", system-ui, sans-serif;
  letter-spacing: -0.01em;
}

.big-value .unit {
  margin-left: 2px; /* плюс пробел в начале подписи – чтобы число и слово читались раздельно */
  font: 400 16px "Onest", system-ui, sans-serif;
  letter-spacing: 0;
  color: var(--ink-2);
}

.big-value.bump {
  animation: bump 120ms var(--ease-out);
}

/* Заряды кисти: деления, полные – чернильные; число справа. */
.charges {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  margin-bottom: 4px;
}

.charges .segment {
  width: 36px;
  height: 14px;
  border: 1px solid var(--ink);
  border-radius: 3px;
  transition: background 200ms;
}

.charges .segment.full {
  background: var(--ink);
}

.charges .count {
  margin-left: 8px;
  font: 500 16px "JetBrains Mono", ui-monospace, monospace;
}

.charges .hint {
  font-size: 14px;
  color: var(--ink-2);
}

.charges.nudge {
  animation: shake 240ms;
}

.note {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--ink-2);
}

/* Полоса по верхнему краю поля: заполняется к следующему заряду. Видна только с кистью и не на паузе. */
.board-charge {
  position: absolute;
  inset: -1px 0 auto;
  height: 3px;
  background: var(--ink);
  transform-origin: left;
  transform: scaleX(0);
  transition: transform 250ms linear;
  pointer-events: none;
}

.stage:has(.tools input[value="brush"]:not(:checked)) .board-charge,
body.paused .board-charge {
  display: none;
}

.current-color {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 14px;
}

.current-color .chip {
  width: 16px;
  height: 16px;
}

/* На паузе кисть и пачка не работают – приглушаем их. */
body.paused .tools label:not(:has(input[value="pipette"])) {
  opacity: 0.4;
}

.buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wait-blocks {
  display: inline-flex;
  gap: 3px;
  margin-left: 8px;
}

.wait-blocks span {
  width: 6px;
  height: 6px;
  border: 1px solid currentColor;
}

.wait-blocks span.done {
  background: currentColor;
}

.pipette-result {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 44px;
  color: var(--ink-2);
}

.pipette-result .chip {
  width: 40px;
  height: 40px;
}

.pipette-result .name {
  display: block;
  color: var(--ink);
  font-size: 22px;
  font-weight: 500;
  line-height: 28px;
}

.pipette-result .mono {
  font-size: 12px;
}

.side-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.transactions-section {
  max-height: 260px;
}

.feed-section {
  flex: 1;
  margin-top: 16px;
}

.transactions,
.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
}

.empty-note {
  color: var(--ink-3);
  font-size: 13px;
}

/* ---------- свои транзакции ---------- */

.transaction {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.transaction:last-child {
  border-bottom: 0;
}

.transaction {
  animation: enter 180ms var(--ease-out), tint-fade 1200ms var(--ease-out);
}

.tx-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  line-height: 20px;
}

.tx-call {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
}

a.tx-call:hover {
  text-decoration: underline;
}

.tx-status {
  flex: none;
  font-size: 13px;
  color: var(--ink-2);
}

.tx-status.final {
  color: var(--chain);
  font-weight: 500;
}

.transaction.failed .tx-status {
  color: var(--error);
}

.stage-track {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-top: 8px;
}

.stage-bar {
  display: block;
  height: 4px;
  background: var(--line);
  overflow: hidden;
}

.stage-bar::after {
  content: "";
  display: block;
  height: 100%;
  background: var(--chain);
  transform-origin: left;
  transform: scaleX(0);
}

.stage-step.filled .stage-bar::after {
  transform: scaleX(1);
  animation: fill 160ms var(--ease-out);
}

.stage-step.waiting .stage-bar {
  animation: waiting 700ms ease-in-out infinite alternate;
}

.stage-label,
.stage-time {
  display: block;
  min-height: 14px;
  font-size: 12px;
  line-height: 14px;
  color: var(--ink-3);
}

.stage-label {
  margin-top: 4px;
}

.stage-step.filled .stage-label,
.stage-time {
  color: var(--ink-2);
}

/* Газ одной строкой: на testnet «списано» всегда равно лимиту – Monad берет газ по лимиту. */
.gas {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  font-size: 12px;
  line-height: 16px;
  color: var(--ink-2);
}

/* Подробности (стадии, газ) – только у самой новой транзакции, старые – одной строкой. */
.transaction:not(:first-child) .stage-track,
.transaction:not(:first-child) .gas {
  display: none;
}

/* ---------- лента ---------- */

.feed li {
  display: grid;
  grid-template-columns: 10px auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  font-size: 13px;
}

.feed li.new {
  animation: enter 160ms var(--ease-out);
}

.feed .who {
  font: 400 12px/16px "JetBrains Mono", ui-monospace, monospace;
  color: var(--ink-2);
}

.feed .who.me {
  color: var(--ink);
  font-weight: 600;
}

.chip.blank {
  box-shadow: none;
}

.feed li.empty-note {
  display: block;
}

/* ---------- контракт ---------- */

/* Правила простыми словами – между полем и разделом «Контракт». */
.rules {
  width: var(--composition);
  margin: 72px auto 0;
  padding-top: 32px;
  border-top: 1px solid var(--line);
}

.rules h2 {
  margin: 0 0 8px;
  font-size: 28px;
}

/* Вводная фраза: строка не длиннее ~70 знаков – так ее читают целиком. */
.rules-lead {
  max-width: 64ch;
  margin: 0 0 24px;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink-2);
}

/* Карточки 3 × 2: в каждой строке текста ~45–55 знаков, это удобная длина для чтения. */
.rules-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.rule-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 24px 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.rule-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.rule-heading .icon {
  width: 20px;
  height: 20px;
}

.rule-heading h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

/* Главное число – первым и крупно: его ищут глазами. */
.rule-number {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  line-height: 28px;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.rule-text {
  margin: 0;
  max-width: 52ch;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-2);
}

/* Мини-схема одной высоты во всех карточках – тексты начинаются на одной линии. */
.rule-picture {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 72px;
}

.rule-picture.column {
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
}

.rule-caption {
  font-size: 13px;
  white-space: nowrap;
  color: var(--ink-2);
}

.rule-segment {
  width: 28px;
  height: 12px;
  border: 1px solid var(--ink);
  border-radius: 3px;
}

.rule-segment.full {
  background: var(--ink);
}

.rule-segment + .rule-caption {
  margin-left: 6px;
}

.rule-price {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rule-price .chip {
  width: 20px;
  height: 20px;
}

/* пустая клетка – белая, поэтому с рамкой, иначе ее не видно */
.rule-price .chip.blank {
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.rule-grid {
  display: grid;
  gap: 1px;
}

.rule-grid .cell {
  aspect-ratio: 1;
  background: var(--line);
}

.rule-grid .cell.hit {
  background: var(--chain);
}

.rule-grid.shielded {
  padding: 3px;
  border: 2px solid var(--chain);
  border-radius: 3px;
  background: repeating-linear-gradient(45deg, var(--tint) 0 3px, transparent 3px 6px);
}

.rule-grid.shielded .cell {
  background: rgb(110 84 255 / 0.18);
}

.rule-field {
  position: relative;
  flex: none;
  width: 48px;
  height: 48px;
  background: repeating-linear-gradient(45deg, var(--line) 0 2px, transparent 2px 6px);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.rule-field .open {
  position: absolute;
  top: 0;
  left: 0;
  background: var(--tint);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.rule-field.current {
  box-shadow: inset 0 0 0 1px var(--line-strong), 0 0 0 2px var(--ink);
}

.rule-switch {
  position: relative;
  width: 28px;
  height: 16px;
  border-radius: 8px;
  background: var(--ink);
}

.rule-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 14px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--paper);
}

.contract {
  width: var(--composition);
  margin: 72px auto 96px;
  padding-top: 32px;
  border-top: 1px solid var(--line);
}

.contract-header {
  display: flex;
  align-items: baseline;
  gap: 20px;
  margin-bottom: 28px;
}

.contract-header h2 {
  font-size: 28px;
  line-height: 32px;
  letter-spacing: -0.02em;
}

.contract-header .mono {
  font-size: 13px;
  color: var(--ink-2);
}

.contract-balance {
  margin-left: auto;
  font: 400 13px "JetBrains Mono", ui-monospace, monospace;
}

.contract-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 64px;
}

.function-list {
  margin: 0;
}

.function-group + .function-group {
  margin-top: 20px;
}

.group-label {
  margin: 20px 0 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.function-group .group-label {
  margin-top: 0;
}

#contract-info dl {
  display: grid;
  grid-template-columns: 1fr auto;
}

#contract-info dt,
#contract-info dd,
.function-row {
  display: flex;
  align-items: center;
  min-height: 36px;
  border-bottom: 1px solid var(--line);
}

#contract-info dd {
  margin: 0;
  justify-content: flex-end;
  text-align: right;
}

#contract-info dd.changed {
  animation: value-changed 1200ms var(--ease-out);
}

.function-name,
#contract-info dt {
  font: 400 13px/18px "JetBrains Mono", ui-monospace, monospace;
}

.function-row {
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
}

.function-row > span:last-child:not(.field) {
  color: var(--ink-2);
}

.function-row button {
  min-width: 88px;
  padding: 4px 12px;
}

.field {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.suffix {
  width: 72px;
  font-size: 12px;
  color: var(--ink-3);
}

.field:has(input.invalid) .suffix {
  color: var(--error);
}

/* Управление — только у владельца; остальные видят, что делает функция. */
.contract:not(.is-owner) .owner-control,
.contract.is-owner .function-row:has(.owner-control) .meaning {
  display: none;
}

.meaning {
  color: var(--ink-2);
}

.owner-note {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--ink-2);
}

input.invalid {
  border-color: var(--error);
  animation: shake 240ms;
}

/* ---------- сообщения ---------- */

/* Внизу правой колонки: там свободно, и сообщение не перекрывает холст. */
.toast {
  position: fixed;
  right: var(--gutter);
  bottom: 24px;
  z-index: 10;
  width: 360px;
  margin: 0;
  padding: 10px 16px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--paper);
  animation: toast-in 180ms var(--ease-out);
  cursor: pointer;
}

.toast.error {
  background: var(--error);
}

/* ---------- анимации ---------- */

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

@keyframes value-changed {
  from {
    color: var(--chain);
  }
}

@keyframes tint-fade {
  from {
    background: var(--tint);
  }
}

@keyframes fill {
  from {
    transform: scaleX(0);
  }
}

@keyframes waiting {
  from {
    opacity: 0.25;
  }
  to {
    opacity: 0.6;
  }
}

@keyframes block-in {
  from {
    opacity: 0;
    transform: translateX(8px);
  }
}

@keyframes board-shake {
  25% {
    transform: translate(-3px, 2px);
  }
  50% {
    transform: translate(3px, -2px);
  }
  75% {
    transform: translate(-2px, -1px);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@keyframes pop {
  50% {
    transform: translateX(-8px) scale(1.15);
  }
}

@keyframes bump {
  50% {
    transform: translateY(2px);
  }
}

@keyframes shake {
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

@keyframes nudge {
  50% {
    box-shadow: 0 0 0 3px var(--chain);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition-duration: 0ms !important;
  }
}
