/* ============================================================================
 * SHG Unified Visualization i18n Layout & Anti-Overflow Engine
 * Modular & Zero-Intrusion: Deleting apps/subjects/shared/i18n/ or disabling
 * ENABLE_SHG_I18N cleanly restores 100% original state.
 * ============================================================================ */

/* --- 1. Compact Language Switcher Pill (.shg-i18n-pill) & Dropdown (.shg-i18n-menu) --- */
.shg-i18n-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 30px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    background: rgba(15, 23, 42, 0.78);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #f8fafc;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    z-index: 80;
}

.shg-i18n-pill:hover,
.shg-i18n-pill.is-open {
    border-color: rgba(56, 189, 248, 0.6);
    background: rgba(15, 23, 42, 0.94);
    color: #ffffff;
    box-shadow: 0 6px 16px rgba(14, 165, 233, 0.24);
}

.shg-i18n-pill__icon {
    width: 13px;
    height: 13px;
    opacity: 0.9;
    color: #38bdf8;
    flex-shrink: 0;
}

.shg-i18n-pill__cur {
    color: inherit;
}

.shg-i18n-pill__caret {
    width: 11px;
    height: 11px;
    opacity: 0.65;
    transition: transform 0.18s ease;
    flex-shrink: 0;
}

.shg-i18n-pill.is-open .shg-i18n-pill__caret {
    transform: rotate(180deg);
    opacity: 1;
}

/* Floating Language Popover Menu */
.shg-i18n-menu {
    position: fixed;
    width: 132px;
    padding: 5px;
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.26);
    background: rgba(15, 23, 42, 0.94);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 2px;
    animation: shgI18nMenuFadeIn 0.14s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes shgI18nMenuFadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.shg-i18n-menu__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 7px 10px;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: rgba(226, 232, 240, 0.85);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    text-align: left;
    transition: all 0.14s ease;
}

.shg-i18n-menu__item:hover {
    background: rgba(56, 189, 248, 0.14);
    color: #ffffff;
}

.shg-i18n-menu__item.is-active {
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.24), rgba(16, 185, 129, 0.2));
    color: #ffffff;
    font-weight: 700;
}

.shg-i18n-menu__check {
    color: #38bdf8;
    font-size: 11px;
    font-weight: 800;
}

/* Light theme adaptation (e.g., Physics light catalog / light sim header) */
#homeRoot:not(.theme-dark) .shg-i18n-pill[data-shg-i18n-slot="catalog"],
#simOverlay:not(.sim-theme-dark) .shg-i18n-pill[data-shg-i18n-slot="workbench"] {
    background: rgba(255, 255, 255, 0.92);
    border-color: rgba(15, 23, 42, 0.15);
    color: #0f172a;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

/* Unified Portal Header Right Group */
.shg-portal-header-right {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.shg-i18n-pill[data-shg-i18n-slot="portal"] {
    height: 32px;
    padding: 0 11px;
    font-size: 12px;
}

/* Only show the Portal language switcher on the initial Homepage; hide in subsequent selection/loading stages */
body.portal-stage-is-system .shg-i18n-pill[data-shg-i18n-slot="portal"],
body.portal-stage-is-subjects .shg-i18n-pill[data-shg-i18n-slot="portal"],
body:has(#subjectTransferOverlay.is-visible) .shg-i18n-pill[data-shg-i18n-slot="portal"] {
    display: none !important;
}

@media (max-width: 900px) {
    .shg-i18n-pill[data-shg-i18n-slot="portal"] {
        position: fixed;
        top: 14px;
        right: 14px;
        height: 30px;
        padding: 0 9px;
        font-size: 11px;
        z-index: 9500;
    }
}

/* Chemistry Workbench Top-Right Position */
.shg-i18n-pill[data-shg-i18n-slot="stage"] {
    position: fixed;
    top: 24px;
    right: 28px;
    height: 36px;
    padding: 0 12px;
    font-size: 12px;
    z-index: 95;
}

@media (max-width: 767px) {
    .shg-i18n-pill[data-shg-i18n-slot="stage"] {
        top: 14px;
        right: 14px;
        height: 30px;
        padding: 0 8px;
        font-size: 10px;
    }
}

/* --- 2. Pure Visualization Mode in Multi-Language (Hide Non-Vis Modules) --- */
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) #physicsOlCampaignEntryBtn,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) #labFloatEntry,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) #leftFloatColumn,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) #lsaFloatBadge,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) #floatPracticeBtn,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) #questionBankEntryBtn,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) [aria-label="打开题库练习"],
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) [aria-label="返回题库练习"],
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) .physics-qb-entry,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) [class*="shg-assistant"],
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) [data-shg-hide-in-en="true"] {
    display: none !important;
}

/* --- 3. Zero Button Overflow & Typography Protection Across All Locales --- */
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) button,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) .btn,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) .preset-chip,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) .step-btn,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) .physics-catalog-category,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) .physics-catalog-card__action,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) #tabControls,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) #tabHelp,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) .engine-preview-primary,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) .engine-preview-secondary {
    white-space: nowrap !important;
    word-break: keep-all !important;
    overflow-wrap: normal !important;
    letter-spacing: 0.02em !important;
}

/* Prevent card buttons from overriding multi-line card content inside <button class="physics-catalog-card"> or stage cards */
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) button.physics-catalog-card,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) button.card-hover,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) button[data-card-id] {
    white-space: normal !important;
}

/* Optical sizing inside courseware sidebars & control panels */
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) .sidebar,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) #paneControls,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) #simControls,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) [data-courseware-aside="true"],
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) .control-panel {
    letter-spacing: -0.01em;
}

html[data-shg-lang]:not([data-shg-lang="zh-CN"]) .sidebar button,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) #simControls button,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) [data-courseware-aside="true"] button {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

html[data-shg-lang]:not([data-shg-lang="zh-CN"]) h1,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) h2,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) h3,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) .physics-catalog-card__title,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) .engine-preview-title {
    text-wrap: balance;
}

html[data-shg-lang]:not([data-shg-lang="zh-CN"]) p,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) li,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) .engine-preview-abstract,
html[data-shg-lang]:not([data-shg-lang="zh-CN"]) .engine-preview-point__text {
    text-wrap: pretty;
    hyphens: auto;
}
