@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;600;700&family=Noto+Serif+SC:wght@600;700&display=swap");

/* ===== Design Tokens ===== */
:root {
  color-scheme: light;
  /* Primary */
  --c-primary: #2d6cdf;
  --c-primary-hover: #2459c0;
  --c-primary-soft: #e3f0ff;
  --c-primary-glow: rgba(45, 108, 223, 0.25);
  /* Accent */
  --c-accent: #e8a849;
  --c-accent-soft: #fef7ea;
  /* Semantic */
  --c-danger: #e74c3c;
  --c-danger-soft: #fdecea;
  --c-danger-border: #f5c6cb;
  --c-success: #27ae60;
  --c-success-soft: #eafaf1;
  /* Neutral */
  --c-text: #1a1a2e;
  --c-text-2: #4a5568;
  --c-text-3: #6c7a89;
  --c-text-4: #a0aab4;
  --c-bg: #eef0f4;
  --c-surface: #ffffff;
  --c-surface-dim: #f8f9fb;
  --c-surface-hover: #f5f6fa;
  --c-bg-code: #1e1e2e;
  --c-border: #e2e6ea;
  --c-border-light: #eef1f5;
  --c-border-subtle: #f0f2f5;
  /* Tags */
  --c-tag-op-bg: #fff3cd;
  --c-tag-op-text: #b8860b;
  --c-tag-id-bg: #e8ecf1;
  --c-tag-id-text: #6c7a89;
  /* Misc */
  --c-overlay: rgba(26, 26, 46, 0.45);
  --c-avatar-bg: #e8ecf1;
  /* Radius */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 14px;
  --r-2xl: 16px;
  --r-pill: 9999px;
  /* Shadow */
  --sh-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --sh-sm: 0 1px 4px rgba(0, 0, 0, 0.06);
  --sh-md: 0 2px 12px rgba(0, 0, 0, 0.06);
  --sh-lg: 0 4px 24px rgba(0, 0, 0, 0.08);
  --sh-xl: 0 20px 60px rgba(0, 0, 0, 0.12);
  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur: 0.25s;
  --dur-fast: 0.15s;
}

/* ===== Dark Mode ===== */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --c-primary: #5b8def;
    --c-primary-hover: #4a7de0;
    --c-primary-soft: rgba(91, 141, 239, 0.12);
    --c-primary-glow: rgba(91, 141, 239, 0.2);
    --c-accent: #e8a849;
    --c-accent-soft: rgba(232, 168, 73, 0.1);
    --c-danger: #f87171;
    --c-danger-soft: rgba(248, 113, 113, 0.1);
    --c-danger-border: rgba(248, 113, 113, 0.25);
    --c-success: #4ade80;
    --c-success-soft: rgba(74, 222, 128, 0.1);
    --c-text: #e2e4e9;
    --c-text-2: #b0b8c4;
    --c-text-3: #7a8494;
    --c-text-4: #505868;
    --c-bg: #0c0d12;
    --c-surface: #16181f;
    --c-surface-dim: #111318;
    --c-surface-hover: #1e2028;
    --c-bg-code: #0a0b0f;
    --c-border: #262832;
    --c-border-light: #1e2028;
    --c-border-subtle: #1a1c24;
    --c-tag-op-bg: rgba(232, 168, 73, 0.15);
    --c-tag-op-text: #e8a849;
    --c-tag-id-bg: rgba(255, 255, 255, 0.07);
    --c-tag-id-text: #7a8494;
    --c-overlay: rgba(0, 0, 0, 0.6);
    --c-avatar-bg: #262832;
    --sh-xs: 0 1px 2px rgba(0, 0, 0, 0.15);
    --sh-sm: 0 1px 4px rgba(0, 0, 0, 0.2);
    --sh-md: 0 2px 12px rgba(0, 0, 0, 0.25);
    --sh-lg: 0 4px 24px rgba(0, 0, 0, 0.3);
    --sh-xl: 0 20px 60px rgba(0, 0, 0, 0.4);
  }
}

/* ===== Reset ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Noto Sans SC", -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Microsoft YaHei", sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.6;
  transition: background-color 0.4s var(--ease), color 0.4s var(--ease);
}

/* Ambient gradient background */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 15% -10%, var(--c-primary-soft) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 110%, rgba(232, 168, 73, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px;
}

