/* =============================================
   BAGHCHAL — Design System & Styles
   ============================================= */

:root {
    /* Colors */
    --bg-primary: #d9d9d9;
    --bg-secondary: #ffffff;
    --bg-card: #f3f4f6;
    --bg-board: #f9fafb;
    --board-surface: #f9fafb;
    --board-line: #221105;
    --text-primary: #1a1b1e;
    --text-secondary: #495057;
    --text-muted: #868e96;
    --accent-goat: #0277bd;
    --accent-goat-dark: #01579b;
    --accent-tiger: #d32f2f;
    --accent-tiger-dark: #b71c1c;
    --accent-gold: #f59f00;
    --accent-green: #2b8a3e;
    --danger: #e03131;
    --border: #dee2e6;

    /* Typography */
    --font: "Inter", system-ui, -apple-system, sans-serif;

    /* Spacing */
    --radius: 12px;
    --radius-sm: 8px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ---- App Layout ---- */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ---- Header ---- */
.header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 28px;
    z-index: 10;
    pointer-events: none;
}

.header-title,
.header .btn-restart {
    pointer-events: auto;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-icon {
    font-size: 24px;
    color: var(--accent-gold);
}

.header h1 {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 3px;
    color: var(--text-primary);
}

/* ---- Buttons ---- */
.btn {
    font-family: var(--font);
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 1px;
    padding: 8px 20px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-restart {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-restart:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

/* ---- Game Area ---- */
.game-area {
    margin: 4vh 0 auto 0;
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 24px;
    padding: 60px 20px 80px 20px;
    transform: none;
}

.scores-col,
.logs-col {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.scores-col .panel {
    flex: 1;
    justify-content: center;
}

.btn-replay-launch {
    width: 100%;
    min-height: 48px;
    background: linear-gradient(135deg,
            rgba(34, 17, 5, 0.92),
            rgba(72, 44, 18, 0.92));
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 10px 24px rgba(34, 17, 5, 0.18);
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition:
        opacity 0.2s ease,
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.btn-replay-launch.show {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

.btn-replay-launch:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 14px 28px rgba(34, 17, 5, 0.24);
}

.btn-replay-launch:disabled,
.replay-step-btn:disabled {
    cursor: not-allowed;
    opacity: 0.45;
    box-shadow: none;
    transform: none;
}

.logs-panel {
    flex: 1;
    min-height: 0;
    max-height: min(55vw, 77vh);
    display: flex;
    flex-direction: column;
}

.logs-panel .panel-log {
    flex: 1;
    min-height: 0;
    max-height: none;
    margin-top: 0;
}

/* ---- Side Panels ---- */
.panel {
    display: flex;
    flex-direction: column;
    position: relative;
    width: 10vw;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 16px;
    flex-shrink: 0;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
    transition: box-shadow 0.3s ease;
}

.panel::before {
    content: "";
    position: absolute;
    top: 0;
    left: -1px;
    /* Cover the border */
    bottom: 0;
    width: 6px;
    background: transparent;
    border-top-left-radius: var(--radius);
    border-bottom-left-radius: var(--radius);
    transition: background 0.3s ease;
}

.panel.active::before {
    background: #1e3a8a;
    /* Navy Blue for Goat */
}

#panelBagh.active::before {
    background: #e21d1d;
    /* Red for Tiger */
}

.panel-right::before {
    left: auto;
    right: -1px;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-top-right-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--text-secondary);
}

.piece-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-size: 80%;
    background-position: center;
    background-repeat: no-repeat;
}

.piece-icon-bakhra {
    background-color: transparent;
    background-image: url("goat.png");
    border: 2px solid var(--accent-goat);
}

.piece-icon-bagh {
    background-color: transparent;
    background-image: url("Tiger.png");
    border: 2px solid var(--accent-tiger);
}

.stat-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-value {
    font-size: 20px;
    font-weight: 800;
    color: #000;
    font-variant-numeric: tabular-nums;
}

.stat-value-danger {
    color: #000;
}

.stat-value-warn {
    color: #000;
}

/* ---- Board Container ---- */
.board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

.turn-banner {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 1.5px;
    color: var(--text-primary);
    text-transform: uppercase;
    white-space: nowrap;
}

.board-actions {
    position: absolute;
    bottom: -60px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 16px;
    width: max-content;
}

.board-wrapper {
    width: min(55vw, 77vh);
    min-height: 400px;
    aspect-ratio: 1 / 1;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-secondary);
    box-shadow:
        0 16px 48px rgba(0, 0, 0, 0.1),
        0 0 0 1px rgba(0, 0, 0, 0.04);
}

#gameCanvas {
    display: block;
    cursor: pointer;
    width: 100%;
    height: 100%;
    touch-action: none;
    /* Crucial for mobile drag */
    -webkit-tap-highlight-color: transparent;
}

