/* --- Beginnings State (Idle Start Screen) --- */
body.beginnings-active .container {
    opacity: 1 !important;
    pointer-events: auto !important;
    transform: translate(-50%, -50%) scale(1) !important;
    transition: opacity 0.4s ease, transform 1s linear(0 0%, 0 1.8%, 0.01 3.6%, 0.03 6.35%, 0.07 9.1%, 0.13 11.4%, 0.19 13.4%, 0.27 15%, 0.34 16.1%, 0.54 18.35%, 0.66 20.6%, 0.72 22.4%, 0.77 24.6%, 0.81 27.3%, 0.85 30.4%, 0.88 35.1%, 0.92 40.6%, 0.94 47.2%, 0.96 55%, 0.98 64%, 0.99 74.4%, 1 86.4%, 1 100%) !important;
    z-index: 10 !important;
    cursor: pointer;
}

body.beginnings-active .container .clock {
    cursor: pointer;
}

body.beginnings-active #minihompy-container {
    opacity: 0 !important;
    filter: blur(10px) !important;
    pointer-events: none !important;
    visibility: hidden !important;
    transform: translateY(50%) !important;
}

body.beginnings-active .widget-grid {
    transform: translateY(0) !important;
    transition: opacity 0.4s ease, transform 1s linear(0 0%, 0 1.8%, 0.01 3.6%, 0.03 6.35%, 0.07 9.1%, 0.13 11.4%, 0.19 13.4%, 0.27 15%, 0.34 16.1%, 0.54 18.35%, 0.66 20.6%, 0.72 22.4%, 0.77 24.6%, 0.81 27.3%, 0.85 30.4%, 0.88 35.1%, 0.92 40.6%, 0.94 47.2%, 0.96 55%, 0.98 64%, 0.99 74.4%, 1 86.4%, 1 100%) !important;
}

body.home-screen-active:not(.beginnings-active) .widget-grid {
    opacity: 0 !important;
    filter: blur(10px) !important;
    pointer-events: none !important;
    visibility: hidden !important;
    transform: translateY(-100%) !important;
    transition: opacity 0.35s ease, filter 0.35s ease, transform 1s linear(0 0%, 0 1.8%, 0.01 3.6%, 0.03 6.35%, 0.07 9.1%, 0.13 11.4%, 0.19 13.4%, 0.27 15%, 0.34 16.1%, 0.54 18.35%, 0.66 20.6%, 0.72 22.4%, 0.77 24.6%, 0.81 27.3%, 0.85 30.4%, 0.88 35.1%, 0.92 40.6%, 0.94 47.2%, 0.96 55%, 0.98 64%, 0.99 74.4%, 1 86.4%, 1 100%), visibility 0.35s ease !important;
}

/* --- Home Screen Active State --- */
body.home-screen-active:not(.beginnings-active) .container {
    opacity: 0 !important;
    filter: blur(10px) !important;
    pointer-events: none !important;
    visibility: hidden !important;
    transform: translate(-50%, -250%) !important;
    transition: opacity 0.35s ease, filter 0.35s ease, transform 1s linear(0 0%, 0 1.8%, 0.01 3.6%, 0.03 6.35%, 0.07 9.1%, 0.13 11.4%, 0.19 13.4%, 0.27 15%, 0.34 16.1%, 0.54 18.35%, 0.66 20.6%, 0.72 22.4%, 0.77 24.6%, 0.81 27.3%, 0.85 30.4%, 0.88 35.1%, 0.92 40.6%, 0.94 47.2%, 0.96 55%, 0.98 64%, 0.99 74.4%, 1 86.4%, 1 100%), visibility 0.35s ease !important;
}

body.home-screen-active:not(.beginnings-active):not(.blackout-active):not(.app-active):not(.edit-mode-active) #minihompy-container {
    opacity: 1 !important;
    filter: none !important;
    pointer-events: auto !important;
    visibility: visible !important;
    transform: scale(1) translateY(0) !important;
}

body.home-screen-active:not(.beginnings-active) .clockwidgets {
    z-index: 50;
    bottom: 28px;
    gap: 16px;
}

body.home-screen-active:not(.beginnings-active) .clock-activity-capsule {
    height: 42px;
    padding: 0 14px;
}

body.home-screen-active:not(.beginnings-active) .clock-activity-capsule .clock-activity-text {
    font-size: 1rem;
}

body.home-screen-active:not(.beginnings-active) .clock-activity-capsule  span.clock-activity-icon,
body.home-screen-active:not(.beginnings-active) .clock-activity-capsule .material-symbols-rounded {
    font-size: 18px;
}