/* ===== Progress Bar ===== */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  z-index: 9999;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s;
}

.progress-bar.active {
  opacity: 1;
}

.progress-bar::after {
  content: "";
  position: absolute;
  top: 0;
  left: -50%;
  width: 50%;
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--c-primary), var(--c-primary), transparent);
  border-radius: var(--r-pill);
  animation: progressSweep 1.4s ease-in-out infinite;
}

@keyframes progressSweep {
  0% { left: -50%; }
  100% { left: 100%; }
}

/* ===== Toast Notifications ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--c-surface);
  color: var(--c-text);
  padding: 12px 20px 12px 16px;
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg);
  font-size: 14px;
  max-width: 340px;
  pointer-events: auto;
  cursor: pointer;
  animation: toastIn 0.35s var(--ease-spring);
  border-left: 3.5px solid var(--c-danger);
}

.toast-success {
  border-left-color: var(--c-success);
}

.toast-info {
  border-left-color: var(--c-primary);
}

.toast-exit {
  animation: toastOut 0.25s var(--ease) forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px) scale(0.96); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateX(20px) scale(0.96); }
}

/* ===== Header ===== */
.header {
  text-align: center;
  padding: 36px 0 28px;
}

.header::before {
  content: "";
  display: block;
  width: 36px;
  height: 3px;
  background: var(--c-primary);
  border-radius: var(--r-pill);
  margin: 0 auto 18px;
}

.header h1 {
  font-family: "Noto Serif SC", "Noto Sans SC", serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--c-text);
  letter-spacing: -0.5px;
}

/* ===== Tabs ===== */
.tabs {
  position: relative;
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  background: var(--c-surface);
  border-radius: var(--r-lg);
  padding: 4px;
  box-shadow: var(--sh-sm);
}

.tab-indicator {
  position: absolute;
  top: 4px;
  bottom: 4px;
  background: var(--c-primary);
  border-radius: var(--r-md);
  transition: left var(--dur) var(--ease), width var(--dur) var(--ease);
  box-shadow: 0 2px 8px var(--c-primary-glow);
  z-index: 0;
  pointer-events: none;
}

.tab {
  flex: 1;
  padding: 10px 8px;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--c-text-3);
  cursor: pointer;
  border-radius: var(--r-md);
  transition: color var(--dur) var(--ease);
  position: relative;
  z-index: 1;
  font-family: inherit;
}

.tab:hover {
  color: var(--c-text);
}

.tab.active {
  color: #fff;
  font-weight: 600;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeSlideIn 0.35s var(--ease);
}

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

/* ===== Card ===== */
.card {
  background: var(--c-surface);
  border-radius: var(--r-xl);
  padding: 24px;
  box-shadow: var(--sh-md);
}

.card h2 {
  font-family: "Noto Serif SC", "Noto Sans SC", serif;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--c-text);
}

.desc {
  color: var(--c-text-3);
  font-size: 13px;
  margin-bottom: 20px;
}

/* ===== Form ===== */
.form-row {
  margin-bottom: 16px;
}

.form-row label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-3);
  margin-bottom: 6px;
}

.form-row select,
.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-md);
  font-size: 14px;
  background: var(--c-surface);
  color: var(--c-text);
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}

.form-row select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236c7a89'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.form-input:focus,
.form-textarea:focus,
.form-row select:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(45, 108, 223, 0.1);
}

.datetime-row {
  display: flex;
  gap: 8px;
}

.datetime-row .form-input {
  width: auto;
  flex: 1;
  min-width: 0;
}

.form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-md);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.7;
  resize: vertical;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--c-surface);
  color: var(--c-text);
}

/* ===== Buttons ===== */
.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--c-primary);
  color: #fff;
  border: none;
  border-radius: var(--r-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur-fast), box-shadow var(--dur-fast), transform var(--dur-fast);
  font-family: inherit;
}

.btn-primary:hover {
  background: var(--c-primary-hover);
  box-shadow: 0 4px 14px var(--c-primary-glow);
}

