:root {
  color-scheme: dark;
  --mx: 0;
  --my: 0;
  --px: 50%;
  --py: 50%;
  --ink: #050505;
  --paper: #f7f3ef;
  --rose: #b40f1f;
  --ice: #dcebf0;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #000;
}

body {
  color: var(--paper);
  font-family: ui-monospace, 'Cascadia Code', 'SFMono-Regular', Consolas, monospace;
}

button,
input { font: inherit; }

.stage {
  isolation: isolate;
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: #000;
}

.image-field,
.portrait,
.chroma {
  position: absolute;
  inset: -2.5%;
  width: 105%;
  height: 105%;
}

.image-field {
  z-index: -4;
  transform: translate3d(calc(var(--mx) * -6px), calc(var(--my) * -6px), 0);
  transition: transform 900ms cubic-bezier(.2,.8,.2,1);
}

.portrait {
  object-fit: cover;
  object-position: 50% 50%;
  filter: saturate(.9) contrast(1.05) brightness(.88);
  transform: scale(1.035) translate3d(calc(var(--mx) * -8px), calc(var(--my) * -8px), 0);
  animation: breathe 12s ease-in-out infinite alternate;
  will-change: transform, filter;
}

.chroma {
  background-image: url('./portrait.jpg');
  background-position: center;
  background-size: cover;
  opacity: .045;
  mix-blend-mode: screen;
  pointer-events: none;
}

.chroma-red {
  filter: sepia(1) saturate(7) hue-rotate(310deg);
  transform: translate3d(calc(var(--mx) * 4px + 2px), calc(var(--my) * 2px), 0);
  animation: chroma-red 8s steps(1) infinite;
}

.chroma-cyan {
  filter: sepia(1) saturate(6) hue-rotate(135deg);
  transform: translate3d(calc(var(--mx) * -4px - 2px), calc(var(--my) * -2px), 0);
  animation: chroma-cyan 11s steps(1) infinite;
}

.vignette {
  position: absolute;
  z-index: -2;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at var(--px) var(--py), transparent 0 10%, rgb(0 0 0 / 8%) 38%, rgb(0 0 0 / 58%) 115%),
    linear-gradient(to bottom, rgb(0 0 0 / 18%), transparent 28%, transparent 72%, rgb(0 0 0 / 42%));
}

.scanlines {
  position: absolute;
  z-index: 8;
  inset: 0;
  pointer-events: none;
  opacity: .08;
  background: repeating-linear-gradient(to bottom, transparent 0 3px, rgb(255 255 255 / 15%) 4px);
  mix-blend-mode: soft-light;
}

.eye-glow {
  position: absolute;
  z-index: 2;
  width: clamp(70px, 11vw, 150px);
  aspect-ratio: 1;
  border-radius: 50%;
  pointer-events: none;
  opacity: .4;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgb(255 255 255 / 40%) 0 8%, rgb(215 240 247 / 20%) 18%, transparent 66%);
  filter: blur(2px);
  animation: eye-pulse 4.8s ease-in-out infinite;
}

.eye-trigger {
  position: absolute;
  z-index: 5;
  width: clamp(58px, 9vw, 126px);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: default;
  transform: translate(-50%, -50%);
}

.eye-trigger:focus-visible {
  outline: 1px solid rgb(255 255 255 / 42%);
  outline-offset: 8px;
}

.whisper,
.privacy-note {
  position: absolute;
  z-index: 4;
  margin: 0;
  font-size: 9px;
  letter-spacing: .22em;
  text-shadow: 0 2px 12px #000;
}

