:root {
  --bg: #14121a;
  --bg-panel: #1c1926;
  --bg-cell: #2a2436;
  --gold: #d4af37;
  --gold-soft: #b8933a;
  --red: #c23b2e;
  --red-soft: #8f2a20;
  --black-piece: #1c1c22;
  --text: #f0e6d2;
  --text-muted: #a89a8a;
  --border: #3a3346;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(ellipse at top, #221d2c 0%, var(--bg) 60%);
  color: var(--text);
  font-family: 'Segoe UI', Roboto, Arial, sans-serif;
  min-height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: linear-gradient(180deg, #211b2a, #17131e);
  border-bottom: 2px solid var(--gold-soft);
  flex-wrap: wrap;
  gap: 10px;
}

.app-header h1 {
  font-size: 1.15rem;
  margin: 0;
  color: var(--gold);
  letter-spacing: 0.3px;
}

.app-header h1 span {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.9rem;
}

.header-badges {
  display: flex;
  gap: 8px;
}

.badge {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--border);
}

.badge-red {
  background: rgba(194, 59, 46, 0.25);
  color: #ff9a8a;
  border-color: var(--red-soft);
}

.badge-black {
  background: rgba(0, 0, 0, 0.35);
  color: var(--gold);
  border-color: var(--gold-soft);
}

.badge-muted {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
}

.layout {
  display: grid;
  grid-template-columns: 260px minmax(320px, 640px) 300px;
  gap: 16px;
  padding: 16px;
  justify-content: center;
  align-items: start;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.panel h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--gold-soft);
  margin: 18px 0 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.panel h2:first-child {
  margin-top: 0;
}

.control-group {
  margin-bottom: 16px;
}

.control-label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.radio-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.radio-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-cell);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  cursor: pointer;
  user-select: none;
}

.radio-pill input {
  accent-color: var(--gold);
}

.radio-pill:has(input:checked) {
  border-color: var(--gold);
  background: rgba(212, 175, 55, 0.12);
}

.hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin: 6px 0 0;
}

.piece-palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.palette-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--bg-cell);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 2px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.68rem;
}

.palette-btn img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.palette-btn.active {
  border-color: var(--gold);
  background: rgba(212, 175, 55, 0.15);
  color: var(--gold);
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
  transition: transform 0.05s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn.full-width {
  width: 100%;
  display: block;
  text-align: center;
}

.btn-primary {
  background: var(--gold);
  color: #241d10;
}

.btn-secondary {
  background: var(--bg-cell);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: rgba(194, 59, 46, 0.2);
  color: #ff9a8a;
  border: 1px solid var(--red-soft);
}

.btn-gold {
  background: linear-gradient(180deg, #e8c766, var(--gold));
  color: #241d10;
  font-size: 0.95rem;
  padding: 14px;
}

.btn-gold:disabled {
  opacity: 0.6;
  cursor: wait;
}

.file-btn {
  cursor: pointer;
}

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

.board {
  --cols: 9;
  --rows: 10;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  width: 100%;
  max-width: 460px;
  aspect-ratio: 9 / 10;
  background: linear-gradient(160deg, #2a2830, #1a1820);
  border: 2px solid rgba(230, 230, 235, 0.35);
  border-radius: 8px;
  position: relative;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.6);
}

.cell {
  position: relative;
  border: 1px solid rgba(230, 230, 235, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.cell.palace {
  background: rgba(230, 230, 235, 0.03);
}

.cell.river-top,
.cell.river-bottom {
  border-bottom-color: transparent;
}

.cell.selected {
  background: rgba(212, 175, 55, 0.35) !important;
}

.cell.legal-target::after {
  content: '';
  position: absolute;
  width: 24%;
  height: 24%;
  border-radius: 50%;
  background: rgba(212, 175, 55, 0.55);
}

#arrow-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  overflow: visible;
}

#suggestion-arrow-line {
  transition: opacity 0.15s ease;
  filter: drop-shadow(0 0 3px rgba(110, 231, 255, 0.8));
}

.river-label {
  position: absolute;
  top: calc(4/10 * 100% - 1px);
  left: 0;
  width: 100%;
  height: calc(1/10 * 100%);
  display: flex;
  align-items: center;
  justify-content: space-around;
  color: rgba(230, 230, 235, 0.3);
  font-size: 1.1rem;
  letter-spacing: 6px;
  pointer-events: none;
}

.piece {
  width: 82%;
  height: 82%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6));
}

.piece-red {
  background: radial-gradient(circle at 35% 30%, #ffffff, #e8e0d0);
  border: 2px solid var(--gold);
}

.piece-black {
  background: radial-gradient(circle at 35% 30%, #ffffff, #e8e0d0);
  border: 2px solid var(--gold-soft);
}

.piece-img {
  width: 78%;
  height: 78%;
  object-fit: contain;
  pointer-events: none;
}

.board-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.status-box {
  min-height: 20px;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.status-box.status-win {
  color: #7CFC9A;
}

.status-box.status-check {
  color: #ff9a8a;
}

/* Análise */
.suggestion-box {
  margin-top: 10px;
  font-size: 0.85rem;
}

.suggestion-title {
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 6px;
}

.suggestion-best {
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.suggestion-seq-label {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.suggestion-seq {
  margin: 0 0 10px;
  padding-left: 20px;
  line-height: 1.6;
}

.suggestion-seq .cap {
  color: #ff9a8a;
}

.suggestion-none {
  color: #ff9a8a;
  font-weight: 600;
}

.io-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.io-panel {
  display: none;
  margin-top: 10px;
}

.io-panel.open {
  display: block;
}

#io-box {
  width: 100%;
  background: var(--bg-cell);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font-family: monospace;
  font-size: 0.75rem;
  resize: vertical;
}

/* Responsivo */
@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .panel-pieces {
    order: 2;
  }

  .panel-board {
    order: 1;
  }

  .panel-analysis {
    order: 3;
  }

  .piece-palette {
    grid-template-columns: repeat(7, 1fr);
  }

  .board {
    max-width: 100%;
  }
}