:root {
  /* На телефоне клетки меньше, чтобы влезло широкое поле */
  --cell: clamp(28px, 9.2vw, 40px);
  --gap: 3px;
  --pad: 8px;
  --door-depth: calc(var(--cell) * 0.85);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: #1b2430;
  color: #f2f5f8;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px 10px 32px;
  user-select: none;
  -webkit-user-select: none;
}

.app {
  width: min(100%, 480px);
  text-align: center;
}

.title {
  margin: 0 0 2px;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.level-label {
  margin: 0 0 6px;
  color: #f0c75e;
  font-size: 0.95rem;
  font-weight: 600;
}

.hint {
  margin: 0 0 6px;
  color: #a8b3c2;
  font-size: 0.88rem;
  line-height: 1.35;
}

.status {
  min-height: 1.3em;
  margin: 0 0 12px;
  color: #7dcea0;
  font-size: 0.9rem;
}

.stage {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  margin: 0 auto 14px;
  max-width: 100%;
}

.stage-mid {
  display: flex;
  flex-direction: row;
  align-items: stretch;
}

.door-rail {
  position: relative;
  flex-shrink: 0;
}

.door-rail-top,
.door-rail-bottom {
  height: var(--door-depth);
}

.door-rail-left,
.door-rail-right {
  width: var(--door-depth);
}

.board {
  position: relative;
  display: grid;
  gap: var(--gap);
  padding: var(--pad);
  background: #101820;
  border: 3px solid #3a4a5c;
  border-radius: 8px;
  touch-action: none;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  background: #243041;
  border-radius: 6px;
  border: 1px solid #2f3f52;
}

.wall {
  position: absolute;
  border-radius: 6px;
  background:
    linear-gradient(135deg, #5a6575 25%, transparent 25%) -5px 0 / 10px 10px,
    linear-gradient(225deg, #5a6575 25%, transparent 25%) -5px 0 / 10px 10px,
    linear-gradient(315deg, #5a6575 25%, transparent 25%) 0 0 / 10px 10px,
    linear-gradient(45deg, #5a6575 25%, #3d4654 25%) 0 0 / 10px 10px;
  border: 2px solid #6b7788;
  z-index: 1;
  pointer-events: none;
}

.block {
  position: absolute;
  cursor: grab;
  z-index: 2;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
}

.block:active,
.block.is-dragging {
  cursor: grabbing;
}

.block.is-moving {
  pointer-events: none;
}

.block-cell {
  position: absolute;
  border-radius: 7px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22);
  border: 2px solid rgba(255, 255, 255, 0.22);
}

.block-red .block-cell {
  background: #e74c3c;
}

.block-blue .block-cell {
  background: #3498db;
}

.block-yellow .block-cell {
  background: #f1c40f;
}

.block-green .block-cell {
  background: #2ecc71;
}

.door {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255, 255, 255, 0.75);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.18);
  z-index: 1;
  pointer-events: none;
}

.door::after {
  content: attr(data-arrow);
  font-size: clamp(0.75rem, 3.5vw, 1.05rem);
  font-weight: 800;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.door-red {
  background: linear-gradient(180deg, #c0392b, #e74c3c);
}

.door-blue {
  background: linear-gradient(180deg, #2471a3, #3498db);
}

.door-yellow {
  background: linear-gradient(180deg, #d4ac0d, #f1c40f);
}

.door-green {
  background: linear-gradient(180deg, #1e8449, #2ecc71);
}

.door-rail-top .door {
  border-radius: 10px 10px 4px 4px;
}

.door-rail-bottom .door {
  border-radius: 4px 4px 10px 10px;
}

.door-rail-left .door {
  border-radius: 10px 4px 4px 10px;
}

.door-rail-right .door {
  border-radius: 4px 10px 10px 4px;
}

.block.is-leaving {
  transition: opacity 0.2s ease, transform 0.2s ease;
  opacity: 0;
  transform: scale(0.75);
  pointer-events: none;
}

.toolbar {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: #2ecc71;
  color: #102018;
}

.btn:hover {
  filter: brightness(1.05);
}

.btn-secondary {
  background: #3a4a5c;
  color: #f2f5f8;
}

.win-screen {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 18, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.win-screen[hidden] {
  display: none;
}

.win-card {
  width: min(100%, 340px);
  background: #1e2a38;
  border: 2px solid #4a6078;
  border-radius: 16px;
  padding: 24px 20px;
  text-align: center;
}

.win-title {
  margin: 0 0 8px;
  font-size: 1.45rem;
  font-weight: 700;
  color: #7dcea0;
}

.win-text {
  margin: 0 0 18px;
  color: #c5d0dc;
}

.win-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.level-select {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 18, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 30;
}

.level-select[hidden] {
  display: none;
}

.level-select-card {
  width: min(100%, 380px);
  max-height: min(90vh, 640px);
  overflow: auto;
  background: #1e2a38;
  border: 2px solid #4a6078;
  border-radius: 16px;
  padding: 18px 16px 16px;
  text-align: center;
}

.level-select-title {
  margin: 0 0 4px;
  font-size: 1.3rem;
  font-weight: 700;
  color: #f2f5f8;
}

.level-select-hint {
  margin: 0 0 14px;
  color: #a8b3c2;
  font-size: 0.88rem;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.level-pick {
  appearance: none;
  border: 1px solid #4a6078;
  border-radius: 10px;
  min-height: 44px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  background: #2a3848;
  color: #f2f5f8;
}

.level-pick:hover {
  background: #35485c;
}

.level-pick.is-current {
  background: #2ecc71;
  color: #102018;
  border-color: #7dcea0;
}
