/* game.css — Jigsaw Puzzle v2.3.0 */

/* ── Utilities ───────────────────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.hidden { display: none !important; }

/* ── Shell / container ───────────────────────────────────────────────────── */
.cj-shell {
  padding-bottom: 24px;
}

/* Wider container; 52px top offsets the fixed game-page navbar */
.cj-container {
  max-width: 1400px;
  padding-top: 52px;
}

/* ── Play mode: fill viewport, no page scroll ────────────────────────────── */
body.jigsaw-playing {
  overflow: hidden;
}

body.jigsaw-playing .site-footer {
  display: none;
}

/* Hide SEO content during gameplay to maximize play area */
body.jigsaw-playing .cj-container > section,
body.jigsaw-playing .cj-container > hr {
  display: none;
}

.cj-shell.is-playing {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  padding-bottom: 0;
}

.cj-shell.is-playing .cj-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
}

.cj-page-head {
  margin-bottom: 16px;
}

.cj-page-head h1 {
  margin: 4px 0 4px;
  font-size: 1.75rem;
}

.cj-page-head p {
  color: #6B7280;
  margin: 0;
}

.cj-back {
  display: inline-block;
  color: #2563EB;
  font-size: 0.9rem;
  text-decoration: none;
  margin-bottom: 4px;
}

.cj-back:hover { text-decoration: underline; }

/* ── Setup card ──────────────────────────────────────────────────────────── */
.cj-setup {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
  align-items: start;
}

.cj-setup-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cj-build-col {
  justify-content: flex-end;
}

.cj-label {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: #6B7280;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Upload area */
.cj-upload {
  display: flex;
  border: 2px dashed #D1D5DB;
  border-radius: 8px;
  min-height: 110px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: border-color 0.18s;
  padding: 12px;
  overflow: hidden;
}

.cj-upload:hover,
.cj-upload:focus-within {
  border-color: #2563EB;
}

.cj-upload-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  color: #6B7280;
  font-size: 0.9rem;
}

.cj-upload-inner svg {
  flex-shrink: 0;
}

.cj-preview {
  width: 100%;
  text-align: center;
}

.cj-preview img {
  max-width: 100%;
  max-height: 130px;
  object-fit: contain;
  border-radius: 6px;
  display: block;
  margin: 0 auto;
}

.cj-meta {
  font-size: 0.78rem;
  color: #9CA3AF;
  display: block;
  margin-top: 4px;
}

/* Preset difficulty buttons */
.cj-presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.cj-preset {
  appearance: none;
  border: 1px solid #E0E0E0;
  border-radius: 6px;
  background: #fff;
  padding: 9px 8px;
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: #374151;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 48px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.cj-preset span {
  font-size: 0.72rem;
  font-weight: 400;
  color: #9CA3AF;
}

.cj-preset:hover {
  background: #EFF6FF;
  border-color: #93C5FD;
}

.cj-preset.is-active {
  background: #EFF6FF;
  border-color: #2563EB;
  color: #1D4ED8;
}

.cj-preset.is-active span { color: #2563EB; }

.cj-preset:focus-visible {
  outline: 2px solid #2563EB;
  outline-offset: 2px;
}

/* Custom row/col inputs */
.cj-custom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.cj-custom label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: #6B7280;
}

.cj-custom input {
  width: 100%;
  min-height: 40px;
  border: 1px solid #E0E0E0;
  border-radius: 4px;
  padding: 6px 10px;
  font: inherit;
  font-size: 0.95rem;
  text-align: center;
  color: #111827;
}

.cj-custom input:focus {
  outline: 2px solid #2563EB;
  outline-offset: 1px;
  border-color: #2563EB;
}

/* Build button */
.cj-build-btn {
  appearance: none;
  border: none;
  border-radius: 8px;
  background: #F97316;
  color: #fff;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 14px;
  cursor: pointer;
  width: 100%;
  min-height: 52px;
  transition: background 0.15s;
}

