/* Hachi Maru Pop, loaded from Google Fonts. */
@import url("https://fonts.googleapis.com/css2?family=Hachi+Maru+Pop&display=swap");

/* The hidden attribute must always win over any display rule below. */
[hidden] {
  display: none !important;
}

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

body {
  font-family: "Hachi Maru Pop", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  background: #111111;
  color: #d0d0d0;
  padding: 2rem 1rem;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  text-align: center;
}

.text-content {
  margin-bottom: 2rem;
  line-height: 1.6;
  color: #e0e0e0;
}

.text-content p {
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

.text-content p.title {
  font-size: 1.6rem;
  font-weight: 600;
  color: #fff;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
}

figure {
  background: #050505;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.7);
  transition: transform 0.25s ease, box-shadow 0.25s ease, z-index 0s;
  position: relative;
  z-index: 1;
}

/* Highlight to enlarge: hovering lifts the image above its neighbors and
   scales it up while keeping its original aspect ratio. */
figure:hover {
  transform: scale(1.35);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
  z-index: 10;
}

figure img {
  width: 100%;
  height: auto;          /* preserve original aspect ratio */
  display: block;
}

figcaption {
  padding: 0.7rem 0.9rem;
  font-size: 0.85rem;
  color: #808080;
  word-break: break-word;
  background: #050505;
}

.message-box {
  margin-top: 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  /* Same width as the messages list so edges line up. The left padding
     matches the avatar (44px) + row gap (0.75rem) so the typing box lines
     up with the message bubbles, which sit to the right of their avatars. */
  max-width: 680px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  padding-left: calc(44px + 0.75rem);
}

.name-input {
  width: 100%;
  max-width: 600px;
  background: transparent;
  color: #c4c4c4;
  border: none;
  border-bottom: 1px solid #333;
  border-radius: 0;
  padding: 0.4rem 0.2rem;
  font-family: inherit;
  font-size: 0.9rem;
}

.name-input:focus {
  outline: none;
  border-bottom-color: #666;
}

#message-input {
  width: 100%;
  background: #050505;
  color: #e0e0e0;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 0.75rem;
  font-family: inherit;
  font-size: 1rem;
  /* No manual resize handle; the box auto-grows with the content. */
  resize: none;
  overflow-y: hidden;
  min-height: 2.75rem;
  line-height: 1.4;
}

#message-input:focus {
  outline: none;
  border-color: #666;
}

#message-save {
  background: #2a2a2a;
  color: #e0e0e0;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 0.6rem 1.4rem;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
}

#message-save:hover {
  background: #3a3a3a;
}

#message-save:disabled {
  opacity: 0.5;
  cursor: default;
}

.message-status {
  min-height: 1.2rem;
  font-size: 0.9rem;
  color: #9a9a9a;
}

.messages-list {
  margin-top: 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 680px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  text-align: left;
}

/* A message row: avatar on the left (outside the bubble) + the bubble. */
.message-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

/* Profile photo, aligned to the top, OUTSIDE the text box. */
.message-avatar {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  background: #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.message-avatar--empty {
  color: #777;
  font-size: 1.1rem;
  font-weight: 600;
}

.message-card {
  background: #050505;
  border: 1px solid #2a2a2a;
  border-radius: 10px;
  padding: 1rem 1.1rem;
  position: relative;
  flex: 1;
  min-width: 0;
}

/* Header: bold name on the left, date on the right. */
.message-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.message-card .message-name {
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
}

.message-card .message-time {
  color: #6e6e6e;
  font-size: 0.8rem;
}

