/* =====================================================================
   RESPONSIVE / MOBILE LAYER
   Loaded AFTER style.css. Every original rule is left untouched, this
   file only adapts the existing layout to the current viewport:
     • fluid sizing for phones, tablets, laptops, desktops and TVs
     • safe-area (notch / punch-hole) padding on every screen
     • dedicated portrait and landscape game layouts
     • no horizontal scrolling, no clipped content, no overlapping UI
     • restores touch scrolling inside panels (body uses touch-action:none)
     • visible keyboard focus ring for every control
   ===================================================================== */

:root {
    --app-h: 100vh;
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-l: env(safe-area-inset-left, 0px);
    --gap: clamp(8px, 1.6vmin, 14px);
    --focus: var(--gold-light);
}

@supports (height: 100dvh) {
    :root { --app-h: 100dvh; }
}

* {
    -webkit-touch-callout: none;
}

html {
    height: 100%;
    width: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

html,
body {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

/* Lock the page to the visual viewport: no rubber-banding, no scroll.
   touch-action stays on the body for the board's gestures, but panels
   below are individually re-enabled with pan-y. */
body {
    position: fixed;
    inset: 0;
    height: var(--app-h, 100dvh);
    max-height: 100%;
    touch-action: pan-y;
}

/* ---------- shared screen shell ---------- */
.screen {
    width: 100%;
    max-width: 100%;
    height: var(--app-h, 100dvh);
    max-height: 100%;
    overflow: hidden;
}

#main-menu {
    box-sizing: border-box;
    padding: calc(var(--safe-t) + 4px) calc(var(--safe-r) + 4px) calc(var(--safe-b) + 4px) calc(var(--safe-l) + 4px);
}

/* Menu must never clip: it scrolls if the viewport is very short */
.menu-content {
    box-sizing: border-box;
    width: 100%;
    max-width: min(560px, 100%);
    max-height: 100%;
    padding: 4px 2px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

.game-title {
    font-size: clamp(1.7rem, 9.5vmin, 6rem);
    line-height: 1.05;
    letter-spacing: 0.12em;
    word-break: break-word;
}

.game-subtitle {
    font-size: clamp(0.55rem, 2.4vmin, 1.1rem);
    letter-spacing: 0.3em;
    margin-bottom: clamp(1rem, 4vmin, 3em);
}

.menu-buttons {
    width: 100%;
    gap: var(--gap);
}

.btn {
    min-width: min(120px, 75vw);
    max-width: 100%;
    padding: clamp(9px, 1.9vmin, 14px) clamp(18px, 5vmin, 48px);
    font-size: clamp(0.78rem, 1.95vmin, 1rem);
    touch-action: manipulation;
}

.btn-sm {
    padding: clamp(7px, 1.5vmin, 10px) clamp(14px, 3.5vmin, 32px);
    font-size: clamp(0.72rem, 1.6vmin, 0.85rem);
    min-width: min(150px, 46vw);
}

.btn-back {
    margin-top: 16px;
    padding: 9px 26px;
    min-width: 110px;
    touch-action: manipulation;
}

.btn-difficulty {
    padding: clamp(9px, 1.7vmin, 12px) clamp(14px, 3.5vmin, 28px);
    font-size: clamp(0.72rem, 1.7vmin, 0.9rem);
    min-width: min(100px, 30vw);
    touch-action: manipulation;
}

/* ---------- fullscreen button ---------- */
.btn-fullscreen {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.fs-glyph {
    flex: 0 0 auto;
    width: 1.05em;
    height: 1.05em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.fs-glyph-out {
    display: none;
}

.btn-fullscreen[aria-pressed="true"] .fs-glyph-in {
    display: none;
}

.btn-fullscreen[aria-pressed="true"] .fs-glyph-out {
    display: block;
}

.btn-fullscreen[aria-pressed="true"] {
    border-color: var(--gold);
    color: var(--gold-light);
}

.btn-fullscreen.is-busy {
    opacity: 0.7;
}

/* ---------- panels / modals ---------- */
.panel-overlay {
    box-sizing: border-box;
    padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 10px) calc(var(--safe-b) + 10px) calc(var(--safe-l) + 10px);
    overflow: hidden;
}

.panel {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: min(600px, 100%);
    max-width: 100%;
    max-height: 100%;
    padding: clamp(14px, 4vmin, 40px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

.panel-scroll {
    max-height: 100%;
    text-align: left;
}

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

.panel-title {
    font-size: clamp(1.25rem, 4.4vmin, 2.2rem);
}

.panel-subtitle {
    font-size: clamp(0.95rem, 2.4vmin, 1.1rem);
    margin: 1.2em 0 0.7em;
}

.panel > .btn-back {
    margin-top: auto;
    flex: 0 0 auto;
}

.mode-cards {
    gap: clamp(10px, 2.4vmin, 20px);
    margin: clamp(10px, 2.4vmin, 20px) 0;
}

.mode-card {
    padding: clamp(14px, 3vmin, 30px) clamp(12px, 2.6vmin, 24px);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* Keep the mode titles/descriptions aligned between cards and push the
   SELECT button to the bottom so both buttons line up on any screen. */
.mode-card h3 {
    min-height: 2em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mode-card p {
    flex: 0 0 auto;
}

.mode-card .btn-sm {
    margin-top: auto;
    width: 100%;
    max-width: 120px;
}

.mode-icon {
    font-size: clamp(1.8rem, 6vmin, 2.5rem);
}

.settings-list {
    gap: clamp(8px, 1.6vmin, 12px);
    margin: clamp(10px, 2.4vmin, 20px) 0;
}

.setting-row {
    padding: clamp(8px, 1.8vmin, 12px) clamp(10px, 2.4vmin, 16px);
}

.setting-row span {
    font-size: clamp(0.72rem, 1.9vmin, 0.9rem);
    letter-spacing: 0.03em;
    padding-right: 10px;
}

.toggle-btn {
    flex: 0 0 auto;
    padding: 6px 16px;
    min-width: 56px;
    font-size: clamp(0.7rem, 1.7vmin, 0.8rem);
    touch-action: manipulation;
}

.rules-content {
    padding: 0;
}

.rule-section {
    margin-bottom: clamp(10px, 2.2vmin, 20px);
}

.rule-section h3 {
    font-size: clamp(0.8rem, 2vmin, 0.95rem);
}

.rule-section p {
    font-size: clamp(0.78rem, 1.95vmin, 0.9rem);
    line-height: 1.45;
}

.victory-icon {
    font-size: clamp(2.4rem, 9vmin, 4rem);
}

/* HOW TO PLAY / SETTINGS are `.screen` (z-index 1) but are also shown as
   overlays above the pause menu (`.overlay-screen`, z-index 100). Raise
   them above every in-game overlay so they are never hidden underneath. */
#how-to-play,
#settings-screen {
    z-index: 120;
}

/* ---------- game screen ---------- */
#game-screen {
    box-sizing: border-box;
    padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}

.game-hud {
    gap: 6px;
    padding: clamp(4px, 1.1vmin, 8px) clamp(8px, 2.2vmin, 20px);
}

.player-hud {
    flex: 0 1 auto;
}

.hud-left {
    text-align: left;
}

.hud-center {
    min-width: 0;
    flex: 1 1 auto;
}

.hud-name {
    font-size: clamp(0.62rem, 2.1vmin, 1rem);
    letter-spacing: 0.05em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hud-stats {
    font-size: clamp(0.6rem, 1.9vmin, 0.85rem);
}

.hud-pieces {
    font-size: clamp(0.7rem, 2.2vmin, 1.1rem);
}

.hud-captured,
.hud-kings {
    font-size: clamp(0.52rem, 1.6vmin, 0.75rem);
    white-space: nowrap;
}

.turn-indicator {
    padding: clamp(3px, 0.9vmin, 4px) clamp(8px, 2.4vmin, 20px);
    font-size: clamp(0.6rem, 1.8vmin, 0.85rem);
    letter-spacing: 0.04em;
}

.game-status {
    font-size: clamp(0.62rem, 1.7vmin, 0.8rem);
}

.board-wrapper {
    min-width: 0;
    min-height: 0;
    padding: clamp(4px, 1.2vmin, 10px);
}

.board-frame {
    padding: clamp(4px, 1.1vmin, 8px);
    max-width: 100%;
    border-radius: clamp(6px, 1.6vmin, 12px);
}

.piece.king::after {
    font-size: clamp(0.85em, 2.6vmin, 1.4em);
}

.game-bottom-bar {
    padding: clamp(4px, 1.1vmin, 8px) clamp(8px, 2.2vmin, 20px);
}

.bottom-controls {
    gap: clamp(6px, 1.4vmin, 12px);
    flex-wrap: wrap;
}

.btn-game {
    padding: clamp(6px, 1.5vmin, 8px) clamp(12px, 2.6vmin, 20px);
    font-size: clamp(0.62rem, 1.65vmin, 0.8rem);
    touch-action: manipulation;
}

.multi-jump-banner {
    padding: clamp(5px, 1.3vmin, 8px);
    margin-bottom: clamp(5px, 1.3vmin, 8px);
    font-size: clamp(0.66rem, 1.8vmin, 0.85rem);
}

.ai-thinking-content {
    padding: clamp(10px, 2.4vmin, 16px) clamp(16px, 4vmin, 32px);
    font-size: clamp(0.72rem, 1.9vmin, 1rem);
    max-width: calc(100% - 32px);
    text-align: center;
}

/* piece lifted by touch/mouse drag */
.piece.dragging {
    z-index: 40;
    transform: scale(1.12);
    transition: none;
    box-shadow: 0 0 0 3px var(--gold), 0 12px 26px rgba(0, 0, 0, 0.55);
}

/* ---------- toast ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--safe-b) + 18px);
    transform: translate(-50%, 18px);
    z-index: 500;
    box-sizing: border-box;
    max-width: min(460px, calc(100% - 28px));
    padding: 12px 18px;
    border-radius: 999px;
    background: rgba(17, 24, 39, 0.96);
    border: 1px solid rgba(212, 168, 67, 0.35);
    color: var(--text-primary);
    font-size: 0.82rem;
    line-height: 1.35;
    text-align: center;
    letter-spacing: 0.01em;
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ---------- keyboard focus (tab navigation) ---------- */
:focus {
    outline: none;
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
    border-radius: var(--radius-sm, 8px);
}

.btn:focus-visible,
.btn-back:focus-visible,
.btn-game:focus-visible,
.btn-difficulty:focus-visible,
.toggle-btn:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

/* keep the ring visible even where overflow is clipped */
.panel:focus-visible,
.mode-card:focus-visible {
    outline-offset: 1px;
}

/* =====================================================================
   COMPACT / NARROW PHONES
   ===================================================================== */
@media (max-width: 480px) {
    .player-hud {
        min-width: 76px;
    }

    .hud-name {
        font-size: 0.7rem;
    }

    .hud-captured,
    .hud-kings {
        display: none;
    }

    .game-title {
        font-size: clamp(1.7rem, 10vmin, 2.5rem);
    }

    .game-subtitle {
        font-size: 0.7rem;
        margin-bottom: clamp(0.9rem, 4vmin, 2em);
    }

    .btn {
        min-width: min(180px, 78vw);
        padding: 11px 26px;
    }

    .panel {
        padding: 20px 16px;
    }

    .mode-cards {
        flex-direction: column;
        align-items: center;
    }

    .mode-card {
        width: 100%;
        max-width: 250px;
    }

    .difficulty-buttons {
        flex-direction: column;
        align-items: center;
    }

    .btn-difficulty {
        width: 180px;
    }
}

@media (max-width: 360px) {
    .btn {
        min-width: min(168px, 80vw);
        padding: 10px 16px;
        font-size: 0.76rem;
    }

    .game-title {
        font-size: 1.6rem;
    }
}

/* =====================================================================
   LANDSCAPE GAME LAYOUT
   The HUD becomes a side rail so the board keeps its full height.
   ===================================================================== */
@media (orientation: landscape) and (max-height: 640px) and (min-width: 560px) {
    #game-screen {
        display: grid;
        grid-template-columns: clamp(84px, 21%, 190px) minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) auto;
        grid-template-areas:
            "hud board"
            "foot foot";
        column-gap: 6px;
    }

    .game-hud {
        grid-area: hud;
        flex-direction: column;
        justify-content: space-evenly;
        align-items: center;
        gap: 4px;
        padding: 6px 4px;
        text-align: center;
        border-bottom: none;
        border-right: 1px solid rgba(255, 255, 255, 0.05);
        border-radius: 10px;
        background: rgba(0, 0, 0, 0.25);
    }

    .hud-left,
    .hud-right {
        min-width: 0;
        text-align: center;
    }

    .hud-center {
        flex: 0 1 auto;
        width: 100%;
    }

    .turn-indicator {
        font-size: 0.68rem;
        padding: 3px 8px;
    }

    .hud-captured,
    .hud-kings {
        display: block;
        font-size: 0.62rem;
    }

    .board-wrapper {
        grid-area: board;
        padding: 4px;
    }

    .game-bottom-bar {
        grid-area: foot;
        padding: 4px 8px;
    }

    .multi-jump-banner {
        font-size: 0.68rem;
        padding: 4px 6px;
        margin-bottom: 4px;
    }

    .btn-game {
        padding: 6px 12px;
        font-size: 0.68rem;
    }
}

/* Short landscape menu / panels */
@media (orientation: landscape) and (max-height: 500px) {
    .game-title {
        font-size: clamp(1.5rem, 8.5vmin, 2.4rem);
        margin-bottom: 0.1em;
    }

    .game-subtitle {
        font-size: 0.6rem;
        letter-spacing: 0.24em;
        margin-bottom: clamp(0.6rem, 3vmin, 1.2rem);
    }

    .menu-content {
        padding: 2px;
    }

    .btn {
        padding: 8px 20px;
        min-width: min(200px, 40vw);
        font-size: 0.75rem;
    }

    .btn-fullscreen {
        gap: 7px;
    }
}

@media (orientation: landscape) and (max-height: 360px) {
    .game-subtitle {
        display: none;
    }

    .game-title {
        font-size: clamp(1.15rem, 7vmin, 1.6rem);
        margin-bottom: 0.08em;
    }

    .btn {
        min-width: min(150px, 34vw);
        padding: 6px 14px;
        font-size: 0.68rem;
    }

    .btn-fullscreen {
        gap: 6px;
    }

    .panel {
        padding: 12px 12px;
    }

    .btn-back {
        margin-top: 10px;
        padding: 7px 16px;
    }
}

/* Tall narrow screens (phones in portrait) */
@media (orientation: portrait) and (max-width: 900px) {
    .mode-cards {
        gap: 12px;
    }
}

/* Very large screens: keep the board generous but centred */
@media (min-width: 1600px) and (min-height: 900px) {
    .btn {
        min-width: 260px;
        font-size: 1.05rem;
        padding: 16px 52px;
    }

    .menu-buttons {
        gap: 16px;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .floating-piece {
        animation: none;
    }

    .game-title,
    .turn-indicator,
    .multi-jump-banner {
        animation: none;
    }
}

/* =====================================================================
   SELECT MODE FIX
   Paste this block at the very END of responsive.css (after every other
   rule). It only overrides the mode-select layout; nothing else changes.
   ===================================================================== */

/* Panel children must never be squeezed by the flex column */
.panel > * {
    flex-shrink: 0;
}

/* ---------- the two mode cards: always side by side, equal size ---------- */
.mode-cards {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: stretch;
    justify-content: center;
    gap: clamp(8px, 2vmin, 20px);
    width: 100%;
}

.mode-card {
    box-sizing: border-box;
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    max-width: 240px;
    padding: clamp(12px, 2.6vmin, 30px) clamp(8px, 2vmin, 24px);
}

.mode-card h3 {
    font-size: clamp(0.66rem, 1.9vmin, 0.9rem);
    min-height: 2.4em;
    text-align: center;
}

.mode-card p {
    font-size: clamp(0.62rem, 1.7vmin, 0.8rem);
    margin-bottom: 15px;
}

/* ---------- SELECT buttons stay inside their cards ---------- */
.mode-card .btn,
.mode-card .btn-sm {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    max-width: 150px;
    margin-top: auto;
    padding: 9px 10px;
    letter-spacing: 0.08em;
}

/* ---------- difficulty buttons: one row ---------- */
.difficulty-section {
    width: 100%;
}

.difficulty-buttons {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: clamp(6px, 1.6vmin, 12px);
}

.btn-difficulty {
    box-sizing: border-box;
    width: auto;
    flex: 0 1 auto;
    min-width: min(90px, 28vw);
    padding: 10px clamp(8px, 2.4vmin, 28px);
}

/* ---------- BACK sits cleanly below, never touching the buttons above ---------- */
.panel > .btn-back {
    margin-top: 16px;
}
