*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #1a1a2e;
  --board-bg: #16213e;
  --tile: #0f3460;
  --accent: #e94560;
  --text: #eaeaea;
  --text-muted: #8892a4;
  --radius: 10px;
  --hud-h: 56px;
  --strip-h: 64px;
}

html, body {
  height: 100%;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── SCREENS ─────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.screen.hidden { display: none; }

/* ── MENU ────────────────────────────────── */
.menu-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 40px 24px;
}

/* Decorative logo blocks */
.menu-logo {
  position: relative;
  width: 80px;
  height: 40px;
  margin-bottom: 8px;
}
.logo-block {
  position: absolute;
  border-radius: 6px;
}
.logo-block-main {
  width: 40px; height: 20px;
  background: var(--accent);
  top: 0; left: 0;
}
.logo-block-v {
  width: 16px; height: 40px;
  background: var(--tile);
  top: 0; right: 0;
}
.logo-block-h {
  width: 32px; height: 16px;
  background: var(--tile);
  bottom: 0; left: 20px;
}

.game-title {
  font-size: clamp(2.4rem, 12vw, 3.6rem);
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -1px;
  line-height: 1;
}

.game-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: -16px;
  text-align: center;
}

.difficulty-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.diff-btn {
  padding: 14px 28px;
  border: none;
  border-radius: 50px;
  background: var(--tile);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms, transform 80ms;
  touch-action: manipulation;
}
.diff-btn:hover  { background: #1a3a68; }
.diff-btn:active { background: var(--accent); transform: scale(0.95); }
.diff-btn.small  { padding: 10px 20px; font-size: 0.85rem; }

.ad-slot {
  width: 100%;
  max-width: 320px;
  min-height: 60px;
  display: none; /* activated by ad provider script when online */
}

/* ── HUD ─────────────────────────────────── */
.hud {
  height: var(--hud-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  background: var(--bg);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.menu-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 8px;
  line-height: 1;
  touch-action: manipulation;
  flex-shrink: 0;
}
.menu-btn:active { color: var(--text); }

.hud-level {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.hud-score {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  flex-shrink: 0;
}

.hud-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.hud-label strong {
  color: var(--text);
  font-weight: 700;
}

/* ── GAME AREA ───────────────────────────── */
.game-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px 16px;
  overflow: hidden;
  min-height: 0;
}

.board-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.board {
  position: relative;
  background: var(--board-bg);
  border-radius: var(--radius);
  overflow: hidden;
  touch-action: none;
  /* Square: fill as much space as possible */
  width: min(
    90vw,
    calc(100dvh - var(--hud-h) - var(--strip-h) - 56px)
  );
  height: min(
    90vw,
    calc(100dvh - var(--hud-h) - var(--strip-h) - 56px)
  );
  box-shadow: 0 8px 32px rgba(0,0,0,0.45);
}

.board.winning {
  overflow: visible;
}

/* Exit notch: right edge, row 2 */
.exit-marker {
  position: absolute;
  right: -6px;
  top: calc(2 / 6 * 100% + 3px);
  height: calc(1 / 6 * 100% - 6px);
  width: 6px;
  background: var(--accent);
  border-radius: 0 4px 4px 0;
  z-index: 20;
  box-shadow: 0 0 8px var(--accent);
}

/* ── BLOCKS ──────────────────────────────── */
.block {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 8px;
  cursor: grab;
  will-change: transform;
  transition: transform 80ms ease-out;
  touch-action: none;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.15),
    inset 0 -3px 0 rgba(0,0,0,0.3),
    0 2px 6px rgba(0,0,0,0.3);
}
.block:active { cursor: grabbing; }

.main-block {
  z-index: 5;
}

/* ── DIFFICULTY STRIP ────────────────────── */
.difficulty-strip {
  display: flex;
  gap: 10px;
  height: var(--strip-h);
  align-items: center;
  flex-shrink: 0;
}

/* ── WIN OVERLAY ─────────────────────────── */
.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: overlayIn 220ms ease;
}
.win-overlay.hidden { display: none; }

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.win-card {
  background: var(--board-bg);
  border-radius: 24px;
  padding: 36px 40px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  min-width: 260px;
  animation: cardIn 250ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes cardIn {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.win-emoji { font-size: 2.8rem; line-height: 1; }

.win-level-text {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
}

.win-stats {
  display: flex;
  gap: 36px;
}

.win-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.win-stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.win-stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}

.win-next-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 15px 36px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 80ms, box-shadow 80ms;
  box-shadow: 0 4px 16px rgba(233,69,96,0.4);
}
.win-next-btn:active {
  transform: scale(0.96);
  box-shadow: 0 2px 8px rgba(233,69,96,0.3);
}

/* ── LANDSCAPE LAYOUT ────────────────────── */
@media (orientation: landscape) and (max-height: 500px) {
  .board {
    width: min(80vh, 70vw);
    height: min(80vh, 70vw);
  }
  .win-card { padding: 20px 28px; gap: 12px; }
  .win-emoji { display: none; }
}
