/* merlinduncan.de — v2 */

@font-face {
  font-family: 'Whyte Inktrap';
  src: url('../fonts/WhyteInktrap-Regular.otf') format('opentype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Whyte Inktrap';
  src: url('../fonts/WhyteInktrap-Medium.otf') format('opentype');
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: 'Whyte Inktrap';
  src: url('../fonts/WhyteInktrap-Light.otf') format('opentype');
  font-weight: 300;
  font-display: swap;
}

:root {
  --orange: #FF5000;
  --paper: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --gutter: 20px;
  --stroke: 6px;
  --ease: cubic-bezier(.2, .8, .2, 1);

  /* "S" = Bühnenbreite: alle Größen der Bühne (Wortmarke, Asterisk, Kacheln,
     Detail-Karte) sind Vielfache davon. Auf dem Handy = Bildschirmbreite, auf dem
     Desktop bleibt die Komposition handygroß statt riesig zu werden. JS (app.js
     measure()) setzt denselben Wert nochmal, das hier ist nur der Vorab-Fallback. */
  --S: min(100vw, 56vh);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Whyte Inktrap', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  background: var(--orange);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  z-index: 1000;
  transition: top .15s ease;
}
.skip-link:focus {
  top: 8px;
}

/* focus visibility — the whole site is hand-drawn/orange, so a crisp focus ring matters */
:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 3px;
  border-radius: 4px;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

/* ---------- app shell ---------- */
/* Eine durchgehende Bühne (#stage) für Home → Grid → Detail. Welcher Zustand
   gerade gilt, steht in #app[data-state="home|grid|detail"]; alles Weitere
   (Kacheln fliegen aus dem Asterisk, Karte poppt auf, …) hängt nur daran. */

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#app.no-anim *,
#app.no-anim *::before,
#app.no-anim *::after {
  transition: none !important;
}

#stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Wischen auf dem Canvas: nur im Grid darf der Browser keine eigenen Gesten
   (Scrollen/Zoomen) starten, sonst bekäme das Pan-Handling keine Pointer-Events. */
#app[data-state="grid"] #stage {
  touch-action: none;
  cursor: grab;
}
#app.dragging #stage { cursor: grabbing; }

/* Ursprung der Bühne = Asterisk, wie in der Skizze leicht unter der Bildschirmmitte
   (51 % — Figma-Referenz). Pan verschiebt die ganze #world per --px/--py. */
#world {
  position: absolute;
  left: 50%;
  top: 51%;
  width: 0;
  height: 0;
  transform: translate(var(--px, 0px), var(--py, 0px));
}

#app.pan-anim #world,
#app.pan-anim .tile-in {
  transition: transform .6s var(--ease);
}

/* ---------- Home ---------- */

/* Proportions below are measured directly off the Figma mobile frame (393×852
   reference canvas) and reproduced as fractions of S (= 393 there) / vh:
   - "merlin's": top 120/852=14.08vh, width 160.94/393=.4095 S, center offset +.0274 S
   - "portfolio": top 181.89/852=21.34vh (≈0.8vh below line1), width
     132.97/393=.3384 S, center offset -.0548 S
   - asterisk: true viewport center (434.76/852≈51vh), 73/393=.1858 S wide */

#view-home {
  --WS: var(--S); /* Maßstab der Wortmarke (Desktop: eigener Wert, siehe @media unten) */
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 var(--gutter);
  overflow: hidden;
  pointer-events: none;
  transition: opacity .35s ease, visibility 0s linear 0s;
}

#view-home a,
#view-home button {
  pointer-events: auto;
}

/* Auf Home darf der Browser keine eigenen Gesten starten: Hochziehen = Impressum (ganzer Bildschirm) */
#app[data-state="home"] #home-layer {
  touch-action: none;
}

/* Tipp auf die Wortmarke zeichnet sie neu */
.wordmark-line {
  pointer-events: auto;
  cursor: pointer;
}

/* Grid/Detail: Wortmarke + Links räumen die Bühne (nicht klickbar, nicht fokussierbar) */
#app:not([data-state="home"]) #view-home {
  opacity: 0;
  visibility: hidden;
  transition: opacity .35s ease, visibility 0s linear .35s;
}

.wordmark-line {
  position: relative;
  flex: 0 0 auto;
}