.message-card .message-text {
  color: #e0e0e0;
  font-size: 1.05rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-delete {
  position: absolute;
  bottom: 0.6rem;
  right: 0.9rem;
  background: #050505;
  color: #a35252;
  border: 1px solid #5a2a2a;
  border-radius: 6px;
  padding: 0.25rem 0.7rem;
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
  /* Hidden until the message card is hovered. */
  opacity: 0;
  pointer-events: none;
}

.message-card:hover .message-delete {
  opacity: 1;
  pointer-events: auto;
}

.message-delete:hover {
  background: #5a2a2a;
  color: #fff;
}

.message-delete:disabled {
  opacity: 0.5;
  cursor: default;
}

.hint {
  display: none;
  color: #9a9a9a;
  font-size: 0.95rem;
}

code {
  background: #3a3a3a;
  color: #e0e0e0;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}

/* ---- Profile corner (top-right) ---- */
.profile-corner {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
}

.profile-button {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid #333;
  background: #1a1a1a;
  color: #aaa;
  cursor: pointer;
  overflow: hidden;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease;
}

.profile-button:hover {
  border-color: #666;
}

.profile-button-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.profile-button-fallback {
  font-size: 1.2rem;
  font-weight: 600;
}

.profile-menu {
  position: absolute;
  top: 56px;
  right: 0;
  width: 240px;
  background: #0a0a0a;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

.profile-menu[hidden] {
  display: none;
}

.profile-photo-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}

.profile-preview {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  background: #1a1a1a;
  border: 1px solid #333;
  display: none;
}

.profile-photo-hint {
  font-size: 0.8rem;
  color: #888;
}

.profile-menu .name-input {
  text-align: center;
}

.profile-menu button {
  width: 100%;
  background: #2a2a2a;
  color: #e0e0e0;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 0.5rem;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.profile-menu button:hover {
  background: #3a3a3a;
}

/* Secondary "use existing profile" button. */
.profile-switch-btn {
  background: transparent !important;
  border: 1px solid #3a3a3a !important;
  color: #b5bac1 !important;
  font-size: 0.85rem !important;
}

.profile-switch-btn:hover {
  background: #2a2a2a !important;
}

/* Existing-profile picker. */
.profile-picker {
  width: 100%;
  border-top: 1px solid #2a2a2a;
  margin-top: 0.25rem;
  padding-top: 0.5rem;
}

.profile-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: #8a8a8a;
  margin-bottom: 0.4rem;
}

.profile-picker-close {
  width: auto !important;
  background: transparent !important;
  border: none !important;
  color: #8a8a8a !important;
  padding: 0.1rem 0.3rem !important;
  font-size: 0.9rem !important;
}

.profile-picker-close:hover {
  color: #fff !important;
}

.profile-picker-list {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-height: 240px;
  overflow-y: auto;
}

.profile-pick-row {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  background: transparent !important;
  border: none !important;
  border-radius: 8px !important;
  padding: 0.4rem 0.5rem !important;
  text-align: left;
  cursor: pointer;
}

.profile-pick-row:hover {
  background: #2a2a2a !important;
}

.profile-pick-avatar {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  overflow: hidden;
  background: #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #888;
  font-size: 0.85rem;
}

.profile-pick-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-pick-name {
  flex: 1;
  color: #e0e0e0;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-pick-current {
  flex-shrink: 0;
  font-size: 0.7rem;
  color: #6ea8fe;
  border: 1px solid #2b3a5a;
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
}

.profile-picker-empty {
  color: #888;
  font-size: 0.85rem;
  padding: 0.5rem;
  text-align: center;
}

/* ---- Message box controls ---- */
.message-controls {
  display: flex;
  align-items: stretch;
  gap: 0.6rem;
}



/* ---- File attachments ---- */
.attach-button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #2a2a2a;
  color: #e0e0e0;
  border: 1px solid #444;
  border-radius: 8px;
  /* Match the Save button's vertical padding and font so tops/bottoms line up. */
  padding: 0.6rem 1.1rem;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
}

.attach-button:hover {
  background: #3a3a3a;
}

.attach-plus {
  font-size: 1.2rem;
  line-height: 1;
  font-weight: 600;
}

/* Pending attachments (before sending) shown as chips. */
.attach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.attach-list:empty {
  display: none;
}

.attach-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
  color: #d0d0d0;
  max-width: 100%;
}

.attach-chip > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

/* Upload progress bar inside a chip. */
.attach-uploading {
  min-width: 240px;
}

.attach-progress {
  flex: 1;
  height: 6px;
  background: #333;
  border-radius: 3px;
  overflow: hidden;
  min-width: 80px;
}

.attach-progress-fill {
  height: 100%;
  width: 0;
  background: #6ea8fe;
  transition: width 0.1s linear;
}

.attach-percent {
  font-size: 0.75rem;
  color: #9a9a9a;
  min-width: 2.5em;
  text-align: right;
}

.attach-remove {
  background: transparent;
  border: none;
  color: #a35252;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0;
}

.attach-remove:hover {
  color: #ff6b6b;
}

