/* ============================================================
   LEAN AGILE OPEX — 8 Wastes Memory Game
   Brand: Black #1A1A1A + Green #6DC04B
   Layout: RTL (Hebrew primary)
   ============================================================ */

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

:root {
  --black:      #1A1A1A;
  --green:      #6DC04B;
  --green-dark: #4fa334;
  --green-light:#E8F5E1;
  --white:      #FFFFFF;
  --gray-bg:    #F2F2F2;
  --gray-border:#DDDDDD;
  --gray-text:  #777777;
  --amber:      #F5A623;
  --amber-light:#FFF6E5;

  --font: 'Segoe UI', Arial, 'Helvetica Neue', sans-serif;
  --radius: 12px;
  --card-radius: 10px;
}

html {
  font-family: var(--font);
  background: var(--gray-bg);
  color: var(--black);
  min-height: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
}

/* ============================================================
   SCREENS
   ============================================================ */
.screen {
  display: none;
  width: 100%;
  max-width: 680px;
  flex-direction: column;
  align-items: center;
}

.screen.active {
  display: flex;
}

/* ============================================================
   MENU SCREEN
   ============================================================ */
.menu-logo {
  margin: 24px 0 16px;
  text-align: center;
}

.menu-logo img {
  width: 200px;
  max-width: 80vw;
}

.menu-title {
  text-align: center;
  margin-bottom: 28px;
}

.menu-title .he {
  display: block;
  font-size: clamp(1.2rem, 4vw, 1.7rem);
  font-weight: 800;
  color: var(--black);
  line-height: 1.3;
}

.menu-title .en {
  display: block;
  font-size: clamp(0.75rem, 2.5vw, 0.95rem);
  color: var(--gray-text);
  margin-top: 4px;
}

.level-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 420px;
  padding-bottom: 32px;
}

.level-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--white);
  border: 2px solid var(--gray-border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: right;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.1s;
  width: 100%;
}

.level-btn:hover {
  border-color: var(--green);
  box-shadow: 0 4px 16px rgba(109, 192, 75, 0.2);
  transform: translateY(-1px);
}

.level-btn:active {
  transform: translateY(0);
}

.level-number {
  font-size: 2rem;
  font-weight: 900;
  color: var(--green);
  min-width: 36px;
  text-align: center;
  line-height: 1;
}

.level-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.level-name-he {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--black);
}

.level-name-en {
  font-size: 0.78rem;
  color: var(--gray-text);
}

.level-desc {
  font-size: 0.8rem;
  color: #555;
  margin-top: 2px;
}

/* ============================================================
   GAME SCREEN — HEADER
   ============================================================ */
#game-screen {
  align-items: stretch;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--white);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  gap: 8px;
}

.back-btn {
  background: none;
  border: 1.5px solid var(--gray-border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.8rem;
  color: var(--gray-text);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  font-family: var(--font);
}

.back-btn:hover {
  border-color: var(--black);
  color: var(--black);
}

.game-stats {
  display: flex;
  gap: 20px;
  align-items: center;
}

.stat {
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.62rem;
  color: var(--gray-text);
  line-height: 1;
  margin-bottom: 2px;
}

.stat-value {
  display: block;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--black);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.header-logo img {
  height: 44px;
  display: block;
}

.level-badge-bar {
  text-align: center;
  margin-bottom: 12px;
}

.level-badge {
  display: inline-block;
  background: var(--green);
  color: var(--white);
  padding: 4px 16px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
}

/* ============================================================
   GAME GRID
   ============================================================ */
.game-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
}

/* ============================================================
   CARD
   ============================================================ */
.card {
  aspect-ratio: 3 / 4;
  perspective: 900px;
  cursor: pointer;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.38s ease;
}

.card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--card-radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 6px;
  overflow: hidden;
}

