:root {
  --bg: #f4efe3;
  --panel: rgba(255, 251, 243, 0.92);
  --line: #5c3d1f;
  --board: #e5c38b;
  --grid: #402715;
  --text: #4e3219;
  --muted: #87684f;
  --accent: #b86e34;
  --red: #b23a2d;
  --black: #212121;
  --green: #507b4d;
  --gold: #d1a35f;
  --fog: rgba(38, 31, 25, 0.42);
  --shadow: 0 18px 40px rgba(97, 71, 39, 0.14);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(250, 219, 154, 0.7), transparent 18rem),
    radial-gradient(circle at bottom left, rgba(166, 214, 205, 0.55), transparent 20rem),
    linear-gradient(180deg, #fbf7ef 0%, #f0e4cf 100%);
}

body {
  padding: 14px 14px 10px;
  overflow-x: auto;
}

.page-shell {
  width: 100%;
  display: flex;
  justify-content: center;
}

.hero-block h1 {
  margin: 0;
  font-size: clamp(34px, 3vw, 48px);
  line-height: 1.05;
}

.subtitle {
  margin: 12px 0 0;
  font-size: 16px;
  line-height: 1.85;
  color: var(--muted);
}

.ai-debug-text {
  margin-top: 14px;
  font-size: 12px;
  line-height: 1.65;
  color: #6d5038;
  white-space: pre-line;
  overflow: visible;
}

.hero-tags {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.hero-tags span {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(184, 110, 52, 0.11);
  color: #8b4c1e;
  font-weight: 700;
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(522px, 576px) minmax(216px, 270px);
  gap: 14px;
  align-items: start;
  justify-content: center;
}

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

.left-rail {
  overflow: visible;
}

.board-panel,
.panel-block {
  border: 1px solid rgba(108, 76, 46, 0.15);
  background: var(--panel);
  border-radius: 26px;
  box-shadow: var(--shadow);
}

.board-panel {
  padding: 10px;
}

.board-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin: 0;
}

.turn-badge {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
}

.turn-badge.red {
  background: linear-gradient(135deg, #cc5644, #9f3026);
}

.turn-badge.black {
  background: linear-gradient(135deg, #4b4b4b, #1c1c1c);
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: end;
}

.compact-toolbar {
  display: grid;
  gap: 10px;
}

.side-actions {
  justify-content: start;
}

.ghost-btn,
.text-btn {
  border: none;
  cursor: pointer;
  font: inherit;
}

.ghost-btn {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(107, 79, 51, 0.08);
  color: var(--text);
  transition: 0.18s ease;
}

.ghost-btn:hover {
  background: rgba(107, 79, 51, 0.14);
}

.ghost-btn.active {
  background: rgba(184, 110, 52, 0.14);
  color: #8b4c1e;
}

.ghost-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.danger-btn {
  color: #9f3026;
  background: rgba(178, 58, 45, 0.08);
}

.danger-btn:hover {
  background: rgba(178, 58, 45, 0.14);
}

.text-btn {
  color: var(--accent);
  background: transparent;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 576px;
  margin: 0 auto;
  aspect-ratio: 9 / 10;
  border-radius: 24px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(248, 225, 180, 0.24), rgba(219, 182, 122, 0.14)),
    #f7edd8;
}

#boardCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.overlay-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 24px;
  border-radius: 999px;
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  color: #fff;
  background: rgba(64, 39, 21, 0.86);
  box-shadow: 0 10px 24px rgba(48, 30, 18, 0.22);
  pointer-events: none;
  z-index: 2;
}

.overlay-message.red {
  background: rgba(178, 58, 45, 0.9);
  color: #ffe8e3;
}

.overlay-message.black {
  background: rgba(33, 33, 33, 0.9);
  color: #f3f3f3;
}

.overlay-message.thinking {
  min-height: 40px;
  padding: 0 18px;
  font-size: 18px;
  font-weight: 700;
  background: rgba(64, 39, 21, 0.78);
  color: #fff6ee;
}

.overlay-message.hidden {
  display: none;
}

.panel-block {
  padding: 12px 12px 14px;
}

.left-rail .hero-block {
  overflow: visible;
}

.panel-block h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.facts {
  display: grid;
  gap: 12px;
  margin: 0;
}

.facts div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(112, 84, 53, 0.12);
}

.facts dt {
  color: var(--muted);
}

.facts dd {
  margin: 0;
  font-weight: 700;
}

.tips {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.55;
  font-size: 14px;
}

.feature-list {
  display: grid;
  gap: 10px;
}

.feature-item {
  padding: 12px 12px 10px;
  border-radius: 18px;
  background: rgba(184, 110, 52, 0.08);
}

.feature-item strong {
  display: block;
  margin-bottom: 6px;
  font-size: 18px;
}

.feature-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 15px;
}

.history-block {
  min-height: 182px;
}

.history-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}

.history-import {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.history-import-input {
  width: 100%;
  min-height: 88px;
  padding: 10px 12px;
  border: 1px solid rgba(112, 84, 53, 0.18);
  border-radius: 16px;
  background: rgba(255, 252, 246, 0.88);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
}

.history-import-input:focus {
  outline: none;
  border-color: rgba(184, 110, 52, 0.55);
  box-shadow: 0 0 0 3px rgba(184, 110, 52, 0.12);
}

.history-list {
  margin: 0;
  padding-left: 22px;
  max-height: 182px;
  overflow: auto;
  color: var(--muted);
  line-height: 1.45;
  font-size: 13px;
}

.history-list li {
  padding-right: 8px;
  cursor: pointer;
}

.history-list li.current {
  color: var(--text);
  font-weight: 700;
}

.history-list li.reviewing {
  color: #8b4c1e;
  font-weight: 700;
}

.record-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.mini-btn {
  min-height: 38px;
  padding: 0 10px;
  font-size: 13px;
}

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

  .board-column {
    order: -1;
  }

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

  .toolbar-actions {
    justify-content: start;
  }
}

@media (max-width: 720px) {
  body {
    padding: 14px;
  }

  .ghost-btn {
    min-height: 40px;
    padding: 0 12px;
    font-size: 14px;
  }
}
