/* ── Reset & Base ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    min-height: 100dvh;
    background: #1a1510;
    background-image:
        radial-gradient(ellipse at 50% 0%, rgba(74,59,42,0.5) 0%, transparent 70%),
        repeating-linear-gradient(90deg, rgba(60,48,30,0.15) 0px, rgba(60,48,30,0.15) 2px, transparent 2px, transparent 40px),
        repeating-linear-gradient(0deg, rgba(60,48,30,0.1) 0px, rgba(60,48,30,0.1) 2px, transparent 2px, transparent 40px);
    color: #f5f0e8;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ── Top Bar ─────────────────────────────────────── */
.top-bar {
    width: 100%;
    max-width: 420px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
}

.back-link {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #eebd2b;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
}
.back-link:hover { color: #fcd34d; }

.move-counter {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: #c8b88a;
}
.move-counter .material-symbols-outlined { font-size: 18px; color: #eebd2b; }

/* ── Game Container ──────────────────────────────── */
.game-container {
    width: 100%;
    max-width: 420px;
    padding: 0 16px 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-title {
    font-family: 'MedievalSharp', cursive;
    font-size: 28px;
    color: #eebd2b;
    text-align: center;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
    margin-bottom: 4px;
}

.game-subtitle {
    font-size: 12px;
    color: #9a864c;
    text-align: center;
    margin-bottom: 20px;
}

/* ── Castle Frame ────────────────────────────────── */
.castle-frame {
    position: relative;
    background: linear-gradient(180deg, #3d3425 0%, #2d2616 100%);
    border: 3px solid #5a4a32;
    border-radius: 12px 12px 0 0;
    padding: 16px 16px 4px;
    box-shadow:
        0 0 0 1px rgba(238,189,43,0.1),
        0 8px 32px rgba(0,0,0,0.5),
        inset 0 1px 0 rgba(255,255,255,0.05);
}

.turret {
    position: absolute;
    top: -18px;
    width: 28px;
    height: 18px;
    background: #5a4a32;
    border-radius: 4px 4px 0 0;
}
.turret::before {
    content: '';
    position: absolute;
    top: 0;
    left: 4px;
    right: 4px;
    height: 6px;
    background: repeating-linear-gradient(
        90deg,
        #5a4a32 0px, #5a4a32 4px,
        #3d3425 4px, #3d3425 8px
    );
    border-radius: 2px 2px 0 0;
}
.turret-left { left: 20px; }
.turret-right { right: 20px; }

/* ── Board ───────────────────────────────────────── */
.board {
    position: relative;
    /* 4 cols × 5 rows; cell size set by JS but default here */
    width: calc(4 * 80px + 3 * 4px);
    height: calc(5 * 80px + 4 * 4px);
    background:
        linear-gradient(135deg, rgba(238,189,43,0.03) 25%, transparent 25%) -20px 0,
        linear-gradient(225deg, rgba(238,189,43,0.03) 25%, transparent 25%) -20px 0,
        #251f14;
    border-radius: 8px;
    overflow: hidden;
}

/* Grid lines (visual only) */
.board::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        repeating-linear-gradient(90deg, rgba(90,74,50,0.4) 0px, rgba(90,74,50,0.4) 1px, transparent 1px, transparent 84px),
        repeating-linear-gradient(0deg, rgba(90,74,50,0.4) 0px, rgba(90,74,50,0.4) 1px, transparent 1px, transparent 84px);
    pointer-events: none;
    z-index: 1;
}

/* ── Pieces ───────────────────────────────────────── */
.piece {
    position: absolute;
    background-size: cover;
    background-position: center;
    border-radius: 8px;
    cursor: pointer;
    transition: top 0.15s ease, left 0.15s ease;
    z-index: 2;
    border: 2px solid rgba(238,189,43,0.3);
    box-shadow:
        0 2px 8px rgba(0,0,0,0.4),
        inset 0 1px 0 rgba(255,255,255,0.1);
    overflow: hidden;
}

.piece::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.08) 0%, transparent 50%, rgba(0,0,0,0.15) 100%);
    border-radius: 6px;
    pointer-events: none;
}

