
/* Critical: never let layout rules override .hidden */
#gameModal .game-area.hidden,
#gameModal #kitchenGameArea.hidden,
#gameModal #gameArea.hidden,
#gameModal #memoryGameArea.hidden,
#gameModal #gameSelector.hidden {
  display: none !important;
}
/* MIS STOP Games UI v2 — lobby, burger, memory, chef kitchen */

#gameModal.modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 12, 8, 0.72);
  backdrop-filter: blur(4px);
}
#gameModal.modal.hidden { display: none !important; }

#gameModal .game-close {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 9100;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 3px solid #2b1c16;
  border-radius: 50%;
  background: #fff8ee;
  color: #2b1c16;
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  box-shadow: 4px 4px 0 rgba(0,0,0,.2);
}
#gameModal .game-close:hover { background: #ffd84a; }

#gameModal .game-modal-content {
  position: relative;
  width: min(920px, 96vw);
  max-height: min(90vh, 860px);
  overflow: auto;
  border: 4px solid #2b1c16;
  border-radius: 28px;
  background:
    radial-gradient(circle at 10% 0%, rgba(255,210,79,.5), transparent 34%),
    linear-gradient(165deg, #fffaf0, #ffe8c4 60%, #ffd9a8);
  box-shadow: 12px 12px 0 rgba(43,28,22,.18);
  padding: 16px 16px 20px;
}