.btn-primary:active {
  transform: scale(0.975);
  box-shadow: 0 2px 6px var(--c-primary-glow);
}

.btn-primary:disabled {
  background: var(--c-text-4);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.btn-primary.btn-loading {
  background: var(--c-primary);
  opacity: 0.88;
  cursor: wait;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transform: none;
  box-shadow: none;
}

.btn-spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn-secondary {
  padding: 7px 14px;
  background: var(--c-surface);
  color: var(--c-primary);
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-sm);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--dur-fast);
  font-family: inherit;
}

.btn-secondary:hover {
  background: var(--c-primary);
  color: #fff;
  border-color: var(--c-primary);
}

.btn-secondary:active {
  transform: scale(0.96);
}

.btn-secondary:disabled {
  border-color: var(--c-border);
  color: var(--c-text-4);
  cursor: not-allowed;
}

.history-actions .btn-delete {
  color: var(--c-danger);
  border-color: var(--c-danger-border);
}

.history-actions .btn-delete:hover {
  background: var(--c-danger);
  color: #fff;
  border-color: var(--c-danger);
}

.btn-primary.btn-danger-fill {
  background: var(--c-danger);
  width: auto;
}

.btn-primary.btn-danger-fill:hover {
  background: #d63031;
  box-shadow: 0 4px 14px rgba(231, 76, 60, 0.25);
}

/* ===== Result Area ===== */
.result-area {
  margin-top: 20px;
}

.result-area h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--c-text);
}

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

.result-header h3 {
  margin-bottom: 0;
}

.btn-json {
  font-size: 12px;
  padding: 4px 10px;
  background: var(--c-surface);
  color: var(--c-text-3);
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-family: "SF Mono", "Menlo", monospace;
  transition: all var(--dur-fast);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-json:hover {
  color: var(--c-primary);
  border-color: var(--c-primary);
  background: var(--c-primary-soft);
}

/* ===== User Card ===== */
.user-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--c-surface);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--sh-sm);
  transition: box-shadow var(--dur);
}

.user-card:hover {
  box-shadow: var(--sh-md);
}

#user-new-list,
#user-all-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--c-avatar-bg);
  flex-shrink: 0;
  object-fit: cover;
}

.avatar-lg {
  width: 72px;
  height: 72px;
}

.avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--c-primary-soft);
  color: var(--c-primary);
  font-weight: 700;
  font-size: 20px;
  user-select: none;
}

.avatar-fallback.avatar-lg {
  font-size: 28px;
}

.avatar-fallback.comment-avatar {
  font-size: 11px;
  font-weight: 600;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 15px;
  font-weight: 600;
  flex-wrap: wrap;
}

.tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 500;
  line-height: 1.4;
}

.tag-operator {
  background: var(--c-tag-op-bg);
  color: var(--c-tag-op-text);
}

.tag-id {
  background: var(--c-tag-id-bg);
  color: var(--c-tag-id-text);
  font-family: "SF Mono", "Menlo", monospace;
  font-size: 10px;
}

.user-meta {
  font-size: 13px;
  color: var(--c-text-3);
  margin-bottom: 2px;
}

.inline-heading {
  display: inline;
}

/* ===== Post Card ===== */
.post-card {
  background: var(--c-surface);
  border-radius: var(--r-xl);
  padding: 20px;
  box-shadow: var(--sh-md);
}

.post-category-tag {
  display: inline-block;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: var(--r-lg);
  background: var(--c-primary-soft);
  color: var(--c-primary);
  font-weight: 500;
  margin-bottom: 10px;
}

.post-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 12px;
  line-height: 1.4;
  color: var(--c-text);
}

.post-content {
  font-size: 14px;
  line-height: 1.8;
  color: var(--c-text-2);
  white-space: pre-wrap;
  margin-bottom: 16px;
  padding: 14px;
  background: var(--c-surface-dim);
  border-radius: 10px;
  border: 1px solid var(--c-border-light);
}

.post-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.post-stats {
  display: flex;
  gap: 20px;
  font-size: 13px;
  color: var(--c-text-3);
  padding: 10px 0;
  border-top: 1px solid var(--c-border-subtle);
  border-bottom: 1px solid var(--c-border-subtle);
  margin-bottom: 16px;
}

