/* ==========================================================================
   開窗抖動修正 (Open-Jitter Fix)
   成因：進場動畫含 scale()，動畫結束時整個視窗重新點陣化，而按鈕、圖標、輸入框
    因 translateZ(0) / will-change 各自是獨立圖層，與視窗本體取整位置不同步，
    於是文字與圖標在開窗瞬間產生 0.5～1px 位移。
   作法：1) 新增/編輯視窗改用 margin 置中 + 純位移（不縮放）進場，靜止時 transform: none
    2) 視窗內元件靜止時不再獨立成圖層（互動時的 hover / active 效果完全保留）
    3) 開窗後 360ms 內暫停子元件過渡與 hover 縮放（main.js 的 initModalOpenGuard 加上 .is-opening）
   ========================================================================== */

#editor-modal.shake-animation {
    animation: shakeError 0.4s cubic-bezier(.36, .07, .19, .97) !important;
}

/* 2. 視窗內元件靜止時不獨立成圖層（:where 不增加權重，:hover / :active 縮放照常生效） */
:where(#editor-modal, #full-editor-modal) :is(.btn-primary, .btn-danger, .btn-cancel, .action-delete-btn, .icon-btn, .circle-btn,
    .date-ui-display, .reminder-modal-checkbox, .segment-btn) {
    transform: none;
    will-change: auto;
    -webkit-backface-visibility: visible;
    backface-visibility: visible;
}

/* 預覽框原規則使用 ID 選擇器，需同等權重才能覆蓋；:active 縮放為 !important，不受影響 */
#editor-modal #bookmark-content,
#editor-modal #reminder-content {
    transform: none;
    will-change: auto;
}

:where(#editor-modal) .segment-btn svg {
    transform: scale(1);
    -webkit-backface-visibility: visible;
    backface-visibility: visible;
}

:where(#editor-modal) .segment-btn.active svg {
    transform: scale(1.3);
}

:where(#editor-modal) .segment-slider::before {
    will-change: auto;
}

/* 3. 開窗過程（.is-opening）：子元件不做任何過渡，也不吃 hover 縮放，避免游標恰好在按鈕上時彈跳 */
#editor-modal.is-opening *,
#editor-modal.is-opening *::before,
#editor-modal.is-opening *::after {
    transition: none !important;
}

#editor-modal.is-opening .btn-primary,
#editor-modal.is-opening .btn-danger,
#editor-modal.is-opening .btn-cancel,
#editor-modal.is-opening .action-delete-btn,
#editor-modal.is-opening .reminder-modal-checkbox {
    transform: none !important;
}

/* 輸入框文字：開窗與縮放期間不重排字距，並固定行高避免基線跳動 */
#editor-modal .custom-input,
#full-editor-modal .custom-input {
    text-rendering: auto;
    font-kerning: none;
    -webkit-text-size-adjust: 100%;
    scroll-margin: 0 !important;
}

/* ==========================================================================
   開窗抖動修正 第二輪 (Open-Jitter Fix, Round 2)
   不改動上方任何既有規則，僅以更後面 / 更高權重的規則覆蓋。
   A. 編輯提醒右上角勾勾：.checked svg 原本一出現就播放彈性動畫（scale 1.24 + rotate），
  編輯「已完成」的提醒時剛好與開窗動畫重疊；改為只在使用者實際點擊切換時播放（.check-pop，由 JS 加上）。
  注意：.is-opening 只能停 transition，停不了 animation，且移除 animation:none 會讓動畫重播，所以不能靠它。
   B. #editor-modal 本體的 text-rendering: optimizeLegibility 會讓縮放 / 位移期間字距重排，已合併至第 11 節主規則改回 auto。
   C. 新增 / 編輯視窗改用「整數像素」置中（支援 round() 的瀏覽器），不支援時沿用上一輪的 margin:auto。
   D. 其餘彈窗（日曆 / 確認 / 分類 / 排序 / 設定 / 雲端提示）進場去掉 scale，只用 opacity + translateY。
   E. 視窗外的底部切換軌道：去掉 scale 與 translateZ(0)，並改整數像素置中。
   F. 卡片：開窗時游標原本停在卡片上，hover 的 scale(1.03) 會以「彈性曲線」回彈，
  剛好與開窗重疊，卡片文字因此跟著抖；開窗期間改用不回彈的曲線（hover / active 回饋不變）。
   ========================================================================== */

div[id$="-modal"]:not(#full-editor-modal):not(#editor-modal):not(#sort-modal):not(#category-modal) {
    transform: translate(-50%, calc(-50% + 14px));
}

div[id$="-modal"].active:not(#full-editor-modal):not(#editor-modal):not(#sort-modal):not(#category-modal) {
    transform: translate(-50%, -50%);
}

body:has(#modal-overlay.active, #modal-overlay[style*="display: block"]) :is(.note-card, .reminder-card):not(:active) {
    transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s ease, border-color 0.3s ease;
}

[data-no-glass] .subtitle-pending,
[data-no-glass] .card-pending {
    opacity: 1 !important;
    transform: none !important;
}

[data-no-glass] .reminder-card.is-done.card-pending {
    opacity: 0.4 !important;
}

[data-no-glass] .card-entrance,
[data-no-glass] .title-entrance,
[data-no-glass] .time-entrance,
[data-no-glass] .tabs-entrance,
[data-no-glass] .action-bar-entrance,
[data-no-glass] .subtitle-entrance,
[data-no-glass] .title-scale-pop {
    animation: none !important;
    transform: none !important;
}

[data-no-glass] div[id$="-modal"]:not(#full-editor-modal),
[data-no-glass] div#editor-modal:not(#full-editor-modal),
[data-no-glass] div[id$="-modal"]:not(#full-editor-modal):not(#editor-modal),
[data-no-glass] #full-editor-modal,
[data-no-glass] #sort-modal,
[data-no-glass] #category-modal,
[data-no-glass] .editor-external-top-bar,
[data-no-glass] .editor-external-bottom-bar,
[data-no-glass] .sort-external-top-bar,
[data-no-glass] .sort-external-bottom-bar,
[data-no-glass] .category-external-top-bar,
[data-no-glass] .category-external-bottom-bar,
[data-no-glass] .calendar-top-bar {
    transition: none !important;
}

[data-no-glass] div[id$="-modal"]:not(#full-editor-modal):not(.active),
[data-no-glass] #editor-modal:not(.active),
[data-no-glass] #sort-modal:not(.active),
[data-no-glass] #category-modal:not(.active) {
    transform: translate(-50%, -50%) !important;
}

[data-no-glass] #full-editor-modal:not(.active) {
    transform: translate(-50%, -50%) !important;
}

[data-no-glass] .editor-external-top-bar:not(.active),
[data-no-glass] .editor-external-bottom-bar:not(.active),
[data-no-glass] .sort-external-top-bar:not(.active),
[data-no-glass] .sort-external-bottom-bar:not(.active),
[data-no-glass] .category-external-top-bar:not(.active),
[data-no-glass] .category-external-bottom-bar:not(.active) {
    transform: none !important;
}

[data-no-glass] .calendar-top-bar:not(.active) {
    transform: translate(-50%, 0) !important;
}

@media (max-width: 768px) {
    [data-no-glass] #full-editor-modal:not(.active) {
        transform: translateX(-50%) !important;
    }
}

