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

:root {
  --font: 'Inter', sans-serif;
  --bg: #ffffff;
  --fg: #0f0f0f;
  --fg-dim: rgba(15, 15, 15, 0.4);
  --shadow: rgba(0, 0, 0, 0.08);
}

html.dark {
  --bg: #0f0f0f;
  --fg: #f0f0f0;
  --fg-dim: rgba(240, 240, 240, 0.4);
  --shadow: rgba(255, 255, 255, 0.0);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  transition: background-color 1s ease, color 1s ease;
}

/* ---- Header ---- */

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 28px 36px;
  pointer-events: none;
}

.site-name {
  font-size: 13px;
  font-weight: 300;
  letter-spacing: 0.06em;
  color: var(--fg);
  opacity: 0.6;
  transition: color 1s ease;
}

.contact-link {
  font-size: 13px;
  font-weight: 300;
  letter-spacing: 0.06em;
  color: var(--fg);
  text-decoration: none;
  opacity: 0.6;
  pointer-events: all;
  transition: color 1s ease, opacity 0.2s;
}

.contact-link:hover {
  opacity: 1;
}

/* ---- Viewport & Canvas ---- */

.viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  user-select: none;
}

.canvas {
  position: absolute;
  width: 2600px;
  height: 1600px;
  will-change: transform;
}

/* ---- Project thumbnails ---- */

.project-container {
  position: relative;
  flex-shrink: 0;
}

.project {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: pointer;
  background-color: var(--fg);
  box-shadow: 0 4px 24px var(--shadow);
  transition: box-shadow 1s ease, background-color 1s ease;
}

.project img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  user-select: none;
  opacity: 0;
  transform: translate(var(--img-tx, 0px), var(--img-ty, 0px)) scale(var(--img-scale, 1));
  transition: opacity 0.5s ease, transform 0.1s ease;
}

.project-wrap:hover .project img {
  opacity: 1;
}

.project-wrap:hover .project-container {
  transform: scale(1.02);
  z-index: 10;
}

.project-container {
  transition: transform 0.35s ease;
}

/* Image edit mode */
.project.image-edit {
  outline: 1.5px solid #4a90e2;
  outline-offset: 0;
  cursor: crosshair;
}

.project.image-edit img {
  opacity: 1;
  pointer-events: all;
  transition: none;
  cursor: crosshair;
}

/* ---- Shapes ---- */

.shape-circle {
  border-radius: 50%;
}

.shape-diamond {
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

.shape-rhombus {
  clip-path: polygon(18% 0%, 100% 0%, 82% 100%, 0% 100%);
}

.shape-concave-star {
  clip-path: url(#clip-concave-star);
}

.shape-grid-lines {
  -webkit-mask-image: linear-gradient(
    to bottom,
    black 0%, black 26%,
    transparent 26%, transparent 40%,
    black 40%, black 66%,
    transparent 66%, transparent 80%,
    black 80%, black 100%
  );
  mask-image: linear-gradient(
    to bottom,
    black 0%, black 26%,
    transparent 26%, transparent 40%,
    black 40%, black 66%,
    transparent 66%, transparent 80%,
    black 80%, black 100%
  );
}

/* wide-rect, tall-rect, underscore, long-rect use no clip-path — shape comes from dimensions */

/* ---- Project wrapper + title ---- */

.project-wrap {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
}

.project-title {
  margin-top: 10px;
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: var(--fg);
  opacity: 0;
  text-align: center;
  white-space: nowrap;
  transition: opacity 0.3s ease, color 1s ease;
}

.project-wrap:hover .project-title {
  opacity: 1;
}

/* ---- Presence ---- */

/* Remote cursors */
.rc {
  position: absolute;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.rc-name {
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--c);
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  opacity: 0.9;
  transition: background-color 1s ease;
}

.rc-bubble {
  font-size: 11px;
  font-weight: 300;
  color: #fff;
  background: var(--c);
  padding: 5px 10px;
  border-radius: 10px;
  border-bottom-right-radius: 2px;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.rc-bubble.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Project glow when someone is inside */
.project.has-viewers {
  box-shadow: 0 0 0 2px var(--viewer-color), 0 0 20px 4px color-mix(in srgb, var(--viewer-color) 40%, transparent);
}

/* Viewer shape indicator — fades on hover so it doesn't block the thumbnail */
.viewer-shape-indicator {
  opacity: 1;
  transition: opacity 0.25s ease;
}

.project-wrap:hover .viewer-shape-indicator {
  opacity: 0;
}

/* Self sent bubble */
.self-bubble {
  position: fixed;
  z-index: 300;
  pointer-events: none;
  font-size: 11px;
  font-weight: 300;
  color: #fff;
  background: var(--self-color, #999);
  padding: 5px 10px;
  border-radius: 10px;
  border-bottom-left-radius: 2px;
  white-space: nowrap;
  transform: translateX(-50%) translateY(34px);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease, background-color 1s ease, color 1s ease;
}

.self-bubble.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0px);
}

/* Chat input */
@keyframes chat-appear {
  from { opacity: 0; transform: translateX(-50%) scale(0.65); }
  to   { opacity: 1; transform: translateX(-50%) scale(1); }
}

@keyframes chat-dismiss {
  from { opacity: 1; transform: translateX(-50%) scale(1); }
  to   { opacity: 0; transform: translateX(-50%) scale(0.65); }
}

.chat-input-wrap {
  position: fixed;
  z-index: 300;
  pointer-events: all;
  transform: translateX(-50%);
  animation: chat-appear 0.15s ease forwards;
}

.chat-input-wrap.closing {
  animation: chat-dismiss 0.18s ease forwards;
  pointer-events: none;
}

.chat-input {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.04em;
  color: #fff;
  background: #999;
  border: none;
  outline: none;
  padding: 4px 10px;
  border-radius: 20px;
  text-align: center;
  width: 40px;
  min-width: 40px;
  transition: width 0.15s ease, background-color 1s ease, color 1s ease;
}

.chat-input::placeholder {
  opacity: 0.4;
}

.chat-input-sizer {
  position: absolute;
  visibility: hidden;
  white-space: pre;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.04em;
  padding: 0 10px;
  pointer-events: none;
}

/* Self color dot in header */
#self-color-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: transparent;
  margin-left: 6px;
  vertical-align: middle;
  transition: background-color 0.4s ease;
}

/* Custom cursor for local user */
#self-cursor {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 9999;
  display: none;
}