.post-comments h5 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--c-text);
}

/* ===== Comments ===== */
.comment-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--c-surface-hover);
  font-size: 13px;
}

.comment-item:last-child {
  border-bottom: none;
}

.comment-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--c-avatar-bg);
  flex-shrink: 0;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-spring);
  object-fit: cover;
}

.comment-avatar:hover {
  transform: scale(1.15);
}

.comment-avatar-placeholder {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--c-avatar-bg);
  flex-shrink: 0;
}

.comment-nick {
  color: var(--c-primary);
  font-weight: 600;
  white-space: nowrap;
}

.comment-nick.clickable {
  cursor: pointer;
}

.comment-nick.clickable:hover {
  text-decoration: underline;
}

.comment-text {
  color: var(--c-text-2);
}

/* ===== Post History ===== */
.history-card {
  background: var(--c-surface);
  border-radius: var(--r-xl);
  padding: 20px;
  box-shadow: var(--sh-md);
  margin-top: 14px;
  transition: box-shadow var(--dur), transform var(--dur);
}

.history-card:hover {
  box-shadow: var(--sh-lg);
  transform: translateY(-1px);
}

.history-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.history-time {
  font-size: 12px;
  color: var(--c-text-4);
  margin-left: auto;
}

.history-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--c-border-subtle);
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--c-text-4);
  font-size: 14px;
}

/* ===== Popups ===== */
.popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--c-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: overlayIn 0.2s var(--ease);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.popup-overlay[hidden] {
  display: none;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.popup-card {
  background: var(--c-surface);
  border-radius: var(--r-2xl);
  padding: 24px;
  max-width: 400px;
  width: 90%;
  position: relative;
  box-shadow: var(--sh-xl);
  animation: popIn 0.3s var(--ease-spring);
}

.popup-card-wide {
  max-width: 520px;
}

.popup-card h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--c-text);
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.92) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.popup-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 28px;
  height: 28px;
  border: none;
  background: var(--c-surface-dim);
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-text-3);
  transition: all var(--dur-fast);
}

.popup-close:hover {
  background: var(--c-border);
  color: var(--c-text);
}

.popup-user-card {
  box-shadow: none;
  padding: 0;
}

/* ===== Confirm Dialog ===== */
.confirm-card {
  max-width: 360px;
  text-align: center;
}

.confirm-message {
  font-size: 15px;
  color: var(--c-text-2);
  margin-bottom: 20px;
  line-height: 1.6;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.confirm-actions .btn-secondary,
.confirm-actions .btn-primary {
  width: auto;
  padding: 10px 24px;
}

/* ===== JSON Output (legacy, no longer used) ===== */
.json-output {
  display: none;
}

/* ===== JSON Popup ===== */
.popup-card-json {
  max-width: 640px;
  width: 95%;
  padding: 16px;
}

.json-popup-pre {
  background: var(--c-bg-code);
  color: #d4d8e0;
  padding: 16px;
  border-radius: var(--r-md);
  font-size: 12px;
  font-family: "SF Mono", "Menlo", monospace;
  overflow: auto;
  white-space: pre;
  max-height: 70vh;
  margin-top: 4px;
}

.btn-copy-json {
  position: absolute;
  top: 14px;
  right: 50px;
  font-size: 12px;
  padding: 4px 10px;
  background: var(--c-surface-dim);
  color: var(--c-text-3);
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--dur-fast);
}

.btn-copy-json:hover {
  background: var(--c-primary);
  color: #fff;
  border-color: var(--c-primary);
}

/* ===== Loading (legacy, hidden behind progress bar) ===== */
.loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: transparent;
  display: none;
  z-index: 300;
  pointer-events: none;
}

.loading.visible {
  display: flex;
}

.spinner,
.loading p {
  display: none;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .app {
    padding: 12px 12px;
  }

  .header {
    padding: 24px 0 20px;
  }

  .header h1 {
    font-size: 22px;
  }

  .card {
    padding: 18px;
  }

  .toast-container {
    top: 12px;
    right: 12px;
    left: 12px;
  }

  .toast {
    max-width: none;
  }

  .post-stats {
    flex-wrap: wrap;
    gap: 10px;
  }
}
