:root {
    --glyph-upgrade-stage-left: max(env(safe-area-inset-left), calc((100vw - min(100vw, var(--game-stage-max-width, 500px))) / 2));
}

.glyphUpgradeModal[hidden], .glyphUpgradeModal [hidden] { display: none !important; }
.glyphUpgradeModal {
    position: fixed;
    inset: 0;
    z-index: 8200;
    display: grid;
    place-items: center;
    padding: 16px;
    font-family: "Poppins", sans-serif;
    color: #e6f6ff;
}
.glyphUpgradeModal * { box-sizing: border-box; }
.glyphUpgradeBackdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
    background: rgba(0, 8, 14, .8);
}
.glyphUpgradeDialog {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(620px, 100%);
    max-height: calc(100dvh - 32px);
    overflow: hidden;
    overscroll-behavior: contain;
    border: 1px solid rgba(89, 192, 228, .65);
    border-radius: 16px;
    background: linear-gradient(160deg, #09374b, #031e2e 60%, #021724);
    box-shadow: 0 24px 80px #000b, inset 0 0 0 1px #ffffff08;
}
.glyphUpgradeHeader {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 15px 20px;
    border-bottom: 1px solid #74c9e829;
    background: linear-gradient(90deg, #13668138, transparent);
}
.glyphUpgradeHeader > div:first-child { display: grid; gap: 3px; }
.glyphUpgradeHeader small { font-size: 9px; font-weight: 700; letter-spacing: .2em; color: #87c2d5; }
.glyphUpgradeHeader strong { font-size: 16px; font-weight: 900; letter-spacing: .06em; }
.glyphUpgradeHeaderActions { display:flex; align-items:center; gap:8px; }
.glyphUpgradeMinimize,
.glyphUpgradeClose {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid #5bc1e56b;
    border-radius: 8px;
    background: #04374cb8;
    color: #8fe8ff;
    cursor: pointer;
}
.glyphUpgradeMinimize { font: 900 22px/1 sans-serif; }
.glyphUpgradeClose { font: 24px/1 sans-serif; }
.glyphUpgradeModal.is-minimized { pointer-events:none; padding:0; }
.glyphUpgradeModal.is-minimized .glyphUpgradeBackdrop,
.glyphUpgradeModal.is-minimized .glyphUpgradeDialog { display:none; }
.glyphUpgradeMinimized {
    position: fixed;
    left: var(--glyph-upgrade-stage-left);
    top: 63%;
    z-index: 8202;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 66px;
    min-height: 116px;
    padding: 9px 7px 8px;
    border: 1px solid rgba(89,192,228,.72);
    border-left: 0;
    border-radius: 0 13px 13px 0;
    background: linear-gradient(160deg, rgba(9,55,75,.98), rgba(3,30,46,.98));
    color: #dff8ff;
    box-shadow: 8px 10px 28px #0008, inset 0 0 0 1px #ffffff08;
    transform: translateY(-50%);
    pointer-events: auto;
    cursor: pointer;
    touch-action: manipulation;
    font-family: "Poppins", sans-serif;
}
.glyphUpgradeMinimized:hover { filter: brightness(1.1); }

.glyphUpgradeMinimizedClose {
    position:fixed;
    left:calc(var(--glyph-upgrade-stage-left) + 49px);
    top:calc(63% - 66px);
    z-index:8203;
    display:grid;
    place-items:center;
    width:22px;
    height:22px;
    padding:0;
    border:1px solid rgba(137,218,244,.55);
    border-radius:50%;
    background:rgba(4,39,56,.96);
    color:#dff8ff;
    font:800 15px/1 sans-serif;
    box-shadow:0 3px 10px #0008;
    cursor:pointer;
    touch-action:manipulation;
}
.glyphUpgradeMinimizedClose:hover { filter:brightness(1.12); }
.glyphUpgradeMinimizedClose[hidden] { display:none; }
.glyphUpgradeMinimizedVisual { position:relative; display:grid; place-items:center; width:50px; height:50px; }
.glyphUpgradeMinimizedVisual .glyphVisual { width:50px; height:50px; }
.glyphUpgradeMinimized.is-complete .glyphUpgradeMinimizedVisual::after {
    content:"✓";
    position:absolute;
    right:-3px;
    bottom:-2px;
    display:grid;
    place-items:center;
    width:20px;
    height:20px;
    border:2px solid #073448;
    border-radius:50%;
    background:#28c878;
    color:#fff;
    font:900 13px/1 sans-serif;
    box-shadow:0 2px 7px #0008;
    z-index: inherit;
}
.glyphUpgradeMinimized > strong { font:900 11px/1 "Poppins", sans-serif; color:#c9f4ff; }
.glyphUpgradeMinimized > i { font-size:13px; color:#8fe8ff; }
.glyphUpgradeMinimized[data-phase="pending"] .glyphUpgradeMinimizedVisual { animation:glyphUpgradeMiniPulse .65s ease-in-out infinite alternate; }
@keyframes glyphUpgradeMiniPulse { to { transform:scale(1.06); filter:drop-shadow(0 0 7px #37ecdf99); } }
.glyphUpgradeCompletionNotice {
    position:fixed;
    left:calc(var(--glyph-upgrade-stage-left) + 6px);
    top:auto;
    bottom:calc(50% - 67px);
    z-index:8204;
    max-width:min(280px, calc(100vw - 2px));
    padding:8px 11px;
    border:1px solid rgba(72,214,142,.42);
    border-radius:9px;
    background:rgba(5,42,55,.97);
    color:#bdf7d6;
    font:800 10px/1.25 "Poppins", sans-serif;
    box-shadow:0 7px 20px #0008;
    pointer-events:none;
}
.glyphUpgradeCompletionNotice[hidden] { display:none; }
.glyphUpgradeCompletionNotice.is-visible { animation:glyphUpgradeCompletionNoticeIn .18s ease-out both; }
@keyframes glyphUpgradeCompletionNoticeIn { from { opacity:0; transform:translateY(5px); } to { opacity:1; transform:translateY(0); } }
.glyphUpgradeBody { display: grid; grid-template-columns: .95fr 1.05fr; gap: 18px; padding: 20px; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.glyphUpgradeHero { display: flex; flex-direction: column; align-items: center; min-width: 0; text-align: center; }
.glyphUpgradeHero h2 { margin: 0 0 5px; font-size: 20px; font-weight: 900; text-transform: uppercase; letter-spacing: .03em; }
.glyphUpgradeRarity { color: #9cbecd; font-size: 10px; }
.glyphUpgradeRarity[data-rarity="rare"] { color: #78c6ff; }
.glyphUpgradeRarity[data-rarity="epic"] { color: #f6ce7b; }
.glyphUpgradeRarity[data-rarity="legendary"] { color: #d2a2f7; }
.glyphUpgradeRarity[data-rarity="dark"] { color: #f6ce7b; }
.glyphUpgradeStage { position: relative; display: grid; place-items: center; width: 100%; height: 210px; isolation: isolate; }
.glyphUpgradeStage::before {
    content: "";
    position: absolute;
    width: 90%;
    aspect-ratio: 1;
    z-index: -1;
    background: radial-gradient(ellipse, #11bac02b, #0cc3d10c 45%, transparent 68%);
    transition: opacity .2s;
}
.glyphUpgradeOrbit {
    position: absolute;
    width: 172px;
    height: 172px;
    border: 1px solid #54c5d72b;
    border-radius: 50%;
    box-shadow: 0 0 0 9px #54c5d705, 0 0 0 10px #54c5d71a;
}
.glyphUpgradeOrbit::before, .glyphUpgradeOrbit::after, .glyphUpgradeOrbit > span {
    content: "";
    position: absolute;
    inset: 18px;
    border: 1px solid #54c5d733;
    transform: rotate(45deg);
}
.glyphUpgradeOrbit::after { transform: rotate(15deg); }
.glyphUpgradeOrbit > span { transform: rotate(-15deg); }
.glyphUpgradeVisual { position: relative; width: 125px; height: 125px; filter: drop-shadow(0 8px 12px #0009); }
.glyphUpgradeVisual .glyphVisual { width: 100%; height: 100%; }
.glyphUpgradeLevel { padding: 4px 12px; border: 1px solid #71c5dc33; border-radius: 20px; background: #051b2bb3; font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.glyphUpgradeResult { position: absolute; z-index: 2; font-size: clamp(26px, 5vw, 37px); font-weight: 950; letter-spacing: .04em; color: #ffe79c; text-shadow: 0 3px 0 #765218, 0 0 15px #000, 2px 2px 2px #000; animation: glyphUpgradeReveal .225s ease-out both; }
.glyphUpgradeOutcome { display: grid; align-content: start; gap: 5px; min-height: 53px; margin-top: 12px; font-size: 10px; line-height: 1.6; color: #b3d4df; }
.glyphUpgradeOutcome strong { color: #81eda4; font-size: 10px; }
.glyphUpgradePreview { min-width: 0; padding: 12px; border: 1px solid #5bbed638; border-radius: 11px; background: #01131f80; }
.glyphUpgradePreview h3 { margin: 0 0 12px; font-size: 10px; line-height: 1.5; font-weight: 800; letter-spacing: .05em; color: #c8e8f3; }
.glyphUpgradeProgress { display: grid; justify-items: center; gap: 10px; padding: 12px 6px; margin-bottom: 12px; border-radius: 8px; background: #03111ca6; }
.glyphUpgradeMilestones { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.glyphUpgradeMilestone { font-size: 11px; color: #557b8b; padding: 3px 7px; border: 1px solid #557b8b33; border-radius: 6px; }
.glyphUpgradeMilestone.is-reached { color: #ffcd65; border-color: #ffcd6540; background: #a97b0912; }
.glyphUpgradeMilestone.is-next { color: #81eda4; border-color: #81eda466; background: #29b9641a; }
.glyphUpgradeNextLevel { display: flex; align-items: center; gap: 12px; font-size: 12px; color: #8eafbd; }
.glyphUpgradeNextLevel strong { color: #e6f6ff; font-size: 20px; }
.glyphUpgradeNextLevel strong:last-child { color: #81eda4; }
.glyphUpgradeBonus { margin: 0; color: #81eda4; font-size: 10px; font-weight: 700; text-align: center; }
.glyphUpgradeStats { display: grid; gap: 5px; }
.glyphUpgradeStat { display: flex; align-items: center; gap: 7px; min-height: 38px; padding: 6px 7px; border-radius: 6px; background: #173f512e; border: 1px solid transparent; font-size: 11px; }
.glyphUpgradeStat.is-main { background: #14607730; border-color: #76d2e42b; }
.glyphUpgradeStat.is-proc { border-color: #81eda44d; background: #18754726; }
.glyphUpgradeStat > img { width: 20px; height: 20px; object-fit: contain; }
.glyphUpgradeStatName { flex: 1; min-width: 0; font-size: 10px; font-weight: 700; }
.glyphUpgradeStatName small { display: block; margin-top: 2px; color: #7b9daa; font-size: 8px; font-weight: 400; }
.glyphUpgradeStat > strong { font-size: 11px; white-space: nowrap; }
.glyphUpgradeStatNext { color: #81eda4; }

.glyphUpgradeStat.is-legendary { border-color: rgba(255, 153, 51, .72); background: rgba(155, 76, 9, .24); box-shadow: inset 0 0 0 1px rgba(255, 177, 70, .08); }
.glyphUpgradeStat.is-legendary .glyphUpgradeStatName,
.glyphUpgradeStat.is-legendary > strong { color: #ffad4d; }
.glyphUpgradeStat.is-legendary .glyphUpgradeStatName small { color: #e69442; }
.glyphUpgradeOutcome strong.is-legendary { color: #ff9f32; text-shadow: 0 0 10px rgba(255, 129, 25, .3); }
.glyphUpgradeNoSubs { color: #7296a5; font-size: 10px; text-align: center; padding: 10px 0; }
.glyphUpgradeChance { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-top: 16px; font-size: 10px; color: #95b8c6; }
.glyphUpgradeChance strong { color: #99eaf0; }
.glyphUpgradeChanceTrack { width: 100%; height: 4px; overflow: hidden; border-radius: 4px; background: #07131c; }
.glyphUpgradeChanceTrack i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #087ba3, #1bd3cb); transition: width .3s; }
.glyphUpgradeFooter { display: grid; flex-shrink: 0; grid-template-columns: 1fr auto; align-items: center; gap: 10px 18px; padding: 16px 20px; border-top: 1px solid #74c9e829; background: #01131f66; }
.glyphUpgradeControls { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
.glyphUpgradeControls .glyphUpgradeAction { min-width: 110px; flex: 1; height: 46px; margin: 0; }
.glyphUpgradeTarget { display: flex; flex: 0 0 64px; margin: 0; color: #9dbfce; font-size: 11px; }
.glyphUpgradeTarget select { width: 64px; height: 46px; min-height: 46px; margin: 0; padding: 6px; border: 1px solid #5bc1e56b; border-radius: 8px; background: #043044; color: #e6f6ff; font: inherit; }
.glyphUpgradeTarget select:focus-visible { outline: 2px solid #c6fbff; outline-offset: 3px; }
.glyphUpgradeControls:has([data-upgrade-stop]:not([hidden])) [data-upgrade-action] { display: none; }
.glyphUpgradePrice { display: grid; gap: 3px; }
.glyphUpgradePrice > small { color: #9dbfce; font-size: 10px; }
.glyphUpgradePrice > strong { font-size: 22px; font-weight: 900; }
.glyphUpgradePrice strong small { font-size: 11px; font-weight: 500; }
.glyphUpgradePrice > span { font-size: 9px; color: #7ea4b6; }
.glyphUpgradeCrystal {
    display:inline-block;
    width:18px;
    height:18px;
    margin-right:2px;
    object-fit:contain;
    vertical-align:-3px;
    filter:drop-shadow(0 0 6px rgba(44,200,237,.28));
}
.glyphUpgradeAction { min-height: 46px; min-width: 174px; padding: 12px 20px; border: 1px solid #98ede8; border-radius: 10px; background: linear-gradient(180deg, #15d4dc, #009cae 60%, #00778c); color: #efffff; font: 900 12px/1.2 "Poppins", sans-serif; letter-spacing: .035em; text-shadow: 0 1px 2px #00535d; box-shadow: inset 0 2px 0 #d6ffff5e, inset 0 -3px 0 #00526891, 0 3px 10px #0005; cursor: pointer; touch-action: manipulation; }
.glyphUpgradeAction:hover:not(:disabled) { filter: brightness(1.12); }
.glyphUpgradeAction:active:not(:disabled) { transform: translateY(1px); }
.glyphUpgradeAction:disabled { opacity: .42; cursor: default; }
.glyphUpgradeSell { grid-column: 2; width: 100%; min-height: 36px; padding: 8px 12px; border: 1px solid #ff8f8f99; border-radius: 9px; background: linear-gradient(180deg, #d94b50, #a81f2b 62%, #79151f); color: #fff3f3; font: 900 10px/1.2 "Poppins", sans-serif; letter-spacing: .045em; text-shadow: 0 1px 2px #5a0910; box-shadow: inset 0 1px 0 #ffd2d24a, inset 0 -2px 0 #5b101d99, 0 3px 9px #0005; cursor: pointer; touch-action: manipulation; }
.glyphUpgradeSell:hover:not(:disabled) { filter: brightness(1.12); }
.glyphUpgradeSell:active:not(:disabled) { transform: translateY(1px); }
.glyphUpgradeSell:disabled { opacity: .38; cursor: default; }
.glyphUpgradeDialog button:focus-visible { outline: 2px solid #c6fbff; outline-offset: 3px; }
.glyphUpgradeCostNote, .glyphUpgradeFunds { grid-column: 1 / -1; margin: 0; font-size: 9px; line-height: 1.5; color: #819fac; }
.glyphUpgradeFunds { color: #ffc67a; }
.glyphUpgradeModal[data-phase="pending"] .glyphUpgradeOrbit { animation: glyphUpgradeSpin 1.2s linear infinite; border-color: #5de8e9aa; box-shadow: 0 0 28px #26d7cd50, inset 0 0 20px #26d7cd20; }
.glyphUpgradeModal[data-phase="pending"] .glyphUpgradeVisual { animation: glyphUpgradePulse .325s ease-in-out infinite alternate; }
.glyphUpgradeModal[data-phase="success"] .glyphUpgradeStage::before { background: radial-gradient(ellipse, #25ebd18c, #0cc3d12b 48%, transparent 70%); animation: glyphUpgradeGlow .16s ease-out both; }
.glyphUpgradeModal[data-phase="failure"] .glyphUpgradeResult { color: #ffc0a2; text-shadow: 0 3px 0 #693124, 0 0 15px #000; }
.glyphUpgradeModal[data-phase="failure"] .glyphUpgradeVisual { animation: glyphUpgradeShake .16s ease-out; }
.glyphUpgradeModal[data-phase="error"] .glyphUpgradeOutcome { color: #ffb79e; }
@keyframes glyphUpgradeSpin { to { transform: rotate(360deg); } }
@keyframes glyphUpgradePulse { to { transform: translateY(-4px) scale(1.05); filter: drop-shadow(0 0 20px #37ecdf); } }
@keyframes glyphUpgradeReveal { from { opacity: 0; transform: scale(1.18); } to { opacity: 1; transform: scale(1); } }
@keyframes glyphUpgradeGlow { from { opacity: 1; transform: scale(1.12); } to { opacity: .55; transform: scale(1); } }
@keyframes glyphUpgradeShake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@media (max-width: 540px) {
    .glyphUpgradeModal { padding: 10px; }
    .glyphUpgradeDialog { max-height: calc(100dvh - 20px); border-radius: 12px; }
    .glyphUpgradeHeader { padding: 12px 14px; }
    .glyphUpgradeHeader strong { font-size: 13px; }
    .glyphUpgradeHeaderActions { gap:6px; }
    .glyphUpgradeMinimize, .glyphUpgradeClose { width:30px; height:30px; }
    .glyphUpgradeMinimized { width:58px; min-height:104px; padding:8px 5px 7px; }
    .glyphUpgradeCompletionNotice { left:calc(var(--glyph-upgrade-stage-left) + 6px); bottom:calc(50% + 60px); }
    .glyphUpgradeMinimizedClose { left:calc(var(--glyph-upgrade-stage-left) + 42px); top:calc(63% - 60px); width:21px; height:21px; font-size:14px; }
    .glyphUpgradeMinimizedVisual, .glyphUpgradeMinimizedVisual .glyphVisual { width:44px; height:44px; }
    .glyphUpgradeBody { gap: 10px; padding: 12px; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); }
    .glyphUpgradeHero h2 { font-size: clamp(13px, 3.4vw, 18px); overflow-wrap: anywhere; }
    .glyphUpgradeStage { height: 160px; }
    .glyphUpgradeOrbit { width: min(134px, calc(100% - 20px)); height: auto; aspect-ratio: 1; }
    .glyphUpgradeVisual { width: min(102px, 75%); height: auto; aspect-ratio: 1; }
    .glyphUpgradeOutcome { min-height: 30px; margin-top: 8px; }
    .glyphUpgradePreview { padding: 8px; }
    .glyphUpgradeProgress { gap: 6px; padding: 8px 3px; margin-bottom: 9px; }
    .glyphUpgradeMilestones { gap: 4px; }
    .glyphUpgradeMilestone { padding: 3px 5px; }
    .glyphUpgradeNextLevel { gap: 6px; }
    .glyphUpgradePreview h3 { margin-bottom: 9px; }
    .glyphUpgradeStat { min-height: 34px; }
    .glyphUpgradeChance { margin-top: 12px; }
    .glyphUpgradeFooter { padding: 12px 14px; gap: 8px; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); }
    .glyphUpgradeControls { min-width: 0; gap: 5px; }
    .glyphUpgradeTarget { flex-basis: 54px; }
    .glyphUpgradeTarget select { width: 54px; padding: 4px; }
    .glyphUpgradeControls .glyphUpgradeAction { min-width: 0; padding: 8px 5px; font-size: 9px; overflow-wrap: anywhere; }
    .glyphUpgradePrice > strong { font-size: 19px; }
    .glyphUpgradeAction { min-width: 135px; padding: 11px 12px; font-size: 10px; }
    .glyphUpgradeSell { min-height: 34px; padding: 7px 8px; font-size: 9px; }
}
@media (max-width: 380px) {
    .glyphUpgradeBody { gap: 8px; padding: 10px; }
    .glyphUpgradeStat { flex-wrap: wrap; gap: 4px; padding: 5px; }
    .glyphUpgradeStat > strong { width: 100%; text-align: right; }
    .glyphUpgradeStage { height: 140px; }
    .glyphUpgradeNextLevel { font-size: 10px; }
    .glyphUpgradeNextLevel strong { font-size: 17px; }
}
@media (prefers-reduced-motion: reduce) {
    .glyphUpgradeModal *, .glyphUpgradeModal *::before, .glyphUpgradeModal *::after { animation: none !important; transition: none !important; }
}

/* Rune +13 V1.1 — aucun affixe ne doit élargir le modal horizontalement. */
.glyphUpgradeBody { overflow-x:hidden; }
.glyphUpgradePreview,
.glyphUpgradeStats,
.glyphUpgradeStat { min-width:0; max-width:100%; }
.glyphUpgradeStat {
    display:grid;
    grid-template-columns:20px minmax(0,1fr) auto auto;
    align-items:center;
}
.glyphUpgradeStatName {
    min-width:0;
    overflow-wrap:anywhere;
    word-break:normal;
    line-height:1.12;
}
.glyphUpgradeStat > strong { min-width:0; max-width:100%; }
@media (max-width:380px) {
    .glyphUpgradeStat { grid-template-columns:18px minmax(0,1fr) auto; }
    .glyphUpgradeStat > strong { width:auto; }
    .glyphUpgradeStatNext { grid-column:2 / -1; text-align:right; }
}