body.party-connected #self-cursor {
  display: block;
}

html body.party-connected,
body.party-connected * {
  cursor: none !important;
}

/* Cursor typing / send animations */
.cursor-anim-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
}

@keyframes cursor-spin {
  to { transform: rotate(360deg); }
}

@keyframes cursor-pop {
  0%   { transform: scale(1); }
  55%  { transform: scale(1.5); }
  100% { transform: scale(1); }
}

#self-cursor.typing .cursor-anim-wrap {
  animation: cursor-spin 2.2s linear infinite;
}

.rc.rc-sent .cursor-anim-wrap {
  animation: cursor-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Cursor shapes (self and remote) */
.cursor-shape {
  display: block;
  background: var(--c, #999);
  flex-shrink: 0;
  transform-origin: center center;
}

.cursor-square {
  width: 16px;
  height: 16px;
}

.cursor-diamond {
  width: 16px;
  height: 16px;
}

.cursor-rhombus {
  width: 24px;
  height: 12px;
  clip-path: polygon(18% 0%, 100% 0%, 82% 100%, 0% 100%);
}

.cursor-triangle {
  width: 16px;
  height: 14px;
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}

/* ---- Physics ball ---- */

#physics-ball {
  position: fixed;
  top: 0;
  left: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--fg);
  pointer-events: none;
  z-index: 45;
  opacity: 0;
  transition: opacity 0.5s ease, background-color 0.3s ease;
}

.ball-mark {
  display: none;
}

#physics-ball.hoverable {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--fg);
}

/* ---- Design mode ---- */

.design-mode .project-wrap {
  cursor: move;
}

/* Bounding box overlay — sits over the shape without being clipped */
.project-bbox {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  border: 1px dashed var(--fg);
  transition: opacity 0.2s;
}

.design-mode .project-bbox {
  opacity: 0.5;
  pointer-events: all;
}

/* Corner handles */
.bbox-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--bg);
  border: 1.5px solid var(--fg);
  border-radius: 1px;
}

.bbox-tl { top: -4px;    left: -4px;   cursor: nw-resize; }
.bbox-tr { top: -4px;    right: -4px;  cursor: ne-resize; }
.bbox-bl { bottom: -4px; left: -4px;   cursor: sw-resize; }
.bbox-br { bottom: -4px; right: -4px;  cursor: se-resize; }

/* Panel */
#design-panel {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  display: none;
  align-items: center;
  gap: 16px;
  background: var(--fg);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.06em;
  white-space: nowrap;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.design-mode #design-panel {
  display: flex;
}

.dp-label {
  opacity: 0.5;
  margin-right: 4px;
}

.dp-label kbd {
  font-family: var(--font);
  font-size: 10px;
  opacity: 0.7;
}

.dp-actions {
  display: flex;
  gap: 8px;
}

.dp-btn {
  background: transparent;
  border: 1px solid var(--bg);
  color: var(--bg);
  font-family: var(--font);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.06em;
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.dp-btn:hover {
  opacity: 1;
}

.dp-done {
  opacity: 1;
  background: var(--bg);
  color: var(--fg);
  border-color: var(--bg);
}

/* ---- Mobile lookbook ---- */

.mobile-lookbook {
  display: none;
}

@media (max-width: 768px) {
  html, body {
    overflow: auto;
    height: auto;
  }

  .viewport,
  .design-mode #design-panel {
    display: none !important;
  }

  /* Show header on mobile too */
  .site-header {
    position: fixed;
    display: flex;
    background: var(--bg);
    border-bottom: 1px solid var(--fg-dim);
    transition: background-color 1s ease, border-color 1s ease;
    z-index: 100;
  }

  .site-name {
    opacity: 1;
  }

  /* Lookbook */
  .mobile-lookbook {
    display: block;
    padding-top: 65px; /* below header */
    padding-bottom: 60px;
  }

  .mb-project {
    display: block;
    text-decoration: none;
    color: var(--fg);
    padding: 0 0 48px;
  }

  .mb-img-wrap {
    width: 100%;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background: var(--fg);
  }

  .mb-img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity 0.3s ease;
  }

  .mb-info {
    padding: 12px 20px 0;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
  }

  .mb-title {
    font-size: 13px;
    font-weight: 300;
    letter-spacing: 0.04em;
    color: var(--fg);
    transition: color 1s ease;
  }
}
