:root {
  /* Near-black on near-white: the dichotomy */
  --ink: #141414;
  --ink-soft: #555550;
  --paper: #fbfbf9;
  --line: #141414;

  --split-duration: 1600ms;
  --split-ease: cubic-bezier(0.65, 0, 0.15, 1);

  /* Everything below is overridden live by script.js from the config */
  --cut-top: 100%;
  --cut-bottom: 0%;

  --type-size: 15px;
  --type-tracking: 0.2em;

  --identity-x: 8%;
  --identity-y: 12%;
  --contact-x: 68%;
  --contact-y: 34%;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: "Zen Kaku Gothic New", "Hiragino Sans", sans-serif;
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
}

/* Side bars: fade in on the same clock as the revealed page.
   They sit ABOVE the page (z-index) so widening them just covers more
   paper instead of squeezing the composition. */
.bar {
  position: fixed;
  top: 0;
  bottom: 0;
  width: var(--bar-width, 0);
  background: var(--bar);
  opacity: 0;
  transition: opacity 900ms ease 700ms;
  z-index: 5;
}

.bar-left { left: 0; }
.bar-right { right: 0; }

body.open .bar { opacity: 1; }
body.editing .bar { opacity: 1; transition: none; }

/* ---------- Landing curtain ---------- */

.curtain {
  position: fixed;
  inset: 0;
  cursor: pointer;
  z-index: 10;
  outline: none;
}

.shard {
  position: absolute;
  inset: 0;
  overflow: hidden;
  transition:
    transform var(--split-duration) var(--split-ease),
    opacity var(--fade-duration, 1100ms) ease var(--fade-delay, 300ms);
  will-change: transform, opacity;
  background: #1c1e1a;
}

.shard img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* The left shard runs 1px PAST the cut so the two clip paths overlap instead of
   meeting. Meeting exactly leaves an antialiased hairline that shows the paper
   through, and on a slow first load that line drew the diagonal on the dark
   backing before the photo arrived, telegraphing the split. */
.shard-left  { clip-path: polygon(0 0, calc(var(--cut-top) + 1px) 0, calc(var(--cut-bottom) + 1px) 100%, 0 100%); }
.shard-right { clip-path: polygon(var(--cut-top) 0, 100% 0, 100% 100%, var(--cut-bottom) 100%); }

body.open .shard-left  { transform: translateX(-115%); }
body.open .shard-right { transform: translateX(115%); }
body.open.fade .shard  { opacity: 0; }
body.open .curtain { pointer-events: none; }

/* ---------- Information page ---------- */

.reveal {
  position: fixed;
  inset: 0;
  /* Fixed inset — deliberately NOT --bar-width, so the bar slider
     can't reshape the composition */
  left: var(--stage-inset, 0);
  right: var(--stage-inset, 0);
  overflow: hidden;
  background: var(--paper);
}

/* Desktop (JS adds stage-scaled): the composition keeps its designed size and
   shape, uniformly scaled to fit the window — see layoutStage() in script.js.
   Must sit BEFORE the stage-mobile rules so the phone-frame editor wins. */
body.stage-scaled .reveal {
  inset: auto;
  left: 50%;
  top: 50%;
  width: var(--stage-w, 100%);
  height: var(--stage-h, 100%);
  transform: translate(-50%, -50%) scale(var(--stage-scale, 1));
}

/* Only when a line of text has been pushed past the edge (deep zoom, tiny
   screen). Scrolling becomes possible so nothing is unreachable; the portrait
   is held back from adding scroll of its own. */
.reveal.overflowing { overflow: auto; }
.reveal.overflowing .portrait { overflow: hidden; }

.reveal > * {
  opacity: 0;
  transition: opacity 900ms ease 700ms;
}

body.open .reveal > * { opacity: 1; }

/* The three sketch lines */
.lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.lines line {
  stroke: var(--line);
  stroke-width: var(--line-width, 1px);
}

/* Portrait clipped to the bottom triangle (clip-path set from config by JS) */
.portrait {
  position: absolute;
  inset: 0;
}

.portrait img {
  position: absolute;
  height: auto;
  display: block;
  filter: grayscale(1) contrast(1.02);
}

/* ---------- Text blocks ---------- */

/* Every line of text: one element, absolutely positioned,
   styled per-line from the config. */
.txt {
  position: absolute;
  color: var(--ink);
  text-transform: uppercase;
  text-decoration: none;
  white-space: pre; /* honors the line breaks typed in edit mode */
  line-height: 1.4;
  width: fit-content;
}

