/* Jungle (Dou Shou Qi) — web edition.
   Palette and composition recreate the desktop WPF app (JungleGame.UI Themes/Theme.xaml +
   Views/MainWindow.Rendering.cs): checkerboard land, gradient river with wave lines,
   ⚠ traps, 🏠 dens, radial-gradient discs with emoji + rank pip + name. */

:root {
    --window-bg-top: #252540;
    --window-bg-bottom: #1a1a28;
    --panel: #2a2a3e;
    --panel-border: #3a3a50;
    --board-frame: #3d2b1f;
    --land: #e8c897;
    --land-alt: #dfc08d;
    --river-top: #4169e1;
    --river-bottom: #2149b1;
    --river-wave: rgba(255, 255, 255, 0.5);
    --trap: #c94f4f;
    --trap-marker: #ffeb3b;
    --den: #7a0000;
    --den-frame: #b30000;
    --grid-line: #3c281e;
    --terrain-stroke: #64503c;
    --gold: #ffd700;
    --legal: #00cc00;
    --capture: #ff4444;
    --shadow: rgba(0, 0, 0, 0.4);
    --text: #ffffff;
    --text-secondary: #aaaaaa;
    --text-muted: #888888;
    --green: #4caf50;
    --green-light: #66bb6a;
    --green-dark: #388e3c;
    --btn: #555555;
    --btn-hover: #6e6e6e;
    --btn-pressed: #404040;
    --accent: #ff9800;
    --accent-light: #ffb74d;
    --accent-dark: #f57c00;
    --piece-blue-light: #6e8ef0;
    --piece-blue: #4169e1;
    --piece-blue-dark: #2149b1;
    --piece-red-light: #ff4d6d;
    --piece-red: #dc143c;
    --piece-red-dark: #b01030;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: "Segoe UI", system-ui, sans-serif;
    color: var(--text);
    background: linear-gradient(180deg, var(--window-bg-top), var(--window-bg-bottom));
    background-attachment: fixed;
}

/* ---- Boot overlay (shown until Blazor's first render replaces #app) ---- */
.boot-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    min-height: 100vh;
    text-align: center;
}

.boot-spinner {
    width: 56px;
    height: 56px;
    border: 5px solid var(--panel-border);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: boot-spin 1s linear infinite;
}

.boot-title {
    font-size: 28px;
    font-weight: 600;
    letter-spacing: 2px;
}

.boot-status {
    color: var(--text-secondary);
}

.boot-error {
    color: #ff6d6d;
}

.boot-note {
    font-size: 12px;
    color: var(--text-muted);
}

@keyframes boot-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ---- Layout ---- */
.game-shell {
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px;
}

.game-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
}

.game-header h1 {
    margin: 0;
    font-size: 24px;
}

.subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-left: 8px;
}

.header-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 13px;
    border: 1px solid var(--panel-border);
    color: var(--text-secondary);
}

.badge-ok {
    color: var(--green-light);
    border-color: var(--green-light);
}

.badge-warn {
    color: var(--accent-light);
    border-color: var(--accent-light);
}

.game-main {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.board-column {
    flex: 1 1 auto;
    min-width: 0;
}

/* ---- Status bar ---- */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    padding: 6px 4px;
}

.status-text {
    font-size: 18px;
    font-weight: 600;
}

.status-text.thinking {
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
    50% {
        opacity: 0.55;
    }
}

.turn-text {
    font-size: 13px;
    color: var(--text-secondary);
}

.search-info {
    min-height: 20px;
    padding: 6px 4px;
    font-family: Consolas, monospace;
    font-size: 13px;
    color: var(--text-secondary);
}

/* ---- Board ---- */
.board-wrap {
    position: relative;
    display: inline-block;
    width: 100%;
}

.board-frame {
    border: 10px solid var(--board-frame);
    border-radius: 6px;
    background: var(--board-frame);
    max-width: min(72vh, 660px);
    margin: 0 auto;
}

/* Board with a–g / 1–9 coordinate labels (desktop DrawCoordinates); labels show the
   logical square of each display cell, so they rotate with the flip. */
.board-with-coords {
    display: grid;
    grid-template-columns: 1.3em 1fr;
    grid-template-rows: auto 1fr;
    gap: 2px;
}