/* ---- Game Over Overlay ---- */
.game-over-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    border-radius: var(--radius);
    z-index: 10;
    animation: fadeIn 0.4s ease;
}

.game-over-overlay.show {
    display: flex;
}

.game-over-card {
    text-align: center;
    padding: 36px 48px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.game-over-card h2 {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: 2px;
    margin-bottom: 8px;
}

.game-over-card p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.game-over-card .btn {
    padding: 10px 28px;
    font-size: 14px;
    background: var(--accent-gold);
    color: var(--bg-primary);
}

.game-over-card .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(245, 159, 0, 0.3);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* ---- Replay Bar ---- */
.replay-bar {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 15;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.replay-bar.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.replay-content {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    background: rgba(26, 27, 30, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}

.replay-badge {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 2px;
    color: #ffd740;
    background: rgba(255, 215, 64, 0.12);
    padding: 3px 8px;
    border-radius: 4px;
}

.replay-nav {
    display: flex;
    align-items: center;
    gap: 10px;
}

.replay-step-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 26px;
    padding: 0 6px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 5px;
    line-height: 1;
    cursor: pointer;
    transition:
        background 0.2s ease,
        transform 0.2s ease,
        opacity 0.2s ease;
}

.replay-step-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.16);
    transform: translateY(-1px);
}

.replay-position {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    font-variant-numeric: tabular-nums;
    min-width: 90px;
    text-align: center;
}

.replay-hint {
    font-size: 11px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.4);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    padding-left: 16px;
}

/* ---- Panel Move Logs ---- */
.panel-log {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    /* allow it to fill remaining space if we make panel flex column */
    min-height: 100px;
    max-height: 250px;
}

.panel-log-header {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.panel-log-scroll {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.panel-log-scroll::-webkit-scrollbar {
    width: 4px;
}

.panel-log-scroll::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.log-entry {
    font-size: 12px;
    font-weight: 500;
    color: #000;
    padding: 4px 6px;
    background: transparent;
    border-radius: 4px;
    border-left: 2px solid transparent;
}

.log-entry:last-child {
    font-weight: 600;
}

.log-entry:last-child.log-goat {
    border-left-color: var(--accent-goat);
}

.log-entry:last-child.log-tiger {
    border-left-color: var(--accent-tiger);
}

.log-entry:last-child.log-capture {
    border-left-color: var(--danger);
}

.log-entry:last-child.log-system {
    border-left-color: var(--text-secondary);
}

.log-entry:last-child.log-win {
    border-left-color: var(--accent-gold);
}

.log-entry.log-active {
    background: rgba(2, 119, 189, 0.1);
    border-left-color: var(--accent-goat) !important;
    font-weight: 600;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.log-entry.log-active.log-tiger,
.log-entry.log-active.log-capture {
    background: rgba(211, 47, 47, 0.08);
    border-left-color: var(--accent-tiger) !important;
}

.log-entry.log-active.log-system {
    background: rgba(73, 80, 87, 0.08);
    border-left-color: var(--text-secondary) !important;
}

/* ---- Buy Me a Momo Widget ---- */
.momo-container {
    position: fixed;
    bottom: 30px;
    left: 30px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    cursor: pointer;
}

.momo-img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    filter: drop-shadow(0 10px 15px rgba(0, 0, 0, 0.15));
    animation: bounceFloat 3s ease-in-out infinite;
    transition: transform 0.3s ease;
}

.momo-container:hover .momo-img {
    transform: scale(1.1);
    animation-play-state: paused;
}

.momo-tooltip {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 12px;
    background: #fff8e7;
    color: #4a2e14;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    pointer-events: none;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    animation: attentionTooltip 5s infinite;
}

.momo-tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 40px;
    transform: translateX(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: #fff8e7 transparent transparent transparent;
}

.momo-container:hover .momo-tooltip {
    opacity: 1;
    transform: translateY(0);
    animation: none;
}

.momo-steam-container {
    position: absolute;
    bottom: 60px;
    /* Base of the steam above the image */
    left: 40px;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    opacity: 1;
    pointer-events: none;
    animation: hideSteam 5s infinite;
}

.momo-container:hover .momo-steam-container {
    opacity: 0;
    animation: none;
}

.steam {
    width: 10px;
    height: 30px;
    border-radius: 50%;
    filter: blur(1px);
    opacity: 0;
    background: transparent;
}

.steam-1 {
    border-left: 2px solid rgba(120, 110, 100, 0.6);
    animation: floatSteamA 2.6s infinite ease-in;
}

.steam-2 {
    border-right: 2px solid rgba(120, 110, 100, 0.5);
    animation: floatSteamB 2.2s infinite ease-in 0.4s;
}

.steam-3 {
    border-left: 2px solid rgba(120, 110, 100, 0.7);
    animation: floatSteamA 2.8s infinite ease-in 1s;
}

.steam-4 {
    border-right: 2px solid rgba(120, 110, 100, 0.5);
    animation: floatSteamB 2.4s infinite ease-in 0.7s;
}

@keyframes floatSteamA {
    0% {
        transform: translateY(0) translateX(0) scale(1);
        opacity: 0;
    }

    30% {
        opacity: 1;
    }

    60% {
        transform: translateY(-25px) translateX(3px) scale(1.2);
    }

    100% {
        transform: translateY(-50px) translateX(-4px) scale(1.5);
        opacity: 0;
    }
}

@keyframes floatSteamB {
    0% {
        transform: translateY(0) translateX(0) scale(1);
        opacity: 0;
    }

    30% {
        opacity: 1;
    }

    60% {
        transform: translateY(-25px) translateX(-3px) scale(1.2);
    }

    100% {
        transform: translateY(-50px) translateX(4px) scale(1.5);
        opacity: 0;
    }
}

@keyframes hideSteam {

    0%,
    75%,
    100% {
        opacity: 1;
    }

    80%,
    95% {
        opacity: 0;
    }
}

@keyframes bounceFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-12px);
    }
}

