:root {
  --bg: #161823;
  --bg-surface: #1f2230;
  --bg-elevated: #272a3a;
  --bg-outer: #0b0c12;
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.72);
  --text-muted: rgba(255, 255, 255, 0.48);
  --hairline: rgba(255, 255, 255, 0.08);
  --douyin-red: #fe2c55;
  --douyin-cyan: #25f4ee;
  --douyin-gold: #face15;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-outer);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  line-height: 1.4;
  min-height: 100%;
  overscroll-behavior-y: contain;
}

button, input {
  font: inherit;
  color: inherit;
  border: 0;
  outline: 0;
  background: none;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

#app-shell {
  position: relative;
  width: 100%;
  max-width: 440px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
}

@media (min-width: 520px) {
  #app-shell {
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.55);
  }
}

/* Auth Gate */
#auth-gate {
  position: relative;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
}

.auth-glow {
  position: absolute;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.22;
  pointer-events: none;
}

.auth-glow-pink {
  background: var(--douyin-red);
  top: 12%;
  right: -40px;
}

.auth-glow-cyan {
  background: var(--douyin-cyan);
  bottom: 14%;
  left: -40px;
}

.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 28px 22px 24px;
  border-radius: 18px;
  background: rgba(31, 34, 48, 0.86);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.douyin-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: #12131c;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.auth-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.auth-sub {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  background: #12131c;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  transition: border-color 0.18s ease;
}

.input-wrap:focus-within {
  border-color: var(--douyin-red);
}

#password-input {
  width: 100%;
  padding: 13px 44px 13px 14px;
  font-size: 15px;
}

.pw-eye {
  position: absolute;
  right: 8px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.auth-error {
  margin: 10px 0 0;
  font-size: 13px;
  color: #ff6b84;
}

.auth-submit {
  width: 100%;
  margin-top: 16px;
  padding: 13px;
  border-radius: 10px;
  background: var(--douyin-red);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.auth-submit:active {
  transform: scale(0.985);
}

.auth-submit:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* Profile Topbar */
.profile-topbar {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 440px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: transparent;
  transition: background-color 0.2s ease, border-color 0.2s ease;
  border-bottom: 1px solid transparent;
}

.profile-topbar.scrolled {
  background: rgba(22, 24, 35, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom-color: var(--hairline);
}

.topbar-title {
  font-size: 16px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.profile-topbar.scrolled .topbar-title {
  opacity: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-pill {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.profile-topbar.scrolled .icon-pill {
  background: rgba(255, 255, 255, 0.08);
}

/* Cover Banner */
.cover-wrap {
  position: relative;
  height: calc(172px + var(--safe-top));
  background: linear-gradient(135deg, #2d253d 0%, #1d2236 55%, #161823 100%);
  overflow: hidden;
}

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

.cover-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(22, 24, 35, 0.24) 0%,
    rgba(22, 24, 35, 0.12) 45%,
    rgba(22, 24, 35, 0.88) 88%,
    var(--bg) 100%
  );
}

/* Profile Header */
.profile-header {
  position: relative;
  padding: 0 16px 14px;
  margin-top: -34px;
}

.avatar-row {
  display: flex;
  align-items: flex-end;
  gap: 14px;
}

.avatar-ring {
  width: 90px;
  height: 90px;
  padding: 0;
  border-radius: 50%;
  border: 3px solid var(--bg);
  background: var(--bg-surface);
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

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

.identity-col {
  min-width: 0;
  padding-bottom: 6px;
}

.nickname {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.douyin-id-row {
  margin-top: 4px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.stats-row {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 15px;
}

.stat-item {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.stat-num {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
}

.profile-bio {
  margin: 11px 0 0;
  font-size: 14px;
  color: var(--text-secondary);
  white-space: pre-line;
}

.tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.meta-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  font-size: 11.5px;
}

.cta-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.cta-btn {
  flex: 1;
  height: 38px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease;
}

.cta-btn:active {
  opacity: 0.85;
}

.cta-follow {
  background: var(--douyin-red);
  color: #fff;
}

.cta-follow.followed {
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.cta-msg {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* Sticky Tabs */
.tabs-bar {
  position: sticky;
  top: calc(54px + var(--safe-top));
  z-index: 25;
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
}

.tab-btn {
  position: relative;
  flex: 1;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-muted);
}

.tab-btn.active {
  color: var(--text-primary);
  font-weight: 600;
}

.tab-btn.active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 34px;
  height: 2.5px;
  border-radius: 2px;
  background: var(--douyin-gold);
}

.tab-count {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.lock-ico {
  opacity: 0.72;
}

/* Search & Sort Drawer */
.search-drawer {
  padding: 10px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--hairline);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  height: 36px;
  border-radius: 8px;
  background: #12131c;
  color: var(--text-muted);
}

#search-input {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  color: var(--text-primary);
}

.search-clear {
  font-size: 13px;
  color: var(--text-muted);
  padding: 4px;
}

.sort-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.sort-chip {
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
}

.sort-chip.active {
  background: rgba(254, 44, 85, 0.18);
  color: #ff6987;
  font-weight: 600;
}

.filter-status {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Works 3-Column Grid */
.works-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5px;
  padding-bottom: calc(24px + var(--safe-bottom));
}

.work-tile {
  position: relative;
  aspect-ratio: 3 / 4;
  background: var(--bg-surface);
  overflow: hidden;
  user-select: none;
}

.work-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.work-thumb.loaded {
  opacity: 1;
}

.tile-top-badge {
  position: absolute;
  top: 5px;
  left: 5px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--douyin-gold);
  color: #161823;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.35;
}

.tile-scrim {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 40%;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.62), transparent);
  pointer-events: none;
}

.tile-likes {
  position: absolute;
  left: 6px;
  bottom: 5px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.empty-state, .private-empty {
  padding: 72px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.private-empty svg {
  opacity: 0.45;
  margin-bottom: 10px;
}

/* Full-Screen Video Player */
.player-view {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 440px;
  height: 100dvh;
  z-index: 60;
  background: #000;
  overflow: hidden;
  user-select: none;
}

.player-stage {
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: none;
  overflow: hidden;
}

.player-slide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  will-change: transform;
}

.player-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
}

.player-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 12px 12px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), transparent);
  pointer-events: none;
}

.player-topbar button {
  pointer-events: auto;
}

.player-top-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-counter {
  padding: 4px 9px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.42);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.84);
  font-variant-numeric: tabular-nums;
}