/* Lobby */
#gameSelector { max-width: 1000px; margin: 0 auto; padding: 8px 4px 4px; }
#gameSelector > h2 {
  margin: 0 0 16px;
  font-size: clamp(26px, 4vw, 36px);
  color: #2b1c16;
}
#gameSelector > h2::after {
  content: "Избери предизвикателство";
  display: block;
  margin-top: 6px;
  color: #6d4a3a;
  font-size: 14px;
  font-weight: 800;
}
.game-cards-horizontal {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.game-card-wide {
  position: relative;
  min-height: 160px;
  overflow: hidden;
  border: 3px solid #2b1c16;
  border-radius: 22px;
  background: #1a120e;
  box-shadow: 5px 6px 0 rgba(43,28,22,.2);
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}
.game-card-wide:hover:not(:disabled) {
  transform: translate(-2px, -3px);
  box-shadow: 9px 10px 0 rgba(43,28,22,.2);
}
.game-card-wide .game-card-bg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.game-card-wide .game-card-content {
  position: relative; z-index: 1;
  height: 100%;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 16px;
  background: linear-gradient(180deg, transparent 15%, rgba(15,8,5,.82));
  text-align: left;
}
.game-card-wide .game-card-content h3 {
  margin: 0 0 6px; color: #fffaf0; font-size: 21px;
  text-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.game-card-wide .game-card-content span {
  display: inline-flex; width: fit-content;
  padding: 5px 10px; border-radius: 999px;
  background: rgba(255,210,79,.95); color: #2b1c16;
  font-weight: 900; font-size: 12px;
}
.game-wheel-card {
  grid-column: 1 / -1;
  min-height: 100px;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(120deg, #fff3c4, #ffd76a);
}
.game-wheel-card .game-card-content { background: none; padding: 0; }
.game-wheel-card .game-card-content h3 { color: #2b1c16; text-shadow: none; }
.game-wheel-icon { font-size: 40px; }

/* Shared game chrome */
.game-area { position: relative; min-height: 400px; padding: 8px 4px 12px; }
.back-to-menu {
  position: sticky;
  top: 0;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  border: 3px solid #2b1c16;
  border-radius: 999px;
  background: #fff;
  padding: 8px 14px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(43,28,22,.12);
}
.back-to-menu:hover { background: #ffe27a; }

.game-title-screen {
  position: absolute; inset: 0; z-index: 40;
  display: grid; place-items: center;
  padding: 20px; border-radius: 20px;
  background: linear-gradient(180deg, rgba(20,12,8,.55), rgba(20,12,8,.75)), #3a2418;
  background-size: cover; background-position: center;
}
.game-title-screen.hidden { display: none !important; }
.game-title-box {
  max-width: 420px;
  padding: 22px;
  border: 3px solid #2b1c16;
  border-radius: 22px;
  background: #fff8ee;
  box-shadow: 8px 8px 0 rgba(0,0,0,.18);
  text-align: center;
}
.game-title-box h3 { margin: 0 0 10px; font-size: 26px; color: #2b1c16; }
.game-title-box p { margin: 0; color: #5a4030; font-weight: 700; line-height: 1.45; }
.game-btn-start {
  margin-top: 14px; min-width: 150px; min-height: 50px;
  border: 3px solid #2b1c16; border-radius: 999px;
  background: linear-gradient(180deg, #ffd84a, #f5b400);
  color: #2b1c16; font-weight: 900; font-size: 17px;
  cursor: pointer; box-shadow: 0 5px 0 #2b1c16;
}
.game-btn-start:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #2b1c16; }

.game-stats {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px;
  margin: 8px 0 12px;
}
.game-stats > div {
  background: #fff9f0; border: 3px solid #2b1c16; border-radius: 999px;
  padding: 8px 14px; font-weight: 900; font-size: 14px;
  box-shadow: 3px 3px 0 rgba(43,28,22,.12);
}

.game-result {
  min-height: 28px;
  margin: 12px 0 0;
  text-align: center;
  font-weight: 900;
  font-size: 17px;
  color: #2b1c16;
}
.game-result.is-final {
  display: inline-block;
  width: 100%;
  padding: 12px 16px;
  border-radius: 16px;
  background: rgba(20, 12, 8, 0.88);
  color: #fffef8 !important;
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
  box-sizing: border-box;
}
.game-result.is-final b { color: #ffd84a; }
.game-result.is-good { color: #1b7a32; }
.game-result.is-bad { color: #c92a2a; }

/* Burger field */
#gameArea { min-height: 460px; overflow: hidden; }
#gameArea .game-result.is-final {
  position: relative;
  z-index: 30;
  margin-top: 16px;
}

/* Memory — faster flip */
.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  max-width: 420px;
  margin: 12px auto 0;
  perspective: 800px;
}
.memory-card {
  aspect-ratio: 1;
  border: 3px solid #2b1c16;
  border-radius: 16px;
  cursor: pointer;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.28s ease;
  box-shadow: 3px 3px 0 rgba(43,28,22,.15);
}
.memory-card .front,
.memory-card .back {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  border-radius: 13px;
  backface-visibility: hidden;
  font-size: 28px;
}
.memory-card .front {
  background: linear-gradient(160deg, #ffd76a, #f0a93a);
}
.memory-card .back {
  background: #fff9f0;
  transform: rotateY(180deg);
}
.memory-card.flipped,
.memory-card.matched {
  transform: rotateY(180deg);
}
.memory-card.matched {
  box-shadow: 0 0 0 3px rgba(47,158,68,.35);
  cursor: default;
}

/* ========== CHEF KITCHEN (rebuilt) ========== */
#kitchenGameArea:not(.hidden) {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 520px;
  padding: 8px 6px 14px;
  border-radius: 20px;
  background:
    radial-gradient(circle at 100% 0%, rgba(255,140,60,.25), transparent 42%),
    linear-gradient(180deg, #2a1810 0%, #4a2c1a 28%, #fff1dc 28%, #ffe3c0 100%);
}
#kitchenGameArea .back-to-menu { background: #fff8ee; }
#kitchenTitleScreen {
  background-image:
    linear-gradient(180deg, rgba(20,12,8,.55), rgba(20,12,8,.72)),
    url('assets/games/kitchen-bg.jpeg');
  background-size: cover;
  background-position: center;
}

#kitchenGameArea:not(.kitchen-active) .kitchen-play {
  display: none;
}
#kitchenGameArea.kitchen-active .kitchen-play {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.kitchen-topbar { margin-top: 2px; }
.kitchen-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.kitchen-hud > div {
  background: #fff9f0;
  border: 3px solid #2b1c16;
  border-radius: 999px;
  padding: 7px 12px;
  font-weight: 900;
  font-size: 13px;
  box-shadow: 3px 3px 0 rgba(43,28,22,.12);
}
.kitchen-streak { background: #ffe8a3 !important; }

.kitchen-main {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 12px;
}
@media (max-width: 700px) {
  .kitchen-main { grid-template-columns: 1fr; }
}

.kitchen-ticket {
  border: 3px solid #2b1c16;
  border-radius: 18px;
  background:
    repeating-linear-gradient(0deg, #fffef8 0 12px, #fff8e8 12px 24px);
  padding: 14px 16px;
  box-shadow: 5px 5px 0 rgba(43,28,22,.14);
}
.ticket-header {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .08em;
  color: #8a5a20;
  text-transform: uppercase;
}
.kitchen-ticket h3 {
  margin: 6px 0 10px;
  font-size: clamp(18px, 2.4vw, 24px);
  color: #1f140f;
}
.recipe-hint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: 26px;
  min-height: 36px;
}
.recipe-hint .hint-arrow {
  font-size: 14px;
  color: #8a5a20;
  font-weight: 900;
  margin: 0 2px;
}
.ticket-tip {
  margin: 10px 0 0;
  font-size: 12px;
  font-weight: 800;
  color: #6d4a3a;
}

.kitchen-station {
  border: 3px solid #2b1c16;
  border-radius: 18px;
  background: #fffaf3;
  padding: 12px;
  box-shadow: 5px 5px 0 rgba(43,28,22,.1);
}
.station-label {
  font-weight: 900;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #6d4a3a;
  margin-bottom: 8px;
}
.build-area {
  min-height: 120px;
  border: 3px dashed #2b1c16;
  border-radius: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background: linear-gradient(180deg, #fff, #fff4e0);
  transition: background .2s ease, box-shadow .2s ease;
}
.build-area.is-baking {
  background: linear-gradient(180deg, #ffd28a, #ff9f1c);
  animation: kitchenPulse .6s ease infinite alternate;
}
.build-area.is-ready {
  background: linear-gradient(180deg, #d3f9d8, #8ce99a);
  border-style: solid;
}
.build-placeholder {
  font-size: 14px;
  font-weight: 800;
  color: #9a7b60;
}
.build-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border: 2px solid #2b1c16;
  border-radius: 999px;
  background: #fff;
  font-size: 22px;
  box-shadow: 2px 2px 0 rgba(43,28,22,.12);
}
.build-chip i {
  font-style: normal;
  font-size: 11px;
  font-weight: 900;
  color: #8a5a20;
  background: #ffe8a3;
  border-radius: 50%;
  width: 18px; height: 18px;
  display: grid; place-items: center;
}
.bake-meter {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 900;
  font-size: 13px;
  color: #2b1c16;
}
.bake-meter i {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: #e9d5b5;
  overflow: hidden;
  position: relative;
}
.bake-meter i::after {
  content: '';
  position: absolute; inset: 0;
  width: 0;
  background: linear-gradient(90deg, #ff9f1c, #e85d04);
  animation: bakeFill .9s linear forwards;
}
.bake-meter.done i::after { width: 100%; animation: none; background: #2f9e44; }

@keyframes bakeFill { to { width: 100%; } }
@keyframes kitchenPulse {
  from { box-shadow: inset 0 0 0 0 rgba(255,140,0,.2); }
  to { box-shadow: inset 0 0 0 6px rgba(255,140,0,.25); }
}

.kitchen-ingredients {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.ing-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 64px;
  border: 3px solid #2b1c16;
  border-radius: 14px;
  background: #fff9f0;
  font-size: 12px;
  font-weight: 800;
  color: #2b1c16;
  cursor: pointer;
  box-shadow: 0 4px 0 #2b1c16;
  transition: transform .1s ease, box-shadow .1s ease, background .15s ease;
}
.ing-btn .ing-emoji { font-size: 22px; line-height: 1; }
.ing-btn:hover { background: #fff3d0; }
.ing-btn:active, .ing-btn.is-pressed {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #2b1c16;
}

.kitchen-actions {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1.2fr;
  gap: 10px;
}
.action-btn {
  min-height: 50px;
  border: 3px solid #2b1c16;
  border-radius: 14px;
  padding: 10px 8px;
  font-weight: 900;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 4px 0 #2b1c16;
  color: #1a120e;
}
.action-btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #2b1c16;
}
.action-btn:disabled {
  background: #cfc4b6 !important;
  color: #6a5b4e;
  cursor: not-allowed;
  box-shadow: 0 2px 0 #8a7b6c;
}
#bakeBtn { background: linear-gradient(180deg, #ff8a4c, #e85d04); }
#serveBtn { background: linear-gradient(180deg, #8ce99a, #2f9e44); }
#trashBtn, .action-btn.trash {
  background: linear-gradient(180deg, #ff8787, #e03131);
  color: #fff;
}

@media (max-width: 700px) {
  .game-cards-horizontal { grid-template-columns: 1fr; }
  .game-wheel-card { grid-column: auto; }
  .memory-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kitchen-ingredients { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kitchen-actions { grid-template-columns: 1fr; }
  #gameModal .game-close { top: 10px; right: 10px; width: 42px; height: 42px; }
}


/* ===== FIX PASS: visible back, centered titles, kitchen fits ===== */

#gameModal .game-modal-content {
  display: flex !important;
  flex-direction: column !important;
  max-height: min(90vh, 860px) !important;
  overflow: hidden !important;
  padding: 12px 12px 14px !important;
}

#gameSelector,
.game-area {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

/* Back button — always visible, short, high contrast */
#gameModal .back-to-menu,
.game-area > .back-to-menu,
#kitchenGameArea > .back-to-menu {
  position: relative !important;
  z-index: 60 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: auto !important;
  max-width: 120px !important;
  min-height: 38px !important;
  margin: 0 0 10px 0 !important;
  padding: 8px 14px !important;
  border: 3px solid #2b1c16 !important;
  border-radius: 999px !important;
  background: #ffd84a !important;
  color: #2b1c16 !important;
  font-weight: 900 !important;
  font-size: 14px !important;
  line-height: 1 !important;
  box-shadow: 3px 3px 0 rgba(43,28,22,.18) !important;
  white-space: nowrap !important;
}
#gameModal .back-to-menu:hover {
  background: #ffe27a !important;
}

/* Title screens — true center */
.game-title-screen {
  position: absolute !important;
  inset: 0 !important;
  z-index: 40 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 16px !important;
  box-sizing: border-box !important;
}
.game-title-box {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  text-align: center !important;
  width: min(400px, 92%) !important;
  margin: 0 auto !important;
}
.game-title-box .game-btn-start {
  margin-top: 16px !important;
  align-self: center !important;
}

/* Final scores readable on dark */
.game-result.is-final,
#memoryResult.is-final,
#gameResult.is-final,
#kitchenResult.is-final {
  display: block !important;
  width: 100% !important;
  margin-top: 12px !important;
  padding: 12px 14px !important;
  border-radius: 14px !important;
  background: rgba(20, 12, 8, 0.9) !important;
  color: #fffef8 !important;
  text-shadow: 0 1px 2px rgba(0,0,0,.4) !important;
  box-sizing: border-box !important;
  position: relative !important;
  z-index: 35 !important;
}
.game-result.is-final b { color: #ffd84a !important; }

/* Kitchen: compact, actions always visible */
#kitchenGameArea:not(.hidden) {
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  max-height: 100% !important;
  overflow: hidden !important;
  background: linear-gradient(180deg, #3a2418 0 52px, #fff1dc 52px) !important;
  padding: 8px !important;
  gap: 8px !important;
}
#kitchenGameArea.kitchen-active .kitchen-play {
  display: flex !important;
  flex-direction: column !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  gap: 8px !important;
  overflow: hidden !important;
}
.kitchen-topbar { flex: 0 0 auto !important; }
.kitchen-hud {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 6px !important;
  justify-content: center !important;
}
.kitchen-hud > div {
  padding: 6px 10px !important;
  font-size: 12px !important;
}
.kitchen-main {
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 8px !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
}
.kitchen-ticket,
.kitchen-station {
  min-height: 0 !important;
  overflow: auto !important;
  padding: 10px !important;
}
.kitchen-ticket h3 { font-size: 18px !important; margin: 4px 0 8px !important; }
.recipe-hint { font-size: 22px !important; min-height: 28px !important; }
.ticket-tip { margin-top: 6px !important; font-size: 11px !important; }

.build-area {
  min-height: 72px !important;
  max-height: 110px !important;
  overflow-y: auto !important;
  padding: 8px !important;
  gap: 6px !important;
}
.build-chip { font-size: 18px !important; padding: 4px 8px !important; }

/* Pin ingredients + actions at bottom — never pushed off-screen */
.kitchen-ingredients {
  flex: 0 0 auto !important;
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 6px !important;
  margin: 0 !important;
}
.ing-btn {
  min-height: 54px !important;
  padding: 6px 4px !important;
  font-size: 11px !important;
}
.ing-btn .ing-emoji { font-size: 18px !important; }

.kitchen-actions {
  flex: 0 0 auto !important;
  display: grid !important;
  grid-template-columns: 1fr 1.15fr 1.15fr !important;
  gap: 8px !important;
  margin: 0 !important;
  padding-bottom: 2px !important;
}
.action-btn {
  min-height: 44px !important;
  font-size: 13px !important;
  padding: 8px 6px !important;
}

#kitchenResult.game-result {
  flex: 0 0 auto !important;
  margin: 0 !important;
  min-height: 24px !important;
}

.bake-meter { margin-top: 6px !important; font-size: 12px !important; }

@media (max-width: 700px) {
  .kitchen-main { grid-template-columns: 1fr !important; }
  .kitchen-ingredients { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
  .kitchen-actions { grid-template-columns: 1fr 1fr 1fr !important; }
}