.side-coords {
    grid-row: 2;
    grid-column: 1;
    display: grid;
    grid-template-rows: repeat(9, 1fr);
}

.side-coords span {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: var(--text-muted);
}

.board-main {
    grid-row: 2;
    grid-column: 2;
    display: grid;
    grid-template-rows: auto 1fr;
}

.top-coords {
    grid-row: 1;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}

.top-coords span {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
}

.board-inner {
    position: relative;
    aspect-ratio: 7 / 9;
}

.board-grid {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: repeat(9, 1fr);
}

.square {
    position: relative;
    border: 0.5px solid var(--terrain-stroke);
    cursor: pointer;
    /* Glyph sizing base: board width is capped at min(72vh, 660px), so a cell is
       at most 94px wide; em-based glyphs scale with the board on any viewport. */
    font-size: min(6.6vh, 9.2vw, 94px);
}

.terrain-land.checker-light {
    background: var(--land);
}

.terrain-land.checker-dark {
    background: var(--land-alt);
}

.terrain-river {
    background: linear-gradient(180deg, var(--river-top), var(--river-bottom));
}

.river-waves {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.river-waves line {
    stroke: var(--river-wave);
    stroke-width: 1.5;
    opacity: 0.6;
}

.terrain-trapblue,
.terrain-trapred {
    background: var(--trap);
}

.trap-glyph {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.34em;
    color: var(--trap-marker);
    pointer-events: none;
}

.terrain-denblue,
.terrain-denred {
    background: var(--den);
    box-shadow: inset 0 0 0 2px var(--den-frame);
}

.den-glyph {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.40em;
    pointer-events: none;
}

/* Highlights (desktop DrawHighlight / DrawLegalMoveIndicator). */
.highlight-selected {
    position: absolute;
    inset: 0;
    background: var(--gold);
    opacity: 0.6;
    box-shadow: inset 0 0 0 3px var(--gold);
    pointer-events: none;
}

.highlight-target {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 44%;
    height: 44%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: var(--legal);
    opacity: 0.63;
    pointer-events: none;
}

.highlight-capture {
    position: absolute;
    inset: 0;
    box-shadow: inset 0 0 0 3px var(--capture);
    border-radius: 50%;
    background: var(--capture);
    opacity: 0.4;
    pointer-events: none;
}

.highlight-lastmove {
    position: absolute;
    inset: 0;
    background: var(--gold);
    pointer-events: none;
}

.lastmove-to {
    opacity: 0.25;
}

.lastmove-from {
    opacity: 0.15;
}

/* ---- Piece layer ---- */
.piece-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.piece {
    position: absolute;
    width: calc(100% / 7);
    height: calc(100% / 9);
    display: flex;
    align-items: center;
    justify-content: center;
    /* Font-size basis so em-based glyphs scale with the board (see .square). */
    font-size: min(6.6vh, 9.2vw, 94px);
    /* Desktop: 200 ms CubicEase EaseOut fly animation. */
    transition: left 200ms cubic-bezier(0.33, 1, 0.68, 1), top 200ms cubic-bezier(0.33, 1, 0.68, 1);
}

.disc {
    position: relative;
    width: 84%;
    height: 84%;
    border-radius: 50%;
    border: 2px solid var(--piece-blue-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 2px 4px var(--shadow);
}

.piece.blue .disc {
    background: radial-gradient(circle at 35% 30%, var(--piece-blue-light) 0%, var(--piece-blue) 45%, var(--piece-blue-dark) 100%);
    border-color: var(--piece-blue-dark);
}

.piece.red .disc {
    background: radial-gradient(circle at 35% 30%, var(--piece-red-light) 0%, var(--piece-red) 45%, var(--piece-red-dark) 100%);
    border-color: var(--piece-red-dark);
}

.emoji,
.emoji-shadow {
    position: absolute;
    left: 50%;
    top: 38%;
    transform: translate(-50%, -50%);
    font-size: 0.46em;
    line-height: 1;
}

.emoji-shadow {
    transform: translate(calc(-50% + 0.02em), calc(-50% + 0.02em));
    color: rgba(0, 0, 0, 0.47);
}

.emoji {
    color: var(--text);
}

.piece-name {
    position: absolute;
    left: 50%;
    top: 68%;
    transform: translate(-50%, -50%);
    font-size: 0.16em;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    text-shadow: 0.01em 0.01em 0.02em rgba(0, 0, 0, 0.7);
}

.rank-pip {
    position: absolute;
    right: 2%;
    bottom: 2%;
    width: 26%;
    height: 26%;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.63);
    color: var(--text);
    font-size: 0.13em;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.trap-badge {
    position: absolute;
    right: 3%;
    top: 3%;
    font-size: 0.24em;
    font-weight: 900;
    color: var(--trap-marker);
    text-shadow: 0.01em 0.01em 0.02em rgba(0, 0, 0, 0.8);
}

/* Desktop capture feedback: expanding, fading gold ring (220 ms QuadraticEase EaseOut). */
.capture-ring {
    position: absolute;
    width: calc(100% / 7 * 0.84);
    height: calc(100% / 9 * 0.84);
    border: 3px solid var(--gold);
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
    animation: capture-ring 220ms cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes capture-ring {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.4);
        opacity: 0;
    }
}

/* ---- Result overlay ---- */
.result-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    border-radius: 6px;
    z-index: 10;
}

