/* ===== Global Reset & Base ===== */

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

:root {
    /* ===== Game Palette (from config.ts) ===== */
    --c-wood-dark: #5d4037; /* Bar/Border */
    --c-wood-med: #8b4513; /* Point 1 */
    --c-wood-light: #deb887; /* Point 2 */
    --c-wheat: #f5deb3; /* Board */

    /* ===== UI Mappings ===== */
    --bg-dark: #121212;
    --border-color: #3e2723;

    --controls-bg: var(--c-wood-dark);
    --modal-bg: var(--c-wood-dark);
    --modal-header: rgba(0, 0, 0, 0.2);

    --text-color: var(--c-wheat);
    --text-muted: rgba(245, 222, 179, 0.6);

    --btn-bg: rgba(0, 0, 0, 0.2);
    --btn-hover: rgba(0, 0, 0, 0.4);

    --input-bg: rgba(0, 0, 0, 0.3);
    --accent: var(--c-wood-light);

    font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
    line-height: 1.5;
    font-weight: 400;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: var(--text-color);
}

body {
    margin: 0;
    padding: 0;
    width: 100dvw;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: hidden; /* Default: no scroll (Yandex/production) */
    background-color: var(--bg-dark);

    /* STOPS the whole page from bouncing/refreshing */
    overscroll-behavior: none;
    touch-action: none;
}

/* Google builds: Enable vertical scroll for SEO content below fold */
body.scrollable-body {
    overflow-y: auto;
    height: auto;
    touch-action: pan-y;
}

/* Yandex Strict Compliance: No text selection allowed anywhere */
body.yandex-env,
.game-modal {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Allow scrolling in modal content */
.modal-content {
    touch-action: pan-y;
    overflow-y: auto;
}

#app {
    width: 100%;
    min-height: 100%;
}

/* ===== Game Hero Section ===== */

.game-hero {
    width: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

/* Prevent scroll interference during gameplay */
body.scrollable-body .game-hero {
    touch-action: none;
}

/* ===== App Layout ===== */

.app-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* IMPORTANT: This must be visible so the top/bottom bar shows immediately. */
    visibility: visible;

    /* Makes it feel like an App, not a document */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none; /* iOS specific fix */
}

/* Hide ONLY the canvas container initially to prevent black flicker/empty state */
.canvas-container {
    visibility: hidden;
}

/* When the app is mounted (JS loaded), reveal the canvas */
.app-mounted .canvas-container {
    visibility: visible;
}

/* Portrait: Controls at bottom (away from notification pulldown) */
.canvas-area {
    order: 0;
}

.game-controls {
    order: 1;
}

/* ===== Game Controls - Horizontal Bar ===== */

.game-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background-color: var(--controls-bg);
    border-top: 4px solid var(--border-color);
    box-shadow: 0 -4px 6px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
    z-index: 10;
}

.controls-buttons {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--c-wood-med);
    border-radius: 6px;
    background-color: var(--btn-bg);
    color: var(--c-wheat);
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.icon-btn:hover {
    background-color: var(--btn-hover);
    border-color: var(--c-wood-light);
    color: #fff;
}

.icon-btn:active {
    transform: scale(0.95);
}

.ad-placeholder {
    /* Portrait: Mobile leaderboard 320×50, hidden until ad fills */
    width: 320px;
    height: 50px;
    display: none;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    flex-shrink: 0;
    overflow: hidden;
}

/* Show only when ad is filled */
.ad-placeholder:has([data-ad-status="filled"]) {
    display: flex;
}

/* ===== Modals ===== */

.game-modal {
    background: var(--modal-bg);
    color: var(--text-color);
    border: 2px solid var(--c-wood-med);
    border-radius: 8px;
    padding: 0;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
    max-width: 400px;
    width: 90vw;
}

.game-modal::backdrop {
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(3px);
}

.modal-header {
    background: var(--modal-header);
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.4rem;
    color: var(--c-wood-light);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    font-weight: bold;
    letter-spacing: 0.5px;
}

.modal-content {
    padding: 1.5rem;
}

.modal-content section {
    margin-bottom: 1.5rem;
}

.modal-content h4 {
    color: var(--c-wood-light);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 0.8rem;
    margin-top: 0;
    opacity: 0.9;
}

/* Form Elements */
.game-select {
    width: 100%;
    padding: 10px;
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--c-wheat);
    border: 1px solid var(--c-wood-med);
    font-size: 1rem;
    cursor: pointer;
    outline: none;
}

.game-select:focus {
    border-color: var(--c-wood-light);
}

.game-select option {
    background: var(--c-wood-dark);
}

.radio-group {
    display: flex;
    gap: 1.5rem;
}