body.home-screen-active:not(.beginnings-active) .clock-activity-capsule img.clock-activity-icon {
    width: 24px;
    height: 24px;
}

body.beginnings-active .clockwidgets {
    opacity: 1 !important;
    pointer-events: auto !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    z-index: 10 !important;
    cursor: pointer;
}

/* Hide Minihompy during App execution, Blackout, Screen sleep, or Wallpaper editing */
body.app-active #minihompy-container,
body.blackout-active #minihompy-container,
body.edit-mode-active #minihompy-container,
body:has(#wallpaper-switcher-overlay.show) #minihompy-container {
    opacity: 0 !important;
    filter: blur(10px) !important;
    pointer-events: none !important;
    visibility: hidden !important;
    transform: scale(1.1) !important;
}

body.beginnings-active #minihompy-container *,
body.app-active #minihompy-container *,
body.blackout-active #minihompy-container *,
body.edit-mode-active #minihompy-container *,
body:has(#wallpaper-switcher-overlay.show) #minihompy-container * {
    pointer-events: none !important;
}

/* --- Main Minihompy Container --- */
.minihompy-container {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    padding: 0;
    pointer-events: none;
    opacity: 0;
    filter: blur(10px);
    transform: scale(1.1);
    transition: opacity 0.35s ease, filter 0.35s ease, transform 1s linear(0 0%, 0 1.8%, 0.01 3.6%, 0.03 6.35%, 0.07 9.1%, 0.13 11.4%, 0.19 13.4%, 0.27 15%, 0.34 16.1%, 0.54 18.35%, 0.66 20.6%, 0.72 22.4%, 0.77 24.6%, 0.81 27.3%, 0.85 30.4%, 0.88 35.1%, 0.92 40.6%, 0.94 47.2%, 0.96 55%, 0.98 64%, 0.99 74.4%, 1 86.4%, 1 100%), visibility 0.35s ease !important;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

/* --- Home Pages Viewport (Fluid iPadOS Spacing) --- */
.home-pages-viewport {
    width: 100%;
    height: calc(100% - 100px);
    overflow: hidden;
    position: relative;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    touch-action: none;
    margin: 28px auto auto auto;
}

.home-pages-track {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    transition: transform 0.42s cubic-bezier(0.2, 1.15, 0.4, 1);
    will-change: transform;
    touch-action: none;
}

/* --- Individual Home Page (Custom Positioned Container) --- */
.home-page {
    flex: 0 0 100%;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
    touch-action: none;
}

/* Base style for absolutely positioned items */
.home-page .home-grid-item {
    position: absolute;
    top: 0;
    left: 0;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: transform 0.32s cubic-bezier(0.2, 0.9, 0.3, 1), width 0.28s ease, height 0.28s ease;
    will-change: transform;
}

/* --- App Icons (1:1 Aspect Ratio) --- */
.home-page .app-icon {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    box-sizing: border-box;
    cursor: pointer;
}

.home-page .app-icon .app-icon-img {
    width: min(72px, 72%);
    height: min(72px, 72%);
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease;
}

.home-page .app-icon .app-icon-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
    corner-shape: inherit;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.28));
}

.home-page .app-icon span, .folder-label, .widget-label {
    font-size: 0.9rem;
    text-align: center;
    color: var(--text-color);
    font-weight: 500;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-shadow: 0 0 5px var(--background-color-tr);
    user-select: none;
    -webkit-user-select: none;
    pointer-events: none;
}

.home-page .app-icon span, .folder-label {
    margin-top: 16px;
}

.widget-label {
    margin-top: 6px;
    height: 20px;
    line-height: 20px;
    flex-shrink: 0;
    max-width: 90% !important;
}

