/* contact.html — chat with the site owner (js/contact.js). Black theme,
   loads after home.css / theme-v2.css / castle.css. The chat pieces follow
   21st.dev's chat components (empty state, suggestion chips, attachment
   tray, auto-growing composer), rebuilt without React. */

.chat-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 22rem;
  gap: 24px;
  align-items: start;
}

/* ---- Panel ------------------------------------------------------------ */
.chat-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-radius: 28px;
  background: var(--h-card);
  border: 1px solid var(--h-line);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow: hidden;
}

.chat-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--h-line);
}
.chat-avatar {
  display: grid; place-items: center; flex: 0 0 auto;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--h-pill-bg); color: var(--h-pill-fg);
}
.chat-bar-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.chat-bar-text b { font: 700 15px 'Anuphan', sans-serif; color: var(--h-fg); }
.chat-bar-text small { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--h-muted); }
.chat-live { width: 7px; height: 7px; border-radius: 50%; background: var(--h-lime); box-shadow: 0 0 8px var(--h-lime); }

/* Icon-only buttons: bright and bordered so they read on black. */
.chat-icon-btn {
  display: grid; place-items: center; flex: 0 0 auto;
  width: 38px; height: 38px; padding: 0;
  border-radius: 50%; border: 1px solid var(--h-line);
  background: #161616; color: #d4d4d4; cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
}
.chat-icon-btn:hover, .chat-icon-btn:focus-visible { background: #242424; color: var(--h-fg); border-color: rgba(250, 250, 250, .25); }
.chat-icon-btn:focus-visible { outline: 2px solid var(--h-lime); outline-offset: 2px; }

/* ---- Thread ----------------------------------------------------------- */
.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: clamp(320px, 56vh, 620px);
  padding: 22px 20px 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #333 transparent;
}

.chat-day {
  align-self: center;
  margin: 10px 0 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: #141414;
  font: 500 11px 'JetBrains Mono', monospace;
  letter-spacing: .08em;
  color: var(--h-muted);
}

.chat-row { display: flex; flex-direction: column; gap: 4px; max-width: min(78%, 34rem); }
.chat-row.me { align-self: flex-end; align-items: flex-end; }
.chat-row.them { align-self: flex-start; align-items: flex-start; }
.chat-row + .chat-row.them, .chat-row.them + .chat-row.me { margin-top: 8px; }

.chat-who { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; color: var(--h-muted); }
.chat-who i { width: 18px; height: 18px; border-radius: 50%; background: var(--h-pill-bg); color: var(--h-pill-fg); display: grid; place-items: center; font: 800 9px 'Inter', sans-serif; font-style: normal; }

