/*
 * «Резонанс» внутри штатной оболочки игры.
 * Все правила ограничены .gmResonanceShell; исходный standalone CSS сюда не подключается.
 */
.gmResonanceShell {
    --res-bg: #172b45;
    --res-panel: #1d344f;
    --res-line: #54729155;
    --res-text: #e3edf7;
    --res-muted: #a8bdd2;
    --res-width: 460px;
    position: relative;
    isolation: isolate;
    width: 100%;
    min-width: 0;
    min-height: 100%;
    color: var(--res-text);
    background: var(--res-bg);
    font: 13px/1.45 "Segoe UI", Arial, sans-serif;
    color-scheme: dark;
}

.gmResonanceShell *,
.gmResonanceShell *::before,
.gmResonanceShell *::after { box-sizing: border-box; }
.gmResonanceShell [hidden] { display: none !important; }
.gmResonanceShell .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.gmResonanceShell #riskApp {
    width: min(100%, var(--res-width));
    min-height: 100%;
    margin-inline: auto;
    padding: 12px 10px calc(24px + env(safe-area-inset-bottom));
    background: var(--res-bg);
}

.gmResonanceShell button {
    min-height: 44px;
    padding: 9px 12px;
    border: 1px solid #5f809d;
    border-radius: 4px;
    color: #e3eef8;
    background: #2b4661;
    box-shadow: none;
    font: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.gmResonanceShell button:hover:not(:disabled) {
    border-color: #9ccddd;
    background: #395b78;
}
.gmResonanceShell button:disabled { opacity: .45; cursor: not-allowed; }
.gmResonanceShell button:focus-visible,
.gmResonanceShell canvas:focus-visible {
    outline: 2px solid #9ce5f2;
    outline-offset: 2px;
}
.gmResonanceShell .risk-primary {
    border-color: #88b5cc;
    background: #376b8f;
}
.gmResonanceShell .risk-danger {
    border-color: #c686a6;
    background: #753c59;
}
.gmResonanceShell .risk-exit {
    border-color: #89c5b3;
    background: #2f635e;
}

/* Header and round selection. */
.gmResonanceShell .risk-header {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 57px;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #6885a43b;
}
.gmResonanceShell .risk-avatar {
    width: 44px;
    height: 44px;
    flex: none;
    border: 1px solid #849bb645;
    border-radius: 50%;
    object-fit: cover;
    object-position: 50% 35%;
    background: #152942;
}
.gmResonanceShell .risk-header h1 {
    margin: 0;
    color: #f1f3f7;
    font-size: 21px;
    font-weight: 600;
    line-height: 1.25;
}
.gmResonanceShell .risk-header small {
    color: #91afc9;
    font-size: 10px;
    letter-spacing: .9px;
}
.gmResonanceShell .risk-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-left: auto;
}
.gmResonanceShell .risk-tools button { padding: 7px 9px; font-size: 12px; }
.gmResonanceShell .res-kicker {
    display: block;
    margin: 0;
    color: #90d8e7;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.8px;
    text-transform: uppercase;
}
.gmResonanceShell .res-round-select h2 {
    margin: 8px 0 10px;
    color: #f0f3f8;
    font-size: 25px;
    font-weight: 600;
}
.gmResonanceShell .res-lead,
.gmResonanceShell .res-local-note {
    margin: 0;
    color: #bed0df;
    font-size: 13px;
    line-height: 1.55;
}
.gmResonanceShell .res-local-note { margin: 20px 2px; font-size: 11px; }
.gmResonanceShell .res-round-cards { display: grid; gap: 10px; margin: 22px 0; }
.gmResonanceShell .res-round-status {
    padding: 16px;
    border: 1px solid #6989a65c;
    border-radius: 8px;
    color: #c9d9e7;
    background: #203a55;
}
.gmResonanceShell .res-round-status p { margin: 0 0 12px; }
.gmResonanceShell .res-round-card {
    display: block;
    width: 100%;
    min-height: 0;
    padding: 15px;
    border: 1px solid #6989a65c;
    border-radius: 8px;
    background: #203a55;
    text-align: left;
}
.gmResonanceShell .res-round-card:hover,
.gmResonanceShell .res-round-card:focus-visible {
    border-color: #96d9e5;
    background: #294a68;
}
.gmResonanceShell .res-round-card-top,
.gmResonanceShell .res-round-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.gmResonanceShell .res-round-card-top {
    color: #9cd8e8;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.gmResonanceShell .res-round-card strong {
    display: block;
    margin: 7px 0 5px;
    color: #f1f4f8;
    font-size: 18px;
    font-weight: 600;
}
.gmResonanceShell .res-round-card p {
    margin: 0;
    color: #b8cbdc;
    font-size: 12px;
    line-height: 1.5;
}
.gmResonanceShell .res-round-card-foot {
    margin-top: 12px;
    color: #a8bed2;
    font-size: 11px;
}
.gmResonanceShell .res-round-card-foot b { color: #a2e4e5; font-weight: 600; }

/* Board, status and queue. Round title and description stay hidden above the board. */
.gmResonanceShell #gameView { min-width: 0; }
.gmResonanceShell .risk-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin: 10px 0 12px;
}
.gmResonanceShell .risk-stat {
    min-width: 0;
    padding: 8px 7px;
    border: 1px solid var(--res-line);
    border-radius: 6px;
    background: var(--res-panel);
}
.gmResonanceShell .risk-stat small {
    display: block;
    color: #a8bfd3;
    font-size: 9px;
}
.gmResonanceShell .risk-stat strong {
    display: block;
    overflow: hidden;
    color: #eef3f8;
    font-size: clamp(14px, 4vw, 19px);
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.gmResonanceShell .risk-stat meter {
    display: block;
    width: 100%;
    height: 7px;
    margin-top: 6px;
    accent-color: #86cfbb;
}
.gmResonanceShell .risk-stat meter::-webkit-meter-bar { border: 0; background: #13253b; }
.gmResonanceShell .risk-stat meter::-webkit-meter-optimum-value { background: #86cfbb; }
.gmResonanceShell .risk-stat.hp-low { border-color: #b5688c; background: #4f354b; }
.gmResonanceShell .risk-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.gmResonanceShell .risk-mapcol,
.gmResonanceShell .risk-grid > * { min-width: 0; }
.gmResonanceShell .risk-canvas-wrap {
    position: relative;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background: var(--res-bg);
}
.gmResonanceShell .risk-canvas-wrap canvas {
    display: block;
    width: 100%;
    height: auto;
    min-height: 0;
    aspect-ratio: 6 / 5;
    background: transparent;
    image-rendering: auto;
    touch-action: manipulation;
}
.gmResonanceShell .risk-panel {
    min-width: 0;
    padding: 10px 0 0;
    border: 0;
    border-radius: 0;
    background: transparent;
}
.gmResonanceShell .risk-queue {
    --queue-space: 8px;
    --queue-item-size: 38px;
    display: flex;
    align-items: center;
    gap: var(--queue-space);
    min-height: calc(var(--queue-item-size) + var(--queue-space) + var(--queue-space));
    padding: var(--queue-space);
    overflow-x: auto;
    border: 0;
    border-radius: 16px;
    background: #132840;
    box-shadow: inset 0 0 0 1px #ffffff10;
    scrollbar-width: thin;
}
.gmResonanceShell .risk-queue button {
    display: flex;
    flex: 0 0 var(--queue-item-size);
    align-items: center;
    justify-content: center;
    width: var(--queue-item-size);
    max-width: var(--queue-item-size);
    height: var(--queue-item-size);
    min-height: var(--queue-item-size);
    padding: 0;
    border: 1px solid #7da4bc66;
    border-radius: 10px;
    color: #a1eaf2;
    background: #314e6b90;
    font-size: 20px;
}
.gmResonanceShell .risk-queue button small { display: none; }
.gmResonanceShell .risk-queue button.selected { border-color: #89d0f5; background: #5589ac80; }
.gmResonanceShell .risk-queue button.is-running { box-shadow: inset 0 0 0 1px #f1d07e; }
.gmResonanceShell .risk-placeholder {
    width: 100%;
    padding: 0;
    color: #bfd0dd;
    font-size: 14px;
    text-align: center;
}
.gmResonanceShell .risk-message {
    margin: 8px 0 0;
    padding: 8px 10px;
    border-left: 3px solid #7ec5d3;
    color: #d4e4f0;
    background: #234259;
    font-size: 12px;
}
.gmResonanceShell .risk-message:empty { display: none; }
.gmResonanceShell .risk-message[data-error="true"] { border-color: #ef8da0; color: #ffc5cd; }
.gmResonanceShell .risk-history { margin-top: 8px; color: #b8c9d3; font-size: 12px; }
.gmResonanceShell .risk-history .tokens {
    padding: 10px 0;
    font-size: 18px;
    letter-spacing: 6px;
    word-break: break-word;
}

/* The controls remain in the game scroll area and cannot cover another app. */
.gmResonanceShell #riskApp:has(#gameView:not([hidden])) {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.gmResonanceShell #riskControlDock {
    position: sticky;
    bottom: 0;
    z-index: 30;
    width: 100%;
    margin-top: 12px;
    padding: 10px 6px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid #54729155;
    background: #172b45f5;
}
.gmResonanceShell .risk-palette {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin: 0;
}
.gmResonanceShell .risk-palette button {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: auto;
    min-height: 0;
    padding: 0;
    border-radius: 10px;
    aspect-ratio: 1;
}
.gmResonanceShell .risk-palette .cmd-glyph {
    display: block;
    color: #a0ebf1;
    font-size: 30px;
    line-height: 1;
    text-shadow: none;
}
.gmResonanceShell .risk-palette .cmd-count {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 21px;
    height: 21px;
    padding: 0 5px;
    border: 1px solid #8ddae5;
    border-radius: 999px;
    color: #eef9fb;
    background: #132739;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
}
.gmResonanceShell .risk-palette .cmd-label { display: none; }
.gmResonanceShell .risk-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    margin: 10px 0 0;
}
.gmResonanceShell .risk-actions button {
    width: 100%;
    min-width: 0;
    min-height: 46px;
    padding: 8px 5px;
    border-radius: 6px;
}
.gmResonanceShell .risk-actions:has(#riskFinish:not([hidden])) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.gmResonanceShell .risk-actions:has(#riskFinish:not([hidden])) button { font-size: 12px; }

/* Native result dialog and tile inspector share the app's visual language. */
.gmResonanceShell #riskDialog {
    width: min(436px, calc(100% - 24px));
    max-height: min(90dvh, 760px);
    padding: 24px;
    overflow-y: auto;
    border: 1px solid #6385a4;
    border-radius: 7px;
    color: #edf4f7;
    background: #1b314b;
    box-shadow: 0 10px 40px #020d2099;
}
.gmResonanceShell #riskDialog::backdrop { background: #06101de3; }
.gmResonanceShell #riskDialog h2 { margin: 8px 0 14px; color: #e5edf5; font-size: 22px; }
.gmResonanceShell #riskDialog p { color: #d3dfe6; font-size: 14px; }
.gmResonanceShell #riskDialog .risk-modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}
.gmResonanceShell #riskDialog .risk-modal-actions button { flex: 1; min-width: 130px; }
.gmResonanceShell #riskDialog .risk-big-number { color: #f3a7af; font-size: 38px; font-weight: 650; }
.gmResonanceShell #riskDialog .risk-reward { padding: 12px; border-radius: 8px; color: #f2d99e; background: #344558; }

.gmResonanceShell #tileInspector {
    position: fixed;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 8px;
    z-index: 800;
    display: flex;
    flex-direction: column;
    width: min(calc(100% - 16px), calc(var(--res-width) - 16px));
    max-height: min(69dvh, 650px);
    margin-inline: auto;
    overflow: hidden;
    border: 1px solid #6b89af;
    border-radius: 15px 15px 9px 9px;
    color: #e6edf8;
    background: #13263e;
    box-shadow: 0 14px 38px #060e2070;
    font: 13px/1.48 system-ui, "Segoe UI", sans-serif;
    text-align: left;
}
.gmResonanceShell #tileInspector .ti-header {
    display: flex;
    flex: none;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 13px 10px;
    border-bottom: 1px solid #6685a648;
    background: #19314d;
}
.gmResonanceShell #tileInspector .ti-header small { color: #91ccde; font-size: 9px; font-weight: 650; letter-spacing: 1.4px; }
.gmResonanceShell #tileInspector h2 { margin: 5px 0 4px; color: #f6ebce; font-size: 17px; font-weight: 650; line-height: 1.22; }
.gmResonanceShell #tileInspector #tileInspectLocation { color: #a8bad3; font-size: 11px; }
.gmResonanceShell #tileInspector .ti-close {
    display: grid;
    flex: 0 0 44px;
    place-items: center;
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    border: 1px solid #849db747;
    border-radius: 8px;
    color: #d9e9f4;
    background: #223d5c;
    font-size: 27px;
    line-height: 1;
}
.gmResonanceShell #tileInspector .ti-close:hover { background: #31516f; }
.gmResonanceShell #tileInspector .ti-body {
    min-height: 0;
    padding: 12px;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #587596 #13263e;
}
.gmResonanceShell #tileInspector .ti-overview { display: grid; grid-template-columns: 80px minmax(0, 1fr); align-items: start; gap: 12px; }
.gmResonanceShell #tileInspector p { margin: 5px 0 8px; color: #ccd9e8; font-size: 12px; line-height: 1.52; }
.gmResonanceShell #tileInspector canvas { display: block; max-width: 100%; border-radius: 6px; background: #142943; }
.gmResonanceShell #tileInspector .ti-selected { width: 80px; height: 80px; }
.gmResonanceShell #tileInspector .ti-state {
    display: block;
    width: fit-content;
    margin: 0 0 5px;
    padding: 2px 5px;
    border: 1px solid #64bca940;
    border-radius: 4px;
    color: #97e8d8;
    background: #2653495c;
    font-size: 10px;
    font-weight: 600;
}
.gmResonanceShell #tileInspector .ti-extra { padding: 2px 0; color: #c1d1e3; font-size: 11px; }
.gmResonanceShell #tileInspector .ti-layer { margin: 10px 0; padding: 10px 11px; border-left: 2px solid #8cafd0; background: #203b555c; }
.gmResonanceShell #tileInspector .ti-layer b { display: block; color: #d5e8f6; font-size: 12px; }
.gmResonanceShell #tileInspector .ti-layer small { display: block; margin: 3px 0; color: #91d9cc; }
.gmResonanceShell #tileInspector .ti-warning { margin: 12px 0; padding: 9px 11px; border: 1px solid #da75a253; border-radius: 6px; color: #f3b9cf; background: #793b542c; }
.gmResonanceShell #tileInspector .ti-section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 14px 0 8px; color: #dfeaf5; font-size: 12px; font-weight: 650; }
.gmResonanceShell #tileInspector .ti-section-title h3 { margin: 0; font-size: 12px; font-weight: 650; }
.gmResonanceShell #tileInspector .ti-section-title span { color: #a9bfd4; font-size: 8px; font-weight: 400; white-space: nowrap; }
.gmResonanceShell #tileInspector .ti-dot { display: inline-block; width: 6px; height: 6px; margin-right: 3px; border-radius: 2px; background: #8be9f6; }
.gmResonanceShell #tileInspector .ti-target {
    display: grid;
    grid-template-columns: 108px minmax(0, 1fr);
    align-items: start;
    gap: 11px;
    width: 100%;
    min-height: 126px;
    margin: 7px 0;
    padding: 9px;
    border: 1px solid #3b5977;
    border-radius: 8px;
    color: #d9e6f1;
    background: #1c334e;
    font-size: 11px;
    line-height: 1.4;
    text-align: left;
}
.gmResonanceShell #tileInspector .ti-target:hover,
.gmResonanceShell #tileInspector .ti-target-active { border-color: #dfbc77; background: #233e5d; }
.gmResonanceShell #tileInspector .ti-crop { width: 108px; height: 108px; }
.gmResonanceShell #tileInspector .ti-target-copy { display: block; min-width: 0; }
.gmResonanceShell #tileInspector .ti-target-copy strong { display: flex; align-items: center; gap: 6px; margin: 0 0 6px; color: #eff0e9; font-size: 12px; font-weight: 650; }
.gmResonanceShell #tileInspector .ti-target-copy i { display: inline-grid; flex: none; place-items: center; width: 17px; height: 17px; border-radius: 50%; color: #18324f; background: #eed28e; font-size: 10px; font-style: normal; }
.gmResonanceShell #tileInspector .ti-target-copy > span { display: block; color: #bed0e1; font-size: 11px; line-height: 1.4; }
.gmResonanceShell #tileInspector .ti-target-copy em { display: block; margin-top: 7px; color: #c2dff4; font-size: 10px; font-style: normal; }
.gmResonanceShell #tileInspector .ti-unknown { display: flex; align-items: flex-start; gap: 12px; margin: 8px 0; padding: 12px; border: 1px dashed #516b8b; border-radius: 8px; background: #102137; }
.gmResonanceShell #tileInspector .ti-unknown > span,
.gmResonanceShell #tileInspector .ti-concealed { display: grid; flex: none; place-items: center; border: 1px dashed #7191b6; border-radius: 6px; color: #a9c3e2; background: #182d47; font-size: 28px; }
.gmResonanceShell #tileInspector .ti-unknown > span { width: 42px; height: 42px; }
.gmResonanceShell #tileInspector .ti-concealed { width: 80px; height: 80px; }
.gmResonanceShell #tileInspector .ti-unknown b { color: #b6cbe2; font-size: 12px; }
.gmResonanceShell #tileInspector .ti-unknown p { margin-bottom: 0; font-size: 11px; }
.gmResonanceShell #tileInspector .ti-no-links { padding-top: 10px; border-top: 1px solid #405d794a; color: #91a9c4; font-size: 11px; }
.gmResonanceShell #tileInspector .ti-footer { flex: none; padding: 8px 12px; border-top: 1px solid #45627e55; color: #98afc8; background: #13273e; font-size: 9px; line-height: 1.5; }

@media (max-width: 360px) {
    .gmResonanceShell .risk-stat { padding: 7px 6px; }
    .gmResonanceShell .risk-stat strong { font-size: 16px; }
    .gmResonanceShell .risk-tools button { padding: 7px; font-size: 10px; }
    .gmResonanceShell #tileInspector .ti-target { grid-template-columns: 78px minmax(0, 1fr); min-height: 94px; }
    .gmResonanceShell #tileInspector .ti-crop { width: 78px; height: 78px; }
}

@media (max-height: 760px) {
    .gmResonanceShell .risk-canvas-wrap canvas {
        height: clamp(210px, calc(100dvh - 430px), 340px);
        aspect-ratio: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .gmResonanceShell * { scroll-behavior: auto !important; }
}
