/* Cờ Tướng Online · plugin cotuong-game
   Màu nhấn chính: đỏ son (--ctg-accent). Đổi trong Cài đặt → Cờ Tướng. */

.ctg {
  --ctg-accent: #b3221d;
  --ctg-accent-strong: #8f1913;
  --ctg-accent-soft: #fbeae8;
  --ctg-on-accent: #ffffff;
  --ctg-ink: #1c1f1e;
  --ctg-muted: #59615d;
  --ctg-line: #dcdfda;
  --ctg-surface: #ffffff;
  --ctg-surface-2: #f4f4f1;
  --ctg-wood: #e4be80;
  --ctg-wood-line: #6b4724;
  --ctg-frame: #c3934f;
  --ctg-face: #f6ecd7;
  --ctg-black: #1c1f1e;
  --ctg-last: #c9820f;
  --ctg-check: #e0312b;
  --ctg-radius: 14px;
  --ctg-font: inherit;
  --ctg-cjk: "Noto Serif TC", "Noto Serif CJK TC", "Songti TC", "STSong", "PMingLiU", "SimSun", "KaiTi", serif;

  container-type: inline-size;
  color: var(--ctg-ink);
  font-family: var(--ctg-font);
  line-height: 1.5;
  margin: 1.5em 0;
  -webkit-tap-highlight-color: transparent;
}
.ctg *, .ctg *::before, .ctg *::after { box-sizing: border-box; }

:root[data-theme="dark"] .ctg, .dark .ctg, .ctg.ctg--dark {
  --ctg-accent: #e0463f;
  --ctg-accent-strong: #f0625b;
  --ctg-accent-soft: #3a1c1a;
  --ctg-ink: #ecefec;
  --ctg-muted: #a8b0ab;
  --ctg-line: #343b37;
  --ctg-surface: #1b1f1d;
  --ctg-surface-2: #232825;
}

/* ---------------------------------------------------------------- bố cục */
.ctg-layout { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@container (min-width: 820px) {
  .ctg-layout { grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); gap: 28px; }
  .ctg--compact .ctg-layout { grid-template-columns: minmax(0, 1.2fr) minmax(260px, 1fr); }
}
.ctg-main { display: flex; flex-direction: column; gap: 8px; min-width: 0; max-width: 680px; width: 100%; margin-inline: auto; }
.ctg--compact .ctg-main { max-width: 520px; }

.ctg-strip { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; padding: 0 4px; font-size: 14px; }
.ctg-who { display: flex; align-items: center; gap: 9px; min-width: 0; }
.ctg-who strong { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctg-badge {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--ctg-accent); color: #fff; font: 900 14px/1 var(--ctg-cjk);
}
.ctg-badge.is-black { background: var(--ctg-black); }
.ctg-strip-meta { color: var(--ctg-muted); font-size: 13px; white-space: nowrap; }
.ctg-turn { color: var(--ctg-accent); font-weight: 650; }
.ctg-turn::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; margin-right: 6px; vertical-align: 1px; }
.ctg-thinking { color: var(--ctg-accent); font-weight: 600; }
.ctg-thinking::after { content: "…"; display: inline-block; animation: ctg-dots 1s steps(4) infinite; width: 1.2em; overflow: hidden; vertical-align: bottom; }
@keyframes ctg-dots { from { width: 0; } to { width: 1.2em; } }