a.txt {
  padding-bottom: 0.25em;
  border-bottom: 1px solid transparent;
  transition: border-color 300ms ease;
}

a.txt:hover,
a.txt:focus-visible {
  border-color: var(--ink);
}

/* A ring only for someone moving by keyboard; a mouse user never sees it. */
a.txt:focus-visible { outline: 2px solid var(--ink); outline-offset: 6px; }

/* ---------- Edit mode ---------- */

body.editing:not(.replaying) .curtain { display: none; }
body.replaying .curtain { pointer-events: none; }

/* Mobile editing stage: the page becomes a phone-sized frame */
body.stage-mobile { background: #c9c7c0; }
body.stage-mobile .reveal {
  inset: auto;
  left: calc((100vw - 250px - 24px) / 2); /* centered in the space left of the panel */
  top: 50%;
  transform: translate(-50%, -50%);
  width: 390px;
  height: min(800px, calc(100vh - 32px));
  background: var(--paper);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.35), 0 18px 50px rgba(0,0,0,0.3);
}
body.editing .reveal > * { opacity: 1; transition: none; }

body.editing .txt {
  cursor: grab;
  outline: 1px dashed rgba(20, 20, 20, 0.18);
  outline-offset: 6px;
}

body.editing .txt.selected {
  outline: 1.5px solid #2563eb;
  outline-offset: 6px;
}

/* Grips on the selected line: the one on the right edge sets how wide the
   block is, the one in the corner changes width and type size together.
   Double-click either to let the line size itself to its words again. */
.txt-handles {
  position: absolute;
  pointer-events: none;
  z-index: 60;
  outline: 1px solid rgba(37, 99, 235, 0.35);
  outline-offset: 6px;
}
.txt-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #2563eb;
  border: 2px solid #fff;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
}
.txt-handle.side { right: -12px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.txt-handle.corner { right: -12px; bottom: -12px; cursor: nwse-resize; }

.edit-panel {
  position: fixed;
  right: 12px;
  top: 12px;
  z-index: 100;
  width: 250px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid #d6d6d0;
  padding: 14px;
  font-size: 11px;
  line-height: 1.4;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.edit-panel h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 10px 0 4px;
  font-weight: 500;
}

.edit-panel h2:first-child { margin-top: 0; }

.edit-panel label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin: 2px 0;
}

.edit-panel input[type="range"] { width: 130px; }
.edit-panel select { font: inherit; max-width: 150px; }

.edit-panel input[type="text"],
.edit-panel textarea {
  font: inherit;
  padding: 5px 7px;
  border: 1px solid #bbb;
  background: #fff;
  width: 100%;
  resize: vertical;
}
.edit-panel output { width: 34px; text-align: right; }

.edit-panel .buttons {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.edit-panel button {
  flex: 1;
  padding: 5px 0;
  font: inherit;
  background: #141414;
  color: #fff;
  border: 0;
  cursor: pointer;
}

.edit-panel button.secondary {
  background: #fff;
  color: #141414;
  border: 1px solid #141414;
}

.edit-panel .fmt button {
  background: #fff;
  color: #141414;
  border: 1px solid #bbb;
  min-width: 26px;
}

/* Photo library — thumbnails in the panel's Portrait section */
.edit-panel .photo-lib {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 6px 0;
}

.edit-panel .photo-tile {
  position: relative;
  aspect-ratio: 3 / 4;
  border: 2px solid #d6d6d0;
  cursor: pointer;
  overflow: hidden;
}

.edit-panel .photo-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.edit-panel .photo-tile.active { border-color: #141414; }

.edit-panel .photo-tile .photo-del {
  position: absolute;
  top: 0;
  right: 0;
  width: 16px;
  height: 16px;
  padding: 0;
  line-height: 14px;
  font-size: 12px;
  background: rgba(20, 20, 20, 0.75);
  color: #fff;
  border: 0;
  flex: none;
}

.edit-panel .photo-lib.flash { outline: 2px solid #141414; outline-offset: 2px; }

.edit-panel .fmt button.active {
  background: #141414;
  color: #fff;
  border-color: #141414;
}

/* ---------- Motion preferences ---------- */

@media (prefers-reduced-motion: reduce) {
  .shard { transition-duration: 1ms; }
  .reveal > * { transition-delay: 0ms; transition-duration: 1ms; }
}
