/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f6f6f6;
  --surface:     #ffffff;
  --border:      #e4e4e4;
  --text:        #272727;
  --text-muted:  #757575;
  --accent:      #f0523d;
  --accent-dark: #e4351e;
  --danger:      #bd0000;
  --success:     #22c55e;
  --warning:     #fd971f;

  --radius:   10px;
  --shadow:   0 2px 12px rgba(0,0,0,.08);

  /* Region palette — 12 saturated, clearly distinct colours */
  --r0:  #ff9999;  /* red    */
  --r1:  #ffbb66;  /* orange */
  --r2:  #ffee55;  /* yellow */
  --r3:  #77dd77;  /* green  */
  --r4:  #55ddcc;  /* teal   */
  --r5:  #55ccff;  /* sky    */
  --r6:  #8899ff;  /* blue   */
  --r7:  #cc77ff;  /* purple */
  --r8:  #ff77ee;  /* violet */
  --r9:  #ff77aa;  /* pink   */
  --r10: #aadd44;  /* lime   */
  --r11: #b0b0b0;  /* silver */
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
header {
  background: #272727;
  border-bottom: none;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -.3px;
  color: #ffffff;
}
header #timer-wrap {
  color: #bbbbbb;
}
header strong {
  color: #ffffff;
}

/* ── App layout ────────────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 20px;
  padding: 20px 28px;
  max-width: 1600px;
  margin: 0 auto;
  align-items: flex-start;
}

/* ── Board panel ───────────────────────────────────────────────────────────── */
.board-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* How Difficulty Works width matches the board */
.board-info-card {
  width: 100%;
}

.board {
  display: grid;
  gap: 0;
  background: transparent;
  border: 4px solid #1a1a1a;
  border-radius: var(--radius);
  overflow: hidden;
  padding: 0;
  user-select: none;
}

.cell {
  width: 52px;
  height: 52px;
  border-radius: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  line-height: 1;
  transition: filter .1s;
  position: relative;
}
.cell:hover { filter: brightness(.88); }

/* Region colours applied via JS class r0..r11 */
.cell.r0  { background: var(--r0);  }
.cell.r1  { background: var(--r1);  }
.cell.r2  { background: var(--r2);  }
.cell.r3  { background: var(--r3);  }
.cell.r4  { background: var(--r4);  }
.cell.r5  { background: var(--r5);  }
.cell.r6  { background: var(--r6);  }
.cell.r7  { background: var(--r7);  }
.cell.r8  { background: var(--r8);  }
.cell.r9  { background: var(--r9);  }
.cell.r10 { background: var(--r10); }
.cell.r11 { background: var(--r11); }

.cell.violation {
  outline: 3px solid var(--danger);
  outline-offset: -2px;
  z-index: 1;
}

.cell.hint-highlight {
  outline: 3px solid var(--accent);
  outline-offset: -2px;
  animation: pulse 1s ease-in-out 3;
}

@keyframes pulse {
  0%, 100% { filter: brightness(1);   }
  50%       { filter: brightness(.80); }
}

.cell-mark {
  pointer-events: none;
  font-size: 1.5rem;
}
/* Cat head: white circle backdrop so it reads on any region colour */
.cell-mark:not(.x-mark) {
  background: rgba(255,255,255,0.88);
  border-radius: 50%;
  padding: 3px;
  box-shadow: 0 1px 5px rgba(0,0,0,0.28);
  line-height: 1;
}
.cell-mark.x-mark {
  font-size: 1.1rem;
  font-weight: 700;
  color: #555;
}
.cell-mark.queen-bad {
  opacity: 0.55;
}
.queen-x-overlay {
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: 0.75rem;
  font-weight: 900;
  color: var(--danger);
  pointer-events: none;
  line-height: 1;
}

/* Win overlay */
.board-panel .win-banner {
  background: var(--success);
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  border-radius: var(--radius);
  padding: 12px 24px;
  text-align: center;
  animation: pop .3s ease;
}
@keyframes pop {
  0%   { transform: scale(.8); opacity: 0; }
  70%  { transform: scale(1.05); }
  100% { transform: scale(1);  opacity: 1; }
}

/* ── Main panel (col 2) — 2-column grid ────────────────────────────────────── */
.main-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
  min-width: 0;
}

.report-card-full {
  grid-column: 1 / -1;
}

/* Difficulty summary inside score card: score left, stats right */
.diff-summary-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}
.diff-summary-left {
  min-width: 110px;
  flex-shrink: 0;
}
.diff-summary-right {
  flex: 1;
  min-width: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--text);
}