.cj-build-btn:hover  { background: #EA6C0A; }
.cj-build-btn:active { background: #DC5F00; }

.cj-build-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.cj-build-btn:focus-visible {
  outline: 2px solid #F97316;
  outline-offset: 3px;
}

/* ── Play area ───────────────────────────────────────────────────────────── */
.cj-play {
  display: flex;
  flex-direction: column;
  min-height: 420px;
}

/* In play mode the container is a flex column — play area fills it */
.cj-shell.is-playing .cj-play {
  flex: 1;
  min-height: 0;
  height: auto;
}

/* Undo/Redo button group */
.cj-undo-redo {
  display: flex;
  gap: 4px;
}

.cj-icon-btn {
  appearance: none;
  border: 1.5px solid #D1D5DB;
  border-radius: 6px;
  background: #fff;
  color: #374151;
  font: inherit;
  font-size: 1rem;
  width: 32px;
  height: 32px;
  min-width: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, border-color 0.12s;
}

.cj-icon-btn:hover:not(:disabled) {
  background: #F3F4F6;
  border-color: #9CA3AF;
}

.cj-icon-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.cj-icon-btn:focus-visible {
  outline: 2px solid #2563EB;
  outline-offset: 2px;
}

/* Board + Tray side-by-side — fills remaining play height.
   JS overrides grid-template-columns after layout to fit board exactly. */
.cj-play-panels {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 0.6fr);
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.cj-board-panel,
.cj-tray-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: visible;
}

.cj-panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* Board panel head: inline controls toolbar */
.cj-board-head {
  gap: 6px;
  flex-wrap: wrap;
  align-content: center;
  position: relative;
  z-index: 10;
  background: #FFFFFF;
}

.cj-stat-timer {
  font-size: 0.85rem;
  font-weight: 700;
  color: #374151;
  min-width: 32px;
  flex-shrink: 0;
}

.cj-stat-progress {
  font-size: 0.82rem;
  font-weight: 600;
  color: #6B7280;
  white-space: nowrap;
  flex-shrink: 0;
}

.cj-board-hint {
  font-size: 0.75rem;
  color: #9CA3AF;
  text-align: right;
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 0;
}

/* Reset / new-puzzle button at the bottom of the tray panel */
.cj-reset-btn {
  appearance: none;
  border: 1px solid #E0E0E0;
  border-radius: 6px;
  background: #fff;
  color: #9CA3AF;
  font: inherit;
  font-size: 0.78rem;
  padding: 5px 10px;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 6px;
  width: 100%;
  min-height: 32px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.cj-reset-btn:hover {
  background: #FEF2F2;
  color: #DC2626;
  border-color: #FECACA;
}

.cj-reset-btn:focus-visible {
  outline: 2px solid #DC2626;
  outline-offset: 2px;
}

.cj-panel-head h2 {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  color: #6B7280;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.cj-hint {
  font-size: 0.78rem;
  color: #9CA3AF;
  text-align: right;
}

/* Board stage — fills remaining card space */
.cj-board-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  pointer-events: auto;
}

/* Scrollable board stage for Tables / Periodic modes on small screens */
.cj-board-stage.is-board-scrollable {
  overflow: auto;
  align-items: flex-start;
  justify-content: flex-start;
}

.cj-board-stage.is-board-scrollable::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.cj-board-stage.is-board-scrollable::-webkit-scrollbar-track {
  background: transparent;
}

.cj-board-stage.is-board-scrollable::-webkit-scrollbar-thumb {
  background: #D1D5DB;
  border-radius: 3px;
}

.cj-board-stage.is-board-scrollable::-webkit-scrollbar-corner {
  background: transparent;
}

/* Board grid */
.cj-board {
  position: relative;
  overflow: visible;
  flex-shrink: 0;
}

.cj-board.is-empty {
  width: min(100%, 340px);
  height: 240px;
  border: 2px dashed #E0E0E0;
  border-radius: 8px;
  background: #FAFBFC;
}

/* Slot cells */
.cj-slot {
  position: absolute;
  border: 1px dashed #9CA3AF;
  background: transparent;
  appearance: none;
  padding: 0;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.cj-slot:hover,
.cj-slot.is-target {
  background: rgba(37, 99, 235, 0.06);
  border-color: #93C5FD;
}

.cj-slot.is-filled {
  border-style: solid;
  border-color: #E5E7EB;
  background: transparent;
}

.cj-slot:focus-visible {
  outline: 2px solid #2563EB;
  outline-offset: 1px;
}

/* ── Piece buttons ───────────────────────────────────────────────────────── */
.cj-piece {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: grab;
  display: block;
  position: relative;          /* needed for .cj-piece-overlay */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 2px;
  filter: drop-shadow(1px 2px 4px rgba(0,0,0,0.22));
  transition: filter 0.12s, transform 0.1s;
}

.cj-piece:hover {
  filter: drop-shadow(2px 4px 8px rgba(0,0,0,0.3));
  transform: scale(1.05);
}

.cj-piece:active,
.cj-piece.is-dragging {
  cursor: grabbing;
  filter: drop-shadow(2px 6px 10px rgba(0,0,0,0.35));
}

/* Selection: drop-shadow glow traces the piece shape (respects alpha).
   The thick border is drawn by .cj-piece-overlay, sized to the core area only,
   so no oversized bounding-box highlight in the tray. */
.cj-piece.is-selected {
  filter: drop-shadow(0 0 7px rgba(37, 99, 235, 0.65));
}

/* Core-area selection overlay — absolutely positioned to cover pw×ph,
   offset by s.tab so it aligns with the visible piece and ignores protrusions.
   Dimensions are set inline by makePieceBtn(). */
.cj-piece-overlay {
  position: absolute;
  pointer-events: none;
  border: 3px solid transparent;
  border-radius: 3px;
  box-sizing: border-box;
}

.cj-piece.is-selected .cj-piece-overlay {
  border-color: #2563EB;
}

.cj-piece.on-board {
  position: absolute;
  z-index: 2;
}

.cj-piece img {
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Wrong-piece flash animation */
.cj-piece.is-wrong {
  animation: cj-flash-wrong 2s ease-out forwards;
}

@keyframes cj-flash-wrong {
  0%   { filter: drop-shadow(0 0 10px rgba(239,68,68,0.9)); }
  60%  { filter: drop-shadow(0 0 10px rgba(239,68,68,0.9)); }
  100% { filter: drop-shadow(1px 2px 4px rgba(0,0,0,0.22)); }
}

.cj-piece.is-wrong .cj-piece-overlay {
  animation: cj-overlay-wrong 2s ease-out forwards;
}

@keyframes cj-overlay-wrong {
  0%   { border-color: #EF4444; }
  60%  { border-color: #EF4444; }
  100% { border-color: transparent; }
}

/* Tray scroll wrapper — flex row containing the piece tray + custom scroll strip */
.cj-tray-wrapper {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

/* Tray container */
.cj-tray {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-content: flex-start;
  padding: 2px;
}

/* Desktop native scrollbar (overridden to hidden on mobile) */
.cj-tray::-webkit-scrollbar { width: 5px; }
.cj-tray::-webkit-scrollbar-track { background: transparent; }
.cj-tray::-webkit-scrollbar-thumb {
  background: #D1D5DB;
  border-radius: 3px;
}

/* ── Custom scroll strip (mobile tray) ───────────────────────────────────── */

/* Hidden on desktop — shown on mobile via media query */
.cj-scroll-strip {
  display: none;
  width: 22px;
  flex-shrink: 0;
  position: relative;
  background: #F0F1F3;
  border-left: 1px solid #E5E7EB;
  cursor: pointer;
  touch-action: none;
  overflow: hidden;
}

/* When the tray is hidden (reference image shown), hide the strip too */
.cj-tray.hidden + .cj-scroll-strip {
  display: none !important;
}

.cj-scroll-thumb {
  position: absolute;
  left: 3px;
  top: 0;
  width: 16px;
  background: #9CA3AF;
  border-radius: 8px;
  min-height: 36px;
  display: none;
  touch-action: none;
  transition: background 0.12s;
}

.cj-scroll-strip:active .cj-scroll-thumb,
.cj-scroll-thumb.is-dragging {
  background: #6B7280;
}

/* Reference image panel (shown when toggle is active) */
.cj-ref-img {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 4px;
}

.cj-ref-img img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  display: block;
}

/* ── Hint button ─────────────────────────────────────────────────────────── */
.cj-hint-btn {
  appearance: none;
  border: 1.5px solid #F97316;
  border-radius: 6px;
  background: transparent;
  color: #F97316;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 4px 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  min-height: 34px;
  flex-shrink: 0;
  white-space: nowrap;
}

.cj-hint-btn:hover {
  background: #FFF7ED;
}

.cj-hint-btn:active {
  background: #FFEDD5;
}

.cj-hint-btn:focus-visible {
  outline: 2px solid #F97316;
  outline-offset: 2px;
}

/* ── Win flash toast (non-blocking, auto-dismissed) ────────────────────── */
@keyframes cj-flash-in {
  from {
    opacity: 0;
    transform: translateX(-50%, 20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%, 0);
  }
}

@keyframes cj-flash-out {
  from {
    opacity: 1;
    transform: translateX(-50%, 0);
  }
  to {
    opacity: 0;
    transform: translateX(-50%, -8px);
  }
}

@keyframes cj-sparkle {
  0% {
    opacity: 0;
    transform: scale(0) rotate(0deg);
  }
  50% {
    opacity: 1;
    transform: scale(1.4) rotate(180deg);
  }
  100% {
    opacity: 0;
    transform: scale(1) rotate(360deg);
  }
}

.cj-win-flash {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  animation: cj-flash-in 0.35s ease forwards;
}

.cj-win-flash.is-fading {
  animation: cj-flash-out 0.5s ease forwards;
}

.cj-win-flash.hidden {
  display: none !important;
}

.cj-fireworks {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 299;
  display: none;
}

.cj-win-flash:not(.hidden) .cj-fireworks {
  display: block;
}

.cj-win-toast {
  background: #FFFFFF;
  border: 1px solid #E0E0E0;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  width: auto;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  text-align: center;
}

.cj-win-toast-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.cj-win-sparkle-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  min-height: 24px;
}

.cj-sparkle-star {
  font-size: 1.5rem;
  animation: cj-sparkle 1s ease-out forwards;
  display: inline-block;
}

.cj-win-toast strong {
  display: block;
  font-size: 1.5rem;
  color: #16A34A;
  margin: 0;
}

.cj-win-toast p {
  color: #6B7280;
  margin: 0;
  font-size: 1rem;
}

.cj-play-again-btn {
  appearance: none;
  border: none;
  border-radius: 8px;
  background: #2563EB;
  color: #fff;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 13px 32px;
  cursor: pointer;
  min-height: 48px;
  transition: background 0.15s;
}

.cj-play-again-btn:hover  { background: #1D4ED8; }
.cj-play-again-btn:active { background: #1E40AF; }

.cj-play-again-btn:focus-visible {
  outline: 2px solid #1D4ED8;
  outline-offset: 3px;
}

/* ── Solved badge ───────────────────────────────────────────────────────── */
@keyframes cj-badge-in {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.cj-solved-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #DCFCE7;
  color: #16A34A;
  border: 1px solid #86EFAC;
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 0.875rem;
  font-weight: 600;
  flex-shrink: 0;
}

.cj-solved-badge.cj-badge-enter {
  animation: cj-badge-in 0.35s ease forwards;
}

.cj-solved-badge.hidden {
  display: none !important;
}

.cj-solved-badge svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.cj-solved-time {
  font-size: 0.75rem;
  margin-left: 4px;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  /* Use full viewport width during play — removes container side-padding */
  .cj-shell.is-playing .cj-container {
    padding-left: 0;
    padding-right: 0;
  }

  .cj-setup {
    grid-template-columns: 1fr;
  }

  /* Stacked layout: board fills space, tray scrolls below.
     Override any JS-set grid-template-columns. */
  .cj-play-panels {
    grid-template-columns: 1fr !important;
    grid-template-rows: 1fr auto;
  }

  .cj-board-head {
    flex-wrap: wrap;
  }

  .cj-board-panel {
    min-height: 180px;
  }

  .cj-tray-panel {
    min-height: 120px; /* fallback before JS computes piece-based height */
    overflow: hidden;
    /* max-height is set dynamically by JS to exactly 1.5 piece rows */
  }

  .cj-tray {
    max-height: none;
    overflow-y: auto;
    /* Hide native scrollbar — custom strip handles scrolling on mobile */
    scrollbar-width: none;
  }

  .cj-tray::-webkit-scrollbar {
    display: none;
  }

  /* Show the custom wide scroll strip on mobile */
  .cj-scroll-strip {
    display: flex;
  }

  .cj-reset-btn {
    font-size: 0.72rem;
    padding: 4px 8px;
  }
}

@media (max-width: 480px) {
  .cj-page-head h1 { font-size: 1.4rem; }

  .cj-presets {
    grid-template-columns: 1fr 1fr;
  }

  .cj-board-hint {
    display: none; /* hide dimension hint on very small screens */
  }

  /* Flash toast responsive */
  .cj-win-toast {
    max-width: calc(100vw - 32px);
    padding: 16px;
  }

  .cj-win-toast-body {
    gap: 8px;
  }

  .cj-win-toast strong {
    font-size: 1.25rem;
  }

  .cj-play-again-btn {
    padding: 11px 24px;
    font-size: 0.95rem;
  }

  /* Solved badge: stack or shrink on narrow screens */
  .cj-solved-badge {
    padding: 4px 8px;
    font-size: 0.75rem;
    gap: 4px;
  }

  .cj-solved-badge svg {
    width: 14px;
    height: 14px;
  }

  .cj-solved-time {
    font-size: 0.65rem;
  }
}

/* ── SEO content visibility per mode ──────────────────────────────────────── */
.cj-seo-section {
  display: block;
}

.cj-seo-section.hidden {
  display: none !important;
}

/* ── Mode tabs ──────────────────────────────────────────────────────────────── */
.cj-mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
  padding: 0;
  list-style: none;
}

.cj-tab {
  padding: 8px 16px;
  border: 1px solid #E0E0E0;
  border-radius: 6px;
  background: #F3F4F6;
  color: #374151;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.cj-tab:hover {
  background: #E5E7EB;
  border-color: #D1D5DB;
}

.cj-tab.is-active {
  background: #2563EB;
  color: #FFFFFF;
  border-color: #2563EB;
}

.cj-tab span {
  font-size: 0.75rem;
  opacity: 0.8;
  margin-left: 4px;
}

/* ── Number pieces (Tables mode) ──────────────────────────────────────────── */
.cj-num-piece {
  width: 60px;
  height: 60px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #F0F4F8 0%, #FFFFFF 100%);
  border: 2px solid #D1D5DB;
  border-radius: 4px;
  font-size: 1.1rem;
  font-weight: 700;
}

.cj-num-piece:hover {
  border-color: #9CA3AF;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.cj-num-piece.is-selected {
  border-color: #2563EB;
  box-shadow: 0 0 12px rgba(37,99,235,0.4);
}

.cj-num-value {
  color: #111827;
  pointer-events: none;
  font-size: 1.25rem;
}

.cj-num-slot {
  background: #FFFFFF;
  border: 1px dashed #D1D5DB;
}

.cj-num-slot:hover {
  background: #F9FAFB;
}

.cj-slot-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.75rem;
  color: #D1D5DB;
  pointer-events: none;
  opacity: 0.5;
  font-weight: 600;
}

/* ── Element pieces (Periodic Table mode) ────────────────────────────────── */
.cj-element-piece {
  width: 56px;
  height: 64px;
  padding: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: linear-gradient(135deg, #F9FAFB 0%, #FFFFFF 100%);
  border: 1px solid #D1D5DB;
  border-radius: 3px;
  text-align: center;
  font-size: 0.65rem;
  overflow: visible;
}

.cj-element-piece:hover {
  border-color: #9CA3AF;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}

.cj-element-piece.is-selected {
  border-color: #2563EB;
  box-shadow: 0 0 10px rgba(37,99,235,0.4);
}

.cj-el-number {
  font-size: 0.6rem;
  color: #6B7280;
  font-weight: 600;
  align-self: flex-start;
  margin-left: 1px;
}

.cj-el-symbol {
  font-size: 1.2rem;
  font-weight: 700;
  color: #111827;
  line-height: 1;
}

.cj-el-name {
  font-size: 0.5rem;
  color: #6B7280;
  line-height: 1;
  max-width: 100%;
  word-wrap: break-word;
}

.cj-el-weight {
  font-size: 0.5rem;
  color: #9CA3AF;
  line-height: 1;
}

.cj-el-slot {
  background: #FFFFFF;
  border: 1px solid #D1D5DB;
}

.cj-el-slot:hover {
  background: #F9FAFB;
}

.cj-slot-atomic-hint {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 0.65rem;
  color: #6B7280;
  pointer-events: none;
  font-weight: 600;
}

/* ── Disabled cells (Periodic Table) ────────────────────────────────────── */
.cj-slot-disabled {
  position: absolute;
  background: #F3F4F6;
  border: 1px dashed #D1D5DB;
  pointer-events: none;
}

.cj-slot-disabled::before,
.cj-slot-disabled::after {
  content: '';
  position: absolute;
  background: #D1D5DB;
  width: 100%;
  height: 1px;
  top: 50%;
  left: 0;
}

.cj-slot-disabled::before {
  transform: rotate(45deg);
}

.cj-slot-disabled::after {
  transform: rotate(-45deg);
}

/* ── Board panning (Periodic Table) ──────────────────────────────────────── */
.cj-board-stage.is-panning {
  cursor: grabbing;
}

.cj-board-stage.is-panning .cj-piece {
  pointer-events: none;
}

.cj-board-stage.is-panning .cj-slot {
  pointer-events: none;
}

/* ── Responsive adjustments ────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .cj-tab {
    padding: 6px 12px;
    font-size: 0.8rem;
  }

  .cj-tab span {
    display: none;
  }

  .cj-num-piece {
    width: 50px;
    height: 50px;
    font-size: 1rem;
  }

  .cj-element-piece {
    width: 48px;
    height: 56px;
    font-size: 0.6rem;
  }

  .cj-el-symbol {
    font-size: 1rem;
  }
}
