/* ============================================================
   [FILE: core/css/layout.css]
   ============================================================ */

.game-wrapper {
  position: fixed;
  inset: 0;
  z-index: 2;

  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  padding-top:    max(var(--wrapper-pad), env(safe-area-inset-top));
  padding-right:  max(var(--wrapper-pad), env(safe-area-inset-right));
  padding-bottom: max(var(--wrapper-pad), env(safe-area-inset-bottom));
  padding-left:   max(var(--wrapper-pad), env(safe-area-inset-left));

  gap: var(--gap-sm);

  overflow: hidden;
  touch-action: manipulation;
}

/* ============================================================
   [BLOCK: header — [таймер/очки] | лого | [комбо/комбо-бар]
   ============================================================ */

.header {
  flex: 0 0 auto;
  width: 100%;
  height: var(--header-h);
  padding: 0 var(--safe-pad);
  overflow: hidden;
}

.hud-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-xs);
  width: 100%;
  height: 100%;
  min-width: 0;
}

.hud-col {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 4px;
  flex: 0 0 85px;
  min-width: 0;
}

.header-brand {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--gap-xs);
}

.header-logo {
  width: 500px;
  max-width: 100%;
  height: auto;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
}

/* ============================================================
   [BLOCK: board — контейнер доски (полки/ячейки рендерит JS)
   ============================================================ */

