/* -- Peel-back corner (Jen, Nov 13) --
   Day/night is no longer a button in the nav. The top-right corner of the
   page is curled back like paper, and behind the curl you can see the
   colour of the other side: the dark page's black when the page is light,
   the light page's white when it is dark. Clicking the corner peels the
   whole page off (peel.js drives a view transition) and the other theme is
   underneath.

   Nov 13, 2 AM (Jen, from a reference of a curled page): the curl is a
   soft leaf of paper, not a flat triangle. Two curved edges sweep in to a
   point at the bottom left, the back of the paper goes from white at the
   fold into grey, and it casts a soft shadow on the page. No sun or star
   behind it any more, just the colour. Smaller at rest, and hover only
   lifts it a little. Nov 13, 2:20 AM: retraced from her second reference,
   with a rounded roll where the fold meets the edge, a shadow on the
   revealed corner and slightly bigger (56 x 36 at rest, 62 x 40 on hover).

   Geometry: one box pinned to the corner, always 100:64; peel.js draws
   both parts as SVG in a matching 100 x 64 box.
   .peel-under  = above the fold: what is behind the page.
   .peel-flap   = the curled paper. */

#theme-peel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 100002;
  box-sizing: border-box;
  width: 0;
  height: 0;
  padding: 0;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    width 0.5s cubic-bezier(0.34, 1.18, 0.5, 1),
    height 0.5s cubic-bezier(0.34, 1.18, 0.5, 1);
}

/* In once the nav is: the corner curls in from nothing. */
#theme-peel.is-in {
  width: 56px;
  height: 36px;
}

/* Hover lifts the curl just a little. */
@media (hover: hover) {
  #theme-peel.is-in:hover {
    width: 62px;
    height: 40px;
    transition:
      width 0.35s cubic-bezier(0.2, 0.8, 0.2, 1),
      height 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
}

#theme-peel:focus { outline: none; }
#theme-peel:focus-visible .peel-flap path {
  stroke: var(--accent);
  stroke-width: 2px;
  vector-effect: non-scaling-stroke;
}

/* While the page is being peeled off, peel.js sizes the box itself. */
#theme-peel.is-sweeping {
  transition: none !important;
}
#theme-peel.is-sweeping .peel-under { visibility: hidden; }

/* A project pop-up owns the screen; the corner steps out of its way. */
html.cm-open #theme-peel {
  opacity: 0;
  pointer-events: none;
}

