*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: #1a1a1e;
    color: #f0f0f2;
    overflow: hidden;
}

#app {
    min-height: 100%;
    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-root {
    position: relative;
    width: min(100vw, 100dvh, 100%);
    height: min(100vw, 100dvh, 100%);
    max-width: 100%;
    max-height: 100%;
    background: #2a2a30;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    padding: 0.55rem 0.65rem;
    gap: 0.35rem;
    overflow: hidden;
    min-height: 0;
}

#game-root.cr-game-root {
    min-height: min(100vw, 100dvh);
}

.cr-loading {
    margin: 0;
    padding: 1rem;
    text-align: center;
    opacity: 0.85;
}

/* Верх: прогресс студии + клик (t-006) */
.cr-progress-section {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.cr-header-compact {
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.45rem;
    min-height: 0;
}

.cr-header-metrics {
    flex: 1;
    min-width: 0;
    text-align: right;
    font-size: 0.62rem;
    line-height: 1.32;
}

.cr-budget--compact {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.cr-passive--compact {
    opacity: 0.9;
    font-variant-numeric: tabular-nums;
}

.cr-stage--compact {
    color: #9db4ff;
    font-size: 0.6rem;
}

.cr-meta-line {
    font-size: 0.58rem;
    opacity: 0.85;
    margin-top: 0.12rem;
    color: #c8c8d8;
}

.cr-budget-source-row {
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.65rem;
    padding: 0.1rem 0;
}

.cr-budget-source-label {
    opacity: 0.8;
}

.cr-budget-source-select {
    font: inherit;
    font-size: 0.65rem;
    padding: 0.2rem 0.35rem;
    border-radius: 4px;
    border: 1px solid #45454f;
    background: #2a2a32;
    color: #f0f0f2;
    max-width: 12rem;
}

.cr-progress-row {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 0.45rem;
    flex-shrink: 0;
    min-height: 0;
}

.cr-studio-preview--hero {
    width: 6.5rem;
    height: 4.6rem;
    flex-shrink: 0;
}

.cr-active-office-line {
    flex-shrink: 0;
    padding: 0.08rem 0;
}

.cr-title-wrap {
    flex: 1;
    min-width: 0;
}

.cr-game-title {
    margin: 0;
    font-size: clamp(0.85rem, 2.8vw, 1.05rem);
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: 0.01em;
}

.cr-studio-preview {
    flex-shrink: 0;
    width: 4.5rem;
    height: 3.25rem;
    border-radius: 6px;
    border: 1px solid #4a4a58;
    overflow: hidden;
    background: #1e1e26;
}

.cr-studio-art {
    width: 100%;
    height: 100%;
    position: relative;
    transition: background 0.25s ease, box-shadow 0.25s ease;
}

/* Уровень 1: гараж — тусклый квадрат «монитора» */
.cr-studio-preview[data-level="1"] .cr-studio-art {
    background: linear-gradient(160deg, #2c2c34 0%, #18181f 100%);
    box-shadow: inset 0 0 0 2px #3a3a44;
}

.cr-studio-preview[data-level="1"] .cr-studio-art::before {
    content: "";
    position: absolute;
    left: 12%;
    top: 22%;
    width: 52%;
    height: 38%;
    border-radius: 2px;
    background: #111118;
    border: 1px solid #333;
}

.cr-studio-preview[data-level="1"] .cr-studio-art::after {
    content: "";
    position: absolute;
    right: 10%;
    bottom: 14%;
    width: 22%;
    height: 18%;
    border-radius: 2px;
    background: #25252e;
}

/* Уровень 2: два окна */
.cr-studio-preview[data-level="2"] .cr-studio-art {
    background: linear-gradient(165deg, #34344a 0%, #22222c 100%);
}

.cr-studio-preview[data-level="2"] .cr-studio-art::before {
    content: "";
    position: absolute;
    left: 8%;
    top: 18%;
    width: 36%;
    height: 42%;
    border-radius: 3px;
    background: linear-gradient(180deg, #6a7ae8 0%, #3d4580 100%);
    opacity: 0.85;
}

.cr-studio-preview[data-level="2"] .cr-studio-art::after {
    content: "";
    position: absolute;
    right: 8%;
    top: 18%;
    width: 36%;
    height: 42%;
    border-radius: 3px;
    background: linear-gradient(180deg, #8ab4ff 0%, #3d5a80 100%);
    opacity: 0.85;
}

/* Уровень 3: три «окна» полосами */
.cr-studio-preview[data-level="3"] .cr-studio-art {
    background: linear-gradient(
        90deg,
        #2e3548 0 26%,
        #1e2230 26% 30%,
        #6a7ae8 30% 62%,
        #1e2230 62% 66%,
        #5c6bc0 66% 100%
    );
}

.cr-studio-preview[data-level="3"] .cr-studio-art::before,
.cr-studio-preview[data-level="3"] .cr-studio-art::after {
    display: none;
}

/* Уровень 4: «фасад» полосами */
.cr-studio-preview[data-level="4"] .cr-studio-art {
    background: repeating-linear-gradient(
        -8deg,
        #2e3548 0px,
        #2e3548 4px,
        #3d4a68 4px,
        #3d4a68 8px
    );
    box-shadow: inset 0 -8px 0 #1a2238;
}

.cr-studio-preview[data-level="4"] .cr-studio-art::before {
    content: "";
    position: absolute;
    left: 18%;
    top: 20%;
    width: 64%;
    height: 35%;
    border-radius: 2px;
    background: rgba(200, 210, 255, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.cr-studio-preview[data-level="4"] .cr-studio-art::after {
    content: "";
    position: absolute;
    right: 8%;
    top: 10%;
    width: 18%;
    height: 22%;
    border-radius: 1px;
    background: #c9a227;
    opacity: 0.9;
}

/* Уровень 5: небоскрёб + площадка */
.cr-studio-preview[data-level="5"] .cr-studio-art {
    background: linear-gradient(180deg, #1a1e2e 0%, #0f1118 100%);
}

.cr-studio-preview[data-level="5"] .cr-studio-art::before {
    content: "";
    position: absolute;
    left: 28%;
    bottom: 18%;
    width: 22%;
    top: 8%;
    border-radius: 2px 2px 0 0;
    background: linear-gradient(180deg, #a8b8ff 0%, #4a5a90 55%, #2a3350 100%);
    box-shadow: -0.55rem 0.35rem 0 -0.1rem #5a6ab0, 0.55rem 0.4rem 0 -0.1rem #6a7ae8;
}

.cr-studio-preview[data-level="5"] .cr-studio-art::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 18%;
    background: linear-gradient(90deg, #2a3040, #3a4560, #2a3040);
    border-top: 1px solid #5a6a90;
}

.cr-office-tabs {
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.cr-office-tab {
    margin: 0;
    padding: 0.28rem 0.45rem;
    font: inherit;
    font-size: 0.68rem;
    font-weight: 600;
    color: #e8e8ee;
    cursor: pointer;
    border-radius: 5px;
    border: 1px solid #45454f;
    background: #2a2a32;
}

.cr-office-tab:hover {
    border-color: #6a7ae8;
}

.cr-office-tab--active {
    border-color: #8a9aff;
    background: linear-gradient(180deg, #3a4488 0%, #2e3468 100%);
}

.cr-main-stack {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    overflow: hidden;
}

.cr-branches {
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.3rem 0.4rem;
    border-radius: 6px;
    background: #222228;
    border: 1px solid #35353f;
    max-height: 28%;
    min-height: 0;
    overflow: hidden;
}

.cr-branches-title {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.7;
}

.cr-branches-summary {
    font-size: 0.68rem;
    line-height: 1.35;
    opacity: 0.92;
    font-variant-numeric: tabular-nums;
}

.cr-branches-list {
    margin: 0;
    padding-left: 1rem;
    font-size: 0.65rem;
    line-height: 1.35;
    opacity: 0.88;
    overflow-y: auto;
    min-height: 0;
}

.cr-branches-item {
    margin: 0.1rem 0;
}

.cr-office-active-label {
    font-size: 0.68rem;
    font-weight: 600;
    color: #c8d4ff;
    letter-spacing: 0.02em;
}

.cr-goals {
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.35rem 0.45rem;
    border-radius: 6px;
    background: #222228;
    border: 1px solid #35353f;
    max-height: 22%;
    min-height: 0;
    overflow: hidden;
}

.cr-goals-title {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.72;
}

.cr-goals-list {
    margin: 0;
    padding-left: 1rem;
    font-size: 0.7rem;
    line-height: 1.35;
    opacity: 0.92;
    overflow-y: auto;
}

.cr-goals-item {
    margin: 0.12rem 0;
}

.cr-events,
.cr-achievements {
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.28rem 0.4rem;
    border-radius: 6px;
    background: #222228;
    border: 1px solid #35353f;
    max-height: 18%;
    min-height: 0;
    overflow: hidden;
}

.cr-events-title,
.cr-achievements-title {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.7;
}

.cr-events-body,
.cr-achievements-body {
    font-size: 0.65rem;
    line-height: 1.35;
    opacity: 0.9;
    overflow-y: auto;
    min-height: 0;
}

.cr-achievements-summary {
    font-size: 0.65rem;
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.cr-achievements-list {
    margin: 0;
    padding-left: 1rem;
}

.cr-achievements-item {
    margin: 0.08rem 0;
}

.cr-achievements-empty {
    opacity: 0.75;
}

.cr-reborn-wrap {
    flex-shrink: 0;
    display: none;
}

.cr-reborn-btn {
    width: 100%;
    margin: 0;
    padding: 0.35rem 0.45rem;
    font: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    color: #f8f4e8;
    cursor: pointer;
    border-radius: 6px;
    border: 1px solid #c9a227;
    background: linear-gradient(180deg, #6a5520 0%, #4a3a18 100%);
}

.cr-reborn-btn:hover {
    border-color: #e4c04a;
}

.cr-narrative-toast {
    position: absolute;
    left: 0.55rem;
    right: 0.55rem;
    top: 5.25rem;
    z-index: 3;
    padding: 0.45rem 0.55rem;
    border-radius: 6px;
    font-size: 0.72rem;
    line-height: 1.35;
    background: rgba(30, 35, 55, 0.96);
    border: 1px solid #5a6ab0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
}

.cr-narrative-toast.cr-narrative-toast--visible {
    opacity: 1;
}

.cr-upgrades-strip {
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    padding: 0.3rem 0.4rem;
    border-radius: 6px;
    background: #25252e;
    border: 1px solid #3a3a48;
    font-size: 0.68rem;
}

.cr-upgrades-strip-text {
    font-variant-numeric: tabular-nums;
    opacity: 0.92;
}

.cr-upgrades-strip-btn {
    margin: 0;
    padding: 0.28rem 0.45rem;
    font: inherit;
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 5px;
    border: 1px solid #6a7ae8;
    background: linear-gradient(180deg, #4a56a8 0%, #3a4488 100%);
    color: #f0f0f2;
}

.cr-upgrades-strip-btn:hover {
    border-color: #8a9aff;
}

.cr-upgrades {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-height: none;
}

.cr-upgrades-title {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.65;
}

.cr-upgrades-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding-right: 2px;
}

.cr-upgrade-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    padding: 0.35rem 0.45rem;
    border-radius: 6px;
    background: #25252e;
    border: 1px solid #3a3a48;
}

.cr-upgrade-info {
    flex: 1;
    min-width: 0;
}

.cr-upgrade-name {
    font-size: 0.78rem;
    font-weight: 600;
}

.cr-upgrade-detail {
    font-size: 0.68rem;
    opacity: 0.72;
    margin-top: 0.1rem;
}

.cr-upgrade-buy {
    flex-shrink: 0;
    margin: 0;
    padding: 0.35rem 0.5rem;
    font: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    color: #f0f0f2;
    cursor: pointer;
    border-radius: 5px;
    border: 1px solid #6a7ae8;
    background: linear-gradient(180deg, #4a56a8 0%, #3a4488 100%);
    white-space: nowrap;
}

.cr-upgrade-buy:hover:not(:disabled) {
    border-color: #8a9aff;
    background: linear-gradient(180deg, #5a66b8 0%, #4a5498 100%);
}

.cr-upgrade-buy:disabled {
    cursor: not-allowed;
    opacity: 0.45;
    border-color: #4a4a58;
    background: #2a2a32;
}

.cr-progress-row .cr-click-zone {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 3.5rem;
    margin: 0;
    border: 2px dashed #4a4a58;
    border-radius: 8px;
    background: linear-gradient(165deg, #32323c 0%, #26262e 100%);
    color: inherit;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    font: inherit;
    transition: border-color 0.15s ease, background 0.15s ease;
    padding: 0.35rem 0.4rem;
}

.cr-progress-row .cr-click-zone:hover {
    border-color: #6a7ae8;
}

.cr-progress-row .cr-click-zone:active {
    background: #1e1e26;
}

.cr-click-title {
    font-size: clamp(0.85rem, 2.5vw, 1.05rem);
    font-weight: 700;
}

.cr-click-sub {
    font-size: 0.62rem;
    opacity: 0.78;
    line-height: 1.3;
    text-align: center;
    max-width: 100%;
}

/* Справка: табы + скролл внутри панели (t-006) */
.cr-info-tabs {
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-height: 0;
    max-height: 42%;
}

.cr-tablist-row {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.3rem;
    flex-shrink: 0;
}

.cr-tablist-row--game {
    opacity: 0.96;
}

.cr-info-tablist {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.3rem;
    flex-shrink: 0;
}

.cr-info-tab {
    margin: 0;
    padding: 0.26rem 0.42rem;
    font: inherit;
    font-size: 0.65rem;
    font-weight: 600;
    color: #e8e8ee;
    cursor: pointer;
    border-radius: 5px;
    border: 1px solid #45454f;
    background: #2a2a32;
}

.cr-info-tab:hover {
    border-color: #6a7ae8;
}

.cr-info-tab--active {
    border-color: #8a9aff;
    background: linear-gradient(180deg, #3a4488 0%, #2e3468 100%);
}

.cr-info-panels {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 9.5rem;
    overflow: hidden;
}

.cr-info-panel {
    max-height: 9.5rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.4rem 0.5rem;
    border-radius: 6px;
    background: #222228;
    border: 1px solid #35353f;
    font-size: 0.66rem;
    line-height: 1.42;
}

.cr-info-panel--game {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.cr-info-panel--game .cr-upgrades {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
}

.cr-info-panel[hidden] {
    display: none !important;
}

.cr-info-p {
    margin: 0 0 0.45rem;
}

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

.cr-footer {
    flex-shrink: 0;
    text-align: center;
    font-size: 0.68rem;
    opacity: 0.55;
    padding-top: 0.15rem;
}

.cr-version {
    font-variant-numeric: tabular-nums;
}

.cr-achievements-tab-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr));
    gap: 0.35rem;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    padding: 2px;
}

.cr-ach-card {
    padding: 0.35rem 0.4rem;
    border-radius: 6px;
    border: 1px solid #3a3a48;
    background: #25252e;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-height: 4.2rem;
}

.cr-ach-card--unlocked {
    border-color: #5a6a98;
}

.cr-ach-card--locked {
    opacity: 0.72;
}

.cr-ach-card--locked .cr-ach-card-icon {
    opacity: 0.45;
    filter: grayscale(0.85);
}

.cr-ach-card-icon {
    font-size: 1.15rem;
    line-height: 1.2;
}

.cr-ach-card-title {
    font-size: 0.62rem;
    font-weight: 600;
    line-height: 1.25;
}

.cr-ach-card-desc {
    font-size: 0.55rem;
    opacity: 0.78;
    line-height: 1.3;
}

.cr-transfer-row {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
    align-items: center;
    gap: 0.3rem;
    padding: 0.28rem 0.4rem;
    font-size: 0.62rem;
    border-radius: 6px;
    background: #222228;
    border: 1px solid #35353f;
}

.cr-transfer-label {
    opacity: 0.75;
    width: 100%;
    flex-basis: 100%;
}

.cr-transfer-select {
    font: inherit;
    font-size: 0.62rem;
    padding: 0.18rem 0.3rem;
    border-radius: 4px;
    border: 1px solid #45454f;
    background: #2a2a32;
    color: #f0f0f2;
}

.cr-transfer-input {
    width: 4rem;
    font: inherit;
    font-size: 0.62rem;
    padding: 0.18rem 0.3rem;
    border-radius: 4px;
    border: 1px solid #45454f;
    background: #1e1e26;
    color: #f0f0f2;
}

.cr-transfer-btn {
    margin: 0;
    padding: 0.2rem 0.4rem;
    font: inherit;
    font-size: 0.62rem;
    cursor: pointer;
    border-radius: 4px;
    border: 1px solid #6a7ae8;
    background: #3a4488;
    color: #f0f0f2;
}

.cr-unlock-office {
    flex-shrink: 0;
}

.cr-unlock-office-btn {
    width: 100%;
    margin: 0;
    padding: 0.3rem 0.45rem;
    font: inherit;
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
    border: 1px solid #4a8a6a;
    background: linear-gradient(180deg, #2a5a40 0%, #1e4030 100%);
    color: #e8f8ee;
}

.cr-unlock-office-btn:hover:not(:disabled) {
    border-color: #6ad090;
}

.cr-unlock-office-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}