.wordmark-line svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.wordmark-line1 {
  width: calc(var(--WS) * .4095);
  margin-top: 14.08vh;
  transform: translateX(calc(var(--WS) * .0274));
}

.wordmark-line2 {
  width: calc(var(--WS) * .3384);
  margin-top: 0.8vh;
  transform: translateX(calc(var(--WS) * -.0548));
}

/* draw-on effect: each path's own length/duration/delay is set by JS so the
   whole mark draws as one continuous, non-overlapping handwriting motion */
.draw-path {
  stroke-dasharray: var(--len, 1000);
  stroke-dashoffset: var(--len, 1000);
  animation: draw-on var(--dur, 0.3s) linear forwards;
  animation-delay: var(--delay, 0s);
}

@keyframes draw-on {
  to { stroke-dashoffset: 0; }
}

/* once already drawn this session, show statically without animating */
.no-draw .draw-path {
  animation: none;
  stroke-dashoffset: 0;
}

/* everything between the two wordmark lines: empty + flex:0 when closed,
   grows to fill the remaining height when the About insert is open, which is
   what pushes "portfolio" down to the very bottom of the screen
   (About ist aktuell deaktiviert, Mechanik bleibt für ein neues Design) */
#about-insert {
  width: 100%;
  max-width: 400px;
  flex-grow: 0;
  overflow: hidden;
  transition: flex-grow .5s cubic-bezier(.25,.8,.3,1);
}

#view-home.about-open #about-insert {
  flex-grow: 1;
  overflow-y: auto;
}

#view-home.about-open #home-rest,
#view-home.about-open #impressum-pull {
  display: none;
}

/* Der Asterisk sitzt im Ursprung der Bühne und bleibt dort: auf Home ist er der Tap-Ziel
   (öffnet das Grid), im Grid der Anker (schließt es wieder), im Detail verschwindet er
   in der großen Karte. Keine Hover-Bewegung (bewusst). */
.asterisk-tap {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(var(--S) * .24);
  height: calc(var(--S) * .24);
  margin: calc(var(--S) * -.12) 0 0 calc(var(--S) * -.12);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  z-index: 20;
  transition: opacity .35s ease, transform .5s var(--ease);
}

.asterisk-tap svg {
  width: calc(var(--S) * .1858);
  height: auto;
  pointer-events: none;
}

#app[data-state="detail"] .asterisk-tap {
  opacity: 0;
  transform: scale(.4);
  pointer-events: none;
}

.home-links {
  position: absolute;
  left: 50%;
  bottom: 6vh;
  transform: translateX(-50%);
  width: 100%;
  max-width: 320px;
  padding: 0 var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.home-links a {
  display: block;
  text-decoration: none;
}

.home-links svg {
  height: 34px;
  width: auto;
  display: block;
}

/* Für Tastatur/Screenreader: sichtbarer Link zum Impressum nur bei Fokus */
.sr-link {
  position: fixed;
  left: -9999px;
  bottom: 8px;
  z-index: 70;
  padding: 8px 14px;
  background: var(--orange);
  color: #fff;
  border-radius: 8px;
  font-size: 14px;
}
.sr-link:focus { left: 8px; }

/* ---------- Impressum sticky-pull reveal ---------- */
/* intentionally undiscoverable: no visible hint, just a quiet hit-zone along
   the very bottom edge that opens the legal page on a sustained pull */

#home-layer {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  position: fixed;
  inset: 0;
  z-index: 2;
  background: var(--paper);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .28);
  will-change: transform;
}

#view-impressum {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow-y: auto;
  background: var(--orange);
  color: #fff;
  overscroll-behavior: contain;
}

#view-impressum[hidden] { display: none; }

/* Alles in einer Schriftgröße/-stärke (laut Design): Überschriften sind nur eigene Zeilen,
   Abschnitte durch Leerzeilen getrennt. */
#view-impressum .legal-content {
  position: relative;
  max-width: 560px;
  margin: 0 auto;
  padding: 44px 35px calc(12vh + env(safe-area-inset-bottom));
  font-size: 14px;
  line-height: 1.4;
  font-weight: 400;
}

#view-impressum h1,
#view-impressum h2,
#view-impressum p,
#view-impressum address {
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
  font-style: normal;
  margin: 0;
}

#view-impressum section,
#view-impressum h1 { margin: 0 0 1.4em; }

#view-impressum a { color: #fff; }

