/* ═══════════════════════════════════════════════════════════════════════════
   Cờ Tướng AI — Stylesheet
   Aesthetic: Dark lacquerware · Gold · Silk · Vietnamese heritage
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;700;900&family=Be+Vietnam+Pro:wght@300;400;500;600;700&display=swap');

/* ── Variables ────────────────────────────────────────────────────────────── */
.ctg-wrapper {
    --ctg-bg:           #0f0c07;
    --ctg-surface:      #1a1508;
    --ctg-surface-2:    #221c0c;
    --ctg-border:       #3d3010;
    --ctg-gold:         #c8960c;
    --ctg-gold-light:   #f0c040;
    --ctg-gold-dim:     #7a5a06;
    --ctg-red:          #d42b2b;
    --ctg-red-light:    #ff4444;
    --ctg-red-dim:      #7a1515;
    --ctg-black:        #1a1a1a;
    --ctg-black-piece:  #2a2a2a;
    --ctg-text:         #e8d9a0;
    --ctg-text-dim:     #8a7840;
    --ctg-board-light:  #f5ddb4;
    --ctg-board-dark:   #c8a05a;
    --ctg-board-bg:     #e8c878;
    --ctg-board-line:   #8a6020;
    --ctg-river:        #5a8ab8;
    --ctg-shadow:       rgba(0,0,0,0.8);
    --ctg-glow-gold:    rgba(200,150,12,0.4);
    --ctg-glow-red:     rgba(212,43,43,0.4);
    --ctg-radius:       16px;
    --ctg-font-main:    'Be Vietnam Pro', sans-serif;
    --ctg-font-piece:   'Noto Serif SC', serif;
    --ctg-transition:   all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.ctg-wrapper.ctg-theme-light {
    --ctg-bg:           #f5ede0;
    --ctg-surface:      #fdf5e8;
    --ctg-surface-2:    #efe5d0;
    --ctg-border:       #d4b870;
    --ctg-text:         #2a1a05;
    --ctg-text-dim:     #7a5a20;
    --ctg-shadow:       rgba(0,0,0,0.2);
}

/* ── Wrapper ──────────────────────────────────────────────────────────────── */
.ctg-wrapper {
    font-family: var(--ctg-font-main);
    background: var(--ctg-bg);
    color: var(--ctg-text);
    border-radius: var(--ctg-radius);
    overflow: hidden;
    position: relative;
    max-width: 700px;
    margin: 0 auto 2rem;
    box-shadow:
        0 0 0 1px var(--ctg-border),
        0 20px 60px var(--ctg-shadow),
        0 0 120px var(--ctg-glow-gold);
}

/* Decorative background pattern */
.ctg-wrapper::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 20% 20%, rgba(200,150,12,0.06) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(212,43,43,0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.ctg-header {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    background: var(--ctg-surface);
    border-bottom: 1px solid var(--ctg-border);
    flex-wrap: wrap;
    gap: 12px;
}

.ctg-logo {
    display: flex;
    align-items: center;
    gap: 14px;
}

.ctg-logo-icon {
    font-family: var(--ctg-font-piece);
    font-size: 36px;
    line-height: 1;
    color: var(--ctg-gold-light);
    text-shadow: 0 0 20px var(--ctg-glow-gold);
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
    animation: ctg-float 3s ease-in-out infinite;
}

@keyframes ctg-float {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-4px); }
}

.ctg-logo-text {
    display: flex;
    flex-direction: column;
}

.ctg-title {
    font-family: var(--ctg-font-piece);
    font-size: 22px;
    font-weight: 700;
    color: var(--ctg-gold-light);
    letter-spacing: 0.03em;
    line-height: 1;
}

.ctg-subtitle {
    font-size: 11px;
    font-weight: 300;
    color: var(--ctg-text-dim);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-top: 3px;
}

/* Difficulty selector */
.ctg-difficulty-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ctg-difficulty-selector label {
    font-size: 12px;
    color: var(--ctg-text-dim);
    font-weight: 500;
    letter-spacing: 0.05em;
}

.ctg-diff-buttons {
    display: flex;
    background: var(--ctg-surface-2);
    border: 1px solid var(--ctg-border);
    border-radius: 8px;
    overflow: hidden;
}