.piece:hover {
    border-color: rgba(238,189,43,0.6);
    box-shadow:
        0 2px 12px rgba(238,189,43,0.2),
        0 4px 16px rgba(0,0,0,0.4),
        inset 0 1px 0 rgba(255,255,255,0.1);
    z-index: 3;
}

.piece:active {
    transform: scale(0.97);
}

/* Hero piece special glow */
.piece.hero {
    border-color: rgba(238,189,43,0.5);
    box-shadow:
        0 0 16px rgba(238,189,43,0.15),
        0 2px 8px rgba(0,0,0,0.4),
        inset 0 1px 0 rgba(255,255,255,0.1);
}

/* Piece name label */
.piece-label {
    position: absolute;
    bottom: 4px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    pointer-events: none;
    z-index: 1;
}

.piece.hero .piece-label {
    font-size: 13px;
    bottom: 8px;
    color: #eebd2b;
}

/* ── Port Gate (Exit) ────────────────────────────── */
.port-gate {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 0;
    background: linear-gradient(180deg, #2d2616 0%, #1a1510 100%);
    border: 3px solid #5a4a32;
    border-top: none;
    border-radius: 0 0 12px 12px;
    margin: 0 -3px -3px;
    /* Highlight the middle exit area */
    background-image:
        linear-gradient(90deg, transparent 25%, rgba(238,189,43,0.08) 25%, rgba(238,189,43,0.08) 75%, transparent 75%);
}

.gate-icon {
    font-size: 18px;
    color: #eebd2b;
    font-variation-settings: 'FILL' 1;
}

.gate-label {
    font-family: 'MedievalSharp', cursive;
    font-size: 12px;
    letter-spacing: 2px;
    color: #9a864c;
    text-transform: uppercase;
}

/* ── Controls ────────────────────────────────────── */
.controls {
    margin-top: 20px;
    display: flex;
    gap: 12px;
}

.btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 12px;
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s;
    text-decoration: none;
}
.btn:active { transform: scale(0.95); }

.btn-reset {
    background: #3d3425;
    color: #c8b88a;
    border: 1px solid #5a4a32;
}
.btn-reset:hover {
    background: #4a3b2a;
    color: #eebd2b;
}

/* ── Victory Overlay ─────────────────────────────── */
.victory-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}
.victory-overlay.show {
    display: flex;
}

.victory-modal {
    background: linear-gradient(180deg, #fcfbf8 0%, #f5f0e8 100%);
    border-radius: 24px;
    padding: 32px 24px;
    max-width: 360px;
    width: 100%;
    text-align: center;
    box-shadow: 0 16px 48px rgba(0,0,0,0.4);
    animation: modal-in 0.4s ease;
}

@keyframes modal-in {
    from { transform: scale(0.8) translateY(20px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

.victory-icon { font-size: 48px; margin-bottom: 8px; }
.victory-title {
    font-family: 'MedievalSharp', cursive;
    font-size: 28px;
    color: #4a3b2a;
    margin-bottom: 4px;
}
.victory-text {
    font-size: 16px;
    color: #4a3b2a;
    margin-bottom: 4px;
}
.victory-moves {
    font-size: 14px;
    color: #9a864c;
    margin-bottom: 16px;
}

.victory-reward {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #eebd2b20;
    border: 1px solid #eebd2b40;
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 20px;
}
.victory-reward .material-symbols-outlined {
    font-size: 24px;
    color: #eebd2b;
    font-variation-settings: 'FILL' 1;
}
.victory-reward p {
    font-size: 13px;
    color: #4a3b2a;
    text-align: left;
}

.victory-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-coffee {
    background: #eebd2b;
    color: #1b180d;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(238,189,43,0.3);
}
.btn-coffee:hover { background: #fcd34d; }

.btn-play-again {
    background: transparent;
    color: #9a864c;
    border: 1px solid #d4c9a8;
    justify-content: center;
}
.btn-play-again:hover { background: #f5f0e8; color: #4a3b2a; }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 380px) {
    .game-title { font-size: 24px; }
    .castle-frame { padding: 12px 12px 4px; }
}
