/* ── Comment Widget ─────────────────────────────────────────────── */

/* presence-stack just stacks c_widget above discord-presence */
#presence-stack {
  position: fixed;
  bottom: 20px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
  align-items: flex-start;
}

#presence-stack .discord-presence {
  position: relative !important;
  bottom: auto !important;
  left: auto !important;
  top: auto !important;
  transform: none !important;
  width: 300px;
}

/* ── Widget shell — matches discord-presence exactly ── */
#c_widget {
  width: 300px;
  background: linear-gradient(145deg, rgba(15, 20, 30, 0.85), rgba(10, 15, 25, 0.75));
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow:
    0 10px 40px rgba(0, 0, 0, 0.4),
    0 2px 8px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.9);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  overflow: visible;
  opacity: 0;
  transform: translateY(15px);
  animation: cw-fadein 0.6s cubic-bezier(0.23, 1, 0.32, 1) 0.2s forwards;
  position: relative;
}

#c_widget::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent,
    rgba(255,255,255,0.2) 20%,
    rgba(255,255,255,0.2) 80%,
    transparent);
  opacity: 0.3;
  pointer-events: none;
}

@keyframes cw-fadein {
  to { opacity: 1; transform: translateY(0); }
}

/* ── Header ── */
.cw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.cw-header-left {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.4);
}
.cw-header-icon { width: 11px; height: 11px; opacity: 0.5; }

/* Settings gear — top right of header */
.cw-settings-wrap { position: relative; }

.cw-settings-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.cw-settings-btn svg { width: 12px; height: 12px; }
.cw-settings-btn:hover,
.cw-settings-btn.cw-settings-active {
  color: rgba(255,255,255,0.7);
  border-color: rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
}

/* Settings popover */
.cw-settings-popover {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: linear-gradient(145deg, rgba(15,20,30,0.97), rgba(10,15,25,0.95));
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 10px 12px;
  width: 196px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.08);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.18s, transform 0.18s;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cw-settings-popover.cw-popover-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.cw-settings-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cw-settings-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.25);
  flex-shrink: 0;
  width: 36px;
}

/* Colour grid */
.cw-color-grid { display: flex; flex-wrap: wrap; gap: 4px; }
.cw-color-dot {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1.5px solid transparent;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: transform 0.1s;
}
.cw-color-dot:hover { transform: scale(1.2); }
.cw-color-dot.cw-dot-selected { border-color: rgba(255,255,255,0.85); }

/* Anon button */
.cw-anon-btn {
  flex: 1;
  height: 24px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: rgba(255,255,255,0.5);
  font: inherit;
  font-size: 0.7rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.cw-anon-btn:hover {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.85);
}

/* ── Messages ── */
.cw-messages {
  max-height: 180px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-bottom: 10px;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}
.cw-messages::-webkit-scrollbar { width: 3px; }
.cw-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.cw-loading-row { display: flex; justify-content: center; padding: 14px 0; }
.cw-empty {
  text-align: center;
  padding: 14px 0;
  color: rgba(255,255,255,0.25);
  font-size: 0.78rem;
  font-style: italic;
}

/* ── Individual message ── */
.cw-message { display: flex; flex-direction: column; gap: 1px; }

.cw-meta {
  display: flex;
  align-items: baseline;
  gap: 5px;
}
.cw-author {
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}
.cw-flag { font-size: 0.72rem; line-height: 1; }
.cw-date {
  font-size: 0.6rem;
  color: rgba(255,255,255,0.25);
  margin-left: auto;
  flex-shrink: 0;
  cursor: default;
}
.cw-text {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.65);
  line-height: 1.5;
  word-break: break-word;
}

/* ── Reply — static rainbow + tick ── */
.cw-reply {
  margin-top: 5px;
  padding: 5px 8px;
  background: rgba(255,255,255,0.04);
  border-left: 2px solid rgba(74,222,128,0.3);
  border-radius: 0 6px 6px 0;
}
.cw-reply-byline {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-bottom: 3px;
}
.cw-reply-name {
  font-size: 0.72rem;
  font-weight: 700;
  background: linear-gradient(90deg, #f87171, #fbbf24, #4ade80, #38bdf8, #e879f9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.cw-reply-tick {
  font-size: 0.6rem;
  color: #4ade80;
  font-weight: 700;
  -webkit-text-fill-color: #4ade80;
}
.cw-reply-text {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.55);
  line-height: 1.45;
  word-break: break-word;
}

/* ── Input: name row ── */
.cw-row { display: flex; gap: 5px; align-items: center; }
.cw-row + .cw-row { margin-top: 5px; }

#cw-name {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 5px 9px;
  color: rgba(255,255,255,0.9);
  font: inherit;
  font-size: 0.78rem;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}
#cw-name::placeholder { color: rgba(255,255,255,0.22); }
#cw-name:focus {
  border-color: rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
}

/* ── Input: compose row ── */
.cw-row-compose { align-items: flex-end; }

#cw-text {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 6px 9px;
  color: rgba(255,255,255,0.9);
  font: inherit;
  font-size: 0.78rem;
  resize: none;
  outline: none;
  min-height: 30px;
  max-height: 90px;
  line-height: 1.45;
  box-sizing: border-box;
  transition: border-color 0.2s, background 0.2s;
}
#cw-text::placeholder { color: rgba(255,255,255,0.2); }
#cw-text:focus {
  border-color: rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
}

/* Send button */
.cw-send-btn {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.15s;
}
.cw-send-btn svg { width: 11px; height: 11px; }
.cw-send-btn:hover {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.22);
  color: rgba(255,255,255,0.95);
  transform: translateY(-1px);
}
.cw-send-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

/* ── Spinner ── */
.cw-spinner {
  width: 14px; height: 14px;
  border: 1.5px solid rgba(255,255,255,0.12);
  border-top-color: rgba(255,255,255,0.5);
  border-radius: 50%;
  animation: cw-spin 0.75s linear infinite;
}
.cw-spinner-sm { width: 10px; height: 10px; }
@keyframes cw-spin { to { transform: rotate(360deg); } }

/* ── Feedback ── */
.cw-feedback {
  display: none;
  font-size: 0.68rem;
  padding: 4px 8px;
  border-radius: 6px;
  text-align: center;
  font-weight: 500;
  margin-top: 4px;
}
.cw-ok  { color: #4ade80; background: rgba(74,222,128,0.08); border: 1px solid rgba(74,222,128,0.15); }
.cw-err { color: #f87171; background: rgba(248,113,113,0.08); border: 1px solid rgba(248,113,113,0.15); }

/* ── Responsive — mirrors discord-presence breakpoints ── */
@media (max-width: 768px) {
  #presence-stack {
    bottom: auto;
    left: 50%;
    top: max(20px, env(safe-area-inset-top, 20px));
    transform: translateX(-50%);
    width: min(340px, calc(100vw - 30px));
    align-items: stretch;
  }
  #presence-stack .discord-presence,
  #c_widget { width: 100% !important; }
}
@media (max-width: 480px) {
  #presence-stack { width: calc(100vw - 24px); }
}
@media (prefers-reduced-motion: reduce) {
  #c_widget, .cw-spinner { animation-duration: 0.01ms !important; }
}