/* Attachments rendered inside a message. */
.attachments {
  margin-top: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.attachment {
  display: inline-block;
  max-width: 100%;
}

.attachment-title {
  font-size: 0.8rem;
  color: #b5bac1;
  margin-bottom: 0.3rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
}

/* On hover, reveal the full name wrapped across lines. */
.attachment-title:hover {
  overflow: visible;
  white-space: normal;
  word-break: break-word;
}

/* The preview is positioned so the hover download button can overlay it. */
.attachment-preview {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

/* Audio: Discord-style voice-note pill. */
.attachment--audio {
  display: block;
  max-width: 420px;
}

.voice-note {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #1e1f22;
  border: 1px solid #2b2d31;
  border-radius: 999px;
  padding: 0.5rem 0.8rem 0.5rem 0.5rem;
}

.vn-play {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: #5865f2; /* Discord blurple */
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.vn-play:hover {
  background: #4752c4;
}

.vn-wave {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 32px;
  cursor: pointer;
  min-width: 80px;
}

.vn-bar {
  flex: 1;
  min-width: 2px;
  max-width: 4px;
  background: #6b6f78;
  border-radius: 2px;
  transition: background 0.1s ease;
}

.vn-bar--played {
  background: #c4c9f5;
}

.vn-time {
  flex-shrink: 0;
  font-size: 0.8rem;
  color: #b5bac1;
  min-width: 2.6em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.vn-mute,
.vn-download {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: #b5bac1;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.2rem;
  text-decoration: none;
}

.vn-mute:hover,
.vn-download:hover {
  color: #fff;
}

.vn-download {
  opacity: 0;
  transition: opacity 0.15s ease;
}

.voice-note:hover .vn-download {
  opacity: 1;
}

.attachment-download {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  font-size: 1rem;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.attachment-preview:hover .attachment-download {
  opacity: 1;
  pointer-events: auto;
}

.attachment-download:hover {
  background: rgba(0, 0, 0, 0.9);
}

.attachment-image {
  max-width: 100%;
  max-height: 380px;
  border-radius: 8px;
  display: block;
}

.attachment-video {
  max-width: 100%;
  max-height: 380px;
  border-radius: 8px;
  background: #000;
}

.attachment-file {
  display: inline-block;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 0.5rem 0.8rem;
  color: #cfe0ff;
  text-decoration: none;
  word-break: break-all;
}

.attachment-file:hover {
  background: #242424;
}

/* Twemoji images are sized to match the surrounding text (names, messages). */
img.emoji {
  height: 1em;
  width: 1em;
  margin: 0 0.05em 0 0.1em;
  vertical-align: -0.1em;
  display: inline-block;
}

/* Highlighted links inside message text. */
.msg-link {
  color: #6ea8fe;
  text-decoration: underline;
  word-break: break-all;
}

.msg-link:hover {
  color: #9ec5ff;
}


/* ---- Mobile layout ---- */
@media (max-width: 600px) {
  body {
    padding: 1rem 0.75rem;
    /* Leave room so the fixed profile button never overlaps content. */
    padding-top: 3.75rem;
  }

  main {
    max-width: 100%;
  }

  /* Tighter vertical rhythm on phones. */
  .text-content {
    margin-bottom: 1rem;
  }

  .text-content p {
    font-size: 1rem;
  }

  .text-content p.title {
    font-size: 1.35rem;
  }

  .message-box {
    margin-top: 1rem;
    /* Full phone width: no avatar-sized left indent on mobile. */
    padding-left: 0;
  }

  .messages-list {
    margin-top: 1.25rem;
  }

  /* Gallery: single, flexible column that always fits the screen. */
  .gallery {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  figure img {
    height: auto;
    max-height: 70vh;
  }

  /* Message list / box fill the width. */
  .messages-list,
  .message-box {
    max-width: 100%;
  }

  /* The avatar + bubble can get cramped; tighten spacing. */
  .message-row {
    gap: 0.5rem;
  }

  .message-avatar {
    width: 38px;
    height: 38px;
  }

  .message-card {
    padding: 0.8rem 0.9rem;
  }

  /* Slightly smaller message text on phones. */
  .message-card .message-name {
    font-size: 0.9rem;
  }

  .message-card .message-time {
    font-size: 0.72rem;
  }

  .message-card .message-text {
    font-size: 0.95rem;
  }

  /* Controls wrap instead of overflowing. */
  .message-controls {
    flex-wrap: wrap;
  }

  /* Profile menu: keep it on-screen (it was a fixed 240px). */
  .profile-corner {
    top: 0.6rem;
    right: 0.6rem;
  }

  .profile-button {
    width: 40px;
    height: 40px;
  }

  .profile-menu {
    width: min(240px, calc(100vw - 1.2rem));
  }

  /* Voice note shrinks to fit narrow screens. */
  .attachment--audio {
    max-width: 100%;
  }

  .vn-time {
    font-size: 0.75rem;
  }
}

/* Belt-and-suspenders: never let long words/URLs force horizontal scroll. */
.message-text,
.attachment-file,
.msg-link {
  overflow-wrap: anywhere;
}