@keyframes attentionTooltip {

    0%,
    75%,
    100% {
        opacity: 0;
        transform: translateY(10px);
    }

    80%,
    95% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---- Responsive ---- */
@media (max-width: 1100px) {
    .game-area {
        flex-direction: column;
        align-items: center;
        gap: 32px;
        padding: 40px 16px 60px 16px;
        transform: none;
    }

    .turn-banner,
    .board-actions,
    .replay-bar {
        position: static;
        transform: none;
        margin: 0;
    }

    .replay-bar {
        opacity: 0;
        pointer-events: none;
    }

    .replay-bar.show {
        opacity: 1;
        transform: none;
        pointer-events: auto;
    }

    .board-container {
        gap: 16px;
        width: 100%;
        max-width: 600px;
    }


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

    .scores-col {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        width: 100%;
        max-width: 600px;
        order: 1;
    }

    .desktop-only {
        display: none !important;
    }

    .board-container {
        order: 2;
    }

    #panelBakhra {
        grid-column: 1;
        grid-row: 1;
    }

    #panelBagh {
        grid-column: 2;
        grid-row: 1;
    }

    .btn-replay-launch {
        grid-column: 1 / -1;
        grid-row: 2;
        max-width: 100%;
        margin-top: 4px;
    }

    .panel {
        width: 100%;
        max-width: 100%;
        flex-direction: column;
        align-items: center;
        padding: 16px 12px;
    }

    .panel-header {
        flex-direction: column;
        justify-content: center;
        margin-bottom: 12px;
        margin-right: 0;
        padding-bottom: 12px;
        border-bottom: 1px solid var(--border);
        border-right: none;
        padding-right: 0;
        width: 100%;
        gap: 6px;
    }

    .panel-right::before {
        left: -1px;
        right: auto;
        border-radius: var(--radius) 0 0 var(--radius);
    }

    .panel .stat-grid {
        flex-direction: column;
        gap: 10px;
        width: 100%;
    }

    .stat {
        flex-direction: row;
        justify-content: space-between;
        width: 100%;
        text-align: left;
    }

    .panel-log {
        display: none;
    }
}

@media (max-width: 500px) {
    .panel-header h2 {
        display: block;
        font-size: 12px;
    }

    .panel-header {
        margin-bottom: 8px;
        padding-bottom: 8px;
        gap: 4px;
    }

    .panel {
        padding: 12px 10px;
    }

    .panel .stat-grid {
        gap: 6px;
    }

    .scores-col {
        gap: 8px;
    }

    .stat-label {
        font-size: 10px;
    }

    .stat-value {
        font-size: 14px;
    }

    .header {
        padding: 10px 16px;
    }

    .game-area {
        margin: 0;
        padding: 50px 8px 16px 8px;
        gap: 12px;
        min-height: 100svh;
        overflow: hidden;
    }

    .board-container {
        gap: 8px;
        width: 100%;
        align-items: center;
    }

    .board-wrapper {
        width: 100%;
        max-width: calc(100svh - 320px);
        max-height: calc(100svh - 320px);
        margin: 0 auto;
    }

    .momo-container {
        bottom: 80px;
        top: auto;
        left: auto;
        right: 12px;
    }

    .momo-img {
        width: 45px;
        height: 45px;
    }

    .momo-steam-container {
        bottom: 35px;
        left: 22px;
    }

    .momo-tooltip {
        font-size: 11px;
        padding: 6px 10px;
        margin-bottom: 8px;
        left: auto;
        right: 0;
    }

    .momo-tooltip::after {
        left: auto;
        right: 22px;
        transform: translateX(50%);
        border-width: 5px;
    }
}