:root {
  --paper: #f3f3f4;
  --ink: #0c0c0e;
  --night: #0a1b4d;
  --raster: #2a49b8;
  --signal: #ffbf0f;
  --muted: #6b6f7d;
  --line: rgb(12 12 14 / 0.08);
  --bubble: rgb(38 38 41);
  --bubble-mine: rgb(10 132 255);
  --ease: cubic-bezier(.65, 0, .35, 1);
  --font: "Archivo", ui-sans-serif, system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.45 var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }

/* Light table: a pannable plane, curved by app.js, with an edge blur and film grain on top. */
.table {
  position: fixed;
  inset: 0;
  perspective: 1600px;
  perspective-origin: 50% 50%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  overflow: hidden;
}
.table.dragging { cursor: grabbing; }
/* Tiles sink behind the plane (negative z), so the plane itself must let pointers through to them. */
.plane { position: absolute; inset: 0; transform-style: preserve-3d; pointer-events: none; }

.tile {
  position: absolute;
  left: 0;
  top: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: calc(var(--w) * 0.022);
  width: var(--w);
  aspect-ratio: 4 / 3;
  background: #e6e7ea center / cover no-repeat;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 10px 30px -12px rgb(0 0 0 / 0.18);
  cursor: pointer;
  pointer-events: auto;
  will-change: transform;
  backface-visibility: hidden;
  opacity: 0;
  transition: opacity .7s var(--ease), box-shadow .25s ease;
  outline-offset: 4px;
}
.tile.in { opacity: 1; }
.tile:hover, .tile:focus-visible { box-shadow: 0 1px 2px rgb(0 0 0 / 0.08), 0 22px 50px -14px rgb(0 0 0 / 0.32); }
.tile:focus-visible { outline: 2px solid var(--raster); }
.tile .ph {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: .3em;
  padding: 8%;
  border-radius: inherit;
  background: linear-gradient(160deg, #eef1f8, #dfe4f1);
  color: var(--night);
  font-size: calc(var(--w) * 0.06);
  font-weight: 600;
  letter-spacing: -0.02em;
  text-align: center;
}
.tile .ph small { font-size: .55em; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.tile .tag {
  position: absolute;
  left: calc(var(--w) * 0.03);
  top: calc(var(--w) * 0.03);
  padding: .3em .65em;
  border-radius: 99px;
  background: rgb(255 255 255 / 0.92);
  color: var(--ink);
  font-size: max(10px, calc(var(--w) * 0.032));
  font-weight: 600;
  letter-spacing: -0.01em;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.12);
}
.tile .tag[data-kind="live"]::before {
  content: "";
  display: inline-block;
  width: .55em;
  height: .55em;
  margin-right: .4em;
  border-radius: 50%;
  background: #17a34a;
  vertical-align: .05em;
}
.tile .cap {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 10px);
  font-size: max(12px, calc(var(--w) * 0.04));
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.tile .cap span { color: var(--muted); font-weight: 400; }
.tile:hover .cap, .tile:focus-visible .cap { opacity: 1; transform: none; }

.edge {
  position: absolute;
  inset: 0;
  pointer-events: none;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  mask-image: radial-gradient(ellipse 72% 70% at 50% 50%, transparent 62%, black 100%);
  -webkit-mask-image: radial-gradient(ellipse 72% 70% at 50% 50%, transparent 62%, black 100%);
}
.grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .17;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Chrome over the table */
.chrome {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  pointer-events: none;
  z-index: 5;
}
.chrome > * { pointer-events: auto; }
.brand, .pill {
  display: inline-flex;
  align-items: center;
  gap: .55em;
  height: 40px;
  padding: 0 16px 0 12px;
  border: 0;
  border-radius: 99px;
  background: rgb(255 255 255 / 0.86);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 6px 20px -10px rgb(0 0 0 / 0.25);
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
  letter-spacing: -0.02em;
  cursor: pointer;
}
.brand b { font-weight: 650; color: var(--night); }
.pill { padding: 0 16px; }
.count {
  min-width: 1.6em;
  padding: .05em .45em;
  border-radius: 99px;
  background: var(--night);
  color: #fff;
  font-size: .8em;
  font-weight: 600;
  text-align: center;
}
.hint {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  translate: -50% 0;
  margin: 0;
  padding: .55em 1.1em;
  border-radius: 99px;
  background: rgb(12 12 14 / 0.78);
  color: #fff;
  font-size: 13px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity .6s ease, translate .6s var(--ease);
  z-index: 5;
}
.hint.gone { opacity: 0; translate: -50% 8px; }

/* Viewer: the chosen state in a white frame, like a print on the light table */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 16px;
  background: rgb(243 243 244 / 0.62);
  backdrop-filter: blur(14px) saturate(.9);
  -webkit-backdrop-filter: blur(14px) saturate(.9);
  animation: fade .35s var(--ease) both;
}
.viewer[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }

.v-meta {
  width: var(--fw);
  max-width: calc(100vw - 32px);
  display: flex;
  align-items: baseline;
  gap: .8em;
  white-space: nowrap;
  overflow: hidden;
}
.v-meta h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.03em; overflow: hidden; text-overflow: ellipsis; }
.v-meta p { margin: 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.v-meta code { font: 500 .95em ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink); }

.frame {
  position: relative;
  width: var(--fw);
  height: var(--fh);
  padding: var(--edge) var(--edge) 0;
  border-radius: calc(var(--edge) * 1.15);
  background: #fff;
  box-shadow: 0 2px 4px rgb(0 0 0 / 0.04), 0 40px 90px -30px rgb(0 0 0 / 0.35);
  animation: rise .5s var(--ease) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.97); } }
