/* Make the page truly fill the viewport on mobile (especially in the
 * Capacitor APK where there's no browser chrome to absorb extra height).
 * Phaser's canvas is a fixed 640x960 (2:3) but modern phones are roughly
 * 1:2.2 — SHOW_ALL keeps the aspect ratio and leaves letterbox bands
 * above/below. We paint the body in the same dark felt as the in-game
 * table so those bands blend in instead of showing the old #898989 gray.
 */
html, body {
    min-height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: #120806; /* matches the dark edge of images/tower_background.png */
    box-sizing: border-box;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
}

*, *::before, *::after {
    box-sizing: inherit;
}

#game {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: var(--sedma-vh, 100vh);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game canvas {
    display: block;
    max-width: 100vw;
    max-height: var(--sedma-vh, 100vh);
}

.noscript-panel {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: grid;
    place-content: center;
    gap: 10px;
    padding: 24px;
    background: #120806;
    color: #fff4c7;
    text-align: center;
    font-family: Georgia, 'Times New Roman', serif;
}

.noscript-panel h1 {
    margin: 0;
    font-size: 32px;
    letter-spacing: 0;
}

.noscript-panel p {
    margin: 0;
    color: #d8c895;
    font: 16px Arial, sans-serif;
}

.cookie-banner {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 22px max(20px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    background:
        radial-gradient(circle at 12% 0%, rgba(216, 183, 106, 0.16), transparent 34%),
        linear-gradient(180deg, rgba(31, 19, 29, 0.98) 0%, rgba(18, 8, 6, 0.99) 100%);
    border-top: 2px solid rgba(216, 183, 106, 0.55);
    box-shadow: 0 -20px 44px rgba(0, 0, 0, 0.62);
    color: #fff4c7;
    font-family: Arial, sans-serif;
}

.cookie-banner[hidden] {
    display: none;
}

.cookie-banner__icon {
    flex: 0 0 auto;
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(216, 183, 106, 0.7);
    border-radius: 12px;
    background: rgba(216, 183, 106, 0.12);
    color: #f8d86c;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 25px;
    font-weight: bold;
    box-shadow: 0 0 18px rgba(216, 183, 106, 0.2);
}

.cookie-banner__copy {
    flex: 1 1 auto;
    min-width: 0;
}

.cookie-banner__copy h2 {
    margin: 0;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 26px;
    line-height: 1.1;
    color: #ffffff;
}

.cookie-banner__copy p {
    max-width: 760px;
    margin: 8px 0 0 0;
    color: #e2d5ae;
    font-size: 15px;
    line-height: 1.45;
}

.cookie-banner__actions {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(150px, 1fr));
    gap: 12px;
    min-width: min(430px, 100%);
}

.cookie-banner__button {
    min-height: 54px;
    border-radius: 14px;
    padding: 13px 22px;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.08s ease, filter 0.12s ease, border-color 0.12s ease;
}

.cookie-banner__button:hover {
    transform: translateY(-1px);
}

.cookie-banner__button:active {
    transform: translateY(2px);
}

.cookie-banner__button--secondary {
    background: rgba(15, 23, 32, 0.86);
    border: 1px solid rgba(226, 213, 174, 0.68);
    color: #f4ecd5;
}

.cookie-banner__button--secondary:hover {
    border-color: #fff4c7;
}

.cookie-banner__button--primary {
    background: linear-gradient(180deg, #f0c764 0%, #b88b2a 100%);
    border: 1px solid #f8d86c;
    color: #1a1208;
    box-shadow: 0 0 20px rgba(248, 216, 108, 0.32);
}

.cookie-banner__button--primary:hover {
    filter: brightness(1.08);
}

#orientation {
    margin: 0 auto;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url(../images/orientation.jpg);
    background-repeat: no-repeat;
    background-position: center;
    background-color: rgb(0, 0, 0);
    z-index: 999;
    display: none;
}

#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    height: var(--sedma-vh, 100vh);
    z-index: 500;
    display: none;
    pointer-events: none;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

#overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-family: Arial, sans-serif;
}

