:root {
  --je-accent: var(--accent);
  --je-accent-bg: color-mix(in srgb, var(--accent) 12%, transparent);
  --je-accent-border: color-mix(in srgb, var(--accent) 35%, transparent);
}

.hidden { display: none !important; }

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

html, html body {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--news-font-body, var(--font-body), Georgia, serif);
  -webkit-font-smoothing: antialiased;
}

html[data-theme="light"] body {
  color: var(--news-ink, #1e293b);
}

html[data-theme="light"] {
  --je-toolbar-bg: rgba(255,255,255,0.92);
  --je-toolbar-border: rgba(0,0,0,0.12);
  --je-toolbar-text: #1e293b;
  --je-play-bg: #eef2f7;
  --je-piece-shadow: rgba(0,0,0,0.18);
  --je-modal-bg: rgba(0,0,0,0.3);
  --je-modal-card: #fff;
  --je-modal-text: #1e293b;
}

html:not([data-theme="light"]),
html[data-theme="dark"] {
  --je-toolbar-bg: rgba(15,23,42,0.92);
  --je-toolbar-border: rgba(255,255,255,0.1);
  --je-toolbar-text: #e2e8f0;
  --je-play-bg: var(--bg-0);
  --je-piece-shadow: rgba(0,0,0,0.5);
  --je-modal-bg: rgba(0,0,0,0.6);
  --je-modal-card: #1e293b;
  --je-modal-text: #e2e8f0;
}

#je-play-area {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--je-play-bg);
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
}

#je-board-area {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  overflow: visible;
}

/* Header-aware play area: fit below the fixed top menu and within the
   visible canvas on both desktop and mobile. --site-header-height is
   injected by the site navigation script; the 140px allowance covers the
   masthead, toolbar and page padding above the board. */
#je-content.classic-content {
  height: calc(100vh - var(--site-header-height, 0px) - 140px);
  min-height: 360px;
}

.je-piece {
  position: absolute;
  cursor: grab;
  z-index: 5;
  transition: filter 0.15s ease;
  filter: drop-shadow(1px 2px 4px var(--je-piece-shadow));
  will-change: transform;
}

.je-piece:hover {
  filter: drop-shadow(2px 4px 10px var(--je-piece-shadow));
}

.je-piece:active,
.je-piece.je-piece-selected {
  cursor: grabbing;
  filter: drop-shadow(3px 6px 14px var(--je-piece-shadow));
}