/* --- Folders on Home Screen --- */
.home-page .folder-icon-item {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.folder-preview-box {
    width: min(72px, 72%);
    height: min(72px, 72%);
    aspect-ratio: 1 / 1;
    background-color: var(--overlay-color);
    border-radius: 35%;
    corner-shape: superellipse(1.25);
    border: 1px solid var(--glass-border);
    --fx-filter: var(--blur1) glass(0.6, 8, 0);
    box-shadow: var(--sun-shadow);
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 6px;
    padding: 10px;
    box-sizing: border-box;
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.home-page .folder-icon-item:active .folder-preview-box {
    filter: brightness(1.5);
    transform: scale(1.2);
}

body.home-edit-active .home-page .folder-icon-item:active .folder-preview-box {
    transform: none;
    filter: none;
}

.folder-preview-mini-img {
    width: 100%;
    height: 100%;
    border-radius: 40%;
    corner-shape: superellipse(1.25);
    object-fit: cover;
}

/* Target hover effect when dragging an app over another app to create folder */
.folder-target-hover .app-icon-img,
.folder-target-hover .folder-preview-box {
    transform: scale(1.18) !important;
    box-shadow: 0 0 0 4px var(--accent), 0 10px 24px rgba(0, 0, 0, 0.5) !important;
    animation: folder-pulse 0.6s infinite alternate !important;
}

@keyframes folder-pulse {
    from { transform: scale(1.14); }
    to { transform: scale(1.22); }
}

/* --- Folder View Overlay Modal --- */
.home-folder-overlay {
    position: fixed;
    inset: 0;
    z-index: 120;
    background: var(--search-background);
    backdrop-filter: blur(0px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                visibility 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                backdrop-filter 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                -webkit-backdrop-filter 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    user-select: none;
    -webkit-user-select: none;
}

.home-folder-overlay.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    backdrop-filter: blur(10px);
}

.home-folder-modal {
    width: min(520px, 92vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    transform: scale(0.82);
    opacity: 0;
    transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.home-folder-overlay.show .home-folder-modal {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.home-folder-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding: 0 10px;
}

.home-folder-title-input {
    font-size: 1.6rem;
    font-weight: 700;
    background: transparent;
    border: none;
    outline: none;
    font-family: 'Open Runde', 'Inter', sans-serif;
    color: var(--text-color);
    width: 100%;
    cursor: text;
}

.home-folder-title-input:focus {
    border-bottom: 2px solid var(--accent);
}

.home-folder-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 28px 18px;
    overflow-x: hidden;
    overflow-y: auto;
    max-height: 55vh;
    padding: 0;
    justify-items: center;
    touch-action: none;
}

.folder-grid-cell {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 80px;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.24s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.folder-grid-cell .app-icon {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

body.home-edit-active .folder-grid-cell .app-icon {
    animation: ios-jiggle 0.3s ease-in-out infinite alternate !important;
}

body.home-edit-active .folder-grid-cell .home-item-remove-btn {
    display: flex !important;
}

.folder-grid-cell.is-dragging {
    position: fixed !important;
    z-index: 999999 !important;
    pointer-events: none !important;
    opacity: 0.5 !important;
    animation: none !important;
    transition: none !important;
}

.folder-grid-cell.is-dragging .app-icon {
    animation: none !important;
}

/* --- Widgets Inside Home Grid (Widget API) --- */
.home-page .widget-grid-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

.home-page .widget-instance {
    width: calc(100% - 26px);
    height: calc(100% - 26px);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 40px;
    corner-shape: superellipse(1.5);
    background: var(--search-background);
    border: 1px solid var(--glass-border);
    --fx-filter: var(--blur1) glass(0.6, 8, 0);
    box-shadow: var(--sun-shadow);
    overflow: hidden;
    touch-action: none;
    pointer-events: auto;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
}

.home-page .widget-instance iframe {
    width: 100%;
    height: 100%;
    border: none;
    pointer-events: none;
    border-radius: inherit;
    corner-shape: inherit;
}

.widget-instance.sticker-instance.is-transparent.transparent-sticker {
    overflow: visible;
}

.home-page .widget-instance.sticker-instance img {
    object-fit: cover;
}
.widget-instance.sticker-instance.is-transparent.transparent-sticker img {
    object-fit: contain;
}

.home-page .widget-instance-overlay {
    position: absolute;
    inset: 0;
    cursor: pointer;
    z-index: 2;
    border-radius: inherit;
    corner-shape: inherit;
}

/* --- Remove Button & Edit Mode (Material Icons Only) --- */
.home-item-remove-btn {
    position: absolute;
    top: 0px;
    left: 10px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--search-background);
    color: var(--text-color);
    border: 1px solid var(--glass-border);
    box-shadow: var(--sun-shadow), 0 3px 8px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    border: none;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 60;
    padding: 0;
    line-height: 1;
    transition: transform 0.15s ease;
}

.home-item-remove-btn .material-symbols-rounded {
    font-size: 16px;
    font-weight: 700;
}

body.home-edit-active .home-item-remove-btn {
    display: flex !important;
}

@keyframes ios-jiggle {
    0% { transform: rotate(-1.3deg); }
    50% { transform: rotate(1.3deg); }
    100% { transform: rotate(-1.3deg); }
}

body.home-edit-active .home-page .app-icon,
body.home-edit-active .home-page .folder-icon-item,
body.home-edit-active .home-page .widget-grid-item .widget-instance,
body.home-edit-active .home-page .sticker-grid-item .widget-instance {
    animation: ios-jiggle 0.4s ease-in-out infinite alternate !important;
}

body.home-edit-active .home-page .home-grid-item:nth-child(2n) {
    animation-delay: 0.09s !important;
}

/* --- Edit Mode Header (+ and Done) --- */
.home-edit-header {
    position: absolute;
    bottom: 28px;
    left: 28px;
    right: 28px;
    display: none;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    pointer-events: auto;
}

body.home-edit-active .home-edit-header {
    display: flex !important;
}

.home-edit-header-btn {
    background: var(--search-background);
    color: var(--text-color);
    border: 1px solid var(--glass-border);
    box-shadow: var(--sun-shadow);
    border-radius: 99px;
    height: 40px;
    padding: 0 18px;
    font-size: 14px;
    font-weight: 600;
    font-family: 'Open Runde', 'Inter', sans-serif;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    --fx-filter: var(--blur1) glass(0.6, 8, 0);
    transition: transform 0.15s ease, background-color 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
}

.home-edit-add-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
}

.home-edit-add-btn .material-symbols-rounded {
    font-size: 24px;
}

.home-edit-done-btn {
    padding: 0 16px;
    font-weight: 700;
}

/* --- Touch-Driven Widget Resize Handle (Bottom-Right, NO BUTTONS) --- */
.home-widget-resize-handle {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 32px;
    height: 32px;
    z-index: 55;
    display: none;
    touch-action: none;
    cursor: nwse-resize;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    opacity: 0.8;
}

.home-widget-resize-handle .material-symbols-rounded {
    font-size: 18px;
}

body.home-edit-active .home-widget-resize-handle {
    display: flex !important;
}

/* Visual Outline during Live Resize Drag */
.widget-resizing-live {
    z-index: 500 !important;
    transition: none !important;
}

/* --- Dragging Item State (Smooth iOS Floating) --- */
.home-page .is-dragging,
.home-grid-item.is-dragging {
    position: fixed !important;
    z-index: 99999 !important;
    pointer-events: none !important;
    opacity: 0.95 !important;
    animation: none !important;
    transition: none !important;
}

.home-page .is-dragging .widget-instance,
.home-page .is-dragging .app-icon,
.home-page .is-dragging .folder-icon-item {
    animation: none !important;
    transform: none !important;
    opacity: 0.5 !important;
}

/* Slot preview placeholder during drag */
.home-grid-placeholder {
    position: absolute;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.08);
    pointer-events: none;
    box-sizing: border-box;
    transition: transform 0.26s cubic-bezier(0.2, 0.9, 0.3, 1), width 0.24s ease, height 0.24s ease;
    z-index: 5;
}

/* Page Indicator Dots */
.home-page-indicators {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    justify-content: center;
    z-index: 25;
    position: fixed;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
}

.home-page-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-color);
    opacity: 0.35;
    transition: opacity 0.3s ease, transform 0.3s ease, height 0.3s ease;
    cursor: pointer;
}

