.placement-preview {
  z-index: 4 !important;
  opacity: 1;
  filter: none;
}

.placement-preview.invalid {
  filter: none;
}

.placement-preview img {
  opacity: .46;
}

.placement-preview.invalid img {
  opacity: .40;
  filter: sepia(1) saturate(9) hue-rotate(315deg) brightness(.82);
}

.placement-grid-preview {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5 !important;
}

.preview-cell {
  position: absolute;
  left: calc(4px + var(--preview-x)*(var(--cell) + var(--gap)));
  top: calc(4px + var(--preview-y)*(var(--cell) + var(--gap)));
  width: var(--cell);
  height: var(--cell);
  background: rgba(255,255,255,.12);
  box-shadow: inset 0 0 14px rgba(255,255,255,.18);
}

.preview-cell.invalid {
  background: rgba(218,38,27,.20);
  box-shadow: inset 0 0 16px rgba(218,38,27,.28);
}

.preview-cell.edge-top { border-top: 3px solid rgba(255,255,255,.98); }
.preview-cell.edge-right { border-right: 3px solid rgba(255,255,255,.98); }
.preview-cell.edge-bottom { border-bottom: 3px solid rgba(255,255,255,.98); }
.preview-cell.edge-left { border-left: 3px solid rgba(255,255,255,.98); }
.preview-cell.invalid.edge-top { border-top-color: #e02c20; }
.preview-cell.invalid.edge-right { border-right-color: #e02c20; }
.preview-cell.invalid.edge-bottom { border-bottom-color: #e02c20; }
.preview-cell.invalid.edge-left { border-left-color: #e02c20; }

.cursor-piece {
  position: fixed;
  width: 92px;
  height: 92px;
  z-index: 9999;
  pointer-events: none;
  opacity: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  filter:
    drop-shadow(2px 0 0 rgba(255,255,255,.94))
    drop-shadow(-2px 0 0 rgba(255,255,255,.94))
    drop-shadow(0 2px 0 rgba(255,255,255,.94))
    drop-shadow(0 -2px 0 rgba(255,255,255,.94))
    drop-shadow(0 5px 5px rgba(0,0,0,.28));
}

.cursor-piece img {
  max-width: 88px;
  max-height: 88px;
  object-fit: contain;
  opacity: .58;
}

.touch-drag-piece {
  position: fixed;
  width: 92px;
  height: 92px;
  z-index: 10001;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(-50%,-105%);
  filter:
    drop-shadow(2px 0 0 rgba(255,255,255,.94))
    drop-shadow(-2px 0 0 rgba(255,255,255,.94))
    drop-shadow(0 2px 0 rgba(255,255,255,.94))
    drop-shadow(0 -2px 0 rgba(255,255,255,.94))
    drop-shadow(0 7px 7px rgba(0,0,0,.30));
}

.touch-drag-piece img { max-width: 88px; max-height: 88px; object-fit: contain; opacity: .72; }
.touch-drag-piece.mouse { transform: translate(14px,14px); }

/* Keep the source board artwork aligned with the actual 6x6 content grid. */
.board {
  background-origin: content-box;
  background-clip: content-box;
}

.board .cell::after {
  display: none;
}

.board .cell[data-piece]:not(.fixed) {
  box-shadow: none;
}

.qr-frame svg {
  display: block;
  width: 100%;
  height: auto;
}

.qr-error {
  margin: 0;
  padding: 32px 12px;
  color: #b12f22;
  text-align: center;
  line-height: 1.6;
}

.solution-board + .standalone {
  display: block;
  width: calc(var(--cell) * 6 + 20px);
  max-width: 100%;
  margin-left: 0;
  margin-right: 0;
}

.solution-board {
  margin-left: 0;
  margin-right: 0;
}

.solution {
  margin-left: 0;
  margin-right: 0;
}

.telegram-identity {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
}

.header-actions { align-items: center; }

.telegram-avatar {
  display: block;
  width: 32px !important;
  height: 32px !important;
  min-width: 32px;
  min-height: 32px;
  max-width: 32px !important;
  max-height: 32px !important;
  flex: 0 0 32px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  object-fit: cover;
  overflow: hidden;
  border: 1px solid var(--line);
}

.telegram-user {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1;
  letter-spacing: 0;
}

.telegram-404 { max-width: 680px; margin: 16vh auto 0; }
.telegram-404 h1 { margin: 0 0 18px; font: 700 clamp(48px,8vw,88px)/1 Georgia,"Noto Serif SC",serif; }
.telegram-404 p:last-child { color: var(--muted); font: 16px/1.7 -apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif; }

.controls .wide { grid-column: 1 / -1; }

.puzzle-catalog { display: grid; gap: 34px; margin-top: 28px; }
.catalog-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 18px; }
.catalog-actions span { color: var(--muted); font-size: 13px; }
.catalog-actions button { padding: 10px 14px; white-space: nowrap; }
.catalog-actions button:disabled { opacity: .5; cursor: wait; }
.tier-group { min-width: 0; }
.tier-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); padding-bottom: 9px; }
.tier-heading h2 { margin: 0; font: 700 23px/1.2 Georgia,"Noto Serif SC",serif; }
.tier-heading span { color: var(--muted); font: 700 11px/1.2 -apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif; letter-spacing: .08em; }
.tier-group .puzzle-grid { grid-template-columns: repeat(2,minmax(0,1fr)); margin-top: 12px; }
.tier-badge { color: var(--accent); font: 800 11px/1 -apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif; letter-spacing: .12em; }

.surrender-button { border-color: var(--accent) !important; color: var(--accent); }
.surrender-button:hover { background: var(--accent); color: white; }
.surrender-button:disabled { opacity: .55; cursor: wait; }
.controls .primary.not-ready { opacity: .52; }

.leaderboard-panel { margin-top: 24px; border-top: 2px solid var(--ink); }
.leaderboard { list-style: none; margin: 0; padding: 0; }
.leaderboard li { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.leaderboard li b { color: var(--accent); }
.leaderboard li time { font-variant-numeric: tabular-nums; }
.leaderboard .empty { display: block; color: var(--muted); }
.surrender-title { margin-top: 12px; }
.surrender-board li b { color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: max(24px,env(safe-area-inset-bottom)); z-index: 10000; max-width: calc(100vw - 32px); padding: 13px 18px; background: var(--ink); color: white; font: 600 14px/1.45 -apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif; box-shadow: 0 8px 28px rgba(0,0,0,.25); transform: translate(-50%,24px); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { transform: translate(-50%,0); opacity: 1; }

.help-legend { display: grid; grid-template-columns: repeat(4,1fr); gap: 10px; margin: 4px 0 26px; }
.help-legend figure { margin: 0; min-width: 0; padding: 10px 8px; border: 1px solid var(--line); background: #fffdf8; text-align: center; }
.legend-art { display: flex; align-items: center; justify-content: center; height: 66px; overflow: hidden; }
.legend-art img { display: block; max-width: 78px; max-height: 62px; object-fit: contain; }
.legend-art.green-car { position: relative; width: 66px; margin: auto; }
.legend-art.green-car img { position: absolute; width: 130px; max-width: none; max-height: none; left: -54px; top: -62px; }
.help-legend figcaption { display: grid; gap: 3px; margin-top: 7px; font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif; }
.help-legend figcaption b { font-size: 13px; }
.help-legend figcaption small { color: var(--muted); font-size: 11px; line-height: 1.35; }

@media (max-width: 780px) {
  :root { --cell: min(14.2vw, 64px); }
  main { padding-top: 24px; }
  .game-heading { margin-bottom: 18px; }
  .game-layout { gap: 22px; }
  .board-column { width: max-content; max-width: 100%; }
  .piece-panel { border-top-width: 1px; }
  .piece-button { min-height: 88px; touch-action: manipulation; }
  .controls button, .solution-link, .icon-button { touch-action: manipulation; }
  .telegram-user { max-width: 110px; }
  dialog { padding: 28px 22px; max-height: calc(100dvh - 24px); overflow-y: auto; }
  dialog h2 { font-size: 28px; }
  dialog li { grid-template-columns: 92px 1fr; }
  .help-legend { grid-template-columns: 1fr; }
  .help-legend figure { display: grid; grid-template-columns: 90px 1fr; align-items: center; text-align: left; }
  .help-legend figcaption { margin-top: 0; }
  .tier-group .puzzle-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .puzzle-card { min-height: 128px; padding: 15px; }
}

@media (pointer: coarse) {
  .cursor-piece { display: none !important; }
  .piece-button { touch-action: none; }
  .cell:hover { outline: none; }
  .cell:active { outline: 3px solid var(--accent); }
}

.piece-button, .board .cell:not(.fixed) { touch-action: none; user-select: none; -webkit-user-select: none; }
