/* ============================================
   FONTS
   ============================================ */
@font-face {
  font-family: 'Dirtyline';
  src: url('fonts/dirtyline.woff2') format('woff2'),
       url('fonts/dirtyline.woff') format('woff');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* ============================================
   RESET & BASE
   ============================================ */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', 'Noto Sans SC', sans-serif;
  background: #FFFBF0;
  color: #1A1A2E;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'kern' 1, 'liga' 1;
}

a {
  color: inherit;
  text-decoration: none;
}

ul {
  list-style: none;
}

/* ============================================
   FULL-PAGE PHYSICS LAYOUT
   ============================================ */
.physics-page {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
}

/* ============================================
   HEADER OVERLAY
   ============================================ */
.page-header {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 10;
  padding: 2rem 2rem;
  background: transparent;
  pointer-events: none;
}

.page-header a,
.page-header .header-btn,
.page-header .header-copyright {
  pointer-events: all;
}

.header-grid {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 2rem;
}

/* Header buttons */
.header-col--social {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
}

.header-btn {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: #1A1A2E;
  background: transparent;
  border: 0.75px solid #1A1A2E;
  border-radius: 100px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0 0.45rem;
  height: 22px;
  line-height: 20px;
  box-sizing: border-box;
  text-decoration: none;
  transition: background 0.25s ease, color 0.25s ease, transform 0.2s ease;
}

.header-btn:hover {
  background: #1A1A2E;
  color: #FFFBF0;
  transform: scale(1.08) translateY(-2px);
}

.header-btn:active {
  transform: scale(0.95);
}

.header-col--center {
  display: flex;
  justify-content: center;
}

