:root {
  --bg: #f3ead9;
  --panel: rgba(255, 250, 241, 0.92);
  --line: #73452d;
  --line-soft: rgba(115, 69, 45, 0.22);
  --ink: #2d1d17;
  --red: #b33a2f;
  --black: #24313a;
  --gold: #d7a95b;
  --highlight: rgba(215, 169, 91, 0.3);
  --selected: rgba(58, 133, 90, 0.22);
  --danger: #b33a2f;
  --river: rgba(201, 224, 233, 0.5);
  --shadow: 0 18px 46px rgba(57, 36, 27, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
  color: var(--ink);
  font-family: "Noto Serif SC", "Source Han Serif SC", "STSong", serif;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.65), transparent 30%),
    linear-gradient(180deg, #f8efdf 0%, #e9d4b2 46%, #d8b98c 100%);
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px 18px;
  height: 100%;
}

.banner-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.58;
}

.side-banner {
  margin-top: 10px;
  color: rgba(45, 29, 23, 0.72);
}

.primary-btn {
  border: 0;
  border-radius: 999px;
  padding: 11px 16px;
  font: inherit;
  font-size: 15px;
  color: #fff9ef;
  background: linear-gradient(135deg, #a53e29, #7d2d1c);
  cursor: pointer;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.secondary-btn {
  border: 1px solid rgba(115, 69, 45, 0.24);
  border-radius: 999px;
  padding: 10px 15px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: rgba(255, 248, 237, 0.9);
  cursor: pointer;
}

.side-actions {
  margin-bottom: 10px;
}

.primary-btn:hover {
  filter: brightness(1.05);
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.96);
}

.primary-btn:disabled,
.secondary-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) 340px;
  gap: 14px;
  align-items: stretch;
  min-height: 0;
  height: 100%;
}

.board-panel,
.card {
  background: var(--panel);
  border: 1px solid rgba(115, 69, 45, 0.12);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.board-panel {
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 12px;
  max-width: 700px;
  width: 100%;
  justify-self: center;
}

.board-frame {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 18px;
  width: 100%;
  height: 100%;
  max-width: 620px;
  max-height: 100%;
  aspect-ratio: 760 / 840;
  margin: 0 auto;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0.05)),
    linear-gradient(135deg, #efd6ae, #d7b184);
}

.board-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.drag-ghost {
  position: absolute;
  left: 0;
  top: 0;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transform: translate(-50%, -50%);
  border: 3px solid rgba(115, 69, 45, 0.28);
  background: rgba(253, 240, 218, 0.94);
  box-shadow: 0 14px 24px rgba(61, 33, 21, 0.24);
  font-size: 34px;
  font-weight: 700;
}

.drag-ghost.red {
  color: var(--red);
}

.drag-ghost.black {
  color: var(--black);
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  min-height: 0;
}

.card {
  padding: 14px 16px;
}

.side-actions-card {
  padding-top: 12px;
}

.card h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

.status-list {
  margin: 0;
  display: grid;
  gap: 12px;
}

.status-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(115, 69, 45, 0.12);
}

.status-list div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.status-list dt {
  color: rgba(45, 29, 23, 0.64);
}

.status-list dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.detail-list dd {
  max-width: 190px;
  line-height: 1.5;
}

.message-text,
.selection-text {
  margin: 0;
  line-height: 1.7;
}

.message-text {
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(115, 69, 45, 0.08);
}

.message-text.tone-success {
  background: rgba(58, 133, 90, 0.12);
  color: #22553b;
}

.message-text.tone-danger {
  background: rgba(179, 58, 47, 0.12);
  color: #7f241c;
}

.terminal-text {
  display: inline-block;
  margin: 0 0 10px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(58, 133, 90, 0.14);
  color: #22553b;
  font-weight: 700;
}

.selection-text {
  margin-top: 8px;
  color: rgba(45, 29, 23, 0.68);
}

.log-card {
  min-height: 0;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
}

.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.log-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.review-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(115, 69, 45, 0.07);
}

.review-step-text {
  min-width: 88px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: rgba(45, 29, 23, 0.76);
}

.mini-btn {
  padding: 7px 10px;
  font-size: 12px;
}

.move-log {
  margin: 0;
  padding: 0 2px 0 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  line-height: 1.45;
  list-style: none;
  counter-reset: move-item;
}

.move-log li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 1px 0;
}

.move-log li::before {
  content: counter(move-item) ".";
  counter-increment: move-item;
  flex: 0 0 32px;
  text-align: end;
  color: rgba(45, 29, 23, 0.68);
  font-variant-numeric: tabular-nums;
  line-height: 1.9;
}

.move-log .move-side {
  display: inline-block;
  min-width: 28px;
  font-weight: 700;
}

