:root {
  --bg: #fff4df;
  --panel: #ffffff;
  --panel-2: #fff9f1;
  --text: #2d2a32;
  --muted: #6f6b7a;
  --border: #eadfce;
  --shadow: 0 14px 30px rgba(226, 186, 132, 0.25);
  --primary: #f28cb1;
  --primary-hover: #ef77a3;
  --accent: #7a78ff;
  --accent-2: #ffb347;
  --highlight: #ffe6a7;
  --danger: #f06475;
  --success: #4caf90;
  --button-bg: #f28cb1;
  --button-hover: #ef77a3;
  --button-text: #ffffff;
  --button-border: transparent;
  --input-bg: #ffffff;
  --input-text: #2d2a32;
  --input-border: #eadfce;
  --panel-bg: #fff9f1;
  --panel-header-bg: #fff1dc;
  --panel-header-text: #2d2a32;
  --log-bg: #fff9f1;
  --p1: rgba(140, 196, 255, 0.35);
  --p2: rgba(255, 176, 210, 0.4);
}

body[data-theme="cheerful-clean"] {
  --bg: #fff4df;
  --panel: #ffffff;
  --panel-2: #fff9f1;
  --text: #2d2a32;
  --muted: #6f6b7a;
  --border: #eadfce;
  --shadow: 0 14px 30px rgba(226, 186, 132, 0.25);
  --primary: #f28cb1;
  --primary-hover: #ef77a3;
  --accent: #7a78ff;
  --accent-2: #ffb347;
  --highlight: #ffe6a7;
  --danger: #f06475;
  --success: #4caf90;
  --button-bg: #f28cb1;
  --button-hover: #ef77a3;
  --button-text: #ffffff;
  --button-border: transparent;
  --input-bg: #ffffff;
  --input-text: #2d2a32;
  --input-border: #eadfce;
  --panel-bg: #fff9f1;
  --panel-header-bg: #fff1dc;
  --panel-header-text: #2d2a32;
  --log-bg: #fff9f1;
  --p1: rgba(140, 196, 255, 0.35);
  --p2: rgba(255, 176, 210, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Nunito", "Quicksand", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#bgDecor {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

#bgDecor::before,
#bgDecor::after {
  content: "";
  position: absolute;
  top: 50%;
  width: min(320px, 28vw);
  height: min(520px, 60vh);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
  opacity: 0.85;
  transform: translateY(-50%);
}

#bgDecor::before {
  left: 2%;
  background-image: var(--decor-left-url, none);
}

#bgDecor::after {
  right: 2%;
  background-image: var(--decor-right-url, none);
}


.wrap {
  max-width: 1020px;
  margin: 0 auto;
  padding: 24px 18px 32px;
  position: relative;
  z-index: 1;
}

h1 {
  font-size: 18px;
  margin: 0 0 12px;
}

.grid {
  display: grid;
  grid-template-columns: 60% 40%;
  gap: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

label {
  font-size: 12px;
  color: var(--muted);
}

.game-header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  align-items: flex-start;
}

.game-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.game-header__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.game-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.game-header label {
  font-size: 11px;
}

.game-header select,
.game-header button {
  font-size: 12px;
  padding: 6px 10px;
}

.log-header__title {
  font-size: 12px;
  font-weight: 700;
}

.log-header button {
  font-size: 12px;
  padding: 6px 10px;
}

select,
input,
button {
  font: inherit;
  border-radius: 12px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--input-text);
  padding: 8px 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

input {
  flex: 1;
  min-width: 260px;
}

button {
  cursor: pointer;
  background: var(--button-bg);
  color: var(--button-text);
  border-color: var(--button-border);
  box-shadow: 0 6px 14px rgba(242, 140, 177, 0.25);
}

button:hover {
  background: var(--button-hover);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  box-shadow: none;
}

select:focus-visible,
input:focus-visible,
button:focus-visible {
  outline: 2px solid rgba(122, 120, 255, 0.4);
  outline-offset: 2px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

pre {
  margin: 10px 0 0;
  padding: 10px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  overflow: auto;
}

#logOut {
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  scrollbar-width: thin;
  scrollbar-color: rgba(246, 182, 208, 0.7) rgba(255, 244, 223, 0.7);
  background: var(--log-bg);
  border-radius: 14px;
  border: 1px solid var(--border);
}

#logOut::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

#logOut::-webkit-scrollbar-thumb {
  background: rgba(246, 182, 208, 0.7);
  border-radius: 999px;
  border: 2px solid rgba(255, 244, 223, 0.7);
}

#logOut::-webkit-scrollbar-track {
  background: rgba(255, 244, 223, 0.7);
  border-radius: 999px;
}

.small {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 10px 0;
}

.advanced-console {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-bg);
  margin-top: 10px;
  overflow: hidden;
}

.advanced-console summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--panel-header-text);
  background: var(--panel-header-bg);
}

.advanced-console summary::-webkit-details-marker {
  display: none;
}

.advanced-console summary::after {
  content: "▸";
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.advanced-console[open] summary::after {
  transform: rotate(90deg);
}

.advanced-console__body {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border);
}

.advanced-console__body button,
.threats-panel__body button {
  font-size: 12px;
  padding: 6px 10px;
}