/* ---------------------------------------------------------------- bàn cờ */
.ctg-board { position: relative; width: 100%; aspect-ratio: 9 / 10; border-radius: 10px; box-shadow: 0 1px 0 #b0803f, 0 14px 30px rgba(60, 38, 14, .2); background: var(--ctg-wood); }
.ctg-svg-host, .ctg-svg-host svg, .ctg-board > svg { display: block; width: 100%; height: 100%; }
.ctg-svg { touch-action: manipulation; user-select: none; -webkit-user-select: none; cursor: pointer; outline: none; border-radius: 10px; }
.ctg-svg:focus-visible { box-shadow: 0 0 0 3px var(--ctg-accent); }
.ctg-wood { fill: var(--ctg-wood); }
.ctg-grid line { stroke: var(--ctg-wood-line); stroke-width: 2.5; }
.ctg-frame { fill: none; stroke: var(--ctg-wood-line); stroke-width: 5; }
.ctg-star { fill: none; stroke: var(--ctg-wood-line); stroke-width: 2.5; }
.ctg-river { fill: var(--ctg-wood-line); opacity: .72; font: 700 54px var(--ctg-cjk); text-anchor: middle; dominant-baseline: central; letter-spacing: .15em; }

.ctg-piece { transition: transform .2s cubic-bezier(.3, .7, .3, 1); }
.ctg-p-shadow { fill: rgba(60, 36, 10, .32); }
.ctg-p-face { fill: var(--ctg-face); stroke-width: 4; }
.ctg-p-ring { fill: none; stroke-width: 2; }
.ctg-p-label { font: 700 52px var(--ctg-cjk); text-anchor: middle; dominant-baseline: central; }
.ctg-p-label.is-viet { font: 800 42px system-ui, -apple-system, "Segoe UI", sans-serif; letter-spacing: -.02em; }
.ctg-p-label.is-viet.is-long { font-size: 33px; }
.is-red .ctg-p-face, .is-red .ctg-p-ring { stroke: var(--ctg-accent); }
.is-red .ctg-p-label { fill: var(--ctg-accent); }
.is-black .ctg-p-face, .is-black .ctg-p-ring { stroke: var(--ctg-black); }
.is-black .ctg-p-label { fill: var(--ctg-black); }
.ctg-piece > * { transition: transform .15s ease; }
.ctg-piece.is-selected > :not(.ctg-p-shadow) { transform: scale(1.08) translateY(-3px); }
.ctg-piece.is-selected .ctg-p-face { stroke: var(--ctg-accent); stroke-width: 7; }
.ctg-piece.is-selected .ctg-p-shadow { transform: translateY(5px) scale(1.04); }

.ctg-dot { fill: var(--ctg-accent); opacity: .88; }
.ctg-dot-capture { fill: none; stroke: var(--ctg-accent); stroke-width: 6; stroke-dasharray: 16 10; }
.ctg-m-to { fill: none; stroke: var(--ctg-last); stroke-width: 6; }
.ctg-m-from { fill: var(--ctg-last); opacity: .5; }
.ctg-m-check { fill: rgba(224, 49, 43, .16); stroke: var(--ctg-check); stroke-width: 7; animation: ctg-pulse 1.1s ease-in-out infinite; }
.ctg-m-hint { fill: none; stroke: var(--ctg-accent); stroke-width: 6; stroke-dasharray: 12 8; animation: ctg-spin 6s linear infinite; transform-box: fill-box; transform-origin: center; }
.ctg-cursor-box { fill: none; stroke: var(--ctg-accent); stroke-width: 4; stroke-dasharray: 10 8; }
@keyframes ctg-pulse { 50% { stroke-opacity: .35; } }
@keyframes ctg-spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- panel */
.ctg-panel {
  background: var(--ctg-surface); border: 1px solid var(--ctg-line); border-radius: var(--ctg-radius);
  padding: 18px; display: flex; flex-direction: column; gap: 16px; min-width: 0; min-height: 200px;
}
.ctg-panel > noscript, .ctg-panel .ctg-ssr { font-size: 14px; color: var(--ctg-muted); }
.ctg-sec { display: flex; flex-direction: column; gap: 8px; }
.ctg-sec--row { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.ctg-sec-h { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.ctg-sec-h > span:first-child, .ctg-sec-label { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ctg-muted); }
.ctg-sec-note { font-size: 12.5px; color: var(--ctg-muted); text-align: right; }

.ctg-seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding: 4px; border-radius: 11px; background: var(--ctg-surface-2); }
.ctg-seg button {
  appearance: none; border: 0; border-radius: 8px; padding: 10px 8px; background: transparent;
  font: inherit; font-weight: 650; font-size: 15px; color: var(--ctg-muted); cursor: pointer; min-height: 42px;
}
.ctg-seg button[aria-pressed="true"] { background: var(--ctg-accent); color: var(--ctg-on-accent); box-shadow: 0 2px 6px rgba(179, 34, 29, .28); }
.ctg-seg--sm button { padding: 7px 10px; font-size: 13.5px; min-height: 36px; }

.ctg-levels { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.ctg-chip {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  padding: 9px 6px; min-height: 40px; border-radius: 9px; border: 1px solid var(--ctg-line);
  background: var(--ctg-surface); font: inherit; font-size: 14px; color: var(--ctg-ink); cursor: pointer; white-space: nowrap;
}
@container (max-width: 440px) {
  .ctg-panel { padding: 14px; }
  .ctg-chip { font-size: 12.5px; padding: 8px 3px; gap: 3px; }
  .ctg-chip svg { width: 11px; height: 11px; }
}
.ctg-chip:hover { border-color: var(--ctg-accent); color: var(--ctg-accent); }
.ctg-chip.is-on { background: var(--ctg-accent); border-color: var(--ctg-accent); color: var(--ctg-on-accent); font-weight: 650; }
.ctg-chip.is-locked { border-style: dashed; background: var(--ctg-surface-2); color: var(--ctg-muted); }

.ctg-status { display: flex; align-items: center; gap: 11px; padding: 11px 14px; border-radius: 10px; font-size: 14.5px; background: var(--ctg-surface-2); }
.ctg-status-dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--ctg-muted); }
.ctg-status.is-turn { background: var(--ctg-accent-soft); }
.ctg-status.is-turn .ctg-status-dot { background: var(--ctg-accent); }
.ctg-status.is-bad { background: var(--ctg-accent-soft); color: var(--ctg-accent-strong); font-weight: 600; }
.ctg-status.is-bad .ctg-status-dot { background: var(--ctg-check); animation: ctg-pulse 1s infinite; }
.ctg-status.is-good { background: #e8f3ec; color: #1d5b36; }
.ctg-status.is-good .ctg-status-dot { background: #2f8a54; }

.ctg-moves {
  list-style: none; margin: 0; padding: 0; max-height: 232px; overflow-y: auto; overscroll-behavior: contain;
  border: 1px solid var(--ctg-line); border-radius: 10px; font-variant-numeric: tabular-nums; font-size: 15px;
}
.ctg-moves li { display: grid; grid-template-columns: 38px minmax(0, 1fr) minmax(0, 1fr); align-items: center; padding: 3px 10px; }
.ctg-moves li:nth-child(odd) { background: var(--ctg-surface-2); }
.ctg-mv-n { color: var(--ctg-muted); font-size: 13px; }
.ctg-mv { appearance: none; border: 0; background: none; font: inherit; color: var(--ctg-ink); text-align: left; padding: 4px 8px; border-radius: 6px; justify-self: start; cursor: pointer; }
.ctg-mv.is-red { color: var(--ctg-accent); font-weight: 650; }
.ctg-mv.is-current { background: var(--ctg-accent); color: var(--ctg-on-accent); }
.ctg-mv.is-empty { color: var(--ctg-muted); cursor: default; }
.ctg-empty { margin: 0; padding: 12px; font-size: 14px; color: var(--ctg-muted); border: 1px dashed var(--ctg-line); border-radius: 10px; text-align: center; }

.ctg-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.ctg-actions--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ctg-actions--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ctg-actions button, .ctg-controls button {
  appearance: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 60px; padding: 8px 4px; border-radius: 11px; border: 1px solid var(--ctg-line); background: var(--ctg-surface);
  font: inherit; font-size: 13px; color: var(--ctg-ink); cursor: pointer;
}
.ctg-actions button:hover:not(:disabled), .ctg-controls button:hover:not(:disabled) { border-color: var(--ctg-accent); color: var(--ctg-accent); }
.ctg-actions button:disabled, .ctg-controls button:disabled { opacity: .45; cursor: default; }
.ctg-actions button[aria-expanded="true"] { border-color: var(--ctg-accent); color: var(--ctg-accent); background: var(--ctg-accent-soft); }
.ctg-controls { display: grid; grid-template-columns: 1fr 1fr 1.6fr 1fr 1fr; gap: 6px; }
.ctg-controls button { min-height: 48px; flex-direction: row; }
.ctg-controls .is-primary { background: var(--ctg-accent); border-color: var(--ctg-accent); color: var(--ctg-on-accent); font-weight: 650; }
.ctg-controls .is-primary:hover:not(:disabled) { background: var(--ctg-accent-strong); color: var(--ctg-on-accent); }

.ctg-btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--ctg-ink);
  background: transparent; color: var(--ctg-ink); font: inherit; font-weight: 650; font-size: 15px; text-decoration: none; cursor: pointer;
}
.ctg-btn--primary { background: var(--ctg-accent); border-color: var(--ctg-accent); color: var(--ctg-on-accent); }
.ctg-btn--primary:hover { background: var(--ctg-accent-strong); border-color: var(--ctg-accent-strong); color: var(--ctg-on-accent); }
.ctg-btn--dark { background: var(--ctg-ink); border-color: var(--ctg-ink); color: var(--ctg-surface); }
.ctg-btn--block { width: 100%; }
.ctg-link { appearance: none; border: 0; background: none; padding: 0; font: inherit; font-size: 13px; font-weight: 650; color: var(--ctg-accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.ctg-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.ctg-tag { padding: 4px 11px; border-radius: 999px; background: var(--ctg-surface-2); font-size: 13.5px; }
.ctg-tag.is-accent { background: var(--ctg-accent-soft); color: var(--ctg-accent-strong); font-weight: 650; }
.ctg-progress-h { display: flex; justify-content: space-between; font-size: 13.5px; margin-bottom: 6px; }
.ctg-progress-h span:first-child { font-weight: 650; }
.ctg-bar { height: 8px; border-radius: 99px; background: var(--ctg-surface-2); overflow: hidden; }
.ctg-bar span { display: block; height: 100%; background: var(--ctg-accent); border-radius: inherit; transition: width .3s; }
.ctg-solution { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-radius: 10px; border: 1px dashed var(--ctg-accent); font-size: 15px; }
.ctg-solution strong { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ctg-accent); }
.ctg-note { margin: 0; font-size: 13px; color: var(--ctg-muted); }
.ctg-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--ctg-line); font-size: 14px; }