#overlay .panel {
    background: #1f2933;
    padding: clamp(16px, 4vw, 24px);
    border-radius: 8px;
    text-align: center;
    width: min(420px, 100%);
    max-height: calc(var(--sedma-vh, 100vh) - 24px);
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

#overlay h2 {
    margin: 0 0 12px 0;
    font-size: 22px;
}

#overlay p {
    margin: 6px 0;
    font-size: 14px;
    line-height: 1.4;
}

#overlay .room-code {
    font-family: monospace;
    font-size: 18px;
    background: #0f1720;
    padding: 6px 10px;
    border-radius: 6px;
    margin: 8px 0;
    word-break: break-all;
    user-select: all;
}

#overlay .qr {
    background: #fff;
    padding: 10px;
    border-radius: 8px;
    display: inline-block;
    margin: 10px 0;
    max-width: 100%;
}

#overlay .qr canvas,
#overlay .qr img {
    display: block;
    max-width: min(220px, 70vw);
    max-height: max(120px, calc(var(--sedma-vh, 100vh) - 330px));
    height: auto;
}

#overlay button {
    position: relative;
    background: linear-gradient(180deg, #5b3491 0%, #2b1747 100%);
    color: #fff4c7;
    border: 2px solid #d8b76a;
    border-radius: 14px;
    padding: 12px 38px;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 16px;
    font-weight: bold;
    letter-spacing: 0.5px;
    cursor: pointer;
    margin: 8px 4px 0 4px;
    box-shadow:
        0 0 14px rgba(216, 183, 106, 0.55),
        inset 0 0 14px rgba(255, 255, 255, 0.15),
        0 6px 0 #12091f;
    text-shadow:
        0 0 8px rgba(255, 230, 150, 0.6),
        0 2px 4px rgba(0, 0, 0, 0.8);
    transition: all 0.12s ease;
}

/* ✦ flourishes on the plain magic buttons (not the arcane score-screen ones). */
#overlay button:not(.arcane-btn)::before,
#overlay button:not(.arcane-btn)::after {
    content: "✦";
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: #ffe58a;
    font-size: 14px;
    text-shadow: 0 0 10px #ffe58a;
}

#overlay button:not(.arcane-btn)::before { left: 12px; }
#overlay button:not(.arcane-btn)::after { right: 12px; }

#overlay button:not(.arcane-btn):hover {
    transform: translateY(-2px);
    box-shadow:
        0 0 22px rgba(255, 220, 120, 0.9),
        inset 0 0 18px rgba(255, 255, 255, 0.2),
        0 8px 0 #12091f;
}

#overlay button:not(.arcane-btn):active {
    transform: translateY(4px);
    box-shadow:
        0 0 8px rgba(216, 183, 106, 0.4),
        inset 0 0 18px rgba(0, 0, 0, 0.4),
        0 2px 0 #12091f;
}

/* Secondary magic button — same family, but de-emphasised: muted fill, thin
   dim border, no glow, no ✦ flourishes. For lower-priority actions. */
#overlay button.btn-secondary {
    background: rgba(43, 23, 71, 0.5);
    border: 1px solid rgba(216, 183, 106, 0.45);
    color: #c3b2dd;
    font-size: 15px;
    padding: 10px 30px;
    box-shadow: 0 3px 0 rgba(18, 9, 31, 0.65);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

#overlay button.btn-secondary::before,
#overlay button.btn-secondary::after {
    content: "";
    display: none;
}

#overlay button.btn-secondary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 0 rgba(18, 9, 31, 0.65);
    border-color: rgba(216, 183, 106, 0.7);
    color: #e9dcff;
}

#overlay button.btn-secondary:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 rgba(18, 9, 31, 0.65);
}

#overlay button[disabled] {
    opacity: 0.55;
    cursor: default;
}

#overlay table {
    color: #fff;
    margin: 8px auto;
}

#overlay button.secondary {
    background: #cdba52;
}

#overlay .status {
    font-size: 13px;
    color: #cdba52;
    margin-top: 6px;
    min-height: 18px;
}

