/**
 * profile.css - 個人中心與設定頁面 (1:1 對齊 Flutter ProfileView / profile_view.dart)
 * 包含：
 * - 頂部 AppBar (圓弧底、VIP 徽章按鈕)
 * - 中央大頭像 + vip_frame.webp 外框 + 暱稱 + 編輯按鈕
 * - 條列式個人資料 (帳號、UID、推薦碼、信箱驗證按鈕、手機驗證按鈕、2FA)
 * - 圓弧分界過渡 (30px 圓角)
 * - 3 欄九宮格矩陣式功能選單 (SliverGrid: metacube, share, referral, discord, language, historys, signout)
 */

.profile {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  background-color: #040B1F;
  padding: 0 0 calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 24px);
  max-width: var(--max-content-width);
  margin: 0 auto;
  position: relative;
}

@media (max-width: 480px) {
  .profile {
    padding: 0 0 calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 24px);
  }
}

/* ==========================================================================
   1. 頂部 AppBar (底邊 20px 圓角)
   ========================================================================== */
.profile__appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background-color: rgba(239, 247, 255, 0.08);
  border-bottom-left-radius: 20px;
  border-bottom-right-radius: 20px;
}

.profile__appbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile__appbar-icon {
  width: 24px;
  height: 24px;
  color: #FFFFFF;
}

.profile__appbar-title {
  font-size: 18px;
  font-weight: 700;
  color: #FFFFFF;
}

/* VIP 徽章按鈕 */
.profile__vip-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: transform var(--transition-fast);
}

.profile__vip-badge-img {
  height: 24px;
  object-fit: contain;
}

.profile__vip-pill {
  padding: 2px 10px;
  background-color: #0080F6;
  border-radius: 16px;
  font-size: 10px;
  font-weight: 700;
  color: #FFFFFF;
}

/* ==========================================================================
   2. 中央大頭像區 (Character Avatar + VIP Frame)
   ========================================================================== */
.profile__avatar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px 12px;
  position: relative;
}

.profile__avatar-wrapper {
  position: relative;
  width: 90px;
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.profile__avatar-circle {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-full);
  overflow: hidden;
  background-color: #101F42;
}

.profile__avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile__vip-frame {
  position: absolute;
  inset: -14px;
  width: calc(100% + 28px);
  height: calc(100% + 28px);
  pointer-events: none;
  object-fit: contain;
}

.profile__edit-btn {
  position: absolute;
  right: calc(50% - 70px);
  top: 24px;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  background-color: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.profile__nickname {
  margin-top: 10px;
  font-size: 18px;
  font-weight: 700;
  color: #FFFFFF;
  text-align: center;
}

/* ==========================================================================
   3. 條列式個人資訊列表 (User Info Rows)
   ========================================================================== */
.profile__info-list {
  display: flex;
  flex-direction: column;
  padding: 8px 0;
}

.profile__info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 4px 28px;
}

.profile__info-label {
  font-size: 14px;
  font-weight: 700;
  color: #FFFFFF;
}

.profile__info-val {
  font-size: 12px;
  color: #FFFFFF;
  display: flex;
  align-items: center;
  gap: 6px;
}

.profile__copy-icon {
  width: 16px;
  height: 16px;
  cursor: pointer;
  opacity: 0.8;
}

.profile__verified-tag {
  color: #3CDFA4;
  font-size: 12px;
  font-weight: 700;
}

.profile__unverified-btn {
  padding: 3px 12px;
  background: var(--gradient-btn-blue);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  color: #FFFFFF;
  cursor: pointer;
}

/* ==========================================================================
   4. 圓弧過渡分界 (Radius 30px)
   ========================================================================== */
.profile__curved-divider {
  height: 24px;
  background-color: #040B1F;
  border-top-left-radius: 30px;
  border-top-right-radius: 30px;
  margin-top: 12px;
}

.profile__content-container {
  background-color: rgba(239, 247, 255, 0.08);
  border-radius: 30px 30px 0 0;
  padding: 16px 20px 32px;
}

/* 橫幅廣告 (ADsBanner) */
.profile__ads-banner {
  width: 100%;
  aspect-ratio: 16 / 5;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  position: relative;
}

.profile__ads-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  animation: profile-ad-cycle 25s infinite;
}

.profile__ads-img:nth-child(2) { animation-delay: 5s; }
.profile__ads-img:nth-child(3) { animation-delay: 10s; }
.profile__ads-img:nth-child(4) { animation-delay: 15s; }
.profile__ads-img:nth-child(5) { animation-delay: 20s; }

@keyframes profile-ad-cycle {
  0%, 19% { opacity: 1; }
  20%, 100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .profile__ads-img { animation: none; }
  .profile__ads-img:first-child { opacity: 1; }
}

/* ==========================================================================
   5. 3 欄九宮格矩陣式功能選單 (SliverGrid: 3 columns, 97/75 比例)
   ========================================================================== */
.profile__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.profile__grid-item {
  aspect-ratio: 97 / 75;
  background-color: rgba(216, 238, 243, 0.08);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  position: relative;
  transition: all var(--transition-fast);
}

.profile__grid-item:active {
  transform: scale(0.96);
  background-color: rgba(255, 255, 255, 0.15);
}

/* 推薦返佣特殊金色高光 */
.profile__grid-item--special {
  background-color: #D27E00;
  box-shadow: 0 0 16px rgba(210, 126, 0, 0.4);
}