.chat-bubble {
  padding: 10px 14px;
  font: 500 14px/1.55 'Anuphan', sans-serif;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-row.me .chat-bubble { background: var(--h-pill-bg); color: var(--h-pill-fg); border-radius: 20px 20px 6px 20px; }
.chat-row.them .chat-bubble { background: #171717; color: var(--h-fg); border: 1px solid var(--h-line); border-radius: 20px 20px 20px 6px; }
.chat-bubble .chat-img-note { display: inline-flex; align-items: center; gap: 6px; opacity: .7; font-size: 13px; }

.chat-meta { display: flex; align-items: center; gap: 6px; font: 500 10.5px 'JetBrains Mono', monospace; color: #737373; }
.chat-meta .pending { display: inline-flex; align-items: center; gap: 5px; color: var(--h-yellow); font-family: 'Anuphan', sans-serif; font-weight: 600; }
.chat-meta .pending::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chat-meta .done { color: var(--h-lime); font-family: 'Anuphan', sans-serif; font-weight: 600; }

/* New bubbles rise in (only the ones just added — see js/contact.js). */
.chat-row.is-new { transition: opacity .35s ease, translate .45s cubic-bezier(.23, 1, .32, 1); }
@starting-style {
  .chat-row.is-new { opacity: 0; translate: 0 10px; }
}

/* Empty state */
.chat-empty {
  margin: auto;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  max-width: 24rem; text-align: center;
  color: var(--h-muted); font-size: 14px; line-height: 1.6;
}
.chat-empty-ico {
  display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%;
  border: 1px solid var(--h-line); background: #121212; color: var(--h-fg);
  animation: chat-float 3.6s ease-in-out infinite;
}
.chat-empty h2 { margin: 6px 0 0; font: 800 22px 'Anuphan', sans-serif; color: var(--h-fg); }
.chat-empty p { margin: 0; }
@keyframes chat-float { 50% { translate: 0 -5px; } }

/* ---- Suggestion chips ------------------------------------------------- */
.chat-chips { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 18px 12px; }
.chat-chip {
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--h-line); background: transparent; color: #d4d4d4;
  font: 600 12.5px 'Anuphan', sans-serif;
  transition: background .2s, color .2s, border-color .2s, translate .25s cubic-bezier(.23, 1, .32, 1);
}
.chat-chip:hover, .chat-chip:focus-visible { background: #1c1c1c; color: var(--h-fg); border-color: rgba(250, 250, 250, .25); translate: 0 -1px; }
.chat-chip.is-on { background: var(--h-fg); color: #000; border-color: var(--h-fg); }
.chat-chip:focus-visible { outline: 2px solid var(--h-lime); outline-offset: 2px; }

/* ---- Composer --------------------------------------------------------- */
.chat-composer {
  margin: 0 14px;
  padding: 10px 10px 10px 16px;
  border-radius: 22px;
  background: #0d0d0d;
  border: 1px solid var(--h-line);
  transition: border-color .2s, box-shadow .2s;
}
.chat-composer:focus-within { border-color: rgba(250, 250, 250, .28); box-shadow: 0 0 0 4px rgba(255, 255, 255, .04); }

.chat-input {
  display: block;
  width: 100%;
  min-height: 26px;
  max-height: 180px;
  padding: 6px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--h-fg);
  font: 500 15px/1.55 'Anuphan', sans-serif;
  field-sizing: content; /* grows with the text; js/contact.js resizes where unsupported */
}
.chat-input::placeholder { color: #6b6b6b; }

.chat-tools { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.chat-status { flex: 1; min-width: 0; font-size: 12px; color: var(--h-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-status.is-error { color: #fb7185; }
.chat-status.is-ok { color: var(--h-lime); }
.chat-count { font: 500 11px 'JetBrains Mono', monospace; color: #6b6b6b; }
.chat-count.is-near { color: var(--h-yellow); }

.chat-send {
  display: grid; place-items: center;
  width: 42px; height: 42px; padding: 0; border: 0; border-radius: 50%;
  background: var(--h-pill-bg); color: var(--h-pill-fg); cursor: pointer;
  transition: scale .2s cubic-bezier(.23, 1, .32, 1), opacity .2s, background .2s;
}
.chat-send:hover:not(:disabled) { scale: 1.07; }
.chat-send:active:not(:disabled) { scale: .94; }
.chat-send:disabled { background: #262626; color: #6b6b6b; cursor: not-allowed; }
.chat-send:focus-visible { outline: 2px solid var(--h-lime); outline-offset: 3px; }
.chat-send.is-busy .ico-send { animation: chat-send-fly .9s ease-in-out infinite; }

/* Attachment tray (a picked image waiting to go) */
.chat-tray {
  display: flex; align-items: center; gap: 10px;
  width: fit-content; max-width: 100%;
  margin: 2px 0 8px; padding: 6px 8px 6px 6px;
  border-radius: 14px; background: #171717; border: 1px solid var(--h-line);
}
.chat-tray[hidden] { display: none; }
.chat-tray img { width: 44px; height: 44px; object-fit: cover; border-radius: 10px; }
.chat-tray-name { max-width: 14rem; font-size: 12px; color: #d4d4d4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-tray-x {
  display: grid; place-items: center; width: 26px; height: 26px; padding: 0; border-radius: 50%;
  border: 1px solid var(--h-line); background: #222; color: #d4d4d4; cursor: pointer;
}
.chat-tray-x:hover { color: #fb7185; border-color: rgba(244, 63, 94, .4); }

.chat-foot { margin: 8px 0 14px; text-align: center; font: 500 11px 'JetBrains Mono', monospace; color: #5c5c5c; }

/* ---- Side cards ------------------------------------------------------- */
.chat-aside { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 96px; }
.chat-card {
  padding: 20px 22px;
  border-radius: 24px;
  background: var(--h-card);
  border: 1px solid var(--h-line);
}
.chat-kicker { display: block; margin-bottom: 10px; font-size: 12px; font-weight: 700; color: var(--h-muted); }
.chat-tips { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 12px; }
.chat-tips li { position: relative; padding-left: 16px; font-size: 13.5px; line-height: 1.6; color: #c4c4c4; }
.chat-tips li::before { content: ""; position: absolute; left: 0; top: .6em; width: 6px; height: 6px; border-radius: 50%; background: var(--h-sky); }
.chat-tips b { display: block; color: var(--h-fg); }
.chat-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chat-stats div { display: flex; flex-direction: column; gap: 2px; }
.chat-stats b { font: 800 30px 'Inter', sans-serif; letter-spacing: -.02em; color: var(--h-fg); }
.chat-stats div + div b { color: var(--h-lime); }
.chat-stats span { font-size: 12px; color: var(--h-muted); }

/* ---- Icon motion (hover/focus) ---------------------------------------- */
.ico-refresh, .ico-clip, .ico-send { transform-box: fill-box; transform-origin: 50% 50%; }
.ico-refresh { transition: rotate .7s cubic-bezier(.34, 1.56, .64, 1); }
.chat-icon-btn:is(:hover, :focus-visible) .ico-refresh { rotate: 180deg; }
.chat-icon-btn.is-spinning .ico-refresh { animation: chat-spin .8s linear infinite; }
.ico-clip { transition: rotate .4s cubic-bezier(.34, 1.56, .64, 1); }
.chat-icon-btn:is(:hover, :focus-visible) .ico-clip { rotate: -18deg; }
.ico-send { transition: translate .35s cubic-bezier(.34, 1.56, .64, 1); }
.chat-send:is(:hover, :focus-visible):not(:disabled) .ico-send { translate: 2px -2px; }
@keyframes chat-spin { to { rotate: 360deg; } }
@keyframes chat-send-fly { 0% { translate: 0 0; opacity: 1; } 45% { translate: 6px -6px; opacity: 0; } 46% { translate: -6px 6px; opacity: 0; } 100% { translate: 0 0; opacity: 1; } }

@media (max-width: 1100px) {
  .chat-layout { grid-template-columns: minmax(0, 1fr); }
  .chat-aside { position: static; display: grid; grid-template-columns: 1fr 1fr; }
}
@media (max-width: 680px) {
  .chat-aside { grid-template-columns: minmax(0, 1fr); }
  .chat-thread { height: clamp(300px, 58vh, 560px); padding: 16px 12px 10px; }
  .chat-row { max-width: 88%; }
  .chat-composer { margin: 0 8px; }
  .chat-chips { padding: 0 10px 10px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .chat-chip { flex: 0 0 auto; }
  .chat-panel { border-radius: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-empty-ico, .chat-send.is-busy .ico-send, .chat-icon-btn.is-spinning .ico-refresh { animation: none; }
  .ico-refresh, .ico-clip, .ico-send, .chat-chip, .chat-row.is-new { transition: none; }
  .chat-icon-btn .ico-refresh, .chat-icon-btn .ico-clip, .chat-send .ico-send { rotate: none !important; translate: none !important; }
}

/* ---- Playful bits (js/contact.js) ------------------------------------- */

/* Live dot breathes. */
.chat-live { animation: chat-breathe 2.4s ease-in-out infinite; }
@keyframes chat-breathe { 50% { box-shadow: 0 0 0 4px rgba(190, 242, 100, .15), 0 0 12px var(--h-lime); } }

/* Waiting-for-reply dot pulses. */
.chat-meta .pending::before { animation: chat-pulse 1.6s ease-in-out infinite; }
@keyframes chat-pulse { 50% { opacity: .35; scale: .7; } }

/* Bubbles grow in / fade out at the thread's top and bottom edges as you
   scroll the history (decorative, so no fallback without support). */
@media (prefers-reduced-motion: no-preference) {
  @supports ((animation-timeline: view()) and (animation-range: entry)) {
    .chat-thread > .chat-row {
      animation: chat-row-in linear backwards, chat-row-out linear forwards;
      animation-timeline: view();
      animation-range: entry 0% entry 100%, exit 0% exit 100%;
    }
    .chat-row.me { transform-origin: 100% 100%; }
    .chat-row.them { transform-origin: 0 100%; }
  }
}
@keyframes chat-row-in { from { opacity: .2; scale: .9; } }
@keyframes chat-row-out { to { opacity: .2; scale: .94; } }

/* A just-sent bubble springs out of the composer corner. */
.chat-row.me.is-new .chat-bubble { animation: chat-pop .5s cubic-bezier(.34, 1.56, .64, 1) backwards; transform-origin: 100% 100%; }
@keyframes chat-pop { from { scale: .4; opacity: 0; } }

/* An owner reply you haven't seen yet glows for a few beats. */
.chat-row.them.is-fresh .chat-bubble {
  border-color: rgba(190, 242, 100, .55);
  animation: chat-fresh 1.6s ease-in-out 3;
}
@keyframes chat-fresh { 50% { box-shadow: 0 0 0 4px rgba(190, 242, 100, .12), 0 0 22px rgba(190, 242, 100, .35); } }
.chat-new-tag {
  padding: 1px 7px; border-radius: 999px; font: 700 10px 'Anuphan', sans-serif; font-style: normal;
  color: #000; background: var(--h-lime);
}

/* Sparks thrown by burst() — fixed so they fly over the whole page. */
.chat-spark { position: fixed; z-index: 9999; width: 7px; height: 10px; margin: -5px -3px; border-radius: 2px; pointer-events: none; }

/* The corner mascot hides here: its pet shows up inside the chat frame
   instead (.chat-peek), so there aren't two of it on screen. */
.contact-page #rankMascot { display: none; }

/* Pet peeking in from the chat frame's edge — placed and animated by
   js/contact.js; the panel's overflow: hidden clips it at the edge. */
.chat-peek {
  position: absolute; z-index: 4; left: 0; top: 0;
  width: 84px; height: 84px;
  opacity: 0; pointer-events: none;
}
.chat-peek[hidden] { display: none; }
.chat-peek.is-out { opacity: 1; }
.chat-peek svg { width: 100%; height: 100%; display: block; overflow: visible; }

/* The pet's speech bubble (js/contact.js showSay); the tail points back at
   the pet from whichever edge it came in. */
.chat-peek-say {
  position: absolute; z-index: 5; left: 0; top: 0;
  max-width: 15rem; padding: 8px 13px;
  border-radius: 16px; background: #fafafa; color: #0a0a0a;
  font: 700 13px/1.45 'Anuphan', sans-serif;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  pointer-events: none; opacity: 0;
}
.chat-peek-say[hidden] { display: none; }
.chat-peek-say::before {
  content: ""; position: absolute; width: 10px; height: 10px; background: inherit;
  rotate: 45deg; border-radius: 2px;
}
.chat-peek-say[data-side="left"] { transform-origin: 0 50%; }
.chat-peek-say[data-side="left"]::before { left: -4px; top: calc(50% - 5px); }
.chat-peek-say[data-side="right"] { transform-origin: 100% 50%; }
.chat-peek-say[data-side="right"]::before { right: -4px; top: calc(50% - 5px); }
.chat-peek-say[data-side="top"] { transform-origin: 50% 0; }
.chat-peek-say[data-side="top"]::before { top: -4px; left: calc(50% - 5px); }

/* Send button lights up once there's something to send. */
.chat-composer.has-text .chat-send:not(:disabled) { box-shadow: 0 0 0 4px rgba(250, 250, 250, .08), 0 0 18px rgba(250, 250, 250, .18); }

/* Character ring replaces the 0/500 text; shows the count left near the end. */
.chat-count {
  position: relative; display: grid; place-items: center;
  width: 26px; height: 26px; font: 700 9.5px 'JetBrains Mono', monospace;
  --ring: var(--h-sky);
  transition: scale .25s cubic-bezier(.34, 1.56, .64, 1);
}
.chat-count[hidden] { display: none; }
.chat-count::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(var(--ring) calc(var(--p, 0) * 360deg), #262626 0);
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
}
.chat-count.is-near { --ring: var(--h-yellow); scale: 1.15; }
.chat-count.is-full { --ring: var(--h-rose, #fb7185); color: var(--h-rose, #fb7185); }

/* Drag-an-image overlay over the whole panel. */
.chat-panel { position: relative; }
.chat-drop {
  position: absolute; inset: 10px; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  border-radius: 22px; border: 2px dashed rgba(190, 242, 100, .6);
  background: rgba(10, 10, 10, .88); color: var(--h-lime);
  font: 700 15px 'Anuphan', sans-serif;
  opacity: 0; scale: .98; pointer-events: none;
  transition: opacity .2s, scale .25s cubic-bezier(.34, 1.56, .64, 1);
}
.chat-panel.is-drop .chat-drop { opacity: 1; scale: 1; }
.chat-panel.is-drop .chat-drop svg { animation: chat-float 1.2s ease-in-out infinite; }

/* Reply-rate bar under the stats. */
.chat-stats .chat-rate { grid-column: 1 / -1; gap: 6px; }
.chat-rate-bar { position: relative; display: block; height: 6px; border-radius: 999px; background: #1f1f1f; overflow: hidden; }
.chat-rate-bar::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: linear-gradient(90deg, var(--h-sky), var(--h-lime));
  transform-origin: 0 50%; scale: var(--p, 0) 1;
  transition: scale .9s cubic-bezier(.23, 1, .32, 1);
}

@media (prefers-reduced-motion: reduce) {
  .chat-live, .chat-meta .pending::before, .chat-row.me.is-new .chat-bubble, .chat-row.them.is-fresh .chat-bubble,
  .chat-panel.is-drop .chat-drop svg { animation: none; }
  .chat-rate-bar::after, .chat-count, .chat-drop { transition: none; }
}
