/* Pattern Maker - workspace left, controls right (Mandala Maker layout) */

/* Landing page: dress the start card with a repeating polka-dot band
   along its bottom edge (the intro card only - not the related-tools
   cards, which live in .tool-content wrappers) */
.app-intro:not(.tool-content) > .gn-card {
    position: relative;
    overflow: hidden;
}

.app-intro:not(.tool-content) > .gn-card .card-body {
    position: relative;
    z-index: 1;
    padding-bottom: 6.5rem !important;
}

.app-intro:not(.tool-content) > .gn-card::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 84px;
    pointer-events: none;
    background-size: 28px 28px;
    background-repeat: repeat;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 28 28'%3E%3Ccircle cx='7' cy='7' r='4.5' fill='%234a5d8a' opacity='0.8'/%3E%3Ccircle cx='21' cy='21' r='4.5' fill='%23e07a5f' opacity='0.8'/%3E%3C/svg%3E");
    /* Fade the dots in toward the bottom so they never fight the button */
    -webkit-mask-image: linear-gradient(to bottom, transparent, #000 70%);
    mask-image: linear-gradient(to bottom, transparent, #000 70%);
}

.pm-app {
    position: relative;
    display: flex;
    height: 100%;
    overflow: hidden;
}

/* Stage (left): the repeating pattern fills the whole workspace; with a
   preview aspect chosen, the frame letterboxes centered instead */
.pm-stage {
    position: relative;
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    background-color: var(--gn-card-bg);
}

.pm-frame {
    position: relative;
    width: 100%;
    height: 100%;
}

.pm-frame-boxed {
    border: 1px solid var(--gn-card-border);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

/* Pixel-size chip shown in exact-size preview */
.pm-frame-size {
    position: absolute;
    left: 50%;
    bottom: 0.5rem;
    transform: translateX(-50%);
    padding: 0.125rem 0.5rem;
    border-radius: 1rem;
    background-color: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-size: 0.7rem;
    white-space: nowrap;
    pointer-events: none;
}

.pm-svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* Controls panel (right); header/body/footer layout comes from the shared
   .app-side-* classes in css/common.css */
.pm-panel {
    flex: 0 0 300px;
    border-left: 1px solid var(--gn-card-border);
}

.pm-label {
    font-size: 0.8rem;
    color: var(--gn-muted);
    margin-bottom: 0;
    margin-top: 0.5rem;
    display: block;
}

/* Tuck the slider closer to its label + value row */
.pm-app .form-range {
    margin-top: -2px;
}

/* Previous/next pattern buttons share the select's border color */
.pm-shape-nav {
    border: 1px solid var(--bs-border-color);
    color: var(--gn-muted);
    background: none;
}

.pm-shape-nav:hover {
    border-color: var(--bs-border-color);
    background-color: var(--gn-sidebar-hover-bg);
    color: var(--gn-accent);
}

.pm-val {
    float: right;
    color: var(--gn-accent);
    font-size: 0.75rem;
}

.pm-sep {
    margin: 0.75rem 0;
    border-color: var(--gn-card-border);
    opacity: 1;
}

/* Color slots for the selected pattern, at the top of the panel body */
.pm-color-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.25rem 0;
}

.pm-trans-check {
    padding-top: 0.25rem;
}

/* Transparent mode: classic checkerboard behind the pattern */
.pm-frame.pm-transparent {
    background-color: #fff;
    background-image: repeating-conic-gradient(#dfdfdf 0% 25%, #ffffff 0% 50%);
    background-size: 20px 20px;
}

/* Floating round save button on the stage (Camera Funhouse style) */
.pm-fab-wrap {
    position: absolute;
    right: 1rem;
    bottom: 1rem;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
}

.pm-fab {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.2);
    background-color: #fff;
    color: #2b2d42;
    font-size: 1.125rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
    transition: transform 0.1s, border-color 0.15s, color 0.15s;
}

.pm-fab:hover {
    border-color: var(--gn-accent);
    color: var(--gn-accent);
}

.pm-fab:active {
    transform: scale(0.95);
}

/* The aspect fab sits top-right; its menu opens below the button. The wrap
   is capped to the stage height so the menu can never overflow it: the
   aspect list scrolls while the exact-size toggle stays pinned below it */
.pm-aspect-wrap {
    bottom: auto;
    top: 1rem;
    max-height: calc(100% - 2rem);
}

.pm-fab-menu {
    display: flex;
    flex-direction: column;
    min-width: 170px;
    min-height: 0;
    padding: 0.25rem;
    background-color: var(--gn-card-bg);
    border: 1px solid var(--gn-card-border);
    border-radius: 0.5rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.pm-menu-scroll {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
}

.pm-fab-menu.d-none {
    display: none;
}

.pm-fab-menu button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.75rem;
    background: none;
    border: 0;
    border-radius: 0.375rem;
    color: var(--gn-body-color);
    font-size: 0.875rem;
    text-align: left;
    white-space: nowrap;
}

.pm-fab-menu button:hover {
    background-color: var(--gn-sidebar-hover-bg);
}

/* Check mark only on the selected entry */
.pm-fab-menu button .bi {
    color: var(--gn-accent);
    visibility: hidden;
}

.pm-fab-menu button.active .bi {
    visibility: visible;
}

.pm-fab-menu button:disabled {
    color: var(--gn-muted);
    opacity: 0.55;
}

.pm-menu-sep {
    margin: 0.25rem 0.5rem;
    border-color: var(--gn-card-border);
    opacity: 1;
}

/* Save modal: centered card over a dimmed backdrop, inside the app area so
   it works in fullscreen too */
.pm-modal {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background-color: rgba(0, 0, 0, 0.45);
}

.pm-modal.d-none {
    display: none;
}

.pm-modal-card {
    display: flex;
    flex-direction: column;
    width: min(440px, 100%);
    max-height: 100%;
    background-color: var(--gn-card-bg);
    border: 1px solid var(--gn-card-border);
    border-radius: 0.75rem;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.pm-modal-header {
    display: flex;
    align-items: center;
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--gn-card-border);
}

/* On short screens the body scrolls; header and footer stay in view */
.pm-modal-body {
    padding: 0.5rem 1rem 0.75rem;
    min-height: 0;
    overflow-y: auto;
}

.pm-modal-footer {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--gn-card-border);
}

