.editor-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 110px;
  overflow-x: hidden;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: 12px;
  align-items: start;
}

.editor-page .board-column,
.editor-panel {
  background: var(--panel);
  border-radius: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.editor-page .board-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.editor-side-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 4px 0 0;
}

.editor-side-note {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
  margin: 4px 0 0;
}

.spare-pieces {
  display: flex;
  gap: 4px;
  justify-content: center;
  padding: 6px 0;
  flex-wrap: wrap;
  max-width: 100%;
}

.spare-piece {
  width: 40px;
  height: 40px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  cursor: grab;
  border-radius: 4px;
  transition: background-color 0.15s;
}

.spare-piece:hover {
  background-color: var(--line);
}

.spare-piece[data-role="king"][data-color="red"]     { background-image: url("/static/xiangqi/assets/pieces/red_king.png"); }
.spare-piece[data-role="advisor"][data-color="red"]  { background-image: url("/static/xiangqi/assets/pieces/red_advisor.png"); }
.spare-piece[data-role="elephant"][data-color="red"] { background-image: url("/static/xiangqi/assets/pieces/red_elephant.png"); }
.spare-piece[data-role="rook"][data-color="red"]     { background-image: url("/static/xiangqi/assets/pieces/red_rook.png"); }
.spare-piece[data-role="knight"][data-color="red"]   { background-image: url("/static/xiangqi/assets/pieces/red_knight.png"); }
.spare-piece[data-role="cannon"][data-color="red"]   { background-image: url("/static/xiangqi/assets/pieces/red_cannon.png"); }
.spare-piece[data-role="pawn"][data-color="red"]     { background-image: url("/static/xiangqi/assets/pieces/red_pawn.png"); }

.spare-piece[data-role="king"][data-color="black"]     { background-image: url("/static/xiangqi/assets/pieces/black_king.png"); }
.spare-piece[data-role="advisor"][data-color="black"]  { background-image: url("/static/xiangqi/assets/pieces/black_advisor.png"); }
.spare-piece[data-role="elephant"][data-color="black"] { background-image: url("/static/xiangqi/assets/pieces/black_elephant.png"); }
.spare-piece[data-role="rook"][data-color="black"]     { background-image: url("/static/xiangqi/assets/pieces/black_rook.png"); }
.spare-piece[data-role="knight"][data-color="black"]   { background-image: url("/static/xiangqi/assets/pieces/black_knight.png"); }
.spare-piece[data-role="cannon"][data-color="black"]   { background-image: url("/static/xiangqi/assets/pieces/black_cannon.png"); }
.spare-piece[data-role="pawn"][data-color="black"]     { background-image: url("/static/xiangqi/assets/pieces/black_pawn.png"); }

/* ── Spare tools (pointer / trash) — Lichess pattern ─────────────────── */
.spare-tool {
  width: 40px;
  height: 40px;
  background-size: 26px 26px;
  background-repeat: no-repeat;
  background-position: center;
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: background-color 0.15s, border-color 0.15s;
  opacity: 0.7;
}

.spare-tool:hover {
  background-color: var(--line);
  opacity: 1;
}

