/* The Six Finger Punch shell, shared by every project: the badge and its info window, the bar and its menus.
   Copied in by bin/new from templates/shell. Improvements go back there. */
:root {
    --bg: #2a2a2f;
    --ink: #f1f1f3;
    --punch: #fffc00;
    --glass: rgba(22, 22, 28, 0.6);
    --gap: max(16px, env(safe-area-inset-bottom));
}

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    background: var(--bg);
    color: var(--ink);
    font: 600 13px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    -webkit-user-select: none;
    user-select: none;
}

#badge {
    position: fixed;
    top: max(14px, env(safe-area-inset-top));
    left: max(14px, env(safe-area-inset-left));
    width: 40px;
    opacity: 0.85;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.45));
    transition: opacity 0.2s, transform 0.2s;
}

#badge:hover { opacity: 1; transform: scale(1.06) rotate(-4deg); }
#badge img { display: block; width: 100%; height: auto; }

/* The badge's hexagon border, thin, over glass: a Punch Yellow band between black lines, with cut corners.
   The rings are octagons with an octagon hole; each cut moves in by 0.414 of the inset, keeping the band even. */
.frame {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    background: var(--glass);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    clip-path: polygon(8px 0px, calc(100% - 8px) 0px, 100% 8px, 100% calc(100% - 8px), calc(100% - 8px) 100%, 8px 100%, 0px calc(100% - 8px), 0px 8px);
}

.frame::before, .frame::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.frame::before {
    background: #000;
    clip-path: polygon(evenodd, 8px 0px, calc(100% - 8px) 0px, 100% 8px, 100% calc(100% - 8px), calc(100% - 8px) 100%, 8px 100%, 0px calc(100% - 8px), 0px 8px, 8px 0px,
        9.656px 4px, calc(100% - 9.656px) 4px, calc(100% - 4px) 9.656px, calc(100% - 4px) calc(100% - 9.656px), calc(100% - 9.656px) calc(100% - 4px), 9.656px calc(100% - 4px), 4px calc(100% - 9.656px), 4px 9.656px, 9.656px 4px);
}

.frame::after {
    background: var(--punch);
    clip-path: polygon(evenodd, 8.414px 1px, calc(100% - 8.414px) 1px, calc(100% - 1px) 8.414px, calc(100% - 1px) calc(100% - 8.414px), calc(100% - 8.414px) calc(100% - 1px), 8.414px calc(100% - 1px), 1px calc(100% - 8.414px), 1px 8.414px, 8.414px 1px,
        9.242px 3px, calc(100% - 9.242px) 3px, calc(100% - 3px) 9.242px, calc(100% - 3px) calc(100% - 9.242px), calc(100% - 9.242px) calc(100% - 3px), 9.242px calc(100% - 3px), 3px calc(100% - 9.242px), 3px 9.242px, 9.242px 3px);
}

/* Cut corners keep their edge. A CSS border gets clipped away where a corner is cut, so a panel with cut corners
   draws its edge as a ring instead: the outline of the panel with the outline inset by --t cut out of it.
   Going in by t, each corner's cut point moves along by c + 0.414t, which keeps the diagonal as thick as the
   straight sides. Set --c (the cut), --t (the edge) and --edge (its colour). The shell's frames work the same way. */
.cut {
    --c: 8px;
    --t: 1px;
    --edge: var(--punch);
    --i: calc(var(--c) + var(--t) * 0.414);
    position: relative;
    border: 0;
    clip-path: polygon(var(--c) 0, calc(100% - var(--c)) 0, 100% var(--c), 100% calc(100% - var(--c)),
        calc(100% - var(--c)) 100%, var(--c) 100%, 0 calc(100% - var(--c)), 0 var(--c));
}

.cut::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: var(--edge);
    clip-path: polygon(evenodd,
        var(--c) 0, calc(100% - var(--c)) 0, 100% var(--c), 100% calc(100% - var(--c)),
        calc(100% - var(--c)) 100%, var(--c) 100%, 0 calc(100% - var(--c)), 0 var(--c), var(--c) 0,
        var(--i) var(--t), calc(100% - var(--i)) var(--t), calc(100% - var(--t)) var(--i), calc(100% - var(--t)) calc(100% - var(--i)),
        calc(100% - var(--i)) calc(100% - var(--t)), var(--i) calc(100% - var(--t)), var(--t) calc(100% - var(--i)), var(--t) var(--i), var(--i) var(--t));
}

#bar {
    bottom: var(--gap);
    display: flex;
    gap: 2px;
    padding: 8px 10px;
}

/* Long-press menus, above the button that opened them. A panel for the selected thing sits in the same spot. */
.menu, .panel {
    bottom: calc(var(--gap) + 66px);
    z-index: 2;
}

.menu {
    display: flex;
    gap: 2px;
    padding: 8px 10px;
}

.panel {
    width: min(340px, calc(100vw - 32px));
    box-sizing: border-box;
    padding: 16px 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.menu[hidden], .panel[hidden] { display: none; }

#bar .icon { -webkit-touch-callout: none; }

button {
    font: inherit;
    color: var(--ink);
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
}

.icon {
    display: grid;
    place-items: center;
    width: 46px;
    height: 40px;
    clip-path: polygon(4px 0, 100% 0, 100% calc(100% - 4px), calc(100% - 4px) 100%, 0 100%, 0 4px);
}

.icon svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.icon[hidden] { display: none; }
.icon:hover, .icon.on { color: var(--punch); }
.icon:active { color: #000; background: var(--punch); }
.icon.busy svg { animation: pulse 0.7s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.3; } }

input[type=range] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 28px;
    background: none;
    margin: 0 6px;
}