.whisper {
  top: max(24px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  color: rgb(255 255 255 / 54%);
  animation: whisper 5.5s ease forwards;
}

.privacy-note {
  right: max(18px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  color: rgb(255 255 255 / 34%);
}

.gate {
  width: min(430px, calc(100% - 34px));
  padding: 0;
  border: 1px solid rgb(255 255 255 / 18%);
  border-radius: 3px;
  background: rgb(8 8 10 / 84%);
  color: var(--paper);
  box-shadow: 0 32px 120px rgb(0 0 0 / 76%);
  backdrop-filter: blur(24px) saturate(.8);
}

.gate::backdrop {
  background: rgb(0 0 0 / 48%);
  backdrop-filter: blur(8px);
}

.gate[open] { animation: gate-in 360ms cubic-bezier(.2,.8,.2,1); }

.gate-card {
  position: relative;
  padding: 34px;
}

.gate-index,
.gate-message {
  margin: 0;
  color: rgb(255 255 255 / 42%);
  font-size: 9px;
  letter-spacing: .18em;
}

.gate h1 {
  margin: 42px 0 36px;
  font-family: 'Times New Roman', 'Songti SC', serif;
  font-size: clamp(34px, 8vw, 46px);
  font-weight: 400;
  letter-spacing: -.05em;
}

.gate label {
  display: block;
  margin-bottom: 10px;
  color: rgb(255 255 255 / 52%);
  font-size: 9px;
  letter-spacing: .18em;
}

.password-row {
  display: grid;
  grid-template-columns: 1fr 48px;
  border-bottom: 1px solid rgb(255 255 255 / 42%);
}

.password-row input {
  min-width: 0;
  padding: 12px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #fff;
  font-size: 20px;
  letter-spacing: .2em;
}

.password-row button,
.gate-close {
  border: 0;
  background: transparent;
  color: rgb(255 255 255 / 70%);
  cursor: pointer;
}

.password-row button { font-size: 22px; }

.gate-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 32px;
  height: 32px;
  font-size: 22px;
}

.gate-message { min-height: 12px; margin-top: 18px; }

.gate-card.denied { animation: denied 360ms ease; }

.dashboard {
  position: absolute;
  z-index: 20;
  inset: 0;
  overflow: auto;
  padding: clamp(24px, 4vw, 64px);
  background:
    linear-gradient(rgb(4 4 6 / 88%), rgb(4 4 6 / 96%)),
    url('./portrait.jpg') center / cover fixed;
  backdrop-filter: blur(22px);
}

.dashboard[hidden] { display: none; }

.dashboard-header,
.dashboard-actions,
.section-heading,
.device-top,
.device-tags {
  display: flex;
  align-items: center;
}

.dashboard-header {
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 28px;
  border-bottom: 1px solid rgb(255 255 255 / 14%);
}

.dashboard-kicker,
.section-heading span,
.sync-state,
.device-id,
.device-time,
.device-detail dt,
.device-source,
.dashboard-actions button {
  font-size: 9px;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.dashboard-kicker {
  margin: 0 0 8px;
  color: rgb(255 255 255 / 40%);
}

.dashboard h2 {
  margin: 0;
  font-family: 'Times New Roman', 'Songti SC', serif;
  font-size: clamp(36px, 5vw, 66px);
  font-weight: 400;
  letter-spacing: -.05em;
}

.dashboard-actions { gap: 10px; }

.dashboard-actions button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid rgb(255 255 255 / 18%);
  background: rgb(255 255 255 / 4%);
  color: rgb(255 255 255 / 70%);
  cursor: pointer;
}

.dashboard-actions button:hover,
.dashboard-actions button:focus-visible {
  border-color: rgb(255 255 255 / 50%);
  outline: 0;
}

.sync-state {
  margin-right: 8px;
  color: rgb(255 255 255 / 48%);
}

.sync-state i {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 8px;
  border-radius: 50%;
  background: #86e36d;
  box-shadow: 0 0 12px #86e36d;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 28px;
  border-top: 1px solid rgb(255 255 255 / 12%);
  border-left: 1px solid rgb(255 255 255 / 12%);
}

.summary article {
  min-height: 126px;
  padding: 20px;
  border-right: 1px solid rgb(255 255 255 / 12%);
  border-bottom: 1px solid rgb(255 255 255 / 12%);
  background: rgb(255 255 255 / 2%);
}

.summary span {
  display: block;
  color: rgb(255 255 255 / 42%);
  font-size: 10px;
  letter-spacing: .12em;
}

.summary strong {
  display: block;
  margin-top: 26px;
  font-size: clamp(28px, 4vw, 48px);
  font-weight: 300;
  letter-spacing: -.05em;
}

.timeline-panel,
.devices-panel { margin-top: 44px; }

.section-heading {
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-heading h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .12em;
}

.section-heading span { color: rgb(255 255 255 / 36%); }

.timeline {
  display: grid;
  grid-template-columns: repeat(24, minmax(3px, 1fr));
  align-items: end;
  gap: clamp(2px, .5vw, 8px);
  min-height: 130px;
  padding: 18px 0 0;
  border-top: 1px solid rgb(255 255 255 / 12%);
  border-bottom: 1px solid rgb(255 255 255 / 12%);
}

.timeline-bar {
  position: relative;
  min-height: 3px;
  background: linear-gradient(to top, #7a0e1a, #d4dde2);
  opacity: .72;
  transition: height 480ms cubic-bezier(.2,.8,.2,1);
}

.timeline-bar span {
  position: absolute;
  right: 50%;
  bottom: -20px;
  display: none;
  color: rgb(255 255 255 / 42%);
  font-size: 8px;
  transform: translateX(50%);
}

.timeline-bar:nth-child(4n + 1) span { display: block; }

.device-list { border-top: 1px solid rgb(255 255 255 / 12%); }

.device-card {
  display: grid;
  grid-template-columns: minmax(180px, .85fr) minmax(320px, 1.6fr);
  gap: clamp(20px, 4vw, 64px);
  padding: 26px 0;
  border-bottom: 1px solid rgb(255 255 255 / 12%);
}

.device-top {
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.device-name {
  margin: 8px 0 0;
  font-family: 'Times New Roman', 'Songti SC', serif;
  font-size: clamp(22px, 3vw, 34px);
  font-weight: 400;
}

.device-id,
.device-time { color: rgb(255 255 255 / 38%); }

.device-time { white-space: nowrap; text-align: right; }

.device-tags {
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 18px;
}

.device-tags span {
  padding: 5px 8px;
  border: 1px solid rgb(255 255 255 / 14%);
  color: rgb(255 255 255 / 54%);
  font-size: 9px;
}

.device-detail {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px 20px;
  margin: 0;
}

.device-detail div { min-width: 0; }

.device-detail dt {
  margin-bottom: 6px;
  color: rgb(255 255 255 / 34%);
}

.device-detail dd {
  margin: 0;
  overflow: hidden;
  color: rgb(255 255 255 / 76%);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-source {
  grid-column: 1 / -1;
  overflow-wrap: anywhere;
  color: rgb(255 255 255 / 30%);
  line-height: 1.6;
  text-transform: none;
}

.empty-state {
  padding: 48px 0;
  color: rgb(255 255 255 / 42%);
  font-family: 'Times New Roman', 'Songti SC', serif;
  font-size: 22px;
}

.stage.accessing .image-field {
  filter: contrast(1.18) brightness(.65);
  transform: scale(1.035);
}

@keyframes breathe {
  from { transform: scale(1.035) translate3d(-2px, -2px, 0); }
  to { transform: scale(1.085) translate3d(7px, 5px, 0); }
}

@keyframes eye-pulse {
  50% { opacity: .68; transform: translate(-50%, -50%) scale(1.12); filter: blur(4px); }
}

@keyframes whisper {
  0%, 55% { opacity: 0; }
  72% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes gate-in {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
}

@keyframes denied {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

@keyframes chroma-red {
  0%, 92%, 100% { clip-path: inset(0 0 0 0); }
  93% { clip-path: inset(18% 0 63% 0); transform: translateX(8px); }
  95% { clip-path: inset(67% 0 12% 0); transform: translateX(-5px); }
}

@keyframes chroma-cyan {
  0%, 95%, 100% { clip-path: inset(0 0 0 0); }
  96% { clip-path: inset(48% 0 35% 0); transform: translateX(-7px); }
  98% { clip-path: inset(9% 0 76% 0); transform: translateX(5px); }
}

@media (max-width: 640px) {
  .privacy-note { font-size: 7px; letter-spacing: .12em; }
  .gate-card { padding: 28px 24px; }
  .dashboard { padding: 22px 16px 48px; }
  .dashboard-header { align-items: flex-start; flex-direction: column; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary article { min-height: 106px; }
  .device-card { grid-template-columns: 1fr; }
  .device-detail { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sync-state { display: none; }
}

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