html, body { background: var(--bg-inverse); }

/* ---------- Base screens ---------- */
.screen {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}
.screen[hidden] { display: none !important; }

button { font-family: inherit; border: none; cursor: pointer; }

/* ---------- Buttons (design.md §8.2) ---------- */
.btn-primary {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
  background: var(--success);
  border: 1px solid var(--success-dark);
  box-shadow: var(--sh-inset-btn);
  color: var(--ten-white);
  font-weight: 700;
  font-size: 16px;
  border-radius: var(--r-sm);
  padding: 14px 20px;
  transition: background var(--dur-base) var(--ease-out), transform var(--dur-fast);
}
.btn-primary:hover  { background: #17994B; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(232,0,29,0.35); }

.btn-outline {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
  background: transparent;
  border: 1.5px solid rgba(255,255,255,0.75);
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  border-radius: var(--r-sm);
  padding: 13px 20px;
  transition: all var(--dur-base) var(--ease-out);
}
.btn-outline:hover  { background: rgba(255,255,255,0.08); border-color: #fff; }
.btn-outline:active { transform: scale(0.98); }

/* ---------- Dark hero (start + win) — design.md §8.13 / §9.1 ---------- */
.screen-start,
.screen-win {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background: var(--bg-inverse);
  color: #fff;
  text-align: center;
}

.geo-watermark {
  position: absolute;
  pointer-events: none;
  stroke: var(--ten-red);
  fill: none;
  stroke-width: 1.5;
  opacity: 0.20;
}
.geo-a { width: 220px; height: 220px; top: -40px; right: -50px; }
.geo-b { width: 140px; height: 140px; bottom: 10%; left: -30px; }
.geo-c { width: 120px; height: 120px; bottom: -20px; right: 8%; opacity: 0.14; }
@keyframes geo-drift { 0%,100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-12px) rotate(4deg); } }
.geo-drift { animation: geo-drift 9s ease-in-out infinite; }

.start-content, .win-content {
  position: relative;
  z-index: 1;
  max-width: 380px;
  width: 100%;
}

.eyebrow {
  display: inline-block;
  padding: 6px 14px;
  border-radius: var(--r-pill);
  background: rgba(232,0,29,0.16);
  border: 1px solid rgba(232,0,29,0.45);
  color: #FFD9DE;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.h-display {
  font: 700 30px/1.25 var(--font-bangla);
  letter-spacing: var(--tracking-tight);
  margin: 16px 0 10px;
}

.win-sub {
  font: 400 16px/1.5 var(--font-bangla);
  color: rgba(255,255,255,0.75);
  margin: 0 0 24px;
}

.start-medal-peek {
  width: min(58vw, 220px);
  margin: 24px auto 28px;
  border-radius: var(--r-lg);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.18);
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
  -webkit-mask-image: linear-gradient(180deg, #000 55%, transparent 100%);
  mask-image: linear-gradient(180deg, #000 55%, transparent 100%);
}
.start-medal-canvas, .win-medal-canvas { width: 100%; height: auto; display: block; }

.name-field {
  max-width: 320px;
  margin: 0 auto 18px;
  text-align: left;
}
.name-label {
  display: block;
  margin: 0 0 6px 2px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.75);
}
.name-input {
  display: block;
  width: 100%;
  background: rgba(255,255,255,0.08);
  border: 1.5px solid rgba(255,255,255,0.28);
  color: #fff;
  font-size: 16px;
  border-radius: var(--r-sm);
  padding: 12px 14px;
}
.name-input::placeholder { color: rgba(255,255,255,0.45); }
.name-input:focus-visible { outline: none; border-color: rgba(255,255,255,0.5); box-shadow: 0 0 0 3px rgba(232,0,29,0.35); }

.attempt-warning {
  max-width: 320px;
  margin: 0 auto 14px;
  font-size: 13px;
  line-height: 1.5;
  color: rgba(255,255,255,0.6);
}

.form-error {
  max-width: 320px;
  margin: 0 auto 14px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
  color: var(--ten-red-soft);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn-primary:disabled:hover { background: var(--success); }

.win-image-wrap {
  width: min(62vw, 240px);
  margin: 0 auto 20px;
  border-radius: var(--r-lg);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.22);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 0 6px rgba(28,171,85,0.15);
}