.impressum-lang {
  display: block;
  margin: 1.4em 0 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: #fff;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- Kacheln (Grid-Zustand) ---------- */
/* Jede Kachel sitzt im Ursprung der Bühne (unter dem Asterisk) und bekommt ihre
   Zielpositionen als CSS-Variablen von app.js (layoutTiles):
     --gx/--gy  Position im Grid (Scatter um den Asterisk)
     --dx/--dy  nach außen gedrängte Position, solange ein Projekt offen ist
     --w/--h    Größe,   --rot  Start-Drehung beim Herausfliegen
     --delay    Stagger (nur beim Öffnen/Schließen des Grids gesetzt)
   Der Zustandswechsel ist reine CSS-Transition — kein Neu-Rendern. */

.tile {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  width: var(--w);
  height: var(--h);
  margin: calc(var(--h) / -2) 0 0 calc(var(--w) / -2);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(0, 0) scale(.1) rotate(var(--rot, 0deg));
  transition:
    transform .8s var(--ease) var(--delay, 0s),
    opacity .35s ease var(--delay, 0s),
    visibility 0s linear calc(.8s + var(--delay, 0s));
  will-change: transform;
  -webkit-user-drag: none;
}

#app[data-state="grid"] .tile,
#app[data-state="detail"] .tile {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition:
    transform .8s var(--ease) var(--delay, 0s),
    opacity .35s ease var(--delay, 0s),
    visibility 0s linear 0s;
}

#app[data-state="grid"] .tile {
  transform: translate(var(--gx), var(--gy)) scale(1) rotate(0deg);
}

#app[data-state="detail"] .tile {
  transform: translate(var(--dx), var(--dy)) scale(1) rotate(0deg);
}

/* das geöffnete Projekt: die Karte übernimmt, die Kachel bleibt unsichtbar an ihrer Grid-Stelle */
#app[data-state="detail"] .tile.selected {
  transform: translate(var(--gx), var(--gy)) scale(1) rotate(0deg);
  opacity: 0;
  pointer-events: none;
  transition: transform .8s var(--ease), opacity 0s, visibility 0s;
}

/* Karte schrumpft gerade in diese Kachel zurück: unsichtbar halten, danach sofort zeigen */
.tile.hold {
  opacity: 0 !important;
  pointer-events: none;
  transition: transform .8s var(--ease) var(--delay, 0s), opacity 0s !important;
}
.tile.snap {
  transition: transform .8s var(--ease), opacity 0s, visibility 0s !important;
}

.tile:focus-visible {
  outline-offset: 6px;
}

/* Parallax beim Wischen: jede Kachel hat eine Tiefe (--depth, vorn > hinten) und bewegt
   sich zusätzlich zum Canvas um pan·depth; --tilt kippt sie dabei leicht mit */
.tile-in {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform:
    translate(calc(var(--pxn, 0) * var(--depth, 0) * 1px), calc(var(--pyn, 0) * var(--depth, 0) * 1px))
    rotate(calc((var(--pxn, 0) + var(--pyn, 0)) * var(--tilt, 0) * 1deg));
}

.tile-in * {
  pointer-events: none;
  -webkit-user-drag: none;
}

/* Rahmen (siehe js/frame.js): Inhalt per clip-path auf die Form zugeschnitten,
   orange Marker-Strich als SVG darüber. Füllt immer seine Elternbox. */
.frame {
  position: absolute;
  inset: 0;
  --frame-stroke: 4.5px;
}

.frame-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.frame-clip > img,
.frame-clip > video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.frame-stroke {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

/* ---------- Detail-Karte ---------- */
/* Die angetippte Kachel wächst als Pop-up in die Bildschirmmitte: EIN Rahmen
   (gleiche Wobbly-Form wie die Fotos) mit Bild, Meta, Text und Galerie darin,
   in sich scrollbar. Die anderen Kacheln hängen dann am Rand (siehe .tile). */

#card-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.card {
  position: absolute; /* left/top/width/height setzt app.js (und animiert sie beim Öffnen/Schließen) */
  pointer-events: auto;
  will-change: left, top, width, height;
  /* Schriftgröße relativ zur Bühne, damit sie auf Handy und Desktop gleich wirkt */
  --card-fs: clamp(13px, calc(var(--S) * .036), 17px);
}