.ctg-settings { display: flex; flex-direction: column; gap: 4px; padding: 14px; border-radius: 12px; background: var(--ctg-surface-2); }
.ctg-switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; font-size: 14.5px; cursor: pointer; position: relative; }
.ctg-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ctg-switch-ui { flex: none; width: 44px; height: 26px; border-radius: 99px; background: #c5cbc6; position: relative; transition: background .15s; }
.ctg-switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.ctg-switch input:checked + .ctg-switch-ui { background: var(--ctg-accent); }
.ctg-switch input:checked + .ctg-switch-ui::after { transform: translateX(18px); }
.ctg-switch input:focus-visible + .ctg-switch-ui { box-shadow: 0 0 0 3px var(--ctg-accent-soft), 0 0 0 5px var(--ctg-accent); }
.ctg-fen { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; font-size: 13px; }
.ctg-fen label { font-weight: 650; }
.ctg-fen-row { display: flex; gap: 6px; }
.ctg-fen input { flex: 1; min-width: 0; padding: 9px 10px; border: 1px solid var(--ctg-line); border-radius: 8px; font: 12.5px ui-monospace, Menlo, Consolas, monospace; background: var(--ctg-surface); color: var(--ctg-ink); }
.ctg-fen .ctg-btn { min-height: 38px; padding: 6px 10px; border-color: var(--ctg-line); }
.ctg-fen .ctg-link { align-self: flex-start; }

/* ---------------------------------------------------------------- overlay, toast */
.ctg-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(20, 22, 21, .45); border-radius: 10px; z-index: 3; }
.ctg-overlay[hidden], .ctg-toast[hidden] { display: none; }
.ctg-dialog { width: min(100%, 380px); background: var(--ctg-surface); color: var(--ctg-ink); border-radius: 16px; padding: 22px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; box-shadow: 0 18px 40px rgba(0, 0, 0, .3); }
.ctg-dialog-badge { width: 54px; height: 54px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--ctg-face); box-shadow: inset 0 0 0 3px var(--ctg-accent), inset 0 0 0 6px var(--ctg-face), inset 0 0 0 7px var(--ctg-accent); color: var(--ctg-accent); font: 900 26px var(--ctg-cjk); }
.ctg-dialog-badge.is-black { color: var(--ctg-black); box-shadow: inset 0 0 0 3px var(--ctg-black), inset 0 0 0 6px var(--ctg-face), inset 0 0 0 7px var(--ctg-black); }
.ctg-dialog-title { font-size: 24px; line-height: 1.2; }
.ctg-dialog-sub { font-size: 14px; color: var(--ctg-muted); }
.ctg-dialog-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; width: 100%; }
.ctg-dialog-actions .ctg-btn { flex: 1 1 140px; }
.ctg-toast { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 4; max-width: calc(100% - 24px); padding: 9px 16px; border-radius: 999px; background: rgba(28, 31, 30, .92); color: #fff; font-size: 14px; font-weight: 600; pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: ctg-in .18s ease-out; }
@keyframes ctg-in { from { opacity: 0; transform: translate(-50%, -6px); } }

.ctg-sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------------------------------------------------------------- thế cờ hôm nay, danh sách */
.ctg-card { display: flex; flex-wrap: wrap; gap: 24px; align-items: center; padding: 20px; border: 1px solid var(--ctg-line); border-radius: 16px; background: var(--ctg-surface); color: var(--ctg-ink); margin: 1.5em 0; }
.ctg-card-board { flex: 0 1 300px; min-width: 0; }
.ctg-card-board .ctg-board { box-shadow: 0 8px 18px rgba(60, 38, 14, .16); }
.ctg-card-body { flex: 1 1 280px; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.ctg-eyebrow { font-size: 12.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ctg-accent); }
.ctg-card-title { margin: 0; font-size: 1.5em; line-height: 1.2; }
.ctg-card-title a { color: inherit; text-decoration: none; }
.ctg-grid-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; margin: 1.5em 0; padding: 0; list-style: none; }
.ctg-item { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--ctg-line); border-radius: 14px; background: var(--ctg-surface); color: var(--ctg-ink); text-decoration: none; height: 100%; }
.ctg-item:hover { border-color: var(--ctg-accent); }
.ctg-item .ctg-board { box-shadow: none; }
.ctg-item strong { font-size: 15.5px; line-height: 1.3; }
.ctg-item small { color: var(--ctg-muted); font-size: 13px; }
.ctg-item .is-solved { color: var(--ctg-accent); font-weight: 650; }
.ctg-filter { display: flex; flex-wrap: wrap; gap: 6px; margin: 1em 0; }
.ctg-filter a { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--ctg-line); text-decoration: none; color: var(--ctg-ink); font-size: 14px; background: var(--ctg-surface); }
.ctg-filter a.is-on { background: var(--ctg-accent); border-color: var(--ctg-accent); color: var(--ctg-on-accent); font-weight: 650; }
.ctg-pager { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 1.5em 0; }
.ctg-pager .page-numbers { min-width: 42px; min-height: 42px; display: inline-flex; align-items: center; justify-content: center; padding: 0 12px; border: 1px solid var(--ctg-line); border-radius: 9px; text-decoration: none; color: var(--ctg-ink); }
.ctg-pager .page-numbers.current { background: var(--ctg-accent); border-color: var(--ctg-accent); color: var(--ctg-on-accent); }

@media (prefers-reduced-motion: reduce) {
  .ctg *, .ctg *::before, .ctg *::after { animation: none !important; transition: none !important; }
}