.board-container {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.board {
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  position: relative;
}

.shelf {
  display: grid;
  gap: var(--gap-xs);
  width: 100%;
  position: relative;
  padding: var(--pad-panel-y);
  isolation: isolate;
}

.cell {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  padding: 2px;
  aspect-ratio: 1.75 / 1;
  isolation: isolate;
}

.cell-items {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  justify-items: center;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.slot-place {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
}

/* ============================================================
   [BLOCK: item — еда
   ============================================================ */

.item {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: clamp(1.6rem, 8.5vw, 2.6rem);
  line-height: 1;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  cursor: grab;
  pointer-events: auto;
  -webkit-user-drag: element;
  user-select: auto;
  -webkit-user-select: auto;
  overflow: visible;
  touch-action: none;
}

.item:active {
  cursor: grabbing;
}

.item img,
.item canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
  user-drag: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ============================================================
   [BLOCK: merge-эффекты
   ============================================================ */

.merge-burst {
  position: absolute;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  display: flex;
  justify-content: center;
  align-items: center;
}

.merge-flash {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  margin-left: -4px;
  margin-top: -4px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 9998;
  animation: flashExpand 0.5s ease-out forwards;
}

@keyframes flashExpand {
  0%   { transform: translate(-50%, -50%) scale(0.2); opacity: 1; }
  60%  { opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(6); opacity: 0; }
}

.merge-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  margin-top: -8px;
  border-radius: 50%;
  border: 3px solid;
  pointer-events: none;
  z-index: 9997;
  opacity: 0.9;
  animation: ringExpand 0.6s cubic-bezier(0.2, 0.8, 0.4, 1) forwards;
}

@keyframes ringExpand {
  0%   { transform: translate(-50%, -50%) scale(0.5); opacity: 0.95; border-width: 3px; }
  100% { transform: translate(-50%, -50%) scale(6);   opacity: 0;    border-width: 1px; }
}

.spark {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-left: -3px;
  margin-top: -3px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 9999;
  animation: sparkFly 0.55s ease-out forwards;
}

@keyframes sparkFly {
  0%   { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.2); opacity: 0; }
}

.item.match-pop { animation: popOut 0.3s ease forwards; }

@keyframes popOut {
  0%   { transform: scale(1); opacity: 1; }
  45%  { transform: scale(1.5); opacity: 1; }
  100% { transform: scale(0); opacity: 0; }
}

.item.appear { animation: appearIn 0.24s cubic-bezier(0.2, 1.4, 0.4, 1); }

@keyframes appearIn {
  0%   { transform: scale(0.3); opacity: 0; }
  70%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.item.spawn-new { animation: spawnIn 0.35s cubic-bezier(0.2, 1.6, 0.4, 1); }

@keyframes spawnIn {
  0%   { transform: scale(0) rotate(-30deg); opacity: 0; }
  60%  { transform: scale(1.25) rotate(6deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.spawn-badge {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  z-index: 9998;
  pointer-events: none;
  font-size: 1.4rem;
  font-weight: 900;
  animation: badgePop 0.6s ease-out forwards;
}

@keyframes badgePop {
  0%   { transform: translate(-50%, 0) scale(0.5); opacity: 0; }
  30%  { transform: translate(-50%, -20%) scale(1.1); opacity: 1; }
  70%  { transform: translate(-50%, -40%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -70%) scale(0.8); opacity: 0; }
}

.combo-super-banner {
  position: fixed;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  pointer-events: none;
  font-size: clamp(24px, 7vw, 40px);
  font-weight: 900;
  letter-spacing: 2px;
  color: #fff;
  text-align: center;
  white-space: nowrap;
  text-shadow:
    0 0 12px #ffcc33,
    0 0 24px #ff7a00,
    0 3px 0 #7a2c00,
    0 4px 0 #4a1600;
  animation: comboSuperAnim 1.4s ease-out forwards;
}

@keyframes comboSuperAnim {
  0%   { transform: translate(-50%, 40%) scale(0.4); opacity: 0; }
  20%  { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  60%  { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -90%) scale(0.85); opacity: 0; }
}

/* ============================================================
   [BLOCK: hud — статы и таймер
   ============================================================ */

.hud-group {
  display: inline-flex;
}

.hud-stat.timer {
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
  height: 40px;
  box-sizing: border-box;
}

.hud-stat.timer .hud-timer {
  display: block;
  width: 100%;
  text-align: center;
}

.hud-reset {
  pointer-events: auto;
  border-radius: var(--radius-md);
  padding: 5px 10px;
  font-weight: 800;
  font-size: 0.85em;
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}

.hud-reset:active { transform: translateY(3px); }

.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  border-radius: var(--radius-md);
  padding: 3px 10px 4px;
  line-height: 1.1;
  min-width: 0;
  position: relative;
  pointer-events: none;
  height: 40px;
  box-sizing: border-box;
}

.hud-stat .stat-label {
  font-size: 0.6em;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  opacity: 0.9;
  white-space: nowrap;
}

.hud-stat .stat-value {
  font-weight: 900;
  font-size: 1.05em;
  line-height: 1.05;
}

.hud-stat.new-record {
  animation: newRecordPulse 0.7s ease-out;
}

@keyframes newRecordPulse {
  0%   { outline: 0 solid rgba(255, 220, 120, 0.9); }
  50%  { outline: 12px solid rgba(255, 220, 120, 0); }
  100% { outline: 0 solid rgba(255, 220, 120, 0); }
}

/* ============================================================
   [BLOCK: combo-wrap
   ============================================================ */

.combo-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  pointer-events: none;
  width: 100%;
  box-sizing: border-box;
  height: 40px;
}

.combo-bar-track {
  width: 100%;
  height: 100%;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.combo-bar-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 100%;
  border-radius: 0;
  transform-origin: left center;
  transform: scaleX(0);
  transition: none;
}

.combo-label {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  font-weight: 900;
  font-size: 0.55em;
  letter-spacing: 1px;
  pointer-events: none;
  white-space: nowrap;
  opacity: 0.9;
}

.combo-pop {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  pointer-events: none;
  font-weight: 900;
  font-size: 1.5em;
  white-space: nowrap;
  animation: comboPopAnim 0.9s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}

@keyframes comboPopAnim {
  0%   { transform: translate(-50%, 0) scale(0.3); opacity: 0; }
  25%  { transform: translate(-50%, -40%) scale(1.25); opacity: 1; }
  60%  { transform: translate(-50%, -70%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -140%) scale(0.85); opacity: 0; }
}

.combo-glow {
  position: absolute;
  inset: -8px;
  border-radius: 16px;
  opacity: 0;
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.25s ease;
}

.combo-wrap.active-glow .combo-glow { opacity: 1; }

/* ============================================================
   [BLOCK: адаптив
   ============================================================ */

@media (max-width: 380px) {
  .hud-stat { padding: 2px 9px 3px; }
  .hud-stat .stat-label { font-size: 0.55em; }
  .hud-stat .stat-value { font-size: 0.95em; }
  .hud-reset { font-size: 0.78em; padding: 4px 9px; }
  .combo-label { font-size: 0.5em; }
  .board { gap: var(--gap-xs); }
  .shelf { padding: 4px; }
  .cell { border-radius: 4px; }
  .item { font-size: clamp(1.4rem, 7.5vw, 2.2rem); }
}