.peel-under,
.peel-flap-wrap,
.peel-flap {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* -- Behind the page: just the other theme's colour -- */
.peel-under {
  display: block;
  width: 100%;
  height: 100%;
}
#theme-peel[data-paper="light"] .pu-base { fill: #121212; }
#theme-peel[data-paper="dark"] .pu-base { fill: #FCFCFE; }
/* The shadow the curl casts on the revealed corner, along the fold. */
.ps-0 { stop-color: #000; stop-opacity: 0.34; }
.ps-1 { stop-color: #000; stop-opacity: 0.1; }
.ps-2 { stop-color: #000; stop-opacity: 0; }
#theme-peel[data-paper="light"] .ps-0 { stop-opacity: 0.6; }
#theme-peel[data-paper="light"] .ps-1 { stop-opacity: 0.2; }

/* -- The curl -- */
/* The shadow lives on a wrapper so it follows the curl's shape: a faint
   one where the flap lifts off the page. */
.peel-flap-wrap {
  filter:
    drop-shadow(-0.5px 1px 1px rgba(0, 0, 0, 0.16))
    drop-shadow(-1px 3px 5px rgba(0, 0, 0, 0.12));
}
#theme-peel[data-paper="dark"] .peel-flap-wrap {
  filter:
    drop-shadow(-0.5px 1px 1px rgba(0, 0, 0, 0.5))
    drop-shadow(-1px 2.5px 5px rgba(0, 0, 0, 0.4));
}

/* The back of the paper, shaded across the fold as in Jen's reference:
   a bright roll at the fold, a grey band through the middle, lighter
   again toward the tip. */
#theme-peel[data-paper="light"] .pf-0 { stop-color: #f2f2f4; }
#theme-peel[data-paper="light"] .pf-1 { stop-color: #ffffff; }
#theme-peel[data-paper="light"] .pf-2 { stop-color: #bdbdc3; }
#theme-peel[data-paper="light"] .pf-3 { stop-color: #d3d3d8; }
#theme-peel[data-paper="light"] .pf-4 { stop-color: #f0f0f2; }
#theme-peel[data-paper="dark"] .pf-0 { stop-color: #3a3a3d; }
#theme-peel[data-paper="dark"] .pf-1 { stop-color: #4b4b4f; }
#theme-peel[data-paper="dark"] .pf-2 { stop-color: #2c2c2f; }
#theme-peel[data-paper="dark"] .pf-3 { stop-color: #323235; }
#theme-peel[data-paper="dark"] .pf-4 { stop-color: #3c3c3f; }

/* -- The peel itself (view transition) -- */
/* The old page stays put; the new one is revealed by peel.js clipping it
   from the corner, in step with the curl sweeping across. */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
::view-transition-group(theme-peel) {
  animation-duration: 0.95s;
  animation-timing-function: cubic-bezier(0.55, 0, 0.2, 1);
}
::view-transition-old(theme-peel) { animation: none; opacity: 0; }
::view-transition-new(theme-peel) { animation: none; opacity: 1; }

@media (max-width: 720px) {
  #theme-peel.is-in { width: 47px; height: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  #theme-peel { transition: none; }
}

/* Project pages (Jen, Nov 13): the corner stays here too, on the page
   opened on its own and once the pop-up has gone full screen, so the
   sun/moon button leaves the side column / top bar there. Inside the small
   pop-up the corner would sit in a box in the middle of the screen, so
   there the old button stays and the corner waits until full screen. */
html.in-modal #theme-peel { display: none; }
html:not(.in-modal) #modal-side #theme-toggle,
html:not(.in-modal) #topbar:not(.home-nav) > #theme-toggle {
  display: none !important;
}

/* About Me and Playground: the sun/moon button stays in the page (the
   corner presses it) but leaves the pill, along with the gap before it. */
#topbar.home-nav #theme-toggle,
#topbar.home-nav .nav-spacer {
  display: none !important;
}

/* ── Card / grid switch in the nav (Jen, Nov 13) ──
   It sits where the sun/moon button was. Jen: "toggle should follow
   original design", so it is the old bottom pill's switch, just scaled to
   the nav: the frosted shell (see-through panel, blur, inset hairline, even
   drop shadow), the raised white plate with its small shadow, the accent
   colour on the view that is on, and the same 56:40 button shape and
   15/11 corner rounding, all at about 0.82 size. */
#top-nav .view-switch {
  box-sizing: border-box;
  padding: 4px;
  border: none;
  border-radius: 13px;
  background: rgba(var(--panel-rgb), 0.5);
  backdrop-filter: blur(10px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  box-shadow: inset 0 0 0 1px rgba(var(--ink-rgb), 0.08);
  filter: drop-shadow(0 0 6px rgba(0, 0, 0, 0.1));
  pointer-events: auto;
}
#top-nav .toggle-btn {
  width: 46px;
  height: 34px;
  border-radius: 10px;
}
#top-nav .toggle-btn[data-view="cards"] svg { width: 28px; height: 19px; }
#top-nav .toggle-btn[data-view="grid"] svg { width: 19px; height: 19px; }
#top-nav .view-toggle-thumb {
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: 46px;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
:root[data-theme="dark"] #top-nav .view-switch {
  background: rgba(var(--panel-rgb), 0.88);
  filter: drop-shadow(0 0 8px rgba(0, 0, 0, 0.4));
}
:root[data-theme="dark"] #top-nav .view-toggle-thumb {
  background: #3d3d3d;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

#top-nav .view-switch[data-active="grid"] .view-toggle-thumb,
html[data-restore-view="grid"] #top-nav .view-switch .view-toggle-thumb {
  transform: translateX(100%);
}
#top-nav .view-switch.no-thumb-move .view-toggle-thumb { transition: none; }

/* The bottom pill keeps only the tick carousel, so it has nothing to show
   in grid view. */
#view-toggle[data-active="grid"],
html[data-restore-view="grid"] #view-toggle {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* -- Nov 16 (Jen) --------------------------------------------------------- */

/* The peel uncovers the nav with the rest of the page (peel.js adds
   .is-peeling for the length of the peel). Its page-to-page name made it a
   layer of its own, which switched theme ahead of the paper. */
html.is-peeling .nav-cluster { view-transition-name: none !important; }

/* The tick bar under the cards, slightly longer: 156px -> 196px. The track's
   side padding stays half the width so the tick standing on the current
   card is still in the middle. */
#view-toggle.is-open[data-active="cards"] #scrubber,
html[data-intro-done] #view-toggle[data-active="cards"] #scrubber { width: 196px; }
html[data-restore-view="grid"] #view-toggle[data-active="cards"] #scrubber { width: 0; }
#scrubber-track-wrap { width: 196px; }
#scrubber-track { padding: 0 98px; }

/* The card / grid switch being smashed out of the pill on About Me and
   Playground (nav-squeeze.js). A copy of the nav switch above, same sizes
   and colours, drawn only for the squash and then removed. */
.nsq-gap { flex: 0 0 20px; width: 20px; height: 1px; pointer-events: none; }
.nsq-switch {
  position: relative;
  display: flex;
  align-items: center;
  flex: none;
  box-sizing: border-box;
  padding: 4px;
  border-radius: 13px;
  background: rgba(240, 240, 244, 0.5);
  box-shadow: inset 0 0 0 1px rgba(var(--ink-rgb), 0.08);
  filter: drop-shadow(0 0 6px rgba(0, 0, 0, 0.1));
  pointer-events: none;
}
.nsq-thumb {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: 46px;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.nsq-switch[data-active="grid"] .nsq-thumb { transform: translateX(100%); }
.nsq-btn {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 46px;
  height: 34px;
  color: rgba(var(--ink-rgb), 0.35);
}
.nsq-btn.is-on { color: var(--accent); }
.nsq-btn[data-view="cards"] svg { width: 28px; height: 19px; }
.nsq-btn[data-view="grid"] svg { width: 19px; height: 19px; }
.nsq-btn[data-view="cards"] .card-left,
.nsq-btn[data-view="cards"] .card-right { fill: #ffffff; transform-origin: 9px 16px; }
.nsq-btn[data-view="cards"].is-on .card-left { transform: rotate(-12deg); }
.nsq-btn[data-view="cards"].is-on .card-right { transform: rotate(12deg); }
:root[data-theme="dark"] .nsq-switch {
  background: rgba(40, 40, 44, 0.88);
  filter: drop-shadow(0 0 8px rgba(0, 0, 0, 0.4));
}
:root[data-theme="dark"] .nsq-thumb { background: #3d3d3d; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35); }
:root[data-theme="dark"] .nsq-btn[data-view="cards"] .card-left,
:root[data-theme="dark"] .nsq-btn[data-view="cards"] .card-right { fill: #2a2a2a; }

/* Same pill height on every page (Jen, Nov 16: "when I'm switching between
   About and Playground, the nav bar position shifts up"). Home's pill holds
   the 42px card/grid switch, so it is 62px tall; About Me and Playground
   have no switch and came out 48px, which lifted the logo and links 7px.
   Holding those pills at 62px keeps the row on the same line everywhere. */
#topbar.home-nav .nav-cluster { min-height: 62px; }

/* The places in the grid header line link out (Jen, Nov 16). Same grey as
   the line, a faint underline that darkens on hover. */
#grid-hero .gh-org {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(var(--ink-rgb), 0.22);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}
#grid-hero .gh-org:hover,
#grid-hero .gh-org:focus-visible {
  color: var(--t1);
  text-decoration-color: currentColor;
  outline: none;
}

/* About Me / Playground have no card/grid switch, so the pill ends on the
   Playground link: more room on the right (20px) than the 10px top and the
   10px it keeps against the switch's outline on Home (Jen, Nov 16).
   nav-squeeze.js eases between the two. */
#topbar.home-nav .nav-cluster { padding-right: 20px; }

/* Grid header text block narrower (Jen, Nov 16: it was cutting into the
   cards on the right). The table's frame is 2:1 and pinned right, so on a
   laptop the tilted BMW card's left edge sits about 49vw across; the text
   used to run to 7.5vw + 46vw = 53.5vw. 40vw ends it at 47.5vw, clear of
   the cards, and on wide screens it keeps the same gap. */
#grid-hero.gt-has-table > .gh-reveal-mask { max-width: 40vw; }
@media (max-width: 760px) { #grid-hero.gt-has-table > .gh-reveal-mask { max-width: none; } }