.player-icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.mute-pill.is-muted {
  color: var(--douyin-red);
}

.player-pause-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 8;
  pointer-events: none;
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.45));
}

.unmute-hint {
  position: absolute;
  top: calc(62px + var(--safe-top));
  right: 14px;
  z-index: 12;
  padding: 6px 11px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.68);
  color: #fff;
  font-size: 12px;
  pointer-events: none;
}

.player-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 44px 14px calc(10px + var(--safe-bottom));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.78) 0%, rgba(0, 0, 0, 0.36) 65%, transparent 100%);
  pointer-events: none;
}

.player-meta {
  padding-right: 18px;
  margin-bottom: 10px;
  pointer-events: auto;
}

.player-author-date {
  font-size: 15px;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.player-author-date .date-part {
  font-weight: 400;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.76);
}

.player-title {
  margin: 5px 0 0;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.94);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.65);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.player-title.expanded {
  display: block;
  -webkit-line-clamp: unset;
}

.scrub-time-pill {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
  font-variant-numeric: tabular-nums;
}

.player-scrubber {
  pointer-events: auto;
  padding: 10px 0 4px;
  cursor: pointer;
  touch-action: none;
}

.scrubber-track {
  position: relative;
  width: 100%;
  height: 2.5px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.24);
  transition: height 0.12s ease;
}

.player-scrubber.scrubbing .scrubber-track {
  height: 5px;
}

.scrubber-buffered {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.28);
}

.scrubber-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.92);
}

.scrubber-knob {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  transform: translate(-50%, -50%) scale(0);
  transition: transform 0.12s ease;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.6);
}

.player-scrubber.scrubbing .scrubber-knob,
.player-scrubber:hover .scrubber-knob {
  transform: translate(-50%, -50%) scale(1.3);
}

/* Avatar Modal & Sheet */
.modal, .sheet {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop, .sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.84);
}

.avatar-modal-img {
  position: relative;
  z-index: 1;
  width: min(82vw, 340px);
  height: min(82vw, 340px);
  object-fit: cover;
  border-radius: 50%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.65);
}

.sheet {
  align-items: flex-end;
}

.sheet-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  background: var(--bg-surface);
  border-radius: 16px 16px 0 0;
  padding: 8px 12px calc(12px + var(--safe-bottom));
}

.sheet-item {
  width: 100%;
  padding: 15px;
  text-align: center;
  font-size: 16px;
  border-bottom: 1px solid var(--hairline);
}

.sheet-item.danger {
  color: #ff5b77;
}

.sheet-item.cancel {
  border-bottom: 0;
  margin-top: 6px;
  color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 110;
  padding: 9px 16px;
  border-radius: 20px;
  background: rgba(18, 19, 28, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
}