.card-close {
  position: absolute;
  right: 4px;
  top: -54px;
  z-index: 2;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.card-close svg { width: 32px; height: auto; }

.card-scroll {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  font-family: 'Whyte Inktrap', system-ui, sans-serif;
}
.card-scroll::-webkit-scrollbar { display: none; }

/* Titelbild-Karussell oben: mehrere Bilder/Videos, Wischen + Punkte */
.card-hero {
  position: relative;
  width: 100%;
  flex: none;
  overflow: hidden;
}

.carousel,
.carousel-track,
.carousel-slide {
  width: 100%;
  height: 100%;
}

.carousel { position: relative; }

.carousel-track {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  cursor: grab;
}
.carousel-track::-webkit-scrollbar { display: none; }
.carousel-track.dragging { scroll-snap-type: none; cursor: grabbing; }

.carousel-slide {
  flex: 0 0 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.carousel-slide img,
.carousel-slide video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

/* Punkte am unteren Bildrand: zeigen, wie viele Bilder es gibt und welches gerade sichtbar ist */
.carousel-dots {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  display: flex;
  justify-content: center;
  gap: 2px;
  pointer-events: none;
}

.carousel-dot {
  pointer-events: auto;
  width: 20px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  filter: drop-shadow(0 0 1.5px rgba(0, 0, 0, .5));
}

.carousel-dot svg {
  height: 9px;
  width: auto;
  overflow: visible;
}

.carousel-dot.active {
  color: var(--orange);
  filter: drop-shadow(0 0 1px #fff) drop-shadow(0 0 1px #fff);
}

.carousel-dot.active svg {
  height: 17px;
  animation: dot-pop .28s var(--ease);
}

@keyframes dot-pop {
  from { transform: scale(.4); }
  to   { transform: scale(1); }
}

.card-text {
  flex: none;
  color: var(--ink);
}

.detail-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 26px 13% 0 11%;
  font-weight: 300;
  font-size: var(--card-fs);
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.detail-meta .right { text-align: right; }

.detail-body {
  padding: 28px 13% 0 11%;
  font-weight: 300;
  font-size: var(--card-fs);
  line-height: 1.4;
}

.detail-body p { margin: 0 0 1em; }
.detail-body p:last-child { margin-bottom: 0; }

/* Luft am Ende des Scrollens, damit der Text nicht an der Wobbly-Kante klebt */
.card-end { height: 72px; }

/* ---------- About insert (flex-grow mechanics are in the Home section above) ---------- */

.about-divider {
  width: 100%;
  display: block;
}

.about-close {
  float: right;
  width: 44px;
  height: 44px;
  margin: 8px 8px 0 0;
}

.about-close svg { width: 100%; height: auto; }

.about-text {
  clear: both;
  padding: 20px 6px 24px;
  line-height: 1.5;
  white-space: pre-line;
}

/* ---------- Desktop / Querformat: alles links, wie im Desktop-Entwurf ----------
   Maße aus dem Screenshot (16:10): Wortmarke oben links, Links unten links. */
@media (min-width: 768px) and (min-aspect-ratio: 1/1) {
  #view-home {
    --WS: min(42.1vw, 67.4vh);
    align-items: flex-start;
    padding: 0 0 0 5.25vw;
  }
  .wordmark-line1 {
    margin-top: 6.8vh;
    margin-left: calc(var(--WS) * .077);
    transform: none;
  }
  .wordmark-line2 {
    margin-top: calc(var(--WS) * .0173);
    margin-left: 0;
    transform: none;
  }
  .home-links {
    left: 5.25vw;
    bottom: 8vh;
    transform: none;
    width: auto;
    max-width: none;
    padding: 0;
    display: block;
    height: 34px;
  }
  .home-links a { position: absolute; bottom: 0; }
  #link-linkedin { left: 0; }
  #link-mail { left: 8.75vw; }
  #link-pinterest { left: 20.4vw; }
  #view-impressum .legal-content {
    margin: 0;
    max-width: 760px;
    padding-left: 5.25vw;
  }
}

/* ---------- motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .draw-path {
    animation: none !important;
    stroke-dashoffset: 0 !important;
  }
  #view-impressum,
  #about-insert,
  #view-home,
  .tile,
  .asterisk-tap,
  #world {
    transition: none !important;
  }
  .tile-in {
    transform: none !important;
    transition: none !important;
  }
}