.move-log .move-piece {
  display: inline-block;
  min-width: 42px;
}

.move-log .move-notation {
  display: inline-block;
  min-width: 72px;
  font-weight: 700;
}

.move-log .move-coords {
  display: inline-block;
  color: rgba(45, 29, 23, 0.62);
}

.move-log button {
  display: flex;
  flex: 1 1 auto;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  min-width: 0;
  border: 0;
  padding: 5px 8px;
  border-radius: 12px;
  text-align: left;
  font: inherit;
  color: inherit;
  background: transparent;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
}

.move-log button:hover {
  background: rgba(115, 69, 45, 0.08);
}

.move-log button.active {
  background: rgba(58, 133, 90, 0.14);
  color: #22553b;
  font-weight: 700;
}

.move-log .move-coords {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.board-grid-line {
  stroke: var(--line);
  stroke-width: 3;
  stroke-linecap: round;
}

.board-grid-soft {
  stroke: var(--line-soft);
  stroke-width: 2;
  stroke-dasharray: 7 8;
}

.palace-line {
  stroke: var(--line);
  stroke-width: 2.5;
}

.river-band {
  fill: var(--river);
}

.river-text {
  font-size: 28px;
  letter-spacing: 0.26em;
  fill: rgba(115, 69, 45, 0.52);
}

.coord-text {
  display: none;
}

.cell-target {
  fill: transparent;
  cursor: pointer;
}

.cell-target:hover {
  fill: rgba(255, 255, 255, 0.08);
}

.piece-shadow {
  fill: rgba(61, 33, 21, 0.12);
}

.piece-disc {
  fill: #fdf0da;
  stroke: var(--line);
  stroke-width: 3;
}

.piece-ring-red {
  stroke: rgba(179, 58, 47, 0.5);
}

.piece-ring-black {
  stroke: rgba(36, 49, 58, 0.5);
}

.piece-label {
  font-size: 34px;
  font-weight: 700;
  dominant-baseline: middle;
  text-anchor: middle;
  pointer-events: none;
}

.piece-red {
  fill: var(--red);
}

.piece-black {
  fill: var(--black);
}

.piece-select {
  fill: none;
  stroke: #3a855a;
  stroke-width: 5;
}

.move-highlight {
  fill: var(--highlight);
  stroke: rgba(115, 69, 45, 0.24);
  stroke-width: 2;
}

.current-highlight {
  fill: var(--selected);
  stroke: rgba(58, 133, 90, 0.4);
  stroke-width: 2;
}

.check-highlight {
  fill: rgba(179, 58, 47, 0.12);
  stroke: rgba(179, 58, 47, 0.9);
  stroke-width: 4;
}

.legal-move-dot {
  fill: rgba(58, 133, 90, 0.88);
  stroke: rgba(255, 250, 241, 0.9);
  stroke-width: 3;
}

.piece-group {
  cursor: pointer;
  transition: transform 120ms ease;
}

.piece-group.motion {
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1), opacity 220ms ease;
}

.piece-group.disabled {
  cursor: default;
  opacity: 0.82;
}

.piece-group.dragging {
  opacity: 0.22;
}

.outcome-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.outcome-modal.hidden {
  display: none;
}

.outcome-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(36, 24, 18, 0.42);
  backdrop-filter: blur(10px);
}

.outcome-dialog {
  position: relative;
  max-width: 420px;
  margin: min(18vh, 140px) auto 0;
  padding: 28px 28px 24px;
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 252, 246, 0.98), rgba(246, 235, 216, 0.96)),
    linear-gradient(135deg, #efd6ae, #d7b184);
  box-shadow: 0 28px 60px rgba(36, 24, 18, 0.28);
  border: 1px solid rgba(115, 69, 45, 0.18);
}

.outcome-tag {
  margin: 0 0 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 12px;
  color: rgba(45, 29, 23, 0.54);
}

.outcome-dialog h2 {
  margin: 0;
  font-size: 34px;
}

.outcome-summary {
  margin: 12px 0 0;
  line-height: 1.7;
}

.outcome-detail-list {
  margin: 18px 0 0;
  display: grid;
  gap: 10px;
}

.outcome-detail-list div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(115, 69, 45, 0.07);
}

.outcome-detail-list dt {
  color: rgba(45, 29, 23, 0.64);
}

.outcome-detail-list dd {
  margin: 0;
  max-width: 220px;
  text-align: right;
  font-weight: 700;
  line-height: 1.5;
}

.outcome-actions {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.loading .board-frame {
  filter: saturate(0.94);
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    display: grid;
  }

  .board-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .board-actions {
    flex-wrap: wrap;
  }
}
