:root {
  --bg: #17110a;
  --panel: #25180d;
  --panel-2: #312013;
  --text: #fff4dd;
  --muted: #d7b98c;
  --line: #16100a;
  --gold: #ffbf55;
  --red: #d21f1f;
  --black: #111;
  --accent: #ffe0a3;
  --good: #8ef09b;
  --warn: #ffd26c;
  --danger: #ff8a8a;
  --shadow: 0 14px 42px rgba(0,0,0,.30);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
html { background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

button, input { font: inherit; }

button {
  min-height: 38px;
  padding: .5rem .9rem;
  border: 1px solid rgba(255,224,163,.35);
  border-radius: 12px;
  color: var(--text);
  background: linear-gradient(180deg, #4b2e14, #2f1e10);
  cursor: pointer;
  box-shadow: 0 5px 12px rgba(0,0,0,.20);
}

button:hover { border-color: rgba(255,224,163,.7); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.choice.active {
  color: #231304;
  border-color: rgba(255,224,163,.95);
  background: linear-gradient(180deg, #ffe2a1, #f4a735);
  box-shadow: 0 0 0 2px rgba(255,224,163,.16), 0 6px 14px rgba(0,0,0,.22);
}

.app-shell {
  width: min(1400px, 100vw);
  height: min(789px, 100vh);
  margin: 0;
  padding: 0 12px;
  overflow: hidden;
}

h1, h2, h3, p { margin-top: 0; }
h1 {
  margin: 0;
  font-size: 2.3rem;
  letter-spacing: .12em;
  line-height: 1;
  white-space: nowrap;
}
h2 { margin-bottom: .7rem; font-size: 1rem; color: var(--accent); }
p { line-height: 1.5; color: var(--muted); }

.layout {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(710px, 710px) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  min-height: 0;
}

.panel-block {
  background: linear-gradient(180deg, rgba(255,206,127,.08), rgba(255,206,127,.03)), var(--panel);
  border: 1px solid rgba(255,224,163,.22);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.board-card {
  position: relative;
  min-height: 0;
  height: 100%;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: stretch;
  overflow: hidden;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

#board {
  height: 100%;
  width: auto;
  max-width: 100%;
  aspect-ratio: 9 / 10;
  display: block;
  border-radius: 0;
  cursor: pointer;
  background: #c96d13;
  touch-action: manipulation;
}

.captured-strip {
  position: absolute;
  left: 50%;
  z-index: 5;
  width: min(100%, 710px);
  height: 32px;
  padding: 2px 6px;
  transform: translateX(-50%);
  border-radius: 0;
  background: transparent;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 4px;
  overflow: hidden;
  pointer-events: none;
}

.captured-strip:empty { display: none; }

.captured-top { top: 0; justify-content: flex-start; }
.captured-bottom { bottom: 0; justify-content: flex-end; }

.side-panel {
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.side-panel-inner {
  width: 100%;
  max-width: 620px;
  display: grid;
  gap: 14px;
  align-content: center;
}

.panel-block { padding: 16px; }
.title-block {
  padding: 24px 20px;
  text-align: center;
}

.hero-controls {
  padding: 18px;
}

.top-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  justify-content: center;
}

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(255,224,163,.18);
  border-radius: 14px;
  background: rgba(0,0,0,.18);
}

.segmented button {
  min-width: 126px;
  box-shadow: none;
}

.segmented.ai-levels button {
  min-width: 82px;
}

.top-actions {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.top-actions button {
  width: 100%;
  min-width: 0;
}

.status {
  min-height: 3.15rem;
  padding: .8rem;
  border-radius: 13px;
  background: rgba(0,0,0,.20);
  line-height: 1.45;
}

.quick-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.quick-stats span {
  display: inline-flex;
  align-items: center;
  min-height: 1.9rem;
  padding: .3rem .65rem;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid rgba(255,224,163,.16);
  color: var(--accent);
}

.options-block {
  display: grid;
  gap: 10px;
}

.options-block label {
  display: grid;
  color: var(--muted);
}

.ai-note { margin: 2px 0 0; font-size: .92rem; }

.check-row {
  grid-template-columns: 22px 1fr;
  align-items: start;
  gap: 8px !important;
}

.check-row input { margin-top: 3px; accent-color: var(--gold); }

.cap-piece {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #ffe0a3;
  color: #111;
  border: 2px solid #111;
  font-weight: 700;
  font-size: 18px;
  line-height: 1;
}

.cap-piece.red { color: var(--red); border-color: var(--red); }

@media (max-width: 1320px) {
  .app-shell { height: auto; max-height: none; padding: 0 10px 10px; overflow: visible; }
  .layout { height: auto; grid-template-columns: 1fr; }
  .side-panel { justify-content: stretch; }
  .side-panel-inner { max-width: none; }
  .board-card { height: min(789px, 100vh); }
}

@media (max-width: 720px) {
  .app-shell { padding: 10px; }
  h1 { font-size: 1.8rem; }
  .segmented { width: 100%; justify-content: center; flex-wrap: wrap; }
  .segmented button { min-width: 0; flex: 1 1 140px; }
  .top-actions { grid-template-columns: 1fr; }
  .board-card { padding: 0; height: min(720px, 100vh); }
}

/* Bản v7: sửa lỗi bàn cờ bị kéo dài trên điện thoại.
   Khi giao diện chuyển sang một cột, lấy chiều rộng làm chuẩn và để canvas tự giữ tỉ lệ 900x1000. */
@media (max-width: 1320px) {
  body {
    display: block;
    overflow: auto;
  }

  .app-shell {
    width: 100%;
    height: auto;
    min-height: 100vh;
    max-height: none;
    padding: 10px;
    overflow: visible;
  }

  .layout {
    height: auto;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .board-card {
    width: 100%;
    height: auto;
    min-height: 0;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    overflow: visible;
  }

  #board {
    width: min(100%, 710px);
    height: auto;
    max-width: 100%;
    aspect-ratio: auto;
  }

  .captured-strip {
    position: static;
    left: auto;
    z-index: auto;
    width: min(100%, 710px);
    min-height: 38px;
    height: auto;
    padding: 4px 6px;
    transform: none;
    background: rgba(0,0,0,.14);
    display: flex;
    flex-wrap: wrap;
    row-gap: 4px;
    overflow: visible;
  }

  .captured-strip:empty {
    display: none;
  }

  .captured-top {
    top: auto;
    margin-bottom: 4px;
    justify-content: flex-start;
  }

  .captured-bottom {
    bottom: auto;
    margin-top: 4px;
    justify-content: flex-end;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 8px;
  }

  .layout {
    gap: 10px;
  }

  .board-card {
    padding: 0;
    height: auto;
  }

  #board {
    width: 100%;
    height: auto;
    max-height: none;
  }

  .captured-strip {
    min-height: 36px;
    padding: 4px;
    gap: 3px;
    border-radius: 10px;
  }

  .cap-piece {
    width: 25px;
    height: 25px;
    font-size: 16px;
  }
}