.ctg-diff-btn {
    background: none;
    border: none;
    padding: 6px 14px;
    font-family: var(--ctg-font-main);
    font-size: 12px;
    font-weight: 500;
    color: var(--ctg-text-dim);
    cursor: pointer;
    transition: var(--ctg-transition);
    position: relative;
}

.ctg-diff-btn:hover {
    color: var(--ctg-text);
    background: rgba(200,150,12,0.1);
}

.ctg-diff-btn.active {
    background: var(--ctg-gold);
    color: #0f0c07;
    font-weight: 700;
}

/* ── Main Layout ──────────────────────────────────────────────────────────── */
.ctg-main {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 24px;
    gap: 16px;
}

/* ── Player Panels ────────────────────────────────────────────────────────── */
.ctg-player-panel {
    width: 100%;
    max-width: 540px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    background: var(--ctg-surface);
    border: 1px solid var(--ctg-border);
    border-radius: 12px;
    transition: var(--ctg-transition);
}

.ctg-black-panel.ctg-active-panel,
.ctg-red-panel.ctg-active-panel {
    border-color: var(--ctg-gold);
    box-shadow: 0 0 0 1px var(--ctg-gold), 0 0 20px var(--ctg-glow-gold);
}

.ctg-player-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ctg-player-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--ctg-font-piece);
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
    border: 2px solid transparent;
    transition: var(--ctg-transition);
}

.ctg-player-avatar.black {
    background: radial-gradient(circle at 35% 35%, #4a4a4a, #1a1a1a);
    color: #d4c090;
    border-color: #555;
    box-shadow: 0 2px 8px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.1);
}

.ctg-player-avatar.red {
    background: radial-gradient(circle at 35% 35%, #e85050, #8a1515);
    color: #fff8e0;
    border-color: #c03030;
    box-shadow: 0 2px 8px rgba(212,43,43,0.4), inset 0 1px 0 rgba(255,255,255,0.2);
}

.ctg-player-meta {
    display: flex;
    flex-direction: column;
}

.ctg-player-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--ctg-text);
}

.ctg-player-color {
    font-size: 11px;
    color: var(--ctg-text-dim);
    margin-top: 2px;
}

.ctg-timer-display {
    font-family: 'Courier New', monospace;
    font-size: 14px;
    font-weight: 700;
    color: var(--ctg-text-dim);
    background: var(--ctg-surface-2);
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--ctg-border);
}

.ctg-turn-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--ctg-gold-light);
    padding: 6px 12px;
    background: rgba(200,150,12,0.1);
    border: 1px solid var(--ctg-gold-dim);
    border-radius: 20px;
    opacity: 0;
    transition: opacity 0.3s;
}

.ctg-turn-indicator.visible {
    opacity: 1;
}

.ctg-pulse {
    width: 8px;
    height: 8px;
    background: var(--ctg-gold-light);
    border-radius: 50%;
    animation: ctg-pulse 1.5s ease-in-out infinite;
    box-shadow: 0 0 0 0 var(--ctg-glow-gold);
}

@keyframes ctg-pulse {
    0%   { box-shadow: 0 0 0 0 var(--ctg-glow-gold); }
    70%  { box-shadow: 0 0 0 6px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}

/* ── Board Container ──────────────────────────────────────────────────────── */
.ctg-board-container {
    position: relative;
}

.ctg-board-frame {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    box-shadow:
        0 0 0 2px var(--ctg-gold-dim),
        0 0 0 4px var(--ctg-surface),
        0 0 0 5px var(--ctg-border),
        0 8px 40px rgba(0,0,0,0.8),
        0 0 60px rgba(200,150,12,0.1);
}

.ctg-board-canvas {
    display: block;
    max-width: 100%;
    cursor: pointer;
    touch-action: none;
}

/* ── Thinking Overlay ─────────────────────────────────────────────────────── */
.ctg-thinking-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15,12,7,0.75);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    backdrop-filter: blur(2px);
    z-index: 10;
}

.ctg-thinking-overlay.visible {
    display: flex;
}

.ctg-thinking-overlay p {
    font-size: 14px;
    color: var(--ctg-gold-light);
    font-weight: 500;
    letter-spacing: 0.08em;
    margin: 0;
}