/* Rows that do not apply to the current format keep their space (the modal
   never jumps in size); visibility also removes them from the tab order */
.pm-invisible {
    visibility: hidden;
}

/* All note variants are stacked in the same grid cell: the container is
   always as tall as the longest one, so the modal never jumps in size */
.pm-modal-note-stack {
    display: grid;
}

.pm-modal-note-stack > .pm-modal-note {
    grid-area: 1 / 1;
}

.pm-note-sizer {
    visibility: hidden;
}

.pm-modal-note {
    font-size: 0.75rem;
    color: var(--gn-muted);
    margin: 0.625rem 0 0;
}

.pm-size-input {
    max-width: 110px;
}

.pm-size-x {
    color: var(--gn-muted);
}

/* Pattern browser overlay: covers the whole app area */
.pm-browser {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    background-color: var(--gn-card-bg);
}

.pm-browser-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--gn-card-border);
}

.pm-browser-title {
    font-weight: 600;
}

.pm-browser-search {
    max-width: 260px;
}

.pm-browser-empty {
    width: 100%;
    padding: 2rem 0;
    text-align: center;
    color: var(--gn-muted);
}

.pm-browser-grid {
    flex: 1 1 auto;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 8px;
    padding: 1rem;
}

.pm-browser-group {
    width: 100%;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gn-accent);
    border-bottom: 1px solid var(--gn-card-border);
    padding-bottom: 4px;
    margin-top: 8px;
}

.pm-pattern-card {
    width: 132px;
    padding: 8px;
    text-align: center;
    background: none;
    border: 2px solid transparent;
    border-radius: 0.5rem;
    color: var(--gn-body-color);
    transition: border-color 0.15s, background-color 0.15s;
}

.pm-pattern-card:hover,
.pm-pattern-card.active {
    border-color: var(--gn-accent);
    background-color: var(--gn-sidebar-hover-bg);
}

.pm-pattern-card svg {
    display: block;
    width: 112px;
    height: 76px;
    margin: 0 auto 4px;
    border-radius: 0.375rem;
    border: 1px solid var(--gn-card-border);
}

.pm-pattern-card span {
    display: block;
    font-size: 0.7rem;
    color: var(--gn-muted);
    line-height: 1.15;
}

/* Small screens: stack, with the preview pinned at the top so the pattern
   stays visible while dragging sliders in the controls below */
@media (max-width: 767px) {
    .pm-app {
        flex-direction: column;
        overflow-y: auto;
    }

    .pm-stage {
        position: sticky;
        top: 0;
        z-index: 4;
        flex: 0 0 auto;
        height: 40vh;
    }

    .pm-panel {
        flex: 0 0 auto;
        border-left: 0;
        border-top: 1px solid var(--gn-card-border);
    }

    /* The whole app container scrolls instead of the panel body; the
       pattern header sticks right below the preview and the action
       footer sticks to the bottom edge */
    .pm-panel .app-side-body {
        overflow-y: visible;
    }

    .pm-panel .app-side-header {
        position: sticky;
        top: 40vh;
        z-index: 3;
        background-color: var(--gn-card-bg);
    }

    .pm-panel .app-side-footer {
        position: sticky;
        bottom: 0;
        z-index: 3;
        background-color: var(--gn-card-bg);
    }
}