.checkbox-row,
.radio-group label {
    display: flex;
    align-items: center;
    margin-bottom: 0.8rem;
    cursor: pointer;
    color: var(--c-wheat);
}

.checkbox-row:hover,
.radio-group label:hover {
    color: #fff;
}

.checkbox-row input,
.radio-group input {
    margin-right: 12px;
    width: 18px;
    height: 18px;
    accent-color: var(--c-wood-light);
    cursor: pointer;
}

/* Modal Actions */
.modal-actions {
    padding: 1rem 1.5rem;
    background: rgba(0, 0, 0, 0.1);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.btn-primary,
.btn-secondary {
    padding: 0.6rem 1.4rem;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
}

.btn-primary {
    background-color: var(--c-wood-light);
    color: #3e2723;
    border: 1px solid #cca874;
}
.btn-primary:hover {
    background-color: #e6c595;
    transform: translateY(-1px);
}
.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background-color: transparent;
    color: var(--c-wood-light);
    border: 1px solid var(--c-wood-med);
}
.btn-secondary:hover {
    border-color: var(--c-wood-light);
    background-color: rgba(222, 184, 135, 0.1);
}
.btn-secondary:active {
    transform: scale(0.96);
}

/* Specific styling for Reset button to distinguish from standard secondary */
#reset-settings-btn {
    margin-right: auto;
    border-color: #8b4513;
    color: #cc8888;
}
#reset-settings-btn:hover {
    color: #ffaaaa;
    border-color: #a35555;
}

/* Message Modal Specifics */
.message-modal .modal-actions button {
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    border: 1px solid #cca874;
    cursor: pointer;
    background: var(--c-wood-light);
    color: #3e2723;
    font-weight: bold;
    font-size: 1rem;
}
.message-modal #msg-body {
    padding: 1.5rem;
    font-size: 1.1rem;
    line-height: 1.5;
    color: var(--c-wheat);
    white-space: pre-wrap;
}
.message-modal h3 {
    background: var(--modal-header);
    padding: 1rem;
    margin: 0;
    border-bottom: 1px solid var(--border-color);
    color: var(--c-wood-light);
}

/* ===== Language Toggle (CSS-only i18n for static content) ===== */
/* Default: show Turkish (for crawlers without JS, primary market) */
.lang-en,
.lang-ru,
.lang-ja {
    display: none;
}

/* When data-lang is set, show only that language */
html[data-lang="en"] .lang-tr,
html[data-lang="en"] .lang-ru {
    display: none;
}
html[data-lang="en"] .lang-en {
    display: inline;
}

html[data-lang="ru"] .lang-tr,
html[data-lang="ru"] .lang-en {
    display: none;
}
html[data-lang="ru"] .lang-ru {
    display: inline;
}

/* Block-level elements need display: block instead of inline */
html[data-lang="en"] p.lang-en,
html[data-lang="en"] ul.lang-en,
html[data-lang="en"] div.lang-en {
    display: block;
}
html[data-lang="ru"] p.lang-ru,
html[data-lang="ru"] ul.lang-ru,
html[data-lang="ru"] div.lang-ru {
    display: block;
}

/* Japanese language rules */
html[data-lang="ja"] .lang-tr,
html[data-lang="ja"] .lang-en,
html[data-lang="ja"] .lang-ru {
    display: none;
}
html[data-lang="ja"] .lang-ja {
    display: inline;
}
html[data-lang="ja"] p.lang-ja,
html[data-lang="ja"] ul.lang-ja,
html[data-lang="ja"] div.lang-ja {
    display: block;
}

/* ===== Below-Fold Content Section (Google builds only) ===== */

.page-content {
    padding: 3rem 1rem 4rem;
    max-width: 900px;
    margin: 0 auto;
    color: var(--c-wheat);
}

/* Section containers with card-like appearance */
.content-section,
.content-intro,
.faq-section,
.tips-section {
    margin-bottom: 2.5rem;
    padding: 2rem;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 12px;
    border: 1px solid rgba(139, 69, 19, 0.3);
}

/* Main headings */
.page-content h1 {
    color: var(--c-wood-light);
    border-bottom: 2px solid var(--c-wood-med);
    padding-bottom: 0.5rem;
    margin-bottom: 2rem;
    font-size: 2rem;
}

.page-content h2,
.section-heading {
    color: var(--c-wood-light);
    margin: 0 0 1.5rem 0;
    font-size: 1.5rem;
    border-bottom: 2px solid var(--c-wood-med);
    padding-bottom: 0.75rem;
}

/* Subheadings */
.page-content h3 {
    color: var(--c-wood-light);
    font-size: 1.15rem;
    margin: 1.5rem 0 0.75rem;
    opacity: 0.95;
}

/* Card-like subsections */
.info-card {
    background: rgba(0, 0, 0, 0.1);
    padding: 1.25rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border-left: 3px solid var(--c-wood-med);
}