/* ── Form controls ─────────────────────────────────────────────────────────── */
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.control-row label {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
select {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
select:focus { outline: 2px solid var(--accent); border-color: transparent; }
select { border-color: #ddd; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: 7px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .08s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary   { background: var(--accent);  color: #fff; width: 100%; justify-content: center; font-size: 1rem; padding: 11px; }
.btn-primary:hover:not(:disabled)   { background: var(--accent-dark); }
.btn-secondary { background: #f0f0f0; color: #272727; border: 1px solid #ddd; }
.btn-secondary:hover:not(:disabled) { background: #e4e4e4; }
.btn-danger    { background: #f0f0f0; color: var(--danger); border: 1px solid #ddd; }
.btn-danger:hover:not(:disabled)    { background: #e4e4e4; }

.game-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  justify-content: center;
}

/* Hint box below game actions in the board panel */
.board-panel .hint-box {
  width: 100%;
  max-width: 400px;
}

/* ── Spinner ───────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 3px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Difficulty report ─────────────────────────────────────────────────────── */
.diff-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.diff-score-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 16px;
}
.diff-score-denom {
  font-size: 1.1rem;
  color: var(--text-muted);
}
.diff-stats {
  background: var(--bg);
  border-radius: 8px;
  padding: 4px 12px;
  margin-bottom: 4px;
}
.diff-badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 12px;
}
.diff-badge.easy   { background: #dcfce7; color: #16a34a; }
.diff-badge.medium { background: #fef9c3; color: #a16207; }
.diff-badge.hard   { background: #fee2e2; color: #b91c1c; }
.diff-badge.expert { background: #ede9fe; color: #6d28d9; }

.diff-score {
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.diff-score-label {
  font-size: .8rem;
  color: var(--text-muted);
  align-self: flex-end;
  padding-bottom: 4px;
}

.diff-stat-row {
  display: flex;
  justify-content: space-between;
  font-size: .85rem;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.diff-stat-row:last-child { border-bottom: none; }
.diff-stat-label { color: var(--text-muted); }
.diff-stat-value { font-weight: 600; }

/* ── Tactics table ─────────────────────────────────────────────────────────── */
.tactics-title {
  font-size: .85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 16px 0 8px;
}

.tactic-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
  font-size: .83rem;
}
.tactic-name {
  flex: 0 0 130px;
  color: var(--text);
  font-weight: 500;
}
.tactic-bar-wrap {
  flex: 1;
  background: #eef0f5;
  border-radius: 4px;
  height: 10px;
  overflow: hidden;
}
.tactic-bar {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width .5s ease;
}
.tactic-pct {
  flex: 0 0 36px;
  text-align: right;
  color: var(--text-muted);
  font-size: .78rem;
}
.tactic-firings {
  flex: 0 0 20px;
  text-align: right;
  color: var(--text-muted);
  font-size: .78rem;
}

/* ── Entropy chart ─────────────────────────────────────────────────────────── */
.entropy-title {
  font-size: .85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 16px 0 8px;
}
#entropy-canvas {
  width: 100%;
  height: 80px;
  display: block;
  border-radius: 6px;
  background: #f8fafc;
  border: 1px solid var(--border);
}

/* ── Hint display ──────────────────────────────────────────────────────────── */
.hint-box {
  background: #fff5f4;
  border: 1px solid #f0523d;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: .85rem;
}
.hint-rule  { font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.hint-notes { color: var(--text-muted); }

/* ── Info / definitions card ───────────────────────────────────────────────── */
.info-card {
  cursor: default;
}
.info-card summary {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.info-card summary::before {
  content: '▶';
  font-size: .7rem;
  color: var(--text-muted);
  transition: transform .2s;
}
.info-card[open] summary::before {
  transform: rotate(90deg);
}
.info-section-title {
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 16px 0 8px;
}
.info-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: .82rem;
}
.info-dl dt {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  padding: 3px 0;
}
.info-dl dd {
  color: var(--text-muted);
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
  margin: 0;
}
.info-dl dd:last-child { border-bottom: none; }

/* ── Tactics comparison card ───────────────────────────────────────────────── */
.compare-verdict {
  font-size: .9rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.compare-win  { color: #16a34a; }
.compare-loss { color: #b91c1c; }
.compare-tie  { color: #a16207; }
.compare-note {
  font-size: .83rem;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.5;
}
.compare-note em {
  font-style: normal;
  font-weight: 600;
  color: var(--text);
}

/* ── Entropy score card ────────────────────────────────────────────────────── */
.entropy-score {
  margin-top: 10px;
  background: var(--bg);
  border-radius: 7px;
  padding: 8px 12px;
  font-size: .82rem;
}
.escore-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 0;
}
.escore-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}
.escore-label {
  flex: 1;
  color: var(--text-muted);
}
.escore-val {
  font-weight: 700;
  color: var(--text);
  min-width: 38px;
  text-align: right;
}
.escore-divider {
  border-top: 1px solid var(--border);
  margin: 4px 0;
}
.escore-net .escore-label {
  font-weight: 600;
  color: var(--text);
}
.escore-verdict {
  font-size: .78rem;
  font-weight: 700;
  text-align: right;
  margin-top: 2px;
  letter-spacing: .3px;
}

/* ── Utility ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
    padding: 12px;
  }
  .board-panel { align-items: center; }
  .cell { width: 42px; height: 42px; font-size: 1.2rem; }
  .main-panel { grid-template-columns: 1fr; }
  .report-card-full { grid-column: 1; }
}