#debug-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(15, 18, 25, 0.96);
    color: #fff;
    font-family: Arial, sans-serif;
    z-index: 1000;
    max-height: 85vh;
    overflow-y: auto;
    display: none;
    border-bottom: 3px solid #ff9b3a;
    padding: 12px 14px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

#debug-panel.active {
    display: block;
}

#debug-panel .headline {
    font-size: 17px;
    font-weight: bold;
    color: #ffd24d;
    line-height: 1.3;
    margin-bottom: 10px;
    padding: 8px 10px;
    background: rgba(255, 155, 58, 0.15);
    border-radius: 6px;
    border-left: 4px solid #ff9b3a;
}

#debug-panel .actions {
    margin: 10px 0;
}

#debug-panel button {
    background: #cdba52;
    color: #000;
    border: none;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: bold;
    border-radius: 6px;
    margin: 0 4px 4px 0;
    cursor: pointer;
}

#debug-panel button.danger {
    background: #ff6b6b;
    color: #fff;
}

#debug-panel summary {
    cursor: pointer;
    color: #cdba52;
    font-size: 12px;
    padding: 4px 0;
    user-select: none;
}

#debug-panel pre {
    margin: 6px 0 0 0;
    white-space: pre-wrap;
    word-break: break-all;
    color: #e0e0e0;
    font-family: monospace;
    font-size: 11px;
    background: rgba(0, 0, 0, 0.4);
    padding: 8px;
    border-radius: 4px;
}

#debug-panel .version {
    font-size: 10px;
    color: #888;
    text-align: right;
    margin-top: 6px;
}

#debug-toggle {
    position: fixed;
    top: max(6px, env(safe-area-inset-top));
    right: max(6px, env(safe-area-inset-right));
    width: 34px;
    height: 34px;
    background: rgba(0, 0, 0, 0.55);
    color: #ffd24d;
    border: 1px solid #ff9b3a;
    border-radius: 50%;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    z-index: 999;
    display: none;
    line-height: 30px;
    text-align: center;
    padding: 0;
}

#debug-toggle.active {
    display: block;
}

@media (max-height: 640px) {
    #overlay .panel {
        padding: 14px;
    }

    #overlay h2 {
        font-size: 18px;
        margin-bottom: 8px;
    }

    #overlay p {
        font-size: 12px;
    }

    #overlay button {
        padding: 8px 12px;
    }
}

@media (max-width: 760px) {
    .cookie-banner {
        align-items: stretch;
        flex-direction: column;
        gap: 14px;
        padding-top: 18px;
    }

    .cookie-banner__icon {
        display: none;
    }

    .cookie-banner__copy h2 {
        font-size: 22px;
    }

    .cookie-banner__copy p {
        font-size: 14px;
    }

    .cookie-banner__actions {
        grid-template-columns: 1fr;
        min-width: 0;
        width: 100%;
    }

    .cookie-banner__button {
        min-height: 50px;
    }
}

/* ============================================================
 * Arcane round-results dialog (Sedma.ScoreInfo).
 * Dark blue + gold fantasy theme matching the in-game UI.
 * ============================================================ */

#overlay .arcane-panel {
    width: min(360px, 92vw);
    padding: 22px 22px 18px 22px;
    background:
        radial-gradient(circle at top, rgba(56, 86, 140, 0.35), transparent 65%),
        linear-gradient(180deg, #0f1a30 0%, #0a1224 100%);
    border: 2px solid #d8b45a;
    border-radius: 14px;
    box-shadow:
        0 0 0 1px rgba(216, 180, 90, 0.22) inset,
        0 14px 36px rgba(0, 0, 0, 0.55),
        0 0 30px rgba(127, 240, 255, 0.05);
    color: #f4ecd5;
    text-align: center;
    font-family: Georgia, 'Times New Roman', serif;
}

#overlay .arcane-title {
    margin: 0 0 14px 0;
    font-size: 22px;
    font-weight: bold;
    color: #f8d86c;
    letter-spacing: 1px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(216, 180, 90, 0.35);
}

#overlay .arcane-table {
    width: 100%;
    margin: 4px 0 14px 0;
    border-collapse: collapse;
    font-size: 15px;
    color: #f4ecd5;
}