.info-card h3 {
    margin-top: 0;
}

.info-card:last-child {
    margin-bottom: 0;
}

/* Paragraphs and lists */
.page-content p,
.page-content ul,
.page-content ol {
    line-height: 1.8;
    opacity: 0.9;
    margin-bottom: 1rem;
}

.page-content ul,
.page-content ol {
    padding-left: 1.5rem;
}

.page-content li {
    margin-bottom: 0.5rem;
}

.page-content strong {
    color: var(--c-wood-light);
}

.page-content a {
    color: var(--c-wood-light);
    text-decoration: underline;
    text-underline-offset: 3px;
    transition: color 0.2s;
}

.page-content a:hover {
    color: #fff;
}

/* ===== FAQ Accordion Styling ===== */

.faq-item {
    margin-bottom: 0.75rem;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    border: 1px solid rgba(139, 69, 19, 0.2);
    overflow: hidden;
}

.faq-item:last-child {
    margin-bottom: 0;
}

.faq-item summary {
    padding: 1rem 1.25rem;
    cursor: pointer;
    font-weight: 600;
    color: var(--c-wood-light);
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.2s ease;
}

.faq-item summary::-webkit-details-marker {
    display: none;
}

/* Custom arrow indicator */
.faq-item summary::after {
    content: "+";
    font-size: 1.4rem;
    font-weight: 400;
    color: var(--c-wood-med);
    transition: transform 0.2s ease;
    flex-shrink: 0;
    margin-left: 1rem;
}

.faq-item[open] summary::after {
    content: "−";
}

.faq-item summary:hover {
    background: rgba(222, 184, 135, 0.1);
}

.faq-item > p {
    padding: 0 1.25rem 1rem;
    margin: 0;
    border-top: 1px solid rgba(139, 69, 19, 0.15);
}

/* ===== Page Footer ===== */

.page-footer {
    text-align: center;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--c-wood-med);
    opacity: 0.6;
    font-size: 0.9rem;
}

.page-footer p {
    margin: 0.5rem 0;
}

.privacy-link {
    color: #ff9800;
    text-decoration: underline;
    text-underline-offset: 4px;
    transition: all 0.2s;
}

.privacy-link:hover {
    color: #ffb74d;
}

/* ===== Below-Fold Content Responsive ===== */

@media (max-width: 600px) {
    .page-content {
        padding: 2rem 1rem;
    }

    .content-section,
    .content-intro,
    .faq-section,
    .tips-section {
        padding: 1.5rem 1rem;
        margin-bottom: 2rem;
    }

    .page-content h2,
    .section-heading {
        font-size: 1.3rem;
    }

    .info-card {
        padding: 1rem;
    }

    .faq-item summary {
        padding: 0.875rem 1rem;
    }

    .faq-item > p {
        padding: 0 1rem 1rem;
    }
}

/* ===== Canvas Area ===== */

.canvas-area {
    /* Fill all available space in the flex layout */
    flex: 1;
    min-width: 0;
    min-height: 0;
    background-color: var(--c-wood-dark);
}

.canvas-container {
    position: relative;
    background-color: transparent;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

/* ===== Landscape: Sidebar Layout ===== */

@media (orientation: landscape) {
    .app-container {
        flex-direction: row;
    }

    /* Landscape: Controls on left (order 0), canvas after (order 1) */
    .game-controls {
        order: 0;
        width: auto;
        min-width: fit-content;
        flex-direction: column;
        border-top: none;
        border-right: 4px solid var(--border-color);
        box-shadow: 4px 0 6px rgba(0, 0, 0, 0.3);
    }

    .canvas-area {
        order: 1;
    }

    .controls-buttons {
        flex-direction: column;
    }

    /* Keep buttons in row if ad is present (wide sidebar) */
    .game-controls:has(.ad-placeholder:has([data-ad-status="filled"]))
        .controls-buttons {
        flex-direction: row;
    }

    .ad-placeholder {
        /* Landscape: Hidden by default, shown only when ad fills */
        display: none;
        width: 160px;
        height: 600px;
        margin-left: 0;
        margin-top: auto;
    }

    /* Only show when ad is filled */
    .ad-placeholder:has([data-ad-status="filled"]) {
        display: flex;
    }
}

/* ===== Responsive: Small Screens ===== */

@media (max-width: 480px) {
    .game-controls {
        padding: 0.4rem;
        gap: 0.4rem;
    }

    .icon-btn {
        width: 32px;
        height: 32px;
        font-size: 1.1rem;
    }

    .ad-placeholder {
        /* Small mobile: 320×50 */
        width: 320px;
        height: 50px;
    }

    .canvas-area {
        padding: 0;
    }
}
