/* ==========================================================================
   Jungle — Dou Shou Qi (web edition)
   Palette recreated from the desktop WPF app: TerrainBrushConverter and
   PieceBrushConverter are the spec.
   ========================================================================== */

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
    background: radial-gradient(1200px 800px at 20% -10%, #f7efe0 0%, #efe3cc 45%, #e3d2b4 100%);
    color: #3e3226;
}

h1, h2, h3 {
    font-weight: 700;
    color: #4a3521;
}

/* --- Page shell ---------------------------------------------------------------- */

.page main {
    min-height: 100dvh;
}

.game-shell {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px 20px 32px;
}

.game-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px 16px;
    margin-bottom: 14px;
}

.game-header h1 {
    margin: 0;
    font-size: 1.9rem;
    letter-spacing: 0.5px;
}

.game-header .subtitle {
    font-size: 1rem;
    font-weight: 400;
    color: #8a7358;
    margin-left: 8px;
}

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

.badge {
    font-size: 0.72rem;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(122, 96, 61, 0.25);
    color: #6b5638;
    white-space: nowrap;
}

.badge-ok {
    background: #e6f4e8;
    border-color: #7db98a;
    color: #2f6b3c;
}

.badge-warn {
    background: #fdf0dc;
    border-color: #d9a441;
    color: #8a5a10;
}

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

/* --- Board column --------------------------------------------------------------- */

.board-column {
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(122, 96, 61, 0.2);
    border-radius: 8px;
}

.status-text {
    font-weight: 700;
    font-size: 1.02rem;
}

.status-text.thinking::after {
    content: " ⏳";
}

.turn-text {
    color: #7a6549;
    font-size: 0.9rem;
}

.board-wrap {
    position: relative;
    width: min(92vw, 500px, calc((100dvh - 235px) * 7 / 9));
}

