body {
  background: radial-gradient(circle at top right, #e7efff, #f1f6ff 40%, #f7fafc);
  color: #1f2937;
}

.container {
  max-width: 1240px;
}

.temple-header {
  background: linear-gradient(125deg, #143765, #1f528d, #3571b8);
  color: #f8fbff;
  border-radius: 14px;
  padding: 1rem 1.15rem;
  box-shadow: 0 10px 24px rgba(18, 53, 95, 0.22);
}

.temple-header p {
  opacity: 0.92;
}

.temple-layout {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(560px, 1fr);
  gap: 1rem;
  align-items: start;
}

.temple-panel--controls {
  position: sticky;
  top: 12px;
}

.card {
  background: #ffffff;
  color: #111827;
  border: 1px solid #dce5f1;
  border-radius: 14px;
  box-shadow: 0 10px 20px rgba(30, 58, 103, 0.08);
}

.board-card {
  min-height: 560px;
}

.board-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.temple-back-link {
  color: #174781;
  font-weight: 600;
  text-decoration: none;
}

.temple-back-link:hover {
  color: #0f2f59;
  text-decoration: underline;
}

.grid-wrap {
  --cell-size: 34px;
  display: grid;
  gap: 0;
  justify-content: center;
  width: max-content;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.cell {
  position: relative;
  width: var(--cell-size);
  height: var(--cell-size);
  border: 1px solid #d1d5db;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  box-shadow: inset 0 0 0 0 transparent;
}

.cell.unknown {
  background: #e5e7eb;
  color: #374151;
  font-size: 0.56rem;
}

.cell.miss {
  background: #fee2e2;
  color: #991b1b;
}

.cell.green {
  background: #dcfce7;
  color: #166534;
}

.cell.green::after {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #16a34a;
  position: absolute;
}

.cell.purple-any,
.cell.purple-tl,
.cell.purple-tr,
.cell.purple-bl,
.cell.purple-br {
  background: #ede9fe;
  color: #5b21b6;
}

.cell.purple-any::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 0 solid transparent;
  border-right: 0 solid transparent;
  border-bottom: 0 solid transparent;
  position: absolute;
}

.cell.purple-tl::after,
.cell.purple-tr::after,
.cell.purple-bl::after,
.cell.purple-br::after {
  content: "";
  width: 0;
  height: 0;
  position: absolute;
}

.cell.purple-tl::before,
.cell.purple-tr::before,
.cell.purple-bl::before,
.cell.purple-br::before {
  content: "";
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #4c1d95;
  z-index: 2;
}

.cell.purple-tl::after {
  border-bottom: 16px solid #7c3aed;
  border-left: 16px solid transparent;
  bottom: 3px;
  right: 3px;
}

.cell.purple-tl::before {
  bottom: 4px;
  right: 4px;
}

.cell.purple-tr::after {
  border-bottom: 16px solid #7c3aed;
  border-right: 16px solid transparent;
  bottom: 3px;
  left: 3px;
}

.cell.purple-tr::before {
  bottom: 4px;
  left: 4px;
}

.cell.purple-bl::after {
  border-top: 16px solid #7c3aed;
  border-left: 16px solid transparent;
  top: 3px;
  right: 3px;
}

.cell.purple-bl::before {
  top: 4px;
  right: 4px;
}

.cell.purple-br::after {
  border-top: 16px solid #7c3aed;
  border-right: 16px solid transparent;
  top: 3px;
  left: 3px;
}

.cell.purple-br::before {
  top: 4px;
  left: 4px;
}

.cell.blue-h-l,
.cell.blue-h-r,
.cell.blue-h-m,
.cell.blue-v-t,
.cell.blue-v-b,
.cell.blue-v-m {
  background: #dbeafe;
  color: #1e40af;
}

.cell.blue {
  background: #dbeafe;
  color: #1e40af;
}

.cell.blue::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 6px;
  border-radius: 6px;
  background: #3b82f6;
}

.cell.blue-h-l::after,
.cell.blue-h-r::after,
.cell.blue-h-m::after,
.cell.blue-v-t::after,
.cell.blue-v-b::after,
.cell.blue-v-m::after {
  content: "";
  position: absolute;
  background: #3b82f6;
}

.cell.blue-h-l::before,
.cell.blue-h-r::before,
.cell.blue-v-t::before,
.cell.blue-v-b::before {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #1e3a8a;
  z-index: 2;
}

/* Horizontal left part: marker points inward (to the right) */
.cell.blue-h-l::after {
  width: 7px;
  height: 24px;
  right: 3px;
  top: 50%;
  transform: translateY(-50%);
}

.cell.blue-h-l::before {
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
}

/* Horizontal right part: marker points inward (to the left) */
.cell.blue-h-r::after {
  width: 7px;
  height: 24px;
  left: 3px;
  top: 50%;
  transform: translateY(-50%);
}

.cell.blue-h-r::before {
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
}

/* Vertical top part: marker points inward (down) */
.cell.blue-v-t::after {
  width: 24px;
  height: 7px;
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
}

.cell.blue-v-t::before {
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
}

/* Vertical bottom part: marker points inward (up) */
.cell.blue-v-b::after {
  width: 24px;
  height: 7px;
  top: 3px;
  left: 50%;
  transform: translateX(-50%);
}

.cell.blue-v-b::before {
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
}

/* Middle of 1×3 — wide horizontal bar for h, tall vertical bar for v */
.cell.blue-h-m::after {
  width: 26px;
  height: 10px;
  border-radius: 3px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.cell.blue-v-m::after {
  width: 10px;
  height: 26px;
  border-radius: 3px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.cell.blue-h-m::before,
.cell.blue-v-m::before {
  display: none;
}

.cell.yellow,
.cell.yellow-tl,
.cell.yellow-tr,
.cell.yellow-ml,
.cell.yellow-mr,
.cell.yellow-bl,
.cell.yellow-br {
  background: #fef3c7;
  color: #92400e;
}

.cell.yellow::after,
.cell.yellow-tl::after,
.cell.yellow-tr::after,
.cell.yellow-ml::after,
.cell.yellow-mr::after,
.cell.yellow-bl::after,
.cell.yellow-br::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 20px;
  border-radius: 3px;
  background:
    linear-gradient(to right, transparent 48%, #b45309 48%, #b45309 54%, transparent 54%),
    linear-gradient(to bottom, transparent 31%, #b45309 31%, #b45309 35%, transparent 35%, transparent 65%, #b45309 65%, #b45309 69%, transparent 69%),
    #f59e0b;
  box-shadow: inset 0 0 0 2px #b45309;
  z-index: 1;
}

.cell.yellow::before,
.cell.yellow-tl::before,
.cell.yellow-tr::before,
.cell.yellow-ml::before,
.cell.yellow-mr::before,
.cell.yellow-bl::before,
.cell.yellow-br::before {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #fff7ed;
  border: 1px solid #92400e;
  z-index: 2;
}

.cell.yellow::before {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.cell.yellow-tl::before {
  right: 5px;
  bottom: 5px;
}

.cell.yellow-tr::before {
  left: 5px;
  bottom: 5px;
}

.cell.yellow-ml::before {
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
}

.cell.yellow-mr::before {
  left: 5px;
  top: 50%;
  transform: translateY(-50%);
}

.cell.yellow-bl::before {
  right: 5px;
  top: 5px;
}

.cell.yellow-br::before {
  left: 5px;
  top: 5px;
}

/* ── Blue 1×4 middle cells ──────────────────────────────────────────── */
.cell.blue-h-m2,
.cell.blue-h-m3,
.cell.blue-v-m2,
.cell.blue-v-m3 {
  background: #dbeafe;
  color: #1e40af;
}

.cell.blue-h-m2::after,
.cell.blue-h-m3::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 10px;
  border-radius: 3px;
  background: #3b82f6;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.cell.blue-v-m2::after,
.cell.blue-v-m3::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 26px;
  border-radius: 3px;
  background: #3b82f6;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.cell.blue-h-m2::before,
.cell.blue-h-m3::before,
.cell.blue-v-m2::before,
.cell.blue-v-m3::before {
  display: none;
}

/* ── Red 3×3 piece ──────────────────────────────────────────────────── */
.cell.red-tl,
.cell.red-tc,
.cell.red-tr,
.cell.red-ml,
.cell.red-mc,
.cell.red-mr,
.cell.red-bl,
.cell.red-bc,
.cell.red-br {
  background: #fee2e2;
  color: #991b1b;
}

/* Shared decorative bar */
.cell.red-tl::after,
.cell.red-tc::after,
.cell.red-tr::after,
.cell.red-ml::after,
.cell.red-mc::after,
.cell.red-mr::after,
.cell.red-bl::after,
.cell.red-bc::after,
.cell.red-br::after {
  content: "";
  position: absolute;
  border-radius: 3px;
  background: #ef4444;
}

/* Centre cell: full diamond */
.cell.red-mc::after {
  width: 18px;
  height: 18px;
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* Edge cells: angled bar pointing inward */
.cell.red-tc::after { width: 18px; height: 7px; bottom: 3px; left: 50%; transform: translateX(-50%); }
.cell.red-bc::after { width: 18px; height: 7px; top: 3px;    left: 50%; transform: translateX(-50%); }
.cell.red-ml::after { width: 7px;  height: 18px; right: 3px; top:  50%; transform: translateY(-50%); }
.cell.red-mr::after { width: 7px;  height: 18px; left: 3px;  top:  50%; transform: translateY(-50%); }

/* Corner cells: diagonal wedge */
.cell.red-tl::after { width: 7px; height: 18px; right: 3px; bottom: 3px; }
.cell.red-tr::after { width: 7px; height: 18px; left: 3px;  bottom: 3px; }
.cell.red-bl::after { width: 7px; height: 18px; right: 3px; top: 3px; }
.cell.red-br::after { width: 7px; height: 18px; left: 3px;  top: 3px; }

/* Indicator dot */
.cell.red-tl::before,
.cell.red-tc::before,
.cell.red-tr::before,
.cell.red-ml::before,
.cell.red-mc::before,
.cell.red-mr::before,
.cell.red-bl::before,
.cell.red-bc::before,
.cell.red-br::before {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid #7f1d1d;
  z-index: 2;
}

.cell.red-tl::before  { bottom: 4px; right: 4px; }
.cell.red-tc::before  { bottom: 4px; left: 50%; transform: translateX(-50%); }
.cell.red-tr::before  { bottom: 4px; left: 4px; }
.cell.red-ml::before  { right: 4px; top: 50%; transform: translateY(-50%); }
.cell.red-mc::before  { display: none; }
.cell.red-mr::before  { left: 4px; top: 50%; transform: translateY(-50%); }
.cell.red-bl::before  { top: 4px; right: 4px; }
.cell.red-bc::before  { top: 4px; left: 50%; transform: translateX(-50%); }
.cell.red-br::before  { top: 4px; left: 4px; }

.cell.best {
  box-shadow: inset 0 0 0 3px #f59e0b;
}

.piece-row {
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
}

#recommendationText {
  min-height: 1.5rem;
}

#statsText {
  min-height: 1.25rem;
}

#topCells {
  min-height: 11.5rem;
}

#statsText.is-pending,
#topCells.is-pending {
  opacity: 0.65;
}

@media (max-width: 768px) {
  .temple-shell {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .temple-layout {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .temple-panel--controls {
    position: static;
  }

  .temple-header {
    border-radius: 12px;
    padding: 0.85rem 0.95rem;
  }

  .temple-header h1 {
    font-size: 1.4rem;
  }

  .card {
    padding: 0.85rem !important;
    border-radius: 12px;
  }

  .board-card {
    min-height: 0;
  }

  .board-topbar {
    flex-direction: column;
    align-items: stretch;
  }

  #resetGridBtn {
    width: 100%;
  }

  .grid-wrap {
    --cell-size: 31px;
  }

  .cell {
    border-radius: 5px;
  }

  #topCells {
    min-height: 9.5rem;
  }
}
