/* ── Play Layout: main + AI sidebar ───────────────────────── */
.play-layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 24px 48px;
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 24px;
  align-items: start;
}
.play-main {
  max-width: 720px;
}

/* ── AI Results sidebar ──────────────────────────────────── */
.play-aside {
  position: sticky;
  top: 20px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  scrollbar-width: thin;
}
.aside-header h3 {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ── Header ──────────────────────────────────────────────── */
.play-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.play-header h2 {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 700;
  text-transform: capitalize;
}
.timer-display {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
}

/* ── Puzzle canvas ───────────────────────────────────────── */
.puzzle-canvas-wrapper {
  background: var(--puzzle-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 360px;
  overflow: hidden;
  margin-bottom: 10px;
}
#puzzle-container {
  width: 100%;
  min-height: 360px;
}
#puzzle-container canvas {
  display: block;
  margin: 0 auto;
}

/* ── Controls ────────────────────────────────────────────── */
.puzzle-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.puzzle-controls .btn {
  flex: 1;
}

/* ── Check message ────────────────────────────────────────── */
.check-message {
  font-size: 0.82rem;
  font-weight: 600;
  min-height: 1.4em;
  margin-bottom: 8px;
  color: transparent;
}
.check-message.error {
  color: var(--red);
}
.check-message.complete {
  color: var(--green);
}

/* ── Info Panel (always visible) ─────────────────────────── */
.info-panel {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
  font-size: 0.82rem;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 16px;
}
.info-panel .info-label {
  color: var(--text-muted);
  white-space: nowrap;
}
.info-panel .info-value {
  font-family: var(--font-mono);
  font-weight: 500;
  text-align: right;
}
.info-panel .info-value a {
  font-family: var(--font-mono);
}

/* ── Section blocks ──────────────────────────────────────── */
.section-block {
  margin-bottom: 16px;
}
.section-block h3 {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: inline;
}
.section-block > h3 {
  display: block;
}

/* ── Rules ────────────────────────────────────────────────── */
.rules-description {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 10px;
  font-weight: 500;
}
.rules-content {
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--text-dim);
}
.rules-content p {
  margin-bottom: 4px;
}

/* ── Rule Examples ────────────────────────────────────────── */
.examples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.rule-example {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-card);
}
.rule-example-canvas {
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}
.rule-example-canvas canvas {
  display: block;
}
.rule-example-label {
  font-size: 0.75rem;
  line-height: 1.4;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
}
.rule-example-label.ok {
  color: var(--green);
  font-weight: 600;
}
.rule-example-label.ng {
  color: var(--red);
}

/* ── AI Results Table ────────────────────────────────────── */
#ai-summary-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: none;
  letter-spacing: 0;
}
.ai-table-wrapper {
  overflow-x: auto;
}
.ai-results-table {
  width: 100%;
  font-size: 0.75rem;
  border-collapse: collapse;
}
.ai-results-table th {
  text-align: left;
  padding: 4px 6px;
  color: var(--text-muted);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.ai-results-table td {
  padding: 3px 6px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  white-space: nowrap;
}
.ai-results-table .model-col {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-results-table .solved { color: var(--green); font-weight: 600; }
.ai-results-table .failed { color: var(--text-muted); }
.ai-results-table .strategy-col {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ── Completion Modal ────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 36px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
.modal-close:hover { color: var(--text); }
.modal h2 {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  margin-bottom: 12px;
}
.modal-time {
  font-family: var(--font-mono);
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--green);
  margin-bottom: 8px;
}
.modal-stats {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 16px;
}
/* ── Modal Leaderboard ──────────────────────────────────── */
.modal-leaderboard {
  margin-bottom: 16px;
  text-align: left;
}
.modal-leaderboard-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.78rem;
  font-family: var(--font-mono);
}
.modal-leaderboard-list li {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 3px;
  gap: 8px;
}
.modal-leaderboard-list li:nth-child(odd) {
  background: rgba(128,128,128,0.06);
}
.modal-leaderboard-list .lb-rank {
  color: var(--text-muted);
  min-width: 20px;
  text-align: right;
  flex-shrink: 0;
}
.modal-leaderboard-list .lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.modal-leaderboard-list .lb-time {
  flex-shrink: 0;
  color: var(--text-dim);
}
.modal-leaderboard-list .lb-you {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  font-weight: 700;
}
.modal-leaderboard-list .lb-you .lb-name {
  color: var(--accent);
}
.modal-leaderboard-list .lb-you .lb-time {
  color: var(--accent);
  font-weight: 700;
}
.modal-leaderboard-list .lb-failed .lb-name {
  color: var(--text-muted);
}
.modal-leaderboard-list .lb-failed .lb-time {
  color: var(--text-muted);
}
.lb-separator {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.7rem;
  padding: 2px 0;
  letter-spacing: 0.1em;
}

.modal-share {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.share-input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.share-input:focus { border-color: var(--accent); }
.btn-sm { padding: 6px 12px; font-size: 0.78rem; }
.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .play-layout {
    grid-template-columns: 1fr;
    padding: 12px 12px 32px;
  }
  .play-aside {
    position: static;
    max-height: none;
  }
  .play-header h2 { font-size: 1.1rem; }
  .timer-display { font-size: 1.2rem; }
  .examples-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
}