.profile__grid-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.profile__grid-label {
  font-size: 11px;
  font-weight: 700;
  color: #FFFFFF;
  text-align: center;
  padding: 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.profile__grid-lock {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 14px;
  height: 14px;
  object-fit: contain;
}

/* ==========================================================================
   6. 條列式功能分組 (buttonList: History, About, App) - 對齊 Flutter ProfileView
   ========================================================================== */
.profile__section-header {
  padding: 16px 12px 8px 4px;
  font-size: 14px;
  font-weight: 700;
  color: var(--color-primary-200); /* #BDDEFF */
}

.profile__button-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.profile__button-item {
  height: 50px;
  background-color: rgba(216, 238, 243, 0.08); /* enable100 withAlpha 25 */
  border-radius: 10px;
  display: flex;
  align-items: center;
  padding: 0 16px 0 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.profile__button-item:active {
  background-color: rgba(255, 255, 255, 0.15);
  transform: scale(0.98);
}

.profile__button-icon-box {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  flex-shrink: 0;
}

.profile__button-icon {
  width: 20px;
  height: 20px;
  object-fit: contain;
  color: var(--color-primary-100);
}

.profile__button-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-primary-100);
  flex: 1;
}

.profile__button-detail {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-primary-100);
  margin-right: 8px;
}

.profile__button-chevron {
  width: 14px;
  height: 14px;
  color: var(--color-primary-100);
  opacity: 0.8;
  flex-shrink: 0;
}

/* States used by the functional V3 profile while backend routes are pending. */
.profile__grid-item--disabled,
.profile__button-item--disabled {
  opacity: 0.48;
  cursor: not-allowed;
  filter: grayscale(0.35);
}

.profile__grid-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  line-height: 1;
}

.profile__button-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
}

.profile__copy-value {
  padding: 0;
  color: var(--color-text-primary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
}

.profile__copy-value--copied {
  color: var(--color-profit-100);
}

.profile__appbar .profile__back {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
}

.profile__avatar-section {
  gap: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.profile__avatar-wrapper {
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.profile__avatar-circle {
  position: relative;
  flex: 0 0 72px;
}

.profile__avatar-wrapper .profile__vip-frame {
  inset: auto;
  top: 50%;
  left: 50%;
  width: 136px;
  height: 136px;
  transform: translate(-50%, -50%);
}

.profile__target-info {
  margin-top: 0;
}

.profile__target-info .profile__section-heading {
  display: none;
}

.profile__info-row > .profile__info-val {
  margin-left: auto;
  justify-content: flex-end;
  text-align: right;
}

.profile__info-row > .profile__status {
  margin-left: 8px;
}

/* Profile dialogs use the shared Store Flavor modal language, not the old card UI. */
.profile__ui-dialog {
  width: min(calc(100% - 32px), 400px);
  max-width: none;
  max-height: min(85dvh, 680px);
  overflow-y: auto;
  color: var(--color-text-primary);
  background: var(--color-surface);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
}

.profile__ui-dialog::backdrop {
  background: rgba(4, 11, 31, 0.8);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.profile__ui-dialog .profile__password-dialog-header {
  align-items: center;
  padding: var(--spacing-xl) var(--spacing-xl) 0;
  margin: 0;
}

.profile__ui-dialog .profile__section-kicker {
  color: var(--color-primary-200);
  letter-spacing: 0.08em;
}

.profile__ui-dialog .modal__title {
  margin-top: var(--spacing-xs);
  font-size: var(--font-size-bigtitle);
  line-height: var(--line-height-tight);
}

.profile__ui-dialog .profile__dialog-close {
  flex: none;
  width: 36px;
  height: 36px;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  background: transparent;
}

.profile__ui-dialog .profile__dialog-close:hover,
.profile__ui-dialog .profile__dialog-close:focus-visible {
  color: var(--color-text-primary);
  background: var(--color-surface-hover);
}

.profile__ui-dialog .profile__password {
  gap: var(--spacing-base);
  padding: var(--spacing-xl);
}

.profile__ui-dialog .profile__edit-row,
.profile__ui-dialog .profile__password-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--spacing-sm);
  min-height: 0;
  border: 0;
}

.profile__ui-dialog .profile__edit-row > span,
.profile__ui-dialog .profile__password-field > span {
  color: var(--color-text-secondary);
  font-size: var(--font-size-subtitle);
  font-weight: var(--font-weight-medium);
}

.profile__ui-dialog .profile__input,
.profile__ui-dialog .profile__password-field input {
  width: 100%;
  min-height: 44px;
  padding: var(--spacing-sm) var(--spacing-base);
  color: var(--color-text-primary);
  background: var(--color-field);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-md);
  font-size: 16px;
}

.profile__ui-dialog .profile__input:focus,
.profile__ui-dialog .profile__password-field input:focus {
  border-color: var(--color-primary-300);
  box-shadow: 0 0 0 2px rgba(0, 128, 246, 0.25);
}

.profile__ui-dialog .profile__edit-row small {
  grid-column: 1;
  margin: 0;
  color: var(--color-text-muted);
}

.profile__ui-dialog .profile__form-message {
  min-height: 0;
  color: var(--color-alert-300);
  font-size: var(--font-size-content);
}

.profile__ui-dialog .profile__form-message--success {
  color: var(--color-profit-100);
}

.profile__ui-dialog .modal__actions {
  justify-content: stretch;
  gap: var(--spacing-sm);
  margin-top: var(--spacing-sm);
}

.profile__ui-dialog .modal__actions .btn {
  flex: 1;
  min-height: 44px;
  font-size: var(--font-size-subtitle);
}

.profile__ui-dialog .modal__actions .btn--primary {
  background: var(--gradient-btn-blue);
  color: var(--color-text-on-primary);
}

.profile__ui-dialog .modal__actions .btn--outline {
  background: var(--gradient-btn-dark);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-card-border);
}