.ctg-thinking-dots {
    display: flex;
    gap: 8px;
}

.ctg-thinking-dots span {
    width: 10px;
    height: 10px;
    background: var(--ctg-gold);
    border-radius: 50%;
    animation: ctg-bounce 1.2s ease-in-out infinite;
}

.ctg-thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.ctg-thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ctg-bounce {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
    40%           { transform: scale(1.1); opacity: 1; }
}

/* ── Controls ─────────────────────────────────────────────────────────────── */
.ctg-controls {
    position: relative;
    z-index: 1;
    display: flex;
    gap: 10px;
    padding: 0 24px 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.ctg-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 18px;
    border: 1px solid var(--ctg-border);
    border-radius: 8px;
    font-family: var(--ctg-font-main);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--ctg-transition);
    background: var(--ctg-surface);
    color: var(--ctg-text);
    letter-spacing: 0.02em;
}

.ctg-btn svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.ctg-btn:hover {
    border-color: var(--ctg-gold-dim);
    background: var(--ctg-surface-2);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.ctg-btn:active {
    transform: translateY(0);
}

.ctg-btn-new {
    background: linear-gradient(135deg, #b8820a, #d4a010);
    border-color: var(--ctg-gold);
    color: #0f0c07;
    font-weight: 700;
}

.ctg-btn-new:hover {
    background: linear-gradient(135deg, #d4a010, #f0c030);
    border-color: var(--ctg-gold-light);
    box-shadow: 0 4px 16px var(--ctg-glow-gold);
}

/* ── Status Bar ───────────────────────────────────────────────────────────── */
.ctg-status-bar {
    position: relative;
    z-index: 1;
    padding: 10px 24px 16px;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    color: var(--ctg-text-dim);
    letter-spacing: 0.04em;
    border-top: 1px solid var(--ctg-border);
    background: var(--ctg-surface);
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
.ctg-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
    animation: ctg-fade-in 0.3s ease;
}

.ctg-modal-backdrop.visible {
    display: flex;
}

@keyframes ctg-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.ctg-modal {
    background: var(--ctg-surface);
    border: 1px solid var(--ctg-gold-dim);
    border-radius: 20px;
    padding: 40px 36px;
    max-width: 320px;
    width: 90%;
    text-align: center;
    box-shadow:
        0 0 0 1px var(--ctg-gold-dim),
        0 0 60px var(--ctg-glow-gold),
        0 20px 60px rgba(0,0,0,0.8);
    animation: ctg-slide-up 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes ctg-slide-up {
    from { transform: translateY(30px) scale(0.9); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}

.ctg-modal-icon {
    font-size: 56px;
    line-height: 1;
    margin-bottom: 16px;
    animation: ctg-bounce-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
}

@keyframes ctg-bounce-in {
    from { transform: scale(0); }
    to   { transform: scale(1); }
}

.ctg-modal-title {
    font-family: var(--ctg-font-piece);
    font-size: 28px;
    font-weight: 700;
    color: var(--ctg-gold-light);
    margin: 0 0 10px;
}

.ctg-modal-msg {
    font-size: 14px;
    color: var(--ctg-text-dim);
    margin: 0 0 28px;
    line-height: 1.6;
}

.ctg-modal-btn {
    width: 100%;
    justify-content: center;
    padding: 12px;
    font-size: 15px;
}

/* ── Sound Button ─────────────────────────────────────────────────────────── */
.ctg-btn-sound .ctg-icon-sound,
.ctg-btn-sound .ctg-icon-mute {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.ctg-btn-sound.ctg-muted {
    color: var(--ctg-text-dim);
    border-color: var(--ctg-border);
    opacity: 0.5;
    text-decoration: line-through;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 580px) {
    .ctg-header      { padding: 14px 16px; }
    .ctg-main        { padding: 14px 16px; }
    .ctg-controls    { padding: 0 16px 16px; gap: 8px; }
    .ctg-status-bar  { padding: 8px 16px 12px; }
    .ctg-btn         { padding: 8px 14px; font-size: 12px; }
    .ctg-board-frame { border-radius: 8px; }

    .ctg-board-canvas {
        width: 100%;
        height: auto;
    }
}