.screen {
  position: relative;
  width: var(--sw);
  height: var(--sh);
  border-radius: calc(var(--edge) * 0.7);
  overflow: hidden;
  background: #e9eaee;
  isolation: isolate;
}
.stage {
  position: absolute;
  left: 50%;
  top: 0;
  transform-origin: top center;
}
.stage iframe { display: block; border: 0; background: #fff; }
.viewer[data-format="mobile"] .stage { top: 50%; transform-origin: center center; }
.viewer[data-format="mobile"] .stage iframe {
  border-radius: 46px;
  box-shadow: 0 0 0 10px #111, 0 0 0 11px #3a3a3d, 0 30px 60px -20px rgb(0 0 0 / 0.5);
}

.foot {
  height: var(--foot);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
  padding: 0 calc((var(--foot) - .7em) / 2 - var(--edge) + 2px);
  font-size: clamp(15px, calc(var(--foot) * 0.36), 34px);
}
.foot-btn {
  display: inline-flex;
  align-items: center;
  gap: .3em;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font-weight: 500;
  font-stretch: 100%;
  letter-spacing: -0.035em;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.foot-btn svg { width: .7em; height: .7em; fill: currentColor; }
.foot-btn:hover { color: var(--raster); }
.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 99px;
  background: #f1f1f3;
  font-size: 14px;
}
.seg button {
  padding: .45em 1em;
  border: 0;
  border-radius: 99px;
  background: none;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--muted);
  cursor: pointer;
}
.seg button[aria-pressed="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); }

.close, .nav {
  position: absolute;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.9);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08), 0 8px 24px -10px rgb(0 0 0 / 0.3);
  cursor: pointer;
}
.close { top: max(14px, env(safe-area-inset-top)); right: 16px; width: 40px; height: 40px; }
.close svg { width: 15px; height: 15px; }
.close.small { position: static; width: 34px; height: 34px; box-shadow: none; background: #f1f1f3; }
.nav { top: 50%; width: 44px; height: 44px; margin-top: -22px; font-size: 26px; line-height: 1; padding-bottom: 3px; color: var(--ink); }
.nav.prev { left: 16px; }
.nav.next { right: 16px; }
.close:hover, .nav:hover { background: #fff; }

/* The branch's story, replayed as chat balloons (newest at the bottom) */
.thread {
  position: absolute;
  left: calc(var(--edge) + 12px);
  bottom: calc(var(--foot) + 12px);
  transition: opacity .8s ease;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  max-width: min(23em, calc(var(--sw) - 24px));
  font-size: 15px;
  pointer-events: none;
  z-index: 2;
}
.b {
  position: relative;
  max-width: 100%;
  padding: .55em .85em;
  border-radius: 1.1em;
  background: var(--bubble);
  color: #fff;
  line-height: 1.3;
  text-wrap: balance;
  box-shadow: 0 6px 20px -10px rgb(0 0 0 / 0.45);
  animation: pop .45s cubic-bezier(.2, .8, .2, 1) both;
  transition: opacity .5s ease;
}
.b.mine { background: var(--bubble-mine); }
.b strong { display: block; font-size: .78em; font-weight: 600; color: rgb(140 196 255); letter-spacing: 0; }
.b.mine strong { color: rgb(255 255 255 / 0.8); }
.thread.done { opacity: 0; }
.b .w { display: inline-block; animation: word .62s cubic-bezier(.2, .8, .2, 1) both; }
.b .dots { display: inline-flex; gap: .25em; padding: .3em 0; }
.b .dots i { width: .5em; height: .5em; border-radius: 50%; background: currentColor; opacity: .25; animation: dot .5s ease-in-out infinite alternate; }
.b .dots i:nth-child(2) { animation-delay: .25s; }
.b .dots i:nth-child(3) { animation-delay: .5s; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.96); } }
@keyframes word { from { opacity: 0; filter: blur(.4em); translate: 0 .3em; } }
@keyframes dot { to { opacity: .6; } }

/* List of all states */
.list {
  width: min(760px, calc(100vw - 24px));
  max-height: min(86vh, 900px);
  padding: 22px 22px 8px;
  border: 0;
  border-radius: 22px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 40px 100px -30px rgb(0 0 0 / 0.45);
}
.list::backdrop { background: rgb(243 243 244 / 0.6); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.list-head { display: flex; justify-content: space-between; align-items: center; }
.list h2 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.035em; }
.list-lead { margin: 6px 0 16px; color: var(--muted); font-size: 14px; }
.list-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.list-items li {
  display: grid;
  grid-template-columns: 112px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 10px;
  margin: 0 -10px;
  border-radius: 14px;
}
.list-items li:hover { background: #f5f5f7; }
.list-items .th { width: 112px; aspect-ratio: 4 / 3; border-radius: 8px; background: #e6e7ea center / cover; box-shadow: inset 0 0 0 1px var(--line); }
.list-items h3 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.02em; }
.list-items p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.list-items code { font: 500 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink); }
.list-items .acts { display: flex; gap: 6px; }
.list-items .acts a, .list-items .acts button {
  padding: .5em .9em;
  border: 0;
  border-radius: 99px;
  background: #f1f1f3;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}
.list-items .acts button { background: var(--night); color: #fff; }
.kind {
  display: inline-block;
  margin-left: .4em;
  padding: .1em .5em;
  border-radius: 99px;
  background: #eef1f8;
  color: var(--night);
  font-size: 11px;
  font-weight: 600;
  vertical-align: .15em;
}

@media (max-width: 640px) {
  .nav { display: none; }
  .seg { font-size: 13px; }
  .v-meta { flex-direction: column; gap: 0; }
  .thread { font-size: 13px; }
  .list-items li { grid-template-columns: 72px 1fr; }
  .list-items .th { width: 72px; }
  .list-items .acts { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
