/* ==========================================================================
   Himalayan Backpack Tetris — Stylesheet
   Theme: High-Altitude Expedition Rucksack & Tibetan Aesthetics
   ========================================================================== */

:root {
  --color-gold: #f5a425;
  --color-gold-light: #ffd166;
  --color-crimson: #c92a42;
  --color-dark-bg: #060b12;
  --color-card: rgba(14, 23, 36, 0.88);
  --color-border: rgba(245, 164, 37, 0.28);
  --color-text: #f8fafc;
  --color-text-muted: #94a3b8;
  --font-serif: 'Cinzel', serif;
  --font-sans: 'Nunito', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: radial-gradient(circle at 50% 20%, #111d2e 0%, #060a10 85%);
  color: var(--color-text);
  font-family: var(--font-sans);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Prayer Flags Garland ── */
.prayer-flags {
  display: flex;
  width: 100%;
  height: 14px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  position: relative;
  z-index: 1000;
}

.flag {
  flex: 1;
  height: 100%;
  clip-path: polygon(0 0, 100% 0, 100% 80%, 50% 100%, 0 80%);
  animation: flagWave 3s ease-in-out infinite alternate;
}

.flag.blue { background-color: #1e6fa8; animation-delay: 0s; }
.flag.white { background-color: #f8fafc; animation-delay: 0.3s; }
.flag.red { background-color: #cd2e48; animation-delay: 0.6s; }
.flag.green { background-color: #43a047; animation-delay: 0.9s; }
.flag.yellow { background-color: #f5a425; animation-delay: 1.2s; }

@keyframes flagWave {
  0% { transform: translateY(0) skewY(0deg); }
  100% { transform: translateY(2px) skewY(3deg); }
}

/* ── Main Layout ── */
.tetris-app-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 10px 10px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* Header & Breadcrumb */
.game-top-bar {
  width: var(--tetris-workspace-width, 786px);
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 12px;
  box-sizing: border-box;
}

.top-nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

#btnBackToLauncher {
  order: 1;
}

.game-title-group {
  order: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: auto;
  margin-left: 0;
}

.game-title-group .backpack-icon {
  font-size: 1.8rem;
  filter: drop-shadow(0 4px 10px rgba(245, 164, 37, 0.4));
}

.game-title-group h1 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.5px;
}

.game-title-group p {
  font-size: 0.74rem;
  color: var(--color-gold-light);
}

.game-quick-actions {
  order: 3;
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-hud {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--color-border);
  color: #f1f5f9;
  padding: 7px 14px;
  border-radius: 9px;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  transition: all 0.2s ease;
  backdrop-filter: blur(8px);
}

.btn-hud:hover {
  background: rgba(245, 164, 37, 0.2);
  border-color: var(--color-gold);
  color: #fff;
  transform: translateY(-1px);
}

.btn-hud.home-btn {
  background: linear-gradient(135deg, rgba(201, 42, 66, 0.85) 0%, rgba(245, 164, 37, 0.85) 100%);
  border-color: var(--color-gold);
  box-shadow: 0 4px 14px rgba(201, 42, 66, 0.35);
}

.btn-hud.home-btn:hover {
  background: linear-gradient(135deg, #e11d48 0%, #f59e0b 100%);
  box-shadow: 0 6px 18px rgba(245, 164, 37, 0.55);
}

/* ── Backpack Workspace (3 Columns) ── */
.backpack-workspace {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 12px;
  width: var(--tetris-workspace-width, 786px);
  max-width: 100%;
  box-sizing: border-box;
}

/* Side Panels */
.backpack-sidebar {
  width: 220px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-card {
  background: var(--color-card);
  border: 1.5px solid var(--color-border);
  border-radius: 12px;
  padding: 8px 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  position: relative;
  overflow: hidden;
}

.panel-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--color-gold), transparent);
}

.panel-title {
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--color-gold);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-subhint {
  font-size: 0.68rem;
  color: var(--color-text-muted);
  font-weight: normal;
}

/* ── Porter Duffle Card ── */
.duffle-card {
  border-color: rgba(245, 164, 37, 0.4);
  background: linear-gradient(180deg, rgba(20, 32, 48, 0.95) 0%, rgba(10, 18, 28, 0.95) 100%);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.25s ease;
}

.duffle-card.bump {
  transform: scale(1.04);
  box-shadow: 0 0 25px rgba(245, 164, 37, 0.6);
}

.porter-badge {
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(245, 164, 37, 0.18);
  color: var(--color-gold-light);
  border: 1px solid rgba(245, 164, 37, 0.35);
}

.duffle-visual-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.duffle-graphic-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 8px 10px;
}

.duffle-icon-large {
  font-size: 2.2rem;
  filter: drop-shadow(0 3px 8px rgba(0,0,0,0.5));
}

.duffle-info-col {
  display: flex;
  flex-direction: column;
}

.duffle-status-tag {
  font-size: 0.68rem;
  color: #22c55e;
  font-weight: 700;
}

.duffle-weight-number {
  font-size: 1.15rem;
  font-weight: 900;
  font-family: var(--font-serif);
  color: #ffd166;
}

.duffle-meter-track {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
}

.duffle-meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f59e0b, #ef4444);
  border-radius: 4px;
  transition: width 0.35s ease;
}

.duffle-mini-stats {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.duffle-mini-stats b {
  color: #fff;
}

.duffle-items-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 28px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px dashed rgba(245, 164, 37, 0.25);
  border-radius: 8px;
  padding: 4px 6px;
  align-items: center;
  max-height: 70px;
  overflow-y: auto;
}

.tray-placeholder {
  font-size: 0.66rem;
  color: #64748b;
  font-style: italic;
}

.tray-item-pill {
  font-size: 1.1rem;
  padding: 1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  animation: trayPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes trayPop {
  0% { transform: scale(0.2); opacity: 0; }
  70% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

/* Mini Previews */
.preview-canvas-box {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 8, 14, 0.75);
  border: 1px dashed rgba(245, 164, 37, 0.3);
  border-radius: 10px;
  padding: 4px;
  min-height: 105px;
}

/* Altitude Gauge */
.altitude-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.altitude-val {
  font-size: 1.5rem;
  font-weight: 900;
  font-family: var(--font-serif);
  color: #38bdf8;
  text-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

.stage-name {
  font-size: 0.86rem;
  font-weight: 700;
  color: #fff;
}

.stage-level {
  font-size: 0.72rem;
  color: var(--color-gold-light);
  font-weight: 700;
}

/* Weight Meter */
.weight-meter-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.weight-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 700;
}

.weight-val {
  color: var(--color-gold);
}

.weight-progress-track {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
}

.weight-progress-fill {
  height: 100%;
  width: 0%;
  background: #22c55e;
  border-radius: 4px;
  transition: width 0.3s ease, background-color 0.3s ease;
}

/* Active Gear Badge */
.active-item-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(2, 132, 199, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 10px;
  padding: 8px 10px;
}

.active-item-icon {
  font-size: 1.8rem;
}

.active-item-info {
  display: flex;
  flex-direction: column;
}

.active-item-name {
  font-size: 0.82rem;
  font-weight: 800;
  color: #fff;
  line-height: 1.2;
}

.active-item-sub {
  font-size: 0.7rem;
  color: #7dd3fc;
}

/* Score Metrics */
.score-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.score-stat-row:last-child {
  border-bottom: none;
}

.score-label {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.score-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
  font-family: var(--font-serif);
}

.score-value.primary {
  color: var(--color-gold);
  font-size: 1.35rem;
}

/* ── Central Backpack Playfield Frame ── */
.backpack-frame {
  position: relative;
  background: linear-gradient(180deg, #182635 0%, #0d1520 100%);
  border: 3px solid rgba(245, 164, 37, 0.45);
  border-radius: 16px;
  padding: 8px;
  box-shadow: 
    0 12px 35px rgba(0, 0, 0, 0.7),
    inset 0 0 25px rgba(0, 0, 0, 0.6),
    0 0 25px rgba(245, 164, 37, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Decorative Backpack Straps & Buckles */
.backpack-frame::before {
  content: attr(data-strap-label);
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: #c92a42;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 2px 10px;
  border-radius: 10px;
  border: 1.5px solid var(--color-gold);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}

.canvas-wrapper {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.85);
  border: 1.5px solid rgba(255, 255, 255, 0.08);
}

#tetrisCanvas {
  display: block;
}

/* Toast Level Up */
.level-toast {
  position: absolute;
  top: 35px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(14, 23, 36, 0.95);
  border: 1.5px solid var(--color-gold);
  color: #fff;
  padding: 10px 18px;
  border-radius: 25px;
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: 0 8px 25px rgba(245, 164, 37, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 50;
  white-space: nowrap;
}

.level-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Mobile Touch Controls ── */
.mobile-touchpad {
  display: none;
  width: 100%;
  max-width: 480px;
  margin-top: 14px;
  gap: 12px;
  justify-content: space-between;
}

.touchpad-dpad, .touchpad-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  flex: 1;
}

.touchpad-actions {
  grid-template-columns: repeat(2, 1fr);
}

.touch-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--color-border);
  color: #fff;
  height: 52px;
  border-radius: 12px;
  font-size: 1.3rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  user-select: none;
  transition: background 0.1s;
}

.touch-btn:active {
  background: rgba(245, 164, 37, 0.3);
  transform: scale(0.96);
}

.touch-btn.btn-hard-drop {
  background: linear-gradient(135deg, rgba(201, 42, 66, 0.7), rgba(245, 164, 37, 0.7));
  border-color: var(--color-gold);
}

/* ── Modals (Game Over & Pause) ── */
.tetris-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 12, 0.85);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  padding: 16px;
}