.home-page-dot.active {
    opacity: 1;
    background: var(--accent);
}

/* Home Screen Bottom-Right Search Button */
.home-search-btn {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 42px;
    height: 42px;
    border-radius: 50px;
    background: var(--search-background);
    color: var(--text-color);
    border: 1px solid var(--glass-border);
    box-shadow: var(--sun-shadow);
    --fx-filter: var(--blur1) glass(0.6, 8, 0);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 90;
    transition: transform 0.2s cubic-bezier(0.2, 1.2, 0.64, 1), background-color 0.2s ease, opacity 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
    outline: none;
}

body.home-edit-active .home-search-btn,
body.beginnings-active .home-search-btn,
body.app-active .home-search-btn,
body.blackout-active .home-search-btn,
body.edit-mode-active .home-search-btn,
body:has(#wallpaper-switcher-overlay.show) .home-search-btn {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    transform: scale(0.8) !important;
}

/* While resizing, disable transition on the active widget so it tracks without latency */
.home-grid-item.widget-resizing-live {
    transition: none !important;
    z-index: 9999 !important;
}


/* Live ghost bounding-box that previews the target slot */
.home-widget-resize-ghost {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    background: rgba(255, 255, 255, 0.12);
    corner-shape: superellipse(1.5);
    border-radius: 40px;
    backdrop-filter: blur(18px);
    transition: transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1),
                width 0.22s cubic-bezier(0.2, 0.9, 0.3, 1),
                height 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
    z-index: 50;
}

/* Floating pill badge showing target dimensions */
.home-widget-resize-badge {
    position: absolute;
    bottom: -32px;
    right: 0;
    color: var(--text-color);
    padding: 6px 10px;
    border-radius: 50px;
    font-size: 11px;
    background-color: var(--background-color);
    pointer-events: none;
    white-space: nowrap;
    z-index: 10000;
}