:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --border: #e1e5ee;
  --text: #1b1f3b;
  --muted: #5f6783;
  --accent: #3c7afe;
  --accent-soft: rgba(60, 122, 254, 0.1);
  --danger: #ff5d5d;
  --surface-muted: rgba(255, 255, 255, 0.6);
  --scroll-track: #e8ecf8;
  --scroll-thumb: rgba(60, 122, 254, 0.6);
}

body[data-theme="dark"] {
  --bg: #0f1629;
  --card: #131c32;
  --border: #28324c;
  --text: #f9fbff;
  --muted: #b4bdd9;
  --accent: #88a8ff;
  --accent-soft: rgba(136, 168, 255, 0.12);
  --danger: #ff8585;
  --surface-muted: rgba(255, 255, 255, 0.08);
  --scroll-track: #0b1327;
  --scroll-thumb: rgba(136, 168, 255, 0.5);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 1rem 2rem;
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 200%;
  height: 100%;
  background-image: url('/image/Background.png');
  background-size: 50% 100%;
  background-repeat: repeat-x;
  opacity: 0.03;
  z-index: 0;
  animation: scrollBackground 60s linear infinite;
  pointer-events: none;
}

body[data-theme="dark"]::before {
  opacity: 0.05;
}

@keyframes scrollBackground {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-50%);
  }
}

body > * {
  position: relative;
  z-index: 1;
}

a,
.muted a {
  color: var(--accent);
}

.muted {
  color: var(--muted);
}

.partner-info {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.partner-info strong {
  color: var(--text);
}

a {
  color: var(--accent);
}

.site-header {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.5rem 0 0.5rem;
  width: 100%;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  background: var(--card);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(10, 20, 60, 0.12);
  animation: fadeInDown 0.5s ease-out;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.theme-toggle {
  position: absolute;
  right: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.6rem;
}

.brand p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-style: italic;
}


.brand-icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(60, 122, 254, 0.3));
}

.ghost-btn,
.primary-btn,
.danger-btn {
  border: none;
  border-radius: 999px;
  padding: 0.65rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text);
  transition: transform 0.15s ease, background 0.15s ease;
}

.ghost-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.ghost-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 25px rgba(60, 122, 254, 0.3);
}

.primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.primary-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.danger-btn {
  background: var(--danger);
  color: #fff;
}

.danger-btn:disabled,
.ghost-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

.link-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 2rem;
  margin-top: 1rem;
  max-width: 1100px;
  width: 100%;
  align-self: center;
}

.layout > * {
  min-width: 0;
}

.hero {
  background: var(--card);
  border-radius: 24px;
  padding: 2rem;
  border: 1px solid var(--border);
  box-shadow: 0 15px 35px rgba(10, 20, 60, 0.08);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  animation: fadeInUp 0.6s ease-out;
}

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

.hero h2 {
  margin-top: 0;
  font-size: 2rem;
}

.hero-copy p {
  margin: 0;
}

.lead {
  color: var(--muted);
}

.start-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.profile-card {
  border: 1px dashed var(--border);
  border-radius: 16px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: rgba(255, 255, 255, 0.02);
}

.profile-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  justify-content: space-between;
}

.profile-identity {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.profile-card h3 {
  margin: 0 0 0.5rem;
}

.hero {
  margin-bottom: auto;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.label {
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin: 0 0 0.35rem;
}

.field span,
legend {
  font-weight: 600;
}

input[type="text"] {
  border-radius: 14px;
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  background: var(--bg);
  color: var(--text);
}

.interests {
  border: 1px dashed var(--border);
  border-radius: 16px;
  padding: 0.75rem 1rem 1rem;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.5rem 0.75rem;
}

.interests label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
}

@media (max-width: 900px) {
  .interests {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .interests {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.agreement {
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.avatar-upload {
  gap: 0.65rem;
}

.avatar-upload-box {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.avatar-upload-box input {
  display: none;
}

.avatar-preview {
  width: 74px;
  height: 74px;
  border-radius: 20px;
  background: var(--surface-muted);
  background-size: cover;
  background-position: center;
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: border 0.15s ease, transform 0.15s ease;
}

.avatar-preview span {
  pointer-events: none;
}

.avatar-preview.has-image {
  border-style: solid;
}

.avatar-preview.has-image span {
  display: none;
}

.avatar-upload-copy {
  flex: 1;
  font-size: 0.85rem;
  color: var(--muted);
}

.ghost-btn.xs {
  padding: 0.35rem 0.85rem;
  font-size: 0.8rem;
}

.chat-panel {
  background: var(--card);
  border-radius: 24px;
  padding: 1.5rem;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 15px 35px rgba(10, 20, 60, 0.08);
  min-height: 60vh;
  animation: fadeInUp 0.6s ease-out;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status-label {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.1em;
}

#statusText {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.status-copy {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.partner-meta {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.partner-meta-detail {
  margin: 0;
  font-size: 0.8rem;
}

.partner-meta > div {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.online-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #1dd075;
  box-shadow: 0 0 0 0 rgba(29, 208, 117, 0.4);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(29, 208, 117, 0.7);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 10px rgba(29, 208, 117, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(29, 208, 117, 0);
  }
}

.chat-window {
  flex: 0 0 auto;
  height: clamp(320px, 45vh, 520px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1rem;
  overflow-y: auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

.chat-window.searching .placeholder {
  align-items: center;
}

.placeholder {
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.searching-dots {
  display: flex;
  justify-content: center;
  gap: 0.3rem;
}

.searching-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulseDots 1.2s infinite ease-in-out;
}

.searching-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.searching-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes pulseDots {
  0%, 80%, 100% {
    transform: scale(0);
    opacity: 0.3;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.chat-window::-webkit-scrollbar {
  width: 10px;
}

.chat-window::-webkit-scrollbar-track {
  background: var(--scroll-track);
  border-radius: 999px;
}

.chat-window::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.chat-window::-webkit-scrollbar-thumb:hover {
  background: rgba(60, 122, 254, 0.8);
}

body[data-theme="dark"] .chat-window::-webkit-scrollbar-thumb:hover {
  background: rgba(136, 168, 255, 0.7);
}

.message-wrapper {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  width: 100%;
}

.message-wrapper.you {
  flex-direction: row-reverse;
}

.message-wrapper .message-avatar {
  flex-shrink: 0;
  margin-bottom: 0.2rem;
  cursor: pointer;
  position: relative;
}

.message {
  max-width: 80%;
  width: fit-content;
  padding: 0.6rem 0.9rem;
  border-radius: 18px;
  line-height: 1.4;
  font-size: 0.95rem;
  position: relative;
  display: inline-flex;
  flex-direction: column;
  gap: 0.3rem;
  word-break: break-word;
  cursor: default;
}

.message[title]:hover::before {
  content: attr(title);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(30, 30, 35, 0.95);
  color: #fff;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  font-size: 0.8rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  animation: tooltipFadeIn 0.2s ease-out;
}

@keyframes tooltipFadeIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(-8px);
  }
}

body[data-theme="light"] .message[title]:hover::before {
  background: rgba(50, 50, 60, 0.95);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.message-wrapper.stranger .message {
  max-width: calc(80% - 42px);
}

.message.you {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

.message.stranger {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

body[data-theme="dark"] .message.stranger {
  background: rgba(255, 255, 255, 0.04);
}

.message-text {
  margin-bottom: 0.25rem;
}

.message-time {
  display: block;
  font-size: 0.7rem;
  opacity: 0.7;
  text-align: right;
  margin-top: 0.25rem;
}

.message.you .message-time {
  color: rgba(255, 255, 255, 0.9);
}

.message.stranger .message-time {
  color: var(--muted);
}

.avatar-pill {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--surface-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  overflow: hidden;
  background-size: cover;
  background-position: center;
}

.skeleton {
  background: linear-gradient(90deg, var(--surface-muted) 25%, rgba(255,255,255,0.05) 50%, var(--surface-muted) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.avatar-pill.sm {
  width: 32px;
  height: 32px;
  font-size: 1rem;
}

.avatar-pill.xl {
  width: 64px;
  height: 64px;
  font-size: 1.8rem;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.avatar-pill.has-image {
  color: transparent;
}

.typing {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  min-height: 1.2em;
  display: none;
  align-items: center;
  gap: 0.35rem;
}

.typing.visible {
  display: inline-flex;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: typingBlink 1.2s infinite ease-in-out;
}

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

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

@keyframes typingBlink {
  0%, 80%, 100% { opacity: 0.2; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

.chat-input {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

.chat-input button {
  flex-shrink: 0;
  align-self: flex-end;
  height: 44px;
}

.chat-input textarea {
  flex: 1;
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  background: var(--card);
  color: var(--text);
  resize: none;
  min-height: 44px;
  max-height: 150px;
  overflow-y: hidden;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.3;
  outline: none;
  scrollbar-color: var(--accent-soft) var(--card);
}

.chat-input textarea::-webkit-scrollbar {
  width: 8px;
}

.chat-input textarea::-webkit-scrollbar-track {
  background: var(--card);
  border-radius: 10px;
}

.chat-input textarea::-webkit-scrollbar-thumb {
  background: var(--accent-soft);
  border-radius: 10px;
}

.chat-input textarea::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

.chat-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.helper-text {
  font-size: 0.85rem;
  color: var(--muted);
}

.site-footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 768px) {
  body {
    padding: 0 1rem 2rem;
  }

  .site-header {
    padding: 1rem 0 0.5rem;
  }

  .brand h1 {
    font-size: 1.3rem;
  }

  .brand p {
    font-size: 0.75rem;
  }

  .brand-icon {
    width: 40px;
    height: 40px;
  }

  .chat-panel,
  .hero {
    padding: 1.25rem;
  }

  .chat-window {
    height: clamp(280px, 45vh, 420px);
  }

  .message {
    max-width: 90%;
    font-size: 0.9rem;
    padding: 0.55rem 0.8rem;
  }

  .message-wrapper .message {
    max-width: calc(90% - 42px);
  }

  .message-wrapper.you .message {
    max-width: 90%;
  }

  .chat-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .header-actions {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .chat-input {
    gap: 0.5rem;
  }

  .chat-input textarea {
    min-height: 44px;
    font-size: 0.95rem;
  }

  .chat-actions {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .chat-actions button {
    flex: 1 1 calc(50% - 0.25rem);
    min-width: 120px;
  }

  .modal-dialog {
    padding: 1.25rem;
    width: min(420px, 92%);
    margin: 1rem;
  }

  .modal-dialog.rules-dialog {
    width: min(520px, 92%);
  }

  .profile-row {
    flex-direction: column;
    gap: 1rem;
  }

  .start-card {
    padding: 1.25rem;
  }
}

@media (max-width: 480px) {
  body {
    padding: 0 0.75rem 1.5rem;
  }

  .site-header {
    padding: 0.75rem 0 0.5rem;
  }

  .brand h1 {
    font-size: 1.2rem;
  }

  .brand p {
    font-size: 0.7rem;
  }

  .brand-icon {
    width: 36px;
    height: 36px;
  }

  .hero-copy h2 {
    font-size: 1.5rem;
  }

  .hero-copy .lead {
    font-size: 0.9rem;
  }

  .chat-panel,
  .hero {
    padding: 1rem;
  }

  .start-card {
    padding: 1rem;
  }

  .primary-btn,
  .ghost-btn,
  .danger-btn {
    padding: 0.7rem 1.1rem;
    font-size: 0.9rem;
    min-height: 44px;
  }

  .chat-input {
    gap: 0.4rem;
  }

  .chat-input textarea {
    padding: 0.7rem 0.9rem;
    font-size: 0.9rem;
  }

  #sendBtn {
    padding: 0.7rem 1.3rem;
  }

  .chat-window {
    height: clamp(240px, 50vh, 380px);
  }

  .message {
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
  }

  .modal-dialog {
    padding: 1rem;
    width: min(420px, 90%);
    border-radius: 16px;
  }

  .modal-dialog h3 {
    font-size: 1.25rem;
  }

  .modal-close {
    top: 0.75rem;
    right: 0.75rem;
  }

  .chat-actions button {
    font-size: 0.85rem;
    padding: 0.65rem 1rem;
  }

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

  .interests label {
    padding: 0.65rem 0.75rem;
    font-size: 0.9rem;
  }

  .avatar-pill.xl {
    width: 80px;
    height: 80px;
    font-size: 2rem;
  }

  .status-copy {
    width: 100%;
  }

  .partner-meta {
    flex-wrap: wrap;
  }
}

body[data-stage="intro"] .chat-panel {
  display: none;
}

body[data-stage="intro"] #profileCard {
  display: none;
}

body[data-stage="chat"] .start-card {
  display: none;
}

.hero {
  margin-bottom: auto;
}

body[data-stage="chat"] .hero {
  display: none;
}

body[data-stage="chat"] .layout {
  grid-template-columns: minmax(0, 1fr);
  width: min(960px, 100%);
}

body[data-stage="chat"] .chat-panel {
  max-width: 960px;
  width: 100%;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.2rem 0.8rem;
  font-size: 0.85rem;
  border: 1px solid rgba(60, 122, 254, 0.2);
}

.profile-card button {
  align-self: flex-start;
}

.helper-inline {
  font-size: 0.85rem;
  color: var(--muted);
}

body[data-stage="intro"] .helper-text {
  display: none;
}

.edit-profile-inline {
  padding-inline: 0.85rem;
}

body[data-stage="intro"] .edit-profile-inline {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(7, 10, 24, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 10;
}

.modal.visible {
  display: flex;
}

.modal-dialog {
  background: var(--card);
  border-radius: 24px;
  padding: 1.5rem;
  width: min(420px, 100%);
  border: 1px solid var(--border);
  box-shadow: 0 25px 55px rgba(10, 20, 60, 0.35);
  position: relative;
}

.modal-dialog.rules-dialog {
  width: min(520px, 95%);
}

.rules-dialog ol {
  margin-left: 1.2rem;
  padding-left: 0.5rem;
  line-height: 1.6;
}

.rules-dialog li + li {
  margin-top: 0.35rem;
}

.modal-close {
  position: absolute;
  right: 1rem;
  top: 1rem;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal textarea,
.modal select {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  resize: none;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
}
