/* Front page creator: a cover with windows in it, and photos arranged underneath. */

:root {
    --fp-ink: #1d1f1c;
    --fp-muted: #6a6e68;
    --fp-line: #dcdfd8;
    --fp-chrome: #fbfbf8;
    --fp-canvas: #e9ebe6;
    --fp-accent: #0b3d1e;
    --fp-accent-hover: #145a2e;
    --fp-gold: #d9ae3e;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
    background: var(--fp-canvas);
    color: var(--fp-ink);
    font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
}

.fp { display: flex; flex-direction: column; height: 100vh; }

/* ----- Toolbar: wraps a whole group at a time rather than pushing Export off screen ----- */

.fp-bar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
    padding: 7px 10px; background: var(--fp-chrome); border-bottom: 1px solid var(--fp-line);
    flex: 0 0 auto;
}

.fp-group { display: flex; align-items: center; gap: 4px; flex-wrap: nowrap; }
.fp-actions { margin-left: auto; }
.fp-title { font-size: 14px; margin: 0 6px; white-space: nowrap; }
.fp-sep { width: 1px; height: 22px; background: var(--fp-line); margin: 0 4px; }

.fp-btn {
    display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid transparent; background: transparent; color: var(--fp-ink);
    padding: 6px 9px; border-radius: 6px; cursor: pointer; font: inherit; font-size: 12px;
    text-decoration: none; white-space: nowrap;
}
.fp-btn:hover { background: #eef0ea; }
.fp-btn[disabled] { opacity: .38; cursor: default; background: transparent; }
.fp-btn.is-on { background: #e4efe3; border-color: #c2d8c0; color: var(--fp-accent); }
.fp-primary { background: var(--fp-accent); color: #fff; }
.fp-primary:hover { background: var(--fp-accent-hover); color: #fff; }
.fp-danger:hover { background: #fbeaea; color: #a3232d; }
.fp-quiet { color: var(--fp-muted); }
.fp-status { color: var(--fp-muted); font-size: 12px; margin-right: 6px; white-space: nowrap; }

.fp-export { position: relative; }
.fp-menu {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 230px;
    background: #fff; border: 1px solid var(--fp-line); border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .18); padding: 5px;
}
.fp-menu[hidden] { display: none; }
.fp-menu button {
    display: flex; flex-direction: column; align-items: flex-start; width: 100%;
    border: 0; background: transparent; padding: 8px 10px; border-radius: 7px; cursor: pointer;
    font: inherit; color: var(--fp-ink); text-align: left;
}
.fp-menu button:hover { background: #f1f4ee; }
.fp-menu small { color: var(--fp-muted); }
.fp-menu-note { margin: 6px 8px; color: var(--fp-muted); font-size: 12px; }

.fp-history, .fp-library { position: relative; }
.fp-history .fp-menu { max-height: 60vh; overflow-y: auto; }
.fp-library .fp-menu { left: 0; right: auto; }
.fp-menu-wide { width: min(420px, calc(100vw - 24px)); max-height: 60vh; overflow-y: auto; }
.fp-thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; padding: 4px; }
.fp-menu .fp-thumbs button { padding: 0; aspect-ratio: 1; overflow: hidden; border-radius: 6px; background: #eef0ea; }
.fp-thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fp-thumbs button:hover img { opacity: .8; }
.fp-count {
    font-style: normal; font-size: 11px; background: #eef0ea; border-radius: 999px; padding: 0 6px; min-width: 18px; text-align: center;
}
.fp-save.is-dirty { background: var(--fp-gold); color: #1d1f1c; }
.fp-save.is-dirty:hover { background: #e5bd52; }

/* ----- The page ----- */

.fp-stage-wrap {
    position: relative; flex: 1 1 auto; min-height: 0;
    display: flex; align-items: center; justify-content: center; padding: 18px;
}

.fp-stage { box-shadow: 0 10px 34px rgba(0, 0, 0, .22); background: #fff; line-height: 0; }

.fp-drop {
    position: absolute; inset: 10px; display: flex; align-items: center; justify-content: center;
    border: 3px dashed var(--fp-gold); border-radius: 14px; background: rgba(11, 61, 30, .12);
    pointer-events: none;
}
.fp-drop[hidden] { display: none; }
.fp-drop span {
    background: var(--fp-accent); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 15px;
}

.fp-hint {
    flex: 0 0 auto; padding: 7px 14px 9px; text-align: center; color: var(--fp-muted); font-size: 12px;
}

/* Narrow windows: the icons carry the buttons. */
@media (max-width: 1320px) { .fp-bar .fp-btn > span { display: none; } .fp-bar .fp-save > span { display: inline; } }
@media (max-width: 700px) {
    .fp-hint { display: none; }
    .fp-stage-wrap { padding: 8px; }
    /* On a phone even a single group can be wider than the screen, so it may wrap too. */
    .fp-group { flex-wrap: wrap; }
    .fp-sep { display: none; }
}

/* ----- Photo editor ----- */

.fpe {
    position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
    background: rgba(12, 16, 12, .62); padding: 16px;
}
.fpe[hidden] { display: none; }

.fpe-panel {
    display: flex; flex-direction: column; width: min(1180px, 100%); height: min(780px, 100%);
    background: #fff; border-radius: 14px; overflow: hidden; box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
}

.fpe-head {
    display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--fp-line);
}
.fpe-head strong { font-size: 14px; }
.fpe-dims { color: var(--fp-muted); font-size: 12px; }
.fpe-spacer { flex: 1; }

.fpe-body { display: flex; flex: 1; min-height: 0; }

.fpe-view {
    flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center;
    background: #1c1f1b; padding: 22px; overflow: hidden;
}
.fpe-stage { position: relative; line-height: 0; touch-action: none; }
.fpe-stage canvas { display: block; }

/*
    Outside the crop is darkened by one enormous shadow on a hole the same size as the crop.
    The shade is clipped to the photo; the crop box and its handles are not, so a handle on
    the photo's edge can still be grabbed from outside it.
*/
.fpe-shade { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.fpe-hole { position: absolute; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .58); }
.fpe-crop { position: absolute; border: 1.5px solid #fff; cursor: move; }
.fpe-grid {
    position: absolute; inset: 0; pointer-events: none;
    background:
        linear-gradient(to right, transparent 33.2%, rgba(255,255,255,.45) 33.3%, transparent 33.5%,
                        transparent 66.5%, rgba(255,255,255,.45) 66.6%, transparent 66.8%),
        linear-gradient(to bottom, transparent 33.2%, rgba(255,255,255,.45) 33.3%, transparent 33.5%,
                        transparent 66.5%, rgba(255,255,255,.45) 66.6%, transparent 66.8%);
}
.fpe-crop i {
    position: absolute; width: 14px; height: 14px; background: #fff; border: 1px solid #0b3d1e;
    border-radius: 3px; margin: -7px 0 0 -7px;
}
.fpe-crop i[data-h="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.fpe-crop i[data-h="n"]  { left: 50%; top: 0; cursor: ns-resize; }
.fpe-crop i[data-h="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.fpe-crop i[data-h="e"]  { left: 100%; top: 50%; cursor: ew-resize; }
.fpe-crop i[data-h="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.fpe-crop i[data-h="s"]  { left: 50%; top: 100%; cursor: ns-resize; }
.fpe-crop i[data-h="sw"] { left: 0; top: 100%; cursor: nesw-resize; }
.fpe-crop i[data-h="w"]  { left: 0; top: 50%; cursor: ew-resize; }

.fpe-side {
    flex: 0 0 290px; overflow-y: auto; padding: 12px 16px 16px; border-left: 1px solid var(--fp-line);
}
.fpe-side h4 {
    margin: 12px 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--fp-muted);
}
.fpe-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.fpe-chips button {
    border: 1px solid var(--fp-line); background: #fff; border-radius: 999px; padding: 4px 10px;
    font: inherit; font-size: 12px; cursor: pointer;
}
.fpe-chips button.is-on { background: var(--fp-accent); border-color: var(--fp-accent); color: #fff; }
.fpe-row { display: flex; gap: 4px; margin-top: 8px; }
.fpe-row .fp-btn { border: 1px solid var(--fp-line); }

.fpe-slider { display: grid; grid-template-columns: 78px 1fr 34px; align-items: center; gap: 8px; margin: 6px 0; }
.fpe-slider span { font-size: 12px; }
.fpe-slider input { width: 100%; accent-color: var(--fp-accent); }
.fpe-slider output { font-size: 11px; color: var(--fp-muted); text-align: right; font-variant-numeric: tabular-nums; }
.fpe-check { display: flex; align-items: center; gap: 8px; margin: 10px 0 4px; font-size: 12px; }
.fpe-reset { margin-top: 12px; border: 1px solid var(--fp-line); width: 100%; justify-content: center; }
.fpe-note { color: var(--fp-muted); font-size: 11px; margin: 10px 0 0; }

@media (max-width: 760px) {
    .fpe { padding: 0; }
    .fpe-panel { border-radius: 0; height: 100%; }
    .fpe-body { flex-direction: column; }
    .fpe-view { flex: 1 1 55%; padding: 12px; }
    .fpe-side { flex: 1 1 45%; border-left: 0; border-top: 1px solid var(--fp-line); }
}

/* ----- Photo library ----- */

.fpl {
    position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
    background: rgba(12, 16, 12, .55); padding: 16px;
}
.fpl[hidden] { display: none; }
.fpl-panel {
    position: relative; display: flex; flex-direction: column; width: min(1040px, 100%); height: min(760px, 100%);
    background: #fff; border-radius: 14px; overflow: hidden; box-shadow: 0 24px 70px rgba(0, 0, 0, .4);
}
.fpl-head, .fpl-tools, .fpl-foot { display: flex; align-items: center; gap: 6px; padding: 9px 12px; flex-wrap: wrap; }
.fpl-head { border-bottom: 1px solid var(--fp-line); }
.fpl-head strong { font-size: 15px; }
.fpl-foot { border-top: 1px solid var(--fp-line); }
.fpl-foot .fp-btn, .fpl-tools .fp-btn { border: 1px solid var(--fp-line); }
.fpl-foot .fpl-delete { color: #a3232d; }
.fpl-picked { color: var(--fp-muted); font-size: 12px; }
.fpe-chips em { font-style: normal; opacity: .7; }
.fpl-grid {
    flex: 1; min-height: 0; overflow-y: auto; padding: 4px 12px 12px;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; align-content: start;
}
.fpl-tile {
    position: relative; aspect-ratio: 1; padding: 0; border: 2px solid transparent; border-radius: 8px;
    overflow: hidden; background: #eef0ea; cursor: pointer;
}
.fpl-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fpl-tile.is-off img { opacity: .55; }
.fpl-tile.is-picked { border-color: var(--fp-accent); box-shadow: 0 0 0 2px var(--fp-gold); }
.fpl-tile .fpl-tick {
    position: absolute; top: 6px; left: 6px; width: 20px; height: 20px; border-radius: 50%;
    background: rgba(255,255,255,.85); border: 1px solid #9aa097; display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 11px;
}
.fpl-tile.is-picked .fpl-tick { background: var(--fp-accent); border-color: var(--fp-accent); }
.fpl-tile .fpl-badge {
    position: absolute; bottom: 6px; left: 6px; font-size: 10px; padding: 1px 7px; border-radius: 999px;
    background: var(--fp-accent); color: #fff;
}
.fpl-tile.is-off .fpl-badge { background: rgba(0,0,0,.55); }
.fpl-empty { grid-column: 1 / -1; text-align: center; color: var(--fp-muted); padding: 60px 10px; }
.fpl-note { margin: 0; padding: 0 12px 10px; color: var(--fp-muted); font-size: 12px; }
.fpl-drop {
    position: absolute; inset: 8px; display: flex; align-items: center; justify-content: center;
    border: 3px dashed var(--fp-gold); border-radius: 12px; background: rgba(255,255,255,.85); pointer-events: none;
}
.fpl-drop[hidden] { display: none; }
.fpl-drop span { background: var(--fp-accent); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 15px; }
@media (max-width: 700px) {
    .fpl { padding: 0; }
    .fpl-panel { border-radius: 0; height: 100%; }
    .fpl-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
}

/* ----- Cover panel ----- */

/*
    The cover panel is a window, not a sheet over the page: it can be dragged by its bar,
    pulled bigger by its corner and rolled up to its bar, because everything in it is judged
    by looking at the cover behind it.
*/
.fpc {
    position: fixed; z-index: 45; display: flex;
    top: 70px; left: auto; right: 18px; width: 390px; height: min(640px, calc(100vh - 110px));
}
.fpc[hidden] { display: none; }
.fpc-panel {
    position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column;
    background: #fff; border: 1px solid var(--fp-line); border-radius: 12px; overflow: hidden;
    box-shadow: 0 18px 48px rgba(0, 0, 0, .28);
}
.fpc-head { cursor: move; user-select: none; touch-action: none; background: #fbfbf8; }
.fpc-head .fp-btn { cursor: pointer; }
.fpc-drag-hint { color: #b9bdb5; font-size: 12px; }
.fpc-note {
    margin: 0; padding: 8px 12px; border-top: 1px solid var(--fp-line); background: #fbfbf8;
}
.fpc.is-min { height: auto !important; }
.fpc.is-min .fpc-body, .fpc.is-min .fpc-note, .fpc.is-min .fpc-grip { display: none; }
.fpc-grip {
    position: absolute; right: 0; bottom: 0; width: 18px; height: 18px; cursor: nwse-resize;
    touch-action: none;
    background:
        linear-gradient(135deg, transparent 50%, var(--fp-line) 50%, var(--fp-line) 62%, transparent 62%,
                        transparent 72%, var(--fp-line) 72%, var(--fp-line) 84%, transparent 84%);
}
@media (max-width: 700px) {
    /* No room to float on a phone: it sits along the bottom instead. */
    .fpc {
        top: auto !important; bottom: 0; left: 0 !important; right: 0;
        width: 100% !important; height: 60vh !important;
    }
    .fpc-panel { border-radius: 12px 12px 0 0; }
    .fpc-head { cursor: default; }
    .fpc-grip { display: none; }
}
.fpc-body { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 14px 10px; }
.fpc-part { border-bottom: 1px solid var(--fp-line); padding: 10px 0 14px; }
.fpc-part:last-child { border-bottom: 0; }
.fpc-part h4 {
    margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--fp-muted);
}
.fpc-text {
    width: 100%; font: inherit; font-size: 13px; padding: 7px 9px; margin-bottom: 7px;
    border: 1px solid var(--fp-line); border-radius: 7px; resize: vertical;
}
.fpc-part select {
    width: 100%; font: inherit; font-size: 13px; padding: 6px 8px; margin-bottom: 4px;
    border: 1px solid var(--fp-line); border-radius: 7px; background: #fff;
}
.fpc-echo {
    font-style: normal; text-transform: none; letter-spacing: 0; color: var(--fp-ink);
    margin-left: 8px; opacity: .75;
}
.fpc-colour { display: flex; align-items: center; gap: 10px; margin: 8px 0 2px; font-size: 12px; }
.fpc-colour input { width: 46px; height: 26px; padding: 0; border: 1px solid var(--fp-line); border-radius: 6px; background: #fff; }
.fpc-part .fpe-row { margin-bottom: 8px; }
.fpc-part .fpe-row .fp-btn { border: 1px solid var(--fp-line); }
.fpl.is-picking .fpl-tools, .fpl.is-picking .fpl-foot { display: none; }
