:root {
  --cc-primary: #4a90e2;
  /* Modern Blue */
  --cc-primary-hover: #357abd;
  --cc-bg: #ffffff;
  --cc-input-bg: #f5f7fa;
  --cc-text: #333333;
  --cc-text-light: #888888;
  --cc-border: #e1e4e8;
  --cc-danger: #ff4d4f;
  --cc-radius: 12px;
  --cc-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  --cc-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --cc-primary: #5c9ce6;
  --cc-bg: #1f1f1f;
  --cc-input-bg: #2a2a2a;
  --cc-text: #e0e0e0;
  --cc-text-light: #a0a0a0;
  --cc-border: #3a3a3a;
  --cc-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

#custom-comment-wrap {
  padding: 24px;
  background: var(--anzhiyu-card-bg, var(--cc-bg));
  border-radius: var(--cc-radius);
  margin-top: 30px;
  font-family: var(--cc-font);
  box-shadow: var(--cc-shadow);
  color: var(--cc-text);
  border: 1px solid var(--cc-border);
}

#comment-total-count {
  font-size: 1.1em;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--cc-text);
  border-left: 4px solid var(--cc-primary);
  padding-left: 12px;
}

/* Form Styles */
.comment-form-wrapper {
  margin-bottom: 40px;
}

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.form-header h3 {
  margin: 0;
  font-size: 1.2em;
}

.form-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.form-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 200px;
  transition: all 0.3s ease;
}