.header-btn--fill {
  background: #1A1A2E;
  color: #FFFBF0;
  transition: background 0.25s ease, color 0.25s ease, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.header-btn--fill:hover {
  background: #1A1A2E;
  color: #FFFBF0;
  transform: scale(1.08) translateY(-2px);
}

.wave-emoji {
  display: inline-block;
  transition: transform 0.3s ease;
}

.header-btn--fill:hover .wave-emoji {
  animation: waveHand 0.8s ease-in-out;
}

@keyframes waveHand {
  0% { transform: rotate(0deg); }
  15% { transform: rotate(14deg); }
  30% { transform: rotate(-8deg); }
  45% { transform: rotate(14deg); }
  60% { transform: rotate(-4deg); }
  75% { transform: rotate(10deg); }
  100% { transform: rotate(0deg); }
}

.header-col--right {
  text-align: right;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.header-copyright {
  font-size: 0.72rem;
  font-weight: 300;
  letter-spacing: 0.02em;
  color: rgba(26, 26, 46, 0.4);
}

/* ============================================
   PHYSICS PLAYGROUND
   ============================================ */
.physics-playground {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  overflow: hidden;
}

.physics-body {
  position: absolute;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  will-change: transform;
  top: -300px;
  left: 0;
}

.physics-body.dragging {
  cursor: grabbing;
  z-index: 100;
}

/* Text bodies */
.physics-text {
  font-family: 'Dirtyline', 'Noto Sans SC', sans-serif;
  font-size: clamp(3.5rem, 10vw, 9rem);
  font-weight: normal;
  letter-spacing: 0.02em;
  line-height: 1;
  color: #1A1A2E;
  white-space: nowrap;
  pointer-events: all;
}

.physics-text--small {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Noto Sans SC', sans-serif;
  font-size: clamp(1.1rem, 2.5vw, 1.8rem);
  font-weight: 300;
  letter-spacing: -0.01em;
}

/* Per-letter stylistic alternates for Dirtyline collage effect */
/* Font only has alternates for B, C, D, E via salt and ss01 */
.physics-text .ss-default {
  font-feature-settings: normal;
}
.physics-text .ss-salt {
  font-feature-settings: 'salt' on;
}
.physics-text .ss-01 {
  font-feature-settings: 'ss01' on;
}

/* Shape bodies */
.physics-shape {
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: all;
}

.physics-shape svg {
  display: block;
  pointer-events: none;
}

/* ============================================
   CHAT PANEL — ChatGPT style
   ============================================ */
.chat-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(26, 26, 46, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.chat-panel {
  position: fixed;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(24px) saturate(1.5);
  -webkit-backdrop-filter: blur(24px) saturate(1.5);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 36px;
  box-shadow:
    0 24px 80px rgba(26, 26, 46, 0.12),
    0 8px 24px rgba(26, 26, 46, 0.06),
    0 0 0 0.5px rgba(255, 255, 255, 0.3) inset;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Start collapsed at button position — set via JS custom properties */
  top: var(--chat-from-top, 50%);
  left: var(--chat-from-left, 50%);
  width: var(--chat-from-w, 120px);
  height: var(--chat-from-h, 30px);
  opacity: 0;
  transition: top 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              left 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              width 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              height 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              border-radius 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.3s ease;
}

.chat-overlay.active .chat-panel {
  --panel-w: min(680px, 90vw);
  --panel-h: min(600px, 85vh);
  top: calc(50% - min(600px, 85vh) / 2);
  left: calc(50% - min(680px, 90vw) / 2);
  width: min(680px, 90vw);
  height: min(600px, 85vh);
  opacity: 1;
}

.chat-close {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 2;
  background: rgba(26, 26, 46, 0.05);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: rgba(26, 26, 46, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.chat-close:hover {
  background: rgba(26, 26, 46, 0.1);
  color: #1A1A2E;
}

/* Messages — ChatGPT layout */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 5rem 1.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(26, 26, 46, 0.08) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(26, 26, 46, 0.08);
  border-radius: 4px;
}

.chat-message {
  animation: chatFadeIn 0.3s ease;
}

@keyframes chatFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-message p {
  font-size: 0.92rem;
  font-weight: 400;
  line-height: 1.7;
  letter-spacing: -0.01em;
  color: #1A1A2E;
}

/* User: right-aligned bubble */
.chat-message--user {
  align-self: flex-end;
  max-width: 75%;
  background: #f0f0f0;
  padding: 0.65rem 1rem;
  border-radius: 28px;
}

/* Bot: left-aligned bubble */
.chat-message--bot {
  align-self: flex-start;
  max-width: 85%;
  background: rgba(26, 26, 46, 0.05);
  padding: 0.65rem 1rem;
  border-radius: 28px;
}

/* Bottom area — input + disclaimer */
.chat-bottom {
  margin-top: auto;
  padding: 2rem 1.5rem 1.65rem;
}

.chat-form {
  display: flex;
  flex-direction: column;
}

.chat-input-row {
  display: flex;
  align-items: center;
  gap: 0;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(26, 26, 46, 0.08);
  border-radius: 28px;
  padding: 0.3rem 0.35rem 0.3rem 0;
  min-height: 46px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-row:focus-within {
  border-color: rgba(255, 182, 193, 0.6);
  box-shadow: 0 0 0 3px rgba(255, 182, 193, 0.25);
}

.chat-input {
  flex: 1;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 400;
  color: #1A1A2E;
  background: transparent;
  border: none;
  padding: 0.55rem 1rem;
  outline: none;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
}

.chat-input::placeholder {
  color: rgba(26, 26, 46, 0.35);
}

.chat-hint {
  font-size: 0.72rem;
  color: rgba(26, 26, 46, 0.45);
  text-align: center;
  padding: 0.4rem 0 0;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.chat-hint.visible {
  opacity: 1;
}

.chat-send {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: #1A1A2E;
  color: #FFFBF0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.chat-send:hover {
  background: #2a2a4e;
}

.chat-send:disabled {
  opacity: 0.3;
  cursor: default;
}

.chat-disclaimer {
  font-size: 0.68rem;
  color: rgba(26, 26, 46, 0.35);
  text-align: center;
  margin-top: 0.6rem;
  letter-spacing: -0.005em;
}

/* Grain texture overlay */
.chat-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  opacity: 0.3;
  pointer-events: none;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 128px 128px;
}

.chat-panel > *:not(.chat-close) {
  position: relative;
  z-index: 1;
}

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 0.7rem 1rem;
  animation: chatFadeIn 0.3s ease;
}

.chat-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(26, 26, 46, 0.25);
  animation: typingBounce 1.4s ease-in-out infinite;
}

.chat-typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-4px); opacity: 0.8; }
}

/* Send button bounce on click */
.chat-send.sending {
  animation: sendBounce 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes sendBounce {
  0% { transform: scale(1); }
  30% { transform: scale(0.8); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* Scrollbar — only visible on hover */
.chat-messages {
  scrollbar-color: transparent transparent;
}

.chat-messages:hover {
  scrollbar-color: rgba(26, 26, 46, 0.08) transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: transparent;
  transition: background 0.3s ease;
}

.chat-messages:hover::-webkit-scrollbar-thumb {
  background: rgba(26, 26, 46, 0.08);
}

/* Staggered message entrance */
@keyframes chatFadeIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .page-header {
    padding: 2rem 1.5rem 1.5rem;
  }

  .header-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .header-col--center {
    justify-content: flex-start;
    order: -1;
  }

  .header-col--right {
    text-align: left;
  }

  .physics-text {
    font-size: clamp(3rem, 14vw, 7rem);
  }

  .physics-text--small {
    font-size: clamp(1rem, 3.5vw, 1.5rem);
  }

  .chat-overlay.active .chat-panel {
    width: 100%;
    height: 100dvh;
    top: 0;
    left: 0;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }

  .chat-messages {
    padding: 5rem 1.25rem 1.5rem;
  }

  .chat-bottom {
    padding: 0.75rem 1.25rem 1.25rem;
  }
}