.threats-panel {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-bg);
  margin-top: 10px;
  overflow: hidden;
  position: relative;
}

.threats-panel summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--panel-header-text);
  background: var(--panel-header-bg);
}

.threats-panel summary::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(122, 120, 255, 0.2);
}

.threats-panel.ai-panel summary::before {
  background: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(255, 179, 71, 0.2);
}

.threats-panel summary::-webkit-details-marker {
  display: none;
}

.threats-panel summary::after {
  content: "▸";
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.threats-panel[open] summary::after {
  transform: rotate(90deg);
}

.threats-panel__body {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 10px;
}

.ai-panel__body {
  gap: 12px;
}

.ai-panel__summary {
  display: grid;
  gap: 6px;
  font-size: 12px;
}

.ai-summary-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.ai-summary-label {
  color: var(--muted);
  min-width: 90px;
}

.ai-summary-value {
  color: var(--text);
}

.ai-candidates,
.ai-threats-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  font-size: 12px;
}

.ai-candidates li,
.ai-threats-list li {
  padding: 6px 8px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.ai-candidates li.ai-empty,
.ai-threats-list li.ai-empty {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--muted);
  font-style: italic;
  justify-content: flex-start;
}

.ai-candidate-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.ai-chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(122, 120, 255, 0.3);
  background: rgba(122, 120, 255, 0.1);
  color: var(--muted);
}

.ai-chip--highlight {
  color: #2d2a32;
  border-color: rgba(255, 179, 71, 0.4);
  background: rgba(255, 179, 71, 0.25);
}

.ai-threats {
  display: grid;
  gap: 10px;
}

.ai-threats__block {
  display: grid;
  gap: 6px;
}

.ai-threats__title {
  font-size: 12px;
  color: var(--muted);
}

.ai-threats__blocked {
  font-size: 12px;
  color: var(--muted);
  padding-top: 6px;
}

.threats-panel__actions {
  display: flex;
  justify-content: flex-end;
}

.pill {
  display: inline-block;
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
}

.gui-area {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.gui-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.gui-selection {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.gui-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(86px, 1fr));
  gap: 12px;
}

.gui-cell {
  position: relative;
  min-height: 102px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7);
}

.gui-cell.legal-dest {
  border-color: rgba(255, 179, 71, 0.6);
  box-shadow: inset 0 0 0 2px rgba(255, 179, 71, 0.25);
  background: rgba(255, 230, 167, 0.35);
}

.gui-cell.illegal-flash {
  animation: illegalFlash 0.25s ease-in-out;
}

.gui-top {
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
}

.gui-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 11px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.8);
  display: none;
  pointer-events: none;
  font-weight: 700;
}

.gui-reserves {
  display: grid;
  grid-template-columns: repeat(2, minmax(200px, 1fr));
  gap: 12px;
}

.reserve-panel {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px;
  background: var(--panel-2);
}

.reserve-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}

.reserve-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.piece {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}

.piece--board {
  font-size: 14px;
}

.piece--reserve {
  font-size: 12px;
}

.piece--icon {
  --piece-size: 52px;
  --piece-scale: 1;
  width: calc(var(--piece-size) * var(--piece-scale));
  height: calc(var(--piece-size) * var(--piece-scale));
}

.piece--icon.piece--reserve {
  --piece-size: 42px;
}

.piece--icon.piece--small {
  --piece-scale: 0.84;
}

.piece--icon.piece--large {
  --piece-scale: 1;
}

.pieceIcon {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.pieceLabel {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #2d2a32;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.65);
  pointer-events: none;
}

.pieceLabel span {
  background: rgba(255, 255, 255, 0.7);
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.reserve-piece {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  cursor: pointer;
}

.reserve-piece.piece--icon {
  min-width: 0;
  height: auto;
  padding: 6px;
  border-radius: 12px;
  background: transparent;
}

.reserve-piece.p1 {
  background: var(--p1);
}

.reserve-piece.p2 {
  background: var(--p2);
}

.reserve-piece.piece--icon.p1,
.reserve-piece.piece--icon.p2 {
  background: transparent;
}

.reserve-empty {
  font-size: 12px;
  color: var(--muted);
}

.selected {
  outline: 2px solid var(--highlight);
  box-shadow: 0 0 0 3px rgba(255, 230, 167, 0.35);
}

.tooltip {
  position: fixed;
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text);
  box-shadow: 0 10px 24px rgba(120, 92, 66, 0.18);
  pointer-events: none;
  max-width: 240px;
  transition: opacity 0.08s ease, transform 0.08s ease;
}

.tooltip div {
  line-height: 1.4;
}

.tooltip.hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
}

.modal-section {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  background: var(--panel);
}

.modal-section__title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.threats-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 6px;
  font-size: 13px;
}

.threats-list li {
  padding: 6px 8px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.threats-list li.threats-none {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--muted);
  font-style: italic;
}

@keyframes illegalFlash {
  0% { box-shadow: 0 0 0 0 rgba(240, 100, 117, 0.65); }
  100% { box-shadow: 0 0 0 8px rgba(240, 100, 117, 0); }
}

@media (max-width: 900px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .gui-area {
    grid-template-columns: 1fr;
  }

  .gui-reserves {
    grid-template-columns: 1fr;
  }
}