/* --- Card Back --- */
.card-back {
  background: var(--white);
  border: 2px solid var(--green);
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.card-back img {
  width: 82%;
  object-fit: contain;
  pointer-events: none;
}

/* --- Card Front base --- */
.card-front {
  transform: rotateY(180deg);
  border: 2px solid var(--gray-border);
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  gap: 5px;
  text-align: center;
}

/* Emoji card (Level 1 — card A) */
.card-front.type-emoji {
  background: var(--green-light);
  border-color: var(--green);
}

.card-emoji {
  font-size: clamp(1.6rem, 5vw, 2.8rem);
  line-height: 1;
}

/* Name card (card B — all levels) */
.card-front.type-name {
  background: var(--white);
  border-color: var(--black);
}

.card-name-he {
  font-size: clamp(0.6rem, 2vw, 0.9rem);
  font-weight: 800;
  color: var(--black);
  line-height: 1.2;
  word-break: keep-all;
}

.card-name-en {
  font-size: clamp(0.52rem, 1.5vw, 0.72rem);
  color: var(--gray-text);
  line-height: 1.2;
}

/* Text card (Levels 2–4 — card A) */
.card-front.type-text {
  background: var(--amber-light);
  border-color: var(--amber);
}

.card-text {
  font-size: clamp(0.55rem, 1.8vw, 0.75rem);
  line-height: 1.4;
  color: var(--black);
  word-break: break-word;
}

/* --- Hidden (matched & flown away) --- */
.card.gone {
  visibility: hidden;
}

/* ============================================================
   MATCHED PILE  (fixed to screen corner)
   ============================================================ */
.card-pile {
  position: fixed;
  bottom: 22px;
  left: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s;
  z-index: 50;
}

.card-pile.visible { opacity: 1; }

/* Stack of "cards" visual */
.pile-stack {
  position: relative;
  width: 48px;
  height: 62px;
}

/* Bottom two ghost cards */
.pile-stack::before,
.pile-stack::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 6px;
  border: 2px solid var(--green);
}

.pile-stack::before {
  background: #c8e8b0;
  transform: rotate(-7deg);
}

.pile-stack::after {
  background: var(--green-light);
  transform: rotate(4deg);
}

/* Top card — shows logo */
.pile-top {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: var(--white);
  border: 2px solid var(--green);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.pile-top img {
  width: 80%;
  object-fit: contain;
}

.pile-count {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--green);
  line-height: 1;
}

.pile-label {
  font-size: 0.58rem;
  color: var(--gray-text);
  line-height: 1;
}

@keyframes pile-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.22); }
  100% { transform: scale(1); }
}

.card-pile.pop { animation: pile-pop 0.28s ease; }

/* ============================================================
   DISMISS HINT  (tap-to-continue for levels 2–4)
   ============================================================ */
.dismiss-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
  padding: 8px 20px;
  border-radius: 24px;
  background: var(--white);
  border: 1.5px solid var(--amber);
  color: var(--black);
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);

  /* Hidden by default */
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.dismiss-hint.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.dismiss-icon {
  font-size: 1rem;
  animation: hint-bounce 1s ease infinite;
}

@keyframes hint-bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-3px); }
}

/* ============================================================
   WIN SCREEN
   ============================================================ */
#win-screen {
  justify-content: center;
  min-height: 80vh;
}

.win-card {
  background: var(--white);
  border-radius: 20px;
  padding: clamp(24px, 5vw, 44px);
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
}

.win-logo img {
  width: 160px;
  margin-bottom: 8px;
}

.win-confetti {
  font-size: 2.8rem;
  margin-bottom: 8px;
}

.win-title {
  font-size: 2rem;
  font-weight: 900;
  color: var(--black);
  margin-bottom: 2px;
}

.win-subtitle {
  font-size: 0.95rem;
  color: var(--gray-text);
  margin-bottom: 24px;
}

.win-stats {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-bottom: 28px;
}

.win-stat-label {
  display: block;
  font-size: 0.72rem;
  color: var(--gray-text);
  margin-bottom: 4px;
}

.win-stat-value {
  display: block;
  font-size: 2rem;
  font-weight: 800;
  color: var(--green);
}

.win-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-primary {
  background: var(--green);
  color: var(--white);
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.2s, transform 0.1s;
}

.btn-primary:hover  { background: var(--green-dark); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  background: var(--white);
  color: var(--black);
  border: 2px solid var(--gray-border);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.95rem;
  font-family: var(--font);
  cursor: pointer;
  transition: border-color 0.2s;
}

.btn-secondary:hover { border-color: var(--black); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 420px) {
  body { padding: 10px; }

  .game-grid { gap: 6px; }

  .game-header { padding: 8px 10px; }

  .header-logo img { height: 34px; }

  .stat-value { font-size: 1rem; }

  .card-face { padding: 5px 4px; }
}

@media (max-width: 340px) {
  .game-grid { gap: 4px; }
  .card-emoji { font-size: 1.4rem; }
}