.result-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 24px 36px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
}

.result-message {
    font-size: 26px;
    font-weight: 700;
}

/* ---- Control panel ---- */
.control-panel {
    flex: 0 0 260px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-panel h2 {
    margin: 6px 0 2px;
    font-size: 15px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: var(--text-secondary);
}

.field select {
    padding: 6px 8px;
    border-radius: 4px;
    border: 1px solid var(--panel-border);
    background: #1f1f30;
    color: var(--text);
    font-size: 14px;
}

.button-row {
    display: flex;
    gap: 8px;
}

.button-row .btn {
    flex: 1;
}

.captured {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 15px;
}

.captured-label {
    display: inline-block;
    width: 44px;
    color: var(--text-secondary);
    font-size: 13px;
}

.move-history {
    max-height: 240px;
    overflow-y: auto;
    font-family: Consolas, monospace;
    font-size: 12px;
    color: var(--text-secondary);
}

.move-line {
    white-space: pre;
}

.credits {
    margin-top: auto;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ---- Buttons (desktop Primary/Secondary/Accent styles) ---- */
.btn {
    padding: 8px 16px;
    font-size: 14px;
    color: var(--text);
    background: var(--btn);
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.btn:hover {
    background: var(--btn-hover);
}

.btn:active {
    background: var(--btn-pressed);
}

.btn:focus-visible {
    outline: 2px solid var(--gold);
}

.btn:disabled {
    opacity: 0.6;
    cursor: default;
}

.btn-primary {
    background: var(--green);
}

.btn-primary:hover {
    background: var(--green-light);
}

.btn-primary:active {
    background: var(--green-dark);
}

/* ---- Modal ---- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}

.modal-panel {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    max-width: 560px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--panel-border);
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
}

.modal-body {
    padding: 12px 16px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.55;
    color: #dddddd;
}

.modal-body h3 {
    margin: 14px 0 4px;
    font-size: 15px;
    color: var(--text);
}

.modal-body p {
    margin: 0 0 6px;
}

/* ---- Blazor error UI (hidden by default; blazor.webassembly.js toggles it on
   unhandled errors and hides it when the .dismiss anchor is clicked) ---- */
#blazor-error-ui {
    background: rgba(26, 26, 40, 0.97); /* --window-bg-bottom family */
    color: #ff6d6d;                      /* matches .boot-error */
    border-top: 1px solid var(--panel-border);
    bottom: 0;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.5);
    display: none;
    left: 0;
    padding: 0.6rem 3rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    font-size: 14px;
}

#blazor-error-ui .reload {
    margin-left: 8px;
    color: var(--gold);
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
    color: var(--text-secondary);
}

#blazor-error-ui .dismiss:hover {
    color: var(--text);
}

/* ---- Responsive ---- */
@media (max-width: 820px) {
    .game-main {
        flex-direction: column;
        align-items: stretch;
    }

    .control-panel {
        flex-basis: auto;
    }

    .board-frame {
        max-width: none;
    }
}