.form-group label {
  font-weight: 500;
  font-size: 0.9em;
  color: var(--cc-text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group textarea {
  padding: 12px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--cc-input-bg);
  color: var(--cc-text);
  font-family: inherit;
  font-size: 0.95em;
  transition: all 0.2s ease;
  width: 100%;
  box-sizing: border-box;
}

.form-group input:focus,
.form-group textarea:focus {
  background: var(--cc-bg);
  border-color: var(--cc-primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

/* New Input Wrapper Styles */
.comment-input-wrapper {
  position: relative;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--cc-input-bg);
  transition: all 0.2s ease;
}

.comment-input-wrapper:focus-within {
  background: var(--cc-bg);
  border-color: var(--cc-primary);
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.comment-input-div {
  min-height: 120px;
  padding: 12px 16px;
  padding-bottom: 40px;
  /* Space for button */
  border: none;
  border-radius: 8px;
  outline: none;
  background: transparent;
  color: var(--cc-text);
  font-family: inherit;
  font-size: 0.95em;
  width: 100%;
  box-sizing: border-box;
  white-space: pre-wrap;
  word-break: break-word;
}

.comment-input-div:empty::before {
  content: attr(placeholder);
  color: var(--cc-text-light);
  pointer-events: none;
  display: block;
}

.input-actions {
  position: absolute;
  bottom: 8px;
  left: 8px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
}

.char-counter {
  font-size: 0.8em;
  color: var(--cc-text-light);
  transition: color 0.3s;
}

.char-counter.limit-exceeded {
  color: var(--cc-danger);
  font-weight: bold;
}

.form-group input:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  background: var(--cc-input-bg);
  color: var(--cc-text-light);
}

.form-group textarea {
  min-height: 120px;
  resize: vertical;
}

/* Avatar Selector */
.avatar-selector {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.avatar-option {
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 50%;
  padding: 3px;
  transition: transform 0.2s, border-color 0.2s;
}

.avatar-option:hover {
  transform: scale(1.1);
}

.avatar-option.selected {
  border-color: var(--cc-primary);
  transform: scale(1.1);
}

.avatar-option img {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: block;
  background: #fff;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  gap: 10px;
  user-select: none;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: relative;
  width: 50px;
  height: 24px;
  background-color: var(--cc-border);
  border-radius: 24px;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: .4s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

input:checked+.slider {
  background-color: var(--cc-primary);
}

input:checked+.slider:before {
  transform: translateX(20px);
}

@media (max-width: 700px) {
  .slider {
    width: 20vw;
  }

  input:checked+.slider:before {
    transform: translateX(calc(5vw - 3px));
  }
}

.toggle-label {
  width: 80px;
  font-size: 0.9em;
  font-weight: 500;
  color: var(--cc-text);
}

@media (max-width: 700px) {
  .toggle-label {
    width: 145px;
  }
}

/* Sticker Styles */
.sticker-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px 10px;
  color: var(--cc-text-light);
  font-size: 1.2em;
  transition: color 0.3s;
  display: flex;
  align-items: center;
  border-radius: 6px;
}

.sticker-btn:hover,
.sticker-btn.active {
  color: var(--cc-primary);
  background: var(--cc-input-bg);
}

.sticker-popover {
  display: none;
  position: absolute;
  background: var(--cc-bg);
  border: 1px solid var(--cc-border);
  border-radius: var(--cc-radius);
  box-shadow: var(--cc-shadow);
  width: 300px;
  max-width: 90vw;
  z-index: 100;
  bottom: 100%;
  left: 0;
  margin-bottom: 8px;
  overflow: hidden;
}

.sticker-popover.show {
  display: flex;
  flex-direction: column;
}

.sticker-tabs {
  display: flex;
  background: var(--cc-input-bg);
  padding: 5px;
  gap: 5px;
  overflow-x: auto;
  border-bottom: 1px solid var(--cc-border);
}

.sticker-tab {
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 4px;
  opacity: 0.6;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sticker-tab:hover,
.sticker-tab.active {
  opacity: 1;
  background: var(--cc-bg);
}

.sticker-tab img {
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.sticker-list {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 10px;
  /* Fixed height for 3 rows to prevent layout shift */
  min-height: 190px;
}

.sticker-item {
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.sticker-item:hover {
  background: var(--cc-input-bg);
}

.sticker-item img {
  width: 100%;
  height: auto;
  object-fit: contain;
  max-width: 50px;
}

/* Rendered Sticker in Comment */
.comment-sticker {
  height: 50px;
  /* Fixed height for consistency */
  width: auto;
  vertical-align: bottom;
  margin: 0 2px;
  display: inline-block;
}

/* Normal Image in Comment */
.comment-image {
  max-width: 100%;
  max-height: 400px;
  display: block;
  margin: 10px 0;
  border-radius: 8px;
  cursor: zoom-in;
  /* Hint that it might be viewable */
}

/* Anonymous Mode Styles */
.comment-form.is-anonymous .email-group {
  height: 0;
  opacity: 0;
  margin: 0;
  overflow: hidden;
  padding: 0;
}

.comment-form.is-anonymous .notify-group {
  opacity: 0.5;
  pointer-events: none;
}

.comment-form.is-anonymous input[name="nickname"] {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='16' height='16' fill='%23999'%3E%3Cpath d='M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-9-2c0-1.66 1.34-3 3-3s3 1.34 3 3v2H9V6zm9 14H6V10h12v10zm-6-3c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

/* Submit Button */
.submit-btn {
  padding: 12px 30px;
  background: var(--cc-primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 1em;
  align-self: flex-start;
  transition: all 0.2s;
  box-shadow: 0 4px 6px rgba(74, 144, 226, 0.2);
}

.submit-btn:hover {
  background: var(--cc-primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(74, 144, 226, 0.3);
}

.submit-btn:active {
  transform: translateY(0);
}

/* Comment List */
.comment-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.comment-item {
  padding-bottom: 20px;
  border-bottom: 1px solid var(--cc-border);
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.comment-main {
  padding-top: 5px;
  display: flex;
  gap: 16px;
}

.comment-avatar img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.comment-body {
  flex: 1;
}

.comment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.comment-nickname {
  font-weight: 700;
  font-size: 1em;
  color: var(--cc-text);
}

.comment-time {
  font-size: 0.85em;
  color: var(--cc-text-light);
}

.comment-content {
  margin-bottom: 12px;
  line-height: 1.7;
  color: var(--cc-text);
  font-size: 0.95em;
  word-break: break-word;
}

.comment-actions {
  display: flex;
  gap: 16px;
}

.action-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--cc-text-light);
  font-size: 0.85em;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
}

.action-btn:hover {
  color: var(--cc-primary);
  background: rgba(74, 144, 226, 0.1);
}

.action-btn.liked {
  color: var(--cc-danger);
}

.action-btn.liked:hover {
  background: rgba(255, 77, 79, 0.1);
}

.replies-list {
  margin-top: 16px;
  border-left: 3px solid var(--cc-border);
  padding-left: 20px;
  list-style: none;
}

/* Status Message */
.status-message {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 0.9em;
  display: none;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.status-message.error {
  background: #fff2f0;
  border: 1px solid #ffccc7;
  color: #ff4d4f;
}

.status-message.success {
  background: #f6ffed;
  border: 1px solid #b7eb8f;
  color: #52c41a;
}

.status-message.loading {
  background: #e6f7ff;
  border: 1px solid #91d5ff;
  color: #1890ff;
}

/* Reply Form */
.reply-form-container {
  margin-top: 20px;
  padding: 20px;
  background: var(--cc-input-bg);
  border-radius: 8px;
  border: 1px solid var(--cc-border);
  animation: fadeIn 0.3s ease;
}

.reply-form h4 {
  margin: 0 0 15px 0;
  font-size: 1em;
  color: var(--cc-text);
}

/* Modern Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10005;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: var(--cc-bg);
  padding: 30px;
  border-radius: 16px;
  width: 90%;
  max-width: 420px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.show .modal-content {
  transform: scale(1);
}

.modal-icon {
  width: 60px;
  height: 60px;
  background: #fff2f0;
  color: #ff4d4f;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 24px;
}

.modal-title {
  font-size: 1.25em;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--cc-text);
}

.modal-desc {
  color: var(--cc-text-light);
  line-height: 1.6;
  margin-bottom: 25px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.confirm-btn {
  background: var(--cc-primary);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.confirm-btn:hover {
  background: var(--cc-primary-hover);
  transform: translateY(-1px);
}

.cancel-btn {
  background: transparent;
  color: var(--cc-text-light);
  border: 1px solid var(--cc-border);
  padding: 10px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.cancel-btn:hover {
  background: var(--cc-input-bg);
  color: var(--cc-text);
}

@media (max-width: 700px) {
  #custom-comment-wrap {
    padding: 16px;
    margin-top: 20px;
    border-radius: 8px;
  }

  .comment-main {
    gap: 12px;
  }

  .comment-avatar img {
    width: 36px;
    height: 36px;
  }

  .comment-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .comment-nickname {
    font-size: 0.95em;
  }

  .comment-time {
    font-size: 0.8em;
  }

  .comment-content {
    margin-bottom: 8px;
    font-size: 0.9em;
  }

  .comment-actions {
    gap: 12px;
    flex-wrap: wrap;
  }

  .action-btn {
    padding: 2px 6px;
    font-size: 0.8em;
  }

  .comment-ua-wrapper {
    gap: 6px !important;
    margin-top: 6px !important;
    font-size: 0.75rem !important;
  }

  .replies-list {
    padding-left: 10px;
    border-left-width: 2px;
    margin-top: 12px;
  }

  .reply-item .comment-main {
    gap: 8px;
  }

  /* 移动端回复表单样式 - 隐藏原有的嵌入式表单样式（如果有残留） */
  .reply-form-container {
    display: none;
    /* 移动端不使用嵌入式 */
  }

  /* 移动端底部弹窗样式 */
  .mobile-reply-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    backdrop-filter: blur(2px);
  }

  .mobile-reply-overlay.show {
    opacity: 1;
    visibility: visible;
  }

  .mobile-reply-container {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--cc-bg);
    border-radius: 16px 16px 0 0;
    padding: 20px;
    /* padding-bottom: max(20px, env(safe-area-inset-bottom)); */
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-sizing: border-box;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
  }

  .mobile-reply-overlay.show .mobile-reply-container {
    transform: translateY(0);
  }

  .mobile-reply-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--cc-border);
  }

  .mobile-reply-title {
    font-weight: 700;
    font-size: 1.1em;
    color: var(--cc-text);
  }

  .mobile-reply-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--cc-text-light);
    padding: 0 10px;
    cursor: pointer;
    line-height: 1;
  }

  .mobile-reply-form .form-row {
    flex-direction: column;
    gap: 12px;
  }

  .mobile-reply-form .comment-input-div {
    min-height: 100px;
    max-height: 200px;
    overflow-y: auto;
  }

  .mobile-reply-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
  }

  .mobile-reply-actions .submit-btn {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .mobile-reply-actions .cancel-btn {
    flex: 0 0 auto;
  }

  /* 移动端表情面板优化 - 变为底部弹出 */
  .mobile-reply-form .sticker-popover {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 16px 16px 0 0;
    border: none;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
    z-index: 10001;
    /* 比 modal 高 */
    top: auto;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    /* 覆盖默认的 display 切换 */
    flex-direction: column;
    visibility: hidden;
    height: 300px;
    /* 固定高度 */
  }

  .mobile-reply-form .sticker-popover.show {
    transform: translateY(0);
    visibility: visible;
    display: flex;
  }

  .mobile-reply-form .sticker-list {
    flex: 1;
    max-height: none;
    /* 让它占满剩余空间 */
  }
}

/* Sticker Pagination */
.sticker-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-top: 1px solid var(--cc-border);
  background: var(--cc-input-bg);
}

.sticker-page-btn {
  background: var(--cc-bg);
  border: 1px solid var(--cc-border);
  color: var(--cc-text);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85em;
  transition: all 0.2s;
}

.sticker-page-btn:hover:not(:disabled) {
  border-color: var(--cc-primary);
  color: var(--cc-primary);
}

.sticker-page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sticker-page-info {
  font-size: 0.85em;
  color: var(--cc-text-light);
}