* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #f4f1ea;
  color: #1f2933;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0;
}

.back-link {
  color: #315f72;
  font-weight: 700;
  text-decoration: none;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.command-button,
.icon-button,
.level-control select,
.question-form button,
.prompt-buttons button {
  border: 1px solid #8d7a56;
  border-radius: 7px;
  background: #fffaf0;
  color: #1f2933;
  cursor: pointer;
}

.level-control {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #52616f;
  font-size: 0.85rem;
  font-weight: 700;
}

.level-control select {
  min-height: 38px;
  padding: 0 8px;
}

.command-button {
  min-height: 38px;
  padding: 0 14px;
  font-weight: 700;
}

.icon-button {
  min-width: 44px;
  min-height: 38px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 680px) minmax(280px, 1fr);
  gap: 16px;
  align-items: start;
}

.board-area {
  display: grid;
  gap: 10px;
}

.board-wrap {
  display: grid;
  gap: 4px;
}

.files {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  padding-left: 0;
  color: #6b5d43;
  font-size: 0.8rem;
  text-align: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, minmax(32px, 1fr));
  aspect-ratio: 1;
  border: 3px solid #6f5630;
  background: #d9a85d;
  user-select: none;
}

.board.is-busy {
  opacity: 0.72;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid rgba(75, 51, 22, 0.7);
  border-bottom: 1px solid rgba(75, 51, 22, 0.7);
  background: #e4b86f;
}

.cell:nth-child(9n) {
  border-right: 0;
}

.cell:nth-last-child(-n + 9) {
  border-bottom: 0;
}

.cell.selected,
.cell.legal {
  background: #f3d58d;
}

.cell.last-from {
  background: #f6d6a6;
}

.cell.last-to {
  background: #8fc5b3;
  box-shadow: inset 0 0 0 4px #315f72;
}

.cell.last-drop {
  animation: dropPulse 1.2s ease-out 2;
}

@keyframes dropPulse {
  0% {
    box-shadow: inset 0 0 0 5px #315f72, 0 0 0 0 rgba(49, 95, 114, 0.55);
  }
  100% {
    box-shadow: inset 0 0 0 4px #315f72, 0 0 0 14px rgba(49, 95, 114, 0);
  }
}

.coord {
  position: absolute;
  right: 3px;
  bottom: 2px;
  color: rgba(70, 45, 20, 0.45);
  font-size: 0.62rem;
}

.piece {
  display: grid;
  place-items: center;
  width: 76%;
  height: 84%;
  clip-path: polygon(50% 0, 88% 18%, 80% 100%, 20% 100%, 12% 18%);
  background: #f4d28a;
  border: 1px solid #7a5a29;
  color: #171717;
  font-weight: 800;
  font-size: clamp(0.9rem, 3.3vw, 1.45rem);
  line-height: 1;
}

.piece.white {
  transform: rotate(180deg);
  background: #eec47b;
}

.piece.promoted {
  color: #9b1c1c;
}

.hand {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 48px;
  padding: 8px;
  border: 1px solid #d2c5ab;
  border-radius: 7px;
  background: #fffaf0;
}

.hand-title {
  color: #6b5d43;
  font-size: 0.85rem;
  font-weight: 700;
}

.hand-piece {
  min-width: 44px;
  min-height: 38px;
  border: 1px solid #8d7a56;
  border-radius: 7px;
  background: #f4d28a;
  cursor: pointer;
  font-weight: 800;
}

.hand-piece.selected {
  outline: 3px solid #315f72;
  outline-offset: 2px;
}

.side-panel {
  display: grid;
  gap: 12px;
}

.ai-panel,
.moves-panel {
  border: 1px solid #d2c5ab;
  border-radius: 8px;
  background: #fffdfa;
  padding: 14px;
}

.profile {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  align-items: center;
}

.profile img {
  width: 72px;
  height: 72px;
  border-radius: 14px;
}

.label {
  margin: 0;
  color: #6b7280;
  font-size: 0.78rem;
  font-weight: 700;
}

.profile h2,
.moves-panel h2 {
  margin: 0;
  font-size: 1.05rem;
}

.profile p:last-child {
  margin: 4px 0 0;
  color: #52616f;
  font-size: 0.9rem;
  line-height: 1.5;
}

.thinking {
  margin-top: 12px;
  padding: 8px 10px;
  border-radius: 7px;
  background: #eaf3f0;
  color: #315f72;
  font-weight: 700;
}

.status-line {
  margin-top: 8px;
  color: #667085;
  font-size: 0.78rem;
  line-height: 1.4;
}

.speech {
  margin-top: 12px;
  min-height: 84px;
  line-height: 1.7;
}

.speech p {
  margin: 0 0 8px;
}

.prompt-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.prompt-buttons button {
  min-height: 34px;
  padding: 0 10px;
}

.question-form {
  display: grid;
  grid-template-columns: 1fr 58px;
  gap: 8px;
  margin-top: 10px;
}

.question-form input {
  min-width: 0;
  min-height: 38px;
  border: 1px solid #d2c5ab;
  border-radius: 7px;
  padding: 0 10px;
}

.moves-panel ol {
  max-height: 240px;
  overflow: auto;
  margin: 10px 0 0;
  padding-left: 0;
  line-height: 1.45;
  list-style: none;
}

.moves-panel li {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-left: 4px solid #d2c5ab;
  background: #fffaf0;
}

.moves-panel li.move-ai {
  border-left-color: #315f72;
  background: #eef7f4;
}

.move-main {
  font-weight: 800;
}

.move-meta,
.move-reason {
  margin-top: 3px;
  color: #667085;
  font-size: 0.78rem;
}

.move-reason {
  color: #52616f;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 18px;
}

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

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-wrap: wrap;
  }
}