.tetris-modal-content {
  background: #0f1a29;
  border: 2px solid var(--color-gold);
  border-radius: 20px;
  padding: 28px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.8), 0 0 35px rgba(245, 164, 37, 0.25);
  text-align: center;
  position: relative;
}

.modal-header-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}

.tetris-modal-content h2 {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  color: #fff;
  margin-bottom: 6px;
}

.tetris-modal-content p {
  font-size: 0.88rem;
  color: var(--color-text-muted);
  margin-bottom: 20px;
}

.modal-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.modal-stat-box {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
}

.modal-stat-box.full-width {
  grid-column: span 2;
  background: rgba(245, 164, 37, 0.08);
  border-color: rgba(245, 164, 37, 0.3);
}

.modal-stat-label {
  font-size: 0.72rem;
  color: var(--color-text-muted);
}

.modal-stat-value {
  font-size: 1.25rem;
  font-weight: 900;
  color: #fff;
  font-family: var(--font-serif);
}

.modal-stat-box.full-width .modal-stat-value {
  color: var(--color-gold);
  font-size: 1.6rem;
}

.modal-btn-row {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-modal-action {
  flex: 1;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  border: none;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.btn-modal-action.primary {
  background: linear-gradient(135deg, #df6a27 0%, #f5a425 100%);
  color: #fff;
  box-shadow: 0 4px 16px rgba(245, 164, 37, 0.4);
}

.btn-modal-action.primary:hover {
  background: linear-gradient(135deg, #e97a39 0%, #ffb23f 100%);
  transform: translateY(-2px);
}

.btn-modal-action.secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #f1f5f9;
  border: 1px solid var(--color-border);
}

.btn-modal-action.secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* ── Responsive adjustments ── */
@media (max-width: 900px) {
  .game-top-bar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    margin-bottom: 8px;
  }

  .top-nav-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }

  #btnBackToLauncher {
    order: 1;
  }

  .game-quick-actions {
    order: 2;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .game-title-group {
    order: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    margin: 2px 0 0;
    gap: 8px;
  }

  .game-title-group h1 {
    font-size: 1.1rem;
  }

  .game-title-group p {
    font-size: 0.72rem;
  }

  .backpack-workspace {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
  }

  /* 1. Стакан для игры displays higher up, immediately after the top status row */
  .backpack-frame {
    order: 1;
    margin-top: 10px;
    margin-bottom: 6px;
  }

  /* 2. Клапан и Баул (left-sidebar) display right below the стакан */
  .backpack-sidebar.left-sidebar {
    order: 2;
  }

  /* 3. Next piece, active item, score & stats display after that */
  .backpack-sidebar.right-sidebar {
    order: 3;
  }

  .backpack-sidebar {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }

  .panel-card {
    flex: 1 1 calc(50% - 10px);
    min-width: 140px;
  }

  .mobile-touchpad {
    display: flex;
  }
}

@media (max-width: 480px) {
  .tetris-app-container {
    padding: 4px 6px 10px;
  }

  .btn-hud {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .game-title-group h1 {
    font-size: 0.98rem;
  }

  .game-title-group p {
    font-size: 0.68rem;
  }

  .backpack-sidebar {
    max-width: 100%;
  }

  .panel-card {
    flex: 1 1 calc(50% - 6px);
    min-width: 130px;
    padding: 6px 8px;
  }
}
