:root {
  --bg: #f0f8ff;            /* BG_COLOR (240,248,255) */
  --grid: #b4c8dc;          /* GRID_COLOR */
  --text: #14325a;          /* TEXT_COLOR */
  --btn: #28965a;           /* BTN_COLOR */
  --btn-hover: #32b46e;     /* BTN_HOVER_COLOR */
  --success-bg: #dcf5dc;    /* SUCCESS_BG */
  --success-border: #2e8b57;/* SUCCESS_BORDER */
  --tray-bg: #e1ebf5;
  --tray-border: #aabed2;
  --piece-border: #646464;
  --role: #0f4c81;
  --desc: #505050;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.header {
  flex: none;
  text-align: center;
  padding: clamp(8px, 2vh, 20px) 12px 0;
}

.title {
  margin: 0;
  font-size: clamp(22px, 6.2vw, 36px);
  font-weight: bold;
  line-height: 1.15;
}

.hint {
  margin: clamp(4px, 1vh, 10px) 0 0;
  font-size: clamp(14px, 3.6vw, 22px);
  line-height: 1.25;
  min-height: 2.5em; /* резервируем 2 строки, чтобы поле не прыгало */
  display: flex;
  align-items: center;
  justify-content: center;
}
.hint.done { visibility: hidden; }

/* Игровая область: размеры и позиции элементов задаёт game.js */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  touch-action: none;
}

.tray {
  position: absolute;
  background: var(--tray-bg);
  border: 3px solid var(--tray-border);
  border-radius: 10px;
}

.board {
  position: absolute;
  background: #fff;
}
.board .line {
  position: absolute;
  background: var(--grid);
  pointer-events: none;
}
.board .line.h { left: 0; right: 0; height: 2px; }
.board .line.v { top: 0; bottom: 0; width: 2px; }

.piece {
  position: absolute;
  left: 0;
  top: 0;
  background-image: url("image_0.png");
  box-shadow: inset 0 0 0 1px var(--piece-border);
  touch-action: none;
  cursor: grab;
  will-change: transform;
}
.piece.dragging {
  cursor: grabbing;
  box-shadow: inset 0 0 0 1px var(--piece-border), 0 6px 16px rgba(20, 50, 90, .35);
}
.piece.snap { transition: transform .12s ease-out; }
.piece.locked {
  box-shadow: none;
  cursor: default;
  pointer-events: none;
}

/* Экран победы */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, .59);
  overflow-y: auto;
  animation: fade .25s ease-out;
}
.overlay[hidden] { display: none; }

.win {
  width: 100%;
  max-width: 800px;
  margin: auto;
  padding: clamp(18px, 4vw, 40px) clamp(14px, 4vw, 30px);
  text-align: center;
  background: var(--success-bg);
  border: 5px solid var(--success-border);
  border-radius: 15px;
  animation: pop .3s ease-out;
}
.win p, .win h2 { margin: 0; }

.win-title {
  font-size: clamp(24px, 6.4vw, 36px);
  font-weight: bold;
  line-height: 1.15;
  color: var(--success-border);
}
.win-sub {
  margin-top: clamp(14px, 3vh, 30px) !important;
  font-size: clamp(17px, 4.6vw, 28px);
  font-weight: bold;
}
.win-role {
  margin-top: clamp(12px, 2.5vh, 24px) !important;
  font-size: clamp(24px, 6.4vw, 36px);
  font-weight: bold;
  line-height: 1.15;
  color: var(--role);
  overflow-wrap: anywhere;
}
.win-desc {
  margin-top: clamp(8px, 1.6vh, 14px) !important;
  font-size: clamp(15px, 4vw, 20px);
  font-style: italic;
  color: var(--desc);
}
.win-note {
  margin-top: clamp(14px, 3vh, 28px) !important;
  font-size: clamp(15px, 4vw, 22px);
}

.btn {
  margin-top: clamp(16px, 3vh, 28px);
  min-width: 240px;
  min-height: 48px;
  padding: 10px 24px;
  border: 0;
  border-radius: 10px;
  background: var(--btn);
  color: #fff;
  font: bold clamp(18px, 4.6vw, 28px) Arial, "Helvetica Neue", Helvetica, sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { background: var(--btn-hover); }
.btn:active { background: var(--btn-hover); transform: scale(.97); }
.btn:focus-visible { outline: 3px solid var(--text); outline-offset: 3px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .overlay, .win { animation: none; }
  .piece.snap { transition: none; }
}
