.er-layout {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
}

.er-board {
  display: grid;
  grid-template-columns: repeat(15, minmax(0, 1fr));
  grid-template-rows: repeat(15, minmax(0, 1fr));
  gap: 2px;
  width: min(100%, 600px);
  aspect-ratio: 1;
  padding: 6px;
  border-radius: 12px;
  background: #1f5f4a;
  box-shadow: var(--shadow);
}

.er-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 3px;
  background: #d9e6d3;
  color: #1c2a22;
  font: 800 clamp(0.6rem, 2.6vw, 1.1rem) / 1 var(--font);
  cursor: pointer;
}

.er-cell span {
  font-size: clamp(0.25rem, 0.9vw, 0.42rem);
  font-weight: 700;
  line-height: 1.05;
  text-align: center;
  opacity: 0.85;
}

.er-cell.b-W3 {
  background: #e4574a;
  color: #fff;
}

.er-cell.b-W2 {
  background: #f2a7a0;
}

.er-cell.b-L3 {
  background: #3b82c4;
  color: #fff;
}

.er-cell.b-L2 {
  background: #a9d0f0;
}

.er-cell.tile {
  background: linear-gradient(160deg, #fff4d6, #f0d9a0);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15);
  color: #2b2012;
}

.er-cell.tile small,
.er-tile small {
  position: absolute;
  right: 2px;
  bottom: 1px;
  font-size: 0.5em;
  font-weight: 700;
}

.er-cell.draft {
  background: linear-gradient(160deg, #fff, #ffe38a);
  box-shadow: 0 0 0 2px var(--accent);
}

.er-cell.last {
  box-shadow: inset 0 0 0 2px #e0a100;
}

.er-cell.cursor {
  box-shadow: inset 0 0 0 3px var(--accent);
}

.er-cell.cursor::after {
  content: "→";
  position: absolute;
  color: var(--accent);
  font-size: 0.9em;
}

.er-cell.cursor.down::after {
  content: "↓";
}

.er-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(100%, 360px);
}

.er-points {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
}

.er-points div {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 0.8rem;
  color: var(--muted);
}

.er-points b {
  display: block;
  color: var(--text);
  font-size: 1.3rem;
}

.er-rack-wrap {
  position: relative;
}

.er-rack {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  min-height: 50px;
  padding: 8px;
  border-radius: 12px;
  background: #6b4a26;
}

.er-tile {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: linear-gradient(160deg, #fff4d6, #f0d9a0);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
  color: #2b2012;
  font: 800 1.35rem / 1 var(--font);
  cursor: pointer;
}

.er-tile:disabled {
  cursor: default;
}

.er-tile.sel {
  outline: 3px solid var(--accent);
  transform: translateY(-4px);
}

.er-tile.used {
  opacity: 0.25;
}

.er-tile.swap {
  outline: 3px dashed var(--danger);
}

.er-curtain {
  position: absolute;
  inset: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  font-size: 0.85rem;
  text-align: center;
}

.er-curtain[hidden] {
  display: none;
}

.er-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.er-actions .btn {
  flex: 1 1 auto;
  padding: 8px 12px;
  font-size: 0.85rem;
}

.er-actions .btn.active {
  border-color: var(--danger);
}

.er-preview {
  min-height: 1.4em;
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.er-preview.ok {
  color: var(--success);
}

.er-preview.bad {
  color: var(--danger);
}

.er-log {
  max-height: 180px;
  margin: 0;
  padding: 8px 12px 8px 28px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 0.85rem;
}

.er-log:empty {
  display: none;
}

@media (max-width: 520px) {
  .er-cell span {
    display: none;
  }
}

/* телефон: счёт одной строкой, фишки и все кнопки хода в один ряд прямо под полем —
   поле, фишки и «Сделать ход» помещаются на экран вместе */
@media (max-width: 640px) {
  .game-stage {
    gap: 8px;
  }

  .game-stage > .status-line {
    font-size: 0.9rem;
    line-height: 1.35;
  }

  .er-layout {
    gap: 8px;
  }

  .er-board {
    width: min(100%, max(270px, calc(100svh - 365px)));
    padding: 4px;
    gap: 1px;
  }

  .er-side {
    gap: 6px;
    width: 100%;
  }

  .er-points {
    gap: 6px;
  }

  .er-points div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 10px;
  }

  .er-points b {
    font-size: 1.05rem;
  }

  .er-rack {
    gap: 5px;
    min-height: 0;
    padding: 5px;
    border-radius: 10px;
  }

  .er-tile {
    font-size: 1.2rem;
  }

  .er-tile small {
    font-size: 0.56em;
  }

  .er-preview {
    min-height: 1.3em;
    font-size: 0.85rem;
  }

  .er-actions {
    flex-wrap: nowrap;
    gap: 4px;
  }

  .er-actions .btn {
    min-height: 38px;
    padding: 6px 8px;
    font-size: 0.8rem;
  }
}