.board-frame {
    background: linear-gradient(145deg, #7a5638, #6D4C2F 55%, #5d3f25);
    padding: 12px;
    border-radius: 8px;
    box-shadow: 0 10px 24px rgba(61, 41, 20, 0.45);
}

.board-inner {
    position: relative;
    width: 100%;
    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 #B7AE97;
    cursor: pointer;
    overflow: hidden;
}

/* Terrain: checkerboard land tinted per zone, rippled river, tinted traps/dens. */
.square.terrain-land.zone-blue.checker-light { background: #EAF3FC; }
.square.terrain-land.zone-blue.checker-dark  { background: #CFE2F6; }
.square.terrain-land.zone-red.checker-light  { background: #FCECF1; }
.square.terrain-land.zone-red.checker-dark   { background: #F6D3DF; }
.square.terrain-land.zone-neutral.checker-light { background: #F4EFE2; }
.square.terrain-land.zone-neutral.checker-dark  { background: #E5DDC9; }

.square.terrain-river {
    background: linear-gradient(to bottom, #8FC1EA, #5E9CD6);
    cursor: default;
}

.square.terrain-trap.zone-blue { background: #CBE8FA; }
.square.terrain-trap.zone-red  { background: #FAD3E1; }

.square.terrain-den.zone-blue { background: #A5D4F0; }
.square.terrain-den.zone-red  { background: #F2B6CA; }

.river-waves, .trap-marker, .den-marker {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.river-waves path {
    fill: none;
    stroke: #EAF4FD;
    stroke-width: 2.5;
    opacity: 0.75;
}

.trap-marker polygon {
    fill: #FFB300;
    opacity: 0.5;
    stroke: #E65100;
    stroke-width: 1.5;
}

.den-marker polygon {
    fill: #F9A825;
    opacity: 0.6;
    stroke: #F57F17;
    stroke-width: 1.5;
}

/* Highlights */
.highlight-lastmove {
    position: absolute;
    inset: 0;
    border: 3px solid #4FC3F7;
    opacity: 0.85;
    pointer-events: none;
}

.highlight-selected {
    position: absolute;
    inset: 0;
    border: 3.5px solid #FFD700;
    background: rgba(255, 215, 0, 0.18);
    pointer-events: none;
}

.highlight-target {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 31%;
    height: 31%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: rgba(67, 160, 71, 0.47);
    border: 1px solid #2E7D32;
    pointer-events: none;
}

.highlight-capture {
    position: absolute;
    inset: 6%;
    border-radius: 50%;
    border: 3.5px solid #E53935;
    pointer-events: none;
}

/* Piece layer — absolutely positioned above the grid; moves animate via transitions.
   Pieces never intercept clicks: squares own all input. */
.piece-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.piece {
    position: absolute;
    width: calc(100% / 7);
    height: calc(100% / 9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: left 0.18s ease, top 0.18s ease;
    container-type: size;
}

.piece .disc {
    width: 78%;
    aspect-ratio: 1;
    border-radius: 50%;
    border-width: 2.5px;
    border-style: solid;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

.piece.blue .disc {
    background: radial-gradient(circle at 35% 30%, #F2F8FE, #9DCBF2);
    border-color: #1565C0;
}

.piece.red .disc {
    background: radial-gradient(circle at 35% 30%, #FEF3F3, #EFA3A3);
    border-color: #C62828;
}

.piece .emoji {
    font-size: 34cqw;
    line-height: 1;
}

.piece .code {
    font-size: 12.5cqw;
    font-weight: 700;
    line-height: 1.1;
}

.piece.blue .code { color: #0D47A1; }
.piece.red .code  { color: #B71C1C; }

.piece .piece-name {
    margin-top: 1px;
    font-size: 10.5cqw;
    font-weight: 600;
    line-height: 1.15;
    padding: 0 4px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.78);
    white-space: nowrap;
}

.piece.blue .piece-name { color: #0D47A1; }
.piece.red .piece-name  { color: #B71C1C; }

.search-info {
    min-height: 1.3em;
    font-size: 0.8rem;
    color: #7a6549;
    font-variant-numeric: tabular-nums;
    padding: 0 4px;
}

/* Result overlay */
.result-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(38, 26, 13, 0.45);
    border-radius: 8px;
    z-index: 5;
}

.result-panel {
    background: #fffaf0;
    border: 2px solid #c9a25e;
    border-radius: 12px;
    padding: 26px 34px;
    text-align: center;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.result-message {
    font-size: 1.5rem;
    font-weight: 800;
    color: #4a3521;
    margin-bottom: 16px;
}

/* --- Control panel ---------------------------------------------------------------- */

.control-panel {
    flex: 1 1 300px;
    max-width: 340px;
    min-width: 270px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(122, 96, 61, 0.22);
    border-radius: 10px;
    padding: 16px 18px;
    box-shadow: 0 6px 18px rgba(97, 71, 41, 0.16);
    max-height: calc(100dvh - 120px);
    overflow-y: auto;
}

.control-panel h2 {
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: #8a7358;
    margin: 18px 0 8px;
    border-bottom: 1px solid rgba(122, 96, 61, 0.2);
    padding-bottom: 4px;
}

.control-panel h2:first-child {
    margin-top: 0;
}

.field {
    display: block;
    margin-bottom: 10px;
    font-size: 0.86rem;
}

.field span {
    display: block;
    margin-bottom: 3px;
    color: #6b5638;
    font-weight: 600;
}

.field select {
    width: 100%;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid #c9b692;
    background: #fffdf7;
    font: inherit;
    color: #3e3226;
}

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

.btn {
    flex: 1;
    padding: 7px 12px;
    border-radius: 7px;
    border: 1px solid #b99c6d;
    background: #fff8ea;
    color: #4a3521;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s ease, transform 0.05s ease;
}

.btn:hover:not(:disabled) {
    background: #f7ead0;
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

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

.btn-primary {
    background: #6D4C2F;
    border-color: #543a22;
    color: #fdf6e8;
}

.btn-primary:hover:not(:disabled) {
    background: #7d5936;
}

.captured {
    font-size: 0.95rem;
}

.captured-row {
    margin-bottom: 4px;
    line-height: 1.5;
    word-break: break-all;
}

.captured-label {
    font-weight: 700;
    font-size: 0.8rem;
    color: #6b5638;
}

.move-history {
    max-height: 220px;
    overflow-y: auto;
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(122, 96, 61, 0.15);
    border-radius: 6px;
    padding: 6px 8px;
}

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

.credits {
    margin-top: 18px;
    font-size: 0.72rem;
    color: #8a7358;
    line-height: 1.5;
}

/* --- Modal (How to play) ------------------------------------------------------------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(30, 20, 10, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 20px;
}

.modal-panel {
    background: #fffaf0;
    border-radius: 12px;
    max-width: 640px;
    width: 100%;
    max-height: 85dvh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.4);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid #e2d3b3;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.15rem;
}

.modal-close {
    flex: 0;
    padding: 4px 10px;
}

.modal-body {
    padding: 8px 20px 20px;
    overflow-y: auto;
    font-size: 0.92rem;
    line-height: 1.55;
}

.modal-body h3 {
    margin: 16px 0 6px;
    font-size: 0.98rem;
}

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

.modal-body ul {
    margin: 6px 0;
    padding-left: 20px;
}

.modal-body li {
    margin-bottom: 6px;
}

/* --- Boot overlay --------------------------------------------------------------------- */

.boot-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: radial-gradient(1200px 800px at 20% -10%, #f7efe0 0%, #efe3cc 45%, #e3d2b4 100%);
    z-index: 100;
}

.boot-spinner {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 5px solid rgba(109, 76, 47, 0.25);
    border-top-color: #6D4C2F;
    animation: boot-spin 0.9s linear infinite;
}

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

.boot-title {
    font-size: 1.6rem;
    font-weight: 800;
    color: #4a3521;
}

.boot-status {
    font-size: 0.95rem;
    color: #6b5638;
}

.boot-status.boot-error {
    color: #b3261e;
    max-width: 70ch;
    text-align: center;
}

.boot-note {
    font-size: 0.78rem;
    color: #9a8468;
}

/* --- Blazor error UI -------------------------------------------------------------------- */

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .reload {
    margin-left: 8px;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* --- Responsive --------------------------------------------------------------------------- */

@media (max-width: 920px) {
    .game-main {
        flex-direction: column;
        align-items: center;
    }

    .board-wrap {
        width: min(94vw, calc((100dvh - 330px) * 7 / 9), 500px);
    }

    .control-panel {
        max-width: 560px;
        width: 100%;
        max-height: none;
    }
}