#overlay .arcane-table th,
#overlay .arcane-table td {
    padding: 8px 6px;
    vertical-align: middle;
}

#overlay .arcane-table .col-label {
    color: #d8b45a;
    font-weight: bold;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    border-bottom: 1px solid rgba(216, 180, 90, 0.25);
    padding-bottom: 6px;
}

#overlay .arcane-table .row-label {
    text-align: left;
    font-size: 15px;
    color: #f4ecd5;
    padding-left: 4px;
}

#overlay .arcane-table .row-icon {
    width: 22px;
    height: 22px;
    vertical-align: middle;
    margin-right: 8px;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

#overlay .arcane-table .value {
    text-align: center;
    font-size: 19px;
    font-weight: bold;
    color: #f8d86c;
    text-shadow: 0 2px 3px rgba(0, 0, 0, 0.6);
    width: 26%;
}

#overlay .arcane-table .total-row .row-label,
#overlay .arcane-table .total-row .value {
    border-top: 1px solid rgba(216, 180, 90, 0.4);
    padding-top: 10px;
    font-size: 17px;
    color: #ffe9a3;
}

#overlay .arcane-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 14px;
}

#overlay .arcane-actions button {
    margin: 0;
}

#overlay .arcane-btn {
    border: none;
    border-radius: 10px;
    padding: 11px 18px;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 15px;
    font-weight: bold;
    letter-spacing: 0.4px;
    cursor: pointer;
    margin: 0;
    transition: transform 0.06s ease, filter 0.12s ease;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.35) inset,
        0 3px 0 rgba(0, 0, 0, 0.35),
        0 6px 14px rgba(0, 0, 0, 0.45);
}

#overlay .arcane-btn:hover {
    filter: brightness(1.06);
}

#overlay .arcane-btn:active {
    transform: translateY(1px);
    filter: brightness(0.95);
}

#overlay .arcane-btn-primary {
    background: linear-gradient(180deg, #4caf3a 0%, #2b8a23 100%);
    color: #0c1730;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.18);
}

#overlay .arcane-btn-secondary {
    background: linear-gradient(180deg, #f0c764 0%, #b88b2a 100%);
    color: #1a1208;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
}

#overlay .arcane-btn-danger {
    background: linear-gradient(180deg, #d95a5a 0%, #8f242f 100%);
    color: #fff4ef;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

#overlay .arcane-btn[disabled] {
    opacity: 0.55;
    cursor: default;
    filter: grayscale(0.4);
}

#overlay .arcane-panel .status {
    margin-top: 10px;
    font-size: 12.5px;
    color: #c9b87a;
    font-family: Georgia, 'Times New Roman', serif;
    min-height: 16px;
}

/* Mock AdMob banner on the results screen — a standard anchored adaptive
   banner: pinned to the bottom of the screen, spanning the available width
   (capped to a sensible banner width), at the usual ~50px banner height.
   Adapts to the screen rather than the narrow results panel. */
#overlay .arcane-ad {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: max(8px, env(safe-area-inset-bottom));
    width: calc(100% - 16px);
    max-width: 480px;
    height: 50px;
    background: #f2f3f5;
    border: 1px solid #c8ccd4;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: Arial, sans-serif;
    z-index: 1;
}

#overlay .arcane-ad-tag {
    position: absolute;
    top: 4px;
    left: 6px;
    font-size: 10px;
    font-weight: bold;
    color: #6b7280;
}

#overlay .arcane-ad-label {
    font-size: 13px;
    color: #4b5563;
}

#overlay .arcane-ad-note {
    font-size: 10px;
    color: #8a93a3;
    margin-top: 2px;
}

/* ——— Desktop / wide-screen side-rail ad placeholders ————————————————
   The play area is a portrait canvas (logical 640×896, aspect ≈ 0.714), so
   on a wide screen it's letterboxed with empty bands on the left and right.
   Fill those bands with skyscraper-style ad placeholders. Width is derived
   from the actual side margin — (100vw − canvasWidth)/2, where canvasWidth ≈
   71.5vh on a height-limited landscape canvas — and clamped to 0 so the rail
   can never overlap the board. They show only on sufficiently wide screens. */