.je-piece-selected {
  outline: 2px solid var(--je-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.je-piece-placed {
  cursor: default;
  filter: none !important;
  outline: none !important;
  z-index: 2 !important;
  pointer-events: none;
}

.je-piece-captured {
  outline: 2px dashed var(--je-accent);
  outline-offset: 3px;
  filter: drop-shadow(0 0 8px var(--je-accent-bg));
}

/* E key: highlight every border piece. Dashed outline matches the captured
   treatment; placed pieces are locked into the picture and stay clean. */
.je-show-edges .je-piece.je-piece-edge:not(.je-piece-placed) {
  outline: 2px dashed var(--je-accent);
  outline-offset: 1px;
}

.je-ghost {
  position: absolute;
  pointer-events: none;
  z-index: 0;
  border-radius: 4px;
}

/* ── Modals ──────────────────────────────────────────── */

.je-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--je-modal-bg);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.je-modal-overlay.je-modal-open {
  opacity: 1;
  pointer-events: auto;
}

.je-modal {
  background: var(--je-modal-card);
  color: var(--je-modal-text);
  border-radius: 16px;
  padding: 24px 28px;
  max-width: 500px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  transform: translateY(20px);
  transition: transform 0.25s ease;
}

.je-modal-overlay.je-modal-open .je-modal {
  transform: translateY(0);
}

.je-modal h2 {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 700;
  font-family: var(--news-font-display, var(--font-display), Georgia, serif);
}

.je-modal-close {
  margin-top: 16px;
  padding: 8px 20px;
  border: 1px solid var(--je-accent-border);
  background: var(--je-accent-bg);
  color: var(--je-accent);
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.je-modal-close:hover {
  background: var(--je-accent);
  color: #fff;
}

/* Help modal content */
.je-help-content {
  font-size: 14px;
  line-height: 1.7;
}

.je-help-content p {
  margin: 0 0 10px;
}

.je-help-content hr {
  border: none;
  border-top: 1px solid var(--je-toolbar-border);
  margin: 14px 0;
}

.je-help-content kbd {
  display: inline-block;
  padding: 2px 6px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  background: var(--je-accent-bg);
  border: 1px solid var(--je-toolbar-border);
  border-radius: 4px;
  line-height: 1.4;
}

.je-help-keys {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.je-help-keys td {
  padding: 4px 8px;
  border: none;
  width: auto;
  height: auto;
}

.je-help-keys td:first-child {
  width: 60px;
  text-align: center;
}

/* Piece count picker */
.je-piececount-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.je-piececount-btn {
  padding: 10px 8px;
  border: 1px solid var(--je-toolbar-border);
  background: var(--je-accent-bg);
  color: var(--je-modal-text);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.je-piececount-btn:hover {
  background: var(--je-accent);
  color: #fff;
  border-color: var(--je-accent);
}

/* ── Preview overlay ─────────────────────────────────── */

.je-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  background: rgba(0,0,0,0.8);
  cursor: pointer;
  animation: jeFadeIn 0.2s ease;
}

.je-preview-img {
  max-width: 80vw;
  max-height: 75vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.je-preview-label {
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  font-weight: 600;
}

/* ── Completion ──────────────────────────────────────── */

.je-completion-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.6);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.je-completion-overlay.je-completion-show {
  opacity: 1;
  pointer-events: auto;
}

.je-completion-card {
  background: var(--je-modal-card);
  color: var(--je-modal-text);
  border-radius: 20px;
  padding: 32px 36px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  transform: scale(0.9);
  transition: transform 0.3s ease;
  position: relative;
  overflow: hidden;
}

.je-completion-overlay.je-completion-show .je-completion-card {
  transform: scale(1);
}

.je-completion-title {
  font-size: 28px;
  font-weight: 800;
  margin: 0 0 20px;
}

.je-completion-stats {
  display: flex;
  gap: 24px;
  justify-content: center;
  margin-bottom: 24px;
}

.je-completion-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.je-stat-val {
  font-size: 24px;
  font-weight: 800;
  color: var(--je-accent);
}

.je-stat-lbl {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.je-completion-attribution {
  margin: 0 0 20px;
  font-size: 13px;
  font-style: italic;
  line-height: 1.4;
  opacity: 0.7;
  max-width: 320px;
}

.je-completion-close {
  padding: 10px 28px;
  border: none;
  background: var(--je-accent);
  color: #fff;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.15s;
}

.je-completion-close:hover {
  opacity: 0.85;
}

/* ── Board attribution badge ─────────────────────────── */

.je-attribution-box {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 20;
  max-width: 70%;
  padding: 8px 14px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  text-align: right;
  border-radius: 12px;
  border: 1.5px solid rgba(255,255,255,0.85);
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
  text-shadow: 0 1px 2px rgba(0,0,0,0.75);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.je-attribution-box.je-attribution-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Confetti ─────────────────────────────────────────── */

.je-confetti {
  position: absolute;
  top: -10px;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  animation: jeConfettiFall linear forwards;
  pointer-events: none;
  z-index: 10;
}

@keyframes jeConfettiFall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

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

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 960px) {
  .classic-content {
    flex-direction: column;
  }

  /* Mobile: let the column flow naturally instead of a fixed 70vh so the
     board sits above the HOW TO PLAY / KEYBOARD panel without colliding. */
  #je-content.classic-content {
    height: auto;
    min-height: 0;
  }

  .classic-content .classic-clues-section {
    width: 100%;
  }

  .classic-content .classic-grid-section {
    min-height: 360px;
    /* Bound the board region so it never crowds out the panel below it. */
    height: 52vh;
    max-height: 60vh;
  }
}

@media (max-width: 700px) {
  .je-piececount-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .je-modal {
    padding: 18px 20px;
    border-radius: 12px;
  }
}

@media (max-width: 420px) {
  .je-piececount-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .je-piececount-btn {
    padding: 8px 6px;
    font-size: 13px;
  }
}