.spare-tool.selected {
  background-color: var(--accent, #327ee2);
  border-color: var(--accent, #327ee2);
  opacity: 1;
}

.spare-piece.selected {
  background-color: var(--accent, #327ee2);
  border: 2px solid var(--accent, #327ee2);
  box-shadow: 0 0 0 2px var(--accent, #327ee2);
}

.spare-tool.pointer-tool {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23333'><path d='M9 11.24V7.5a2.5 2.5 0 0 1 5 0v3.74c1.21-.81 2-2.18 2-3.74C16 5.01 13.99 3 11.5 3S7 5.01 7 7.5c0 1.56.79 2.93 2 3.74zm9.84 4.63l-4.54-2.26c-.17-.07-.35-.11-.54-.11H13v-6c0-.83-.67-1.5-1.5-1.5S10 6.67 10 7.5v10.74l-3.43-.72c-.08-.01-.15-.03-.24-.03-.31 0-.59.13-.79.33l-.79.8 4.94 4.94c.27.27.65.44 1.06.44h6.79c.75 0 1.33-.55 1.44-1.28l.75-5.27c.01-.07.02-.14.02-.2 0-.62-.38-1.16-.91-1.39z'/></svg>");
}

.spare-tool.pointer-tool.selected {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'><path d='M9 11.24V7.5a2.5 2.5 0 0 1 5 0v3.74c1.21-.81 2-2.18 2-3.74C16 5.01 13.99 3 11.5 3S7 5.01 7 7.5c0 1.56.79 2.93 2 3.74zm9.84 4.63l-4.54-2.26c-.17-.07-.35-.11-.54-.11H13v-6c0-.83-.67-1.5-1.5-1.5S10 6.67 10 7.5v10.74l-3.43-.72c-.08-.01-.15-.03-.24-.03-.31 0-.59.13-.79.33l-.79.8 4.94 4.94c.27.27.65.44 1.06.44h6.79c.75 0 1.33-.55 1.44-1.28l.75-5.27c.01-.07.02-.14.02-.2 0-.62-.38-1.16-.91-1.39z'/></svg>");
}

.spare-tool.trash-tool {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23c0392b'><path d='M9 3v1H4v2h16V4h-5V3H9zm-3 5l1 12h10l1-12H6zm3 2h2v8H9v-8zm4 0h2v8h-2v-8z'/></svg>");
}

.spare-tool.trash-tool.selected {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'><path d='M9 3v1H4v2h16V4h-5V3H9zm-3 5l1 12h10l1-12H6zm3 2h2v8H9v-8zm4 0h2v8h-2v-8z'/></svg>");
}

/* ── Board cursor states ─────────────────────────────────────────────── */
.board-frame.tool-pointer { cursor: default; }

.board-frame.tool-piece {
  cursor: crosshair;
}

.board-frame.tool-trash {
  cursor: not-allowed;
}

.board-frame.tool-piece cg-board,
.board-frame.tool-trash cg-board,
.board-frame.tool-piece piece,
.board-frame.tool-trash piece {
  cursor: inherit !important;
}

/* ── Bottom tools area (FEN + URL below board) ──────────────────────── */
.editor-bottom-tools {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.editor-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.editor-turn-select {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}

.editor-turn-select label:first-child {
  font-weight: 600;
}

.turn-option {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.editor-actions {
  display: flex;
  gap: 8px;
}

.editor-actions button {
  flex: 1;
}

.editor-fen-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.editor-fen-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.editor-fen-group textarea {
  font-family: monospace;
  font-size: 0.8rem;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}

.editor-opening-group,
.editor-url-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.editor-opening-group label,
.editor-url-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.editor-opening-group select {
  font-size: 0.85rem;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.editor-url-row {
  display: flex;
  gap: 6px;
}

.editor-url-row input {
  flex: 1;
  font-family: monospace;
  font-size: 0.75rem;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  min-width: 0;
}

.editor-url-row button {
  flex-shrink: 0;
  padding: 6px 10px;
}

.editor-go-analysis {
  margin-top: 4px;
}

.editor-go-analysis button {
  width: 100%;
  font-size: 1rem;
  padding: 10px 16px;
}

.editor-back-link {
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
}

.editor-back-link:hover {
  text-decoration: underline;
}

.toast-stack {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.9rem;
  color: #fff;
  background: var(--accent, #327ee2);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: auto;
}

.toast--show {
  opacity: 1;
  transform: translateY(0);
}

.toast--error {
  background: #c0392b;
}

.toast--success {
  background: #27ae60;
}

@media (max-width: 768px) {
  .editor-page {
    padding: 12px 8px 80px;
  }

  .editor-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .editor-page .board-column {
    justify-self: stretch;
    padding: 6px;
    border-radius: 12px;
    border: none;
    box-shadow: none;
  }

  .spare-piece,
  .spare-tool {
    width: 30px;
    height: 30px;
  }

  .spare-tool {
    background-size: 20px 20px;
  }
}