.win-title { color: #fff; margin: 0 0 6px; }

.win-time-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  max-width: 320px;
  margin: 0 auto 24px;
  padding: 16px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: var(--r-lg);
}
.win-time-label { font-size: 13px; font-weight: 600; color: rgba(255,255,255,0.7); }
.win-time-value {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
}
.win-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }

.confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.share-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #1A1A1A;
  border: 1px solid rgba(255,255,255,0.22);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--r-pill);
  font-size: 13px;
  z-index: 50;
}

/* ---------- Game screen ---------- */
.screen-game, .screen-leaderboard {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-inverse);
  position: relative;
}

.game-header {
  flex: 0 0 auto;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.brand-mark { display: flex; align-items: center; gap: 8px; }
.brand-mark-logo { height: 26px; width: auto; display: block; }

.header-stats { display: flex; align-items: center; gap: 8px; }

.progress-pill, .timer-pill {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: var(--r-pill);
  padding: 6px 14px;
  font-weight: 700;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: #fff;
}
.progress-sep { margin: 0 3px; color: rgba(255,255,255,0.5); }

.board-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
}

.board {
  position: relative;
  flex: 0 0 auto;
  background: #060809;
  /* An inset ring rather than a border, on purpose. Under the global
     `box-sizing: border-box`, a border shrinks the content box while
     getBoundingClientRect() keeps reporting the border box — which put the
     ghost canvas and the placed pieces on two scales 2px apart, leaving a
     sliver of ghost seam beside every piece. box-shadow does not affect
     layout, so the board's box stays exactly the size layoutBoardSize sets. */
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.14);
  border-radius: var(--r-lg);
  overflow: hidden;
}

/* Absolutely positioned so it resolves against the same padding box the placed
   pieces do, and `fill` so it maps onto that box with no crop — `cover` would
   trim a fraction whenever the box is a hair off-ratio. Dimming is baked into
   the canvas by PuzzleRender.drawGhostGrid so the seam lines stay readable
   against the faded picture. */
.ghost-image {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  -webkit-user-drag: none;
}

.tray {
  flex: 0 0 auto;
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  height: 300px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: center;
  gap: 10px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.12);
  background: var(--bg-inverse);
  scroll-snap-type: y proximity;
  -webkit-overflow-scrolling: touch;
}

/* Wider viewports (tablet/desktop "web view"): 4 columns instead of 3,
   sized to match TRAY_COLS_DESKTOP in puzzle-game.js. Real phones stay
   under this width, so the mobile layout is untouched. */
@media (min-width: 640px) {
  .tray { max-width: 560px; }
}

.tray-error {
  flex: 1 1 auto;
  margin: 0;
  text-align: center;
  font-size: 14px;
  color: rgba(255,255,255,0.78);
}

/* ---------- Puzzle pieces ---------- */
.piece {
  display: block;
  flex: 0 0 auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: grab;
  scroll-snap-align: center;
  transition: filter var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out);
}
.piece.dragging {
  cursor: grabbing;
  z-index: 1000;
  filter: drop-shadow(0 0 14px rgba(255,255,255,0.30));
  transform: scale(1.05);
  transition: none;
}
.piece.locked {
  cursor: default;
  pointer-events: none;
}

.drag-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 900;
}

/* ---------- Leaderboard screen ---------- */
.leaderboard-header {
  flex: 0 0 auto;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.icon-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: var(--r-pill);
  color: #fff;
  font-size: 20px;
  line-height: 1;
}
.icon-back-btn:hover { background: rgba(255,255,255,0.16); }

.leaderboard-title { color: #fff; font-size: 18px; font-weight: 700; margin: 0; }

.leaderboard-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.leaderboard-sub {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.5;
  color: rgba(255,255,255,0.7);
}

.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: var(--r-sm);
  color: #fff;
}
.leaderboard-item.is-first {
  border-color: var(--premium-gold-2);
  background: linear-gradient(135deg, rgba(255,234,180,0.16), rgba(231,185,70,0.10));
}

.leaderboard-rank {
  flex: 0 0 auto;
  min-width: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: rgba(255,255,255,0.65);
}
.leaderboard-item.is-first .leaderboard-rank { color: var(--premium-gold-2); }

.leaderboard-time {
  flex: 1 1 auto;
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.leaderboard-empty {
  text-align: center;
  margin-top: 40px;
  font-size: 14px;
  color: rgba(255,255,255,0.6);
}