.side-ad {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: clamp(0px, calc((100vw - 71.5vh) / 2 - 16px), 260px);
    height: min(600px, 82vh);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: #f2f3f5;
    border: 1px solid #c8ccd4;
    border-radius: 8px;
    font-family: Arial, sans-serif;
    color: #4b5563;
    text-align: center;
    padding: 10px;
    z-index: 1;
    overflow: hidden;
}

.side-ad-left { left: max(8px, env(safe-area-inset-left)); }
.side-ad-right { right: max(8px, env(safe-area-inset-right)); }

.side-ad-tag {
    position: absolute;
    top: 6px;
    left: 8px;
    font-size: 11px;
    font-weight: bold;
    color: #6b7280;
}

.side-ad-label {
    font-size: 15px;
    font-weight: bold;
}

.side-ad-note {
    font-size: 11px;
    color: #8a93a3;
}

@media (orientation: landscape) and (min-aspect-ratio: 6/5) {
    .side-ad { display: flex; }
}

#overlay .arcane-panel-loss {
    background:
        radial-gradient(circle at 50% 0%, rgba(83, 106, 145, 0.22), transparent 58%),
        linear-gradient(180deg, #111827 0%, #070b12 100%);
    border-color: #6f7f99;
}

#overlay .arcane-panel-loss .arcane-title {
    color: #b9c7dd;
}

#overlay .round-result-copy {
    color: #d8cfbd;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 15px;
    margin: 0 0 12px 0;
}

#overlay .arcane-panel-loss .round-result-copy {
    color: #aeb9c9;
}

#overlay .tutorial-feedback-link {
    margin: -2px 0 12px 0;
    font-family: Arial, sans-serif;
    font-size: 13px;
    line-height: 1.35;
}

#overlay .tutorial-feedback-link a {
    color: #f8d86c;
    text-decoration: underline;
    text-underline-offset: 3px;
}

#overlay .tutorial-feedback-link a:hover {
    color: #ffe9a3;
}

#overlay.rewarded-ad-active {
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
    background:
        radial-gradient(circle at 50% 32%, rgba(127, 240, 255, 0.22), transparent 32%),
        radial-gradient(circle at 50% 60%, rgba(185, 108, 255, 0.22), transparent 38%),
        #050711;
}

#overlay .rewarded-ad-shell {
    width: 100%;
    min-height: var(--sedma-vh, 100vh);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 24px;
    color: #f4ecd5;
    text-align: center;
    font-family: Georgia, 'Times New Roman', serif;
}

#overlay .rewarded-ad-sigil {
    width: 110px;
    height: 110px;
    border: 2px solid rgba(248, 216, 108, 0.8);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #f8d86c;
    font-size: 52px;
    box-shadow:
        0 0 20px rgba(248, 216, 108, 0.2),
        0 0 40px rgba(127, 240, 255, 0.15) inset;
}

#overlay .rewarded-ad-title {
    margin: 0;
    color: #f8d86c;
    font-size: 26px;
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.65);
}

#overlay .rewarded-ad-copy {
    max-width: 340px;
    color: #d9cfb8;
    font-size: 15px;
}

#overlay .rewarded-ad-count {
    min-width: 96px;
    padding: 12px 18px;
    border: 1px solid rgba(127, 240, 255, 0.55);
    border-radius: 8px;
    background: rgba(5, 14, 26, 0.76);
    color: #9efcff;
    font-size: 24px;
    font-weight: bold;
}

@media (max-height: 640px) {
    #overlay .arcane-panel {
        padding: 16px 16px 12px 16px;
    }

    #overlay .arcane-title {
        font-size: 18px;
        margin-bottom: 10px;
        padding-bottom: 8px;
    }

    #overlay .arcane-table {
        font-size: 13px;
        margin-bottom: 10px;
    }

    #overlay .arcane-table .value {
        font-size: 16px;
    }

    #overlay .arcane-table .row-icon {
        width: 18px;
        height: 18px;
        margin-right: 6px;
    }

    #overlay .arcane-btn {
        padding: 9px 14px;
        font-size: 14px;
    }
}