input[type=range]::-webkit-slider-runnable-track { height: 2px; background: rgba(255, 255, 255, 0.35); }
input[type=range]::-moz-range-track { height: 2px; background: rgba(255, 255, 255, 0.35); }
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    margin-top: -7px;
    background: var(--punch);
    clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}
input[type=range]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border: 0;
    border-radius: 0;
    background: var(--punch);
    clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

#bar, #badge { z-index: 2; }

/* The info window, opened from the badge. */
#about {
    position: fixed;
    inset: 0;
    z-index: 5;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(10, 10, 14, 0.45);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

#about[hidden] { display: none; }

.window {
    position: relative;
    left: auto;
    transform: none;
    width: min(540px, 100%);
    max-height: calc(100dvh - 32px);
    display: flex;
    flex-direction: column;
    font: 400 16px/1.6 "Chakra Petch", ui-sans-serif, system-ui, sans-serif;
    color: #e6e6ea;
    -webkit-user-select: text;
    user-select: text;
}

/* The text scrolls inside the frame, so the border stays put on short screens. */
.window .inner { overflow-y: auto; padding: 34px 38px 30px; }

.window header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.window .wordmark { display: block; height: 40px; width: auto; flex-shrink: 0; }

.window h1 {
    margin: 0;
    font: 700 56px/1 "Chakra Petch", ui-sans-serif, system-ui, sans-serif;
    letter-spacing: 0.01em;
    color: #fff;
}

.window .version {
    margin: 10px 0 22px;
    font: 500 13px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    letter-spacing: 0.04em;
    white-space: nowrap;
    color: var(--punch);
}

.window p { margin: 0 0 14px; text-wrap: balance; }
.window ol { margin: 0 0 14px; padding-left: 1.4em; }
.window li { margin: 0 0 4px; padding-left: 0.2em; }
.window li::marker { color: var(--punch); font-weight: 500; }

/* Links in the text, like the one in the signature. */
.window p a, .window li a {
    color: var(--punch);
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 252, 0, 0.4);
}

.window p a:hover, .window li a:hover { border-bottom-color: var(--punch); }

.window .sign {
    margin: 22px 0 0;
    text-align: right;
    font-weight: 500;
    color: #fff;
}

.window .sign a {
    color: var(--punch);
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 252, 0, 0.4);
}

.window .sign a:hover { border-bottom-color: var(--punch); }

@media (max-width: 480px) {
    .window { font-size: 15px; }
    .window .inner { padding: 28px 24px 24px; }
    .window h1 { font-size: 44px; }
    .window .wordmark { height: 30px; }
}

/* The preloader covers the page until the project calls ready(). It only shows itself after a moment, so a fast
   load never flashes it. Everything in it moves by transform alone, which keeps going while the page is busy. */
#loader {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 28px;
    background: radial-gradient(circle at 50% 45%, #36363c, var(--bg) 45%, #1f1f23);
    transition: opacity 0.5s;
}

#loader.done { opacity: 0; pointer-events: none; }
#loader > * { animation: loader-in 0.4s 0.3s both; }

/* The badge gives a little punch now and then, and a glint runs across it. */
#loader .mark {
    position: relative;
    width: 84px;
    -webkit-mask: url(sfp.svg) center / contain no-repeat;
    mask: url(sfp.svg) center / contain no-repeat;
    animation: loader-in 0.4s 0.3s both, punch 1.8s 0.7s ease-out infinite;
}

#loader .mark img { display: block; width: 100%; height: auto; }

#loader .mark::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.85) 50%, transparent 65%);
    transform: translateX(-100%);
    animation: glint 1.8s 0.7s ease-in-out infinite;
}

/* Hazard stripes running through a thin black frame. */
#loader .hazard {
    width: 120px;
    padding: 2px;
    background: #000;
    clip-path: polygon(4px 0, 100% 0, 100% calc(100% - 4px), calc(100% - 4px) 100%, 0 100%, 0 4px);
}

#loader .hazard i {
    position: relative;
    display: block;
    height: 6px;
    overflow: hidden;
    /* The stripes' own corners are cut too, 4px less 0.586 of the 2px frame, so the black frame runs evenly
       round the cut corners instead of the stripes poking into them */
    clip-path: polygon(2.83px 0, 100% 0, 100% calc(100% - 2.83px), calc(100% - 2.83px) 100%, 0 100%, 0 2.83px);
}

/* One stripe pair is 16px across the stripes, 22.627px along the bar, so that's how far it moves per loop. */
#loader .hazard i::before {
    content: "";
    position: absolute;
    inset: 0 -23px 0 0;
    background: repeating-linear-gradient(-45deg, var(--punch) 0 8px, #000 0 16px);
    animation: hazard 0.5s linear infinite;
}

@keyframes loader-in { from { opacity: 0; } }
@keyframes punch { 0%, 30%, 100% { transform: none; } 8% { transform: scale(1.1) rotate(-4deg); } }
@keyframes glint { 0% { transform: translateX(-100%); } 45%, 100% { transform: translateX(100%); } }
@keyframes hazard { to { transform: translateX(-22.627px); } }

@media (prefers-reduced-motion: reduce) {
    #loader .mark, #loader .mark::after, #loader .hazard i::before { animation: loader-in 0.4s 0.3s both; }
}
