.profile-wrapper {
  width: 90%;
  max-width: 700px;
  margin: 2em auto;
  font-family: "Comfortaa", sans-serif;
}

/* Castle Display */
.profile-castle-display {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  margin-bottom: 16px;
  min-height: 120px;
}

.profile-castle-container {
  position: relative;
  width: 100px;
  overflow: visible;
}

.profile-castle-container img.profile-castle-img {
  width: 100%;
  display: block;
}

.profile-wall-container {
  width: 25px;
  height: 90px;
  display: flex;
  align-items: flex-end;
}

.profile-wall-texture {
  width: 100%;
  background-size: cover;
  background-repeat: no-repeat;
  border-radius: 2px;
}

.profile-castle-display {
  position: relative;
}

.profile-castle-customize {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 8px;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.2s ease;
  cursor: pointer;
  text-decoration: none;
}

.profile-castle-display.own:hover .profile-castle-customize {
  opacity: 1;
}

/* Header */
.profile-header {
  background: var(--cloud-bg2);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  text-align: center;
}

.profile-identity {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.profile-color-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.3);
}

.profile-name {
  margin: 0;
  color: var(--text);
  font-size: 1.6rem;
}

.profile-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.profile-badge.online {
  background: rgba(40, 167, 69, 0.15);
  color: #28a745;
  border: 1px solid rgba(40, 167, 69, 0.3);
}

.profile-badge.registered {
  background: rgba(6, 167, 125, 0.12);
  color: #06a77d;
  border: 1px solid rgba(6, 167, 125, 0.3);
}

.profile-badge.away {
  background: rgba(212, 168, 23, 0.15);
  color: #d4a817;
  border: 1px solid rgba(212, 168, 23, 0.3);
}

.profile-badge.admin {
  background: rgba(224, 200, 130, 0.15);
  color: #e0c882;
  border: 1px solid rgba(224, 200, 130, 0.3);
}

.profile-rating-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.profile-rating-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.profile-rating {
  color: #06a77d;
  font-size: 1.2rem;
  font-weight: 700;
}

.profile-rank {
  color: #ffc107;
  font-size: 1.1rem;
  font-weight: 600;
}

.profile-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.profile-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  transition: all 0.15s ease;
  text-decoration: none;
}

.profile-action-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.25);
}

.profile-action-btn.invite {
  background: rgba(6, 167, 125, 0.12);
  border-color: rgba(6, 167, 125, 0.3);
  color: #06a77d;
}

.profile-action-btn.invite:hover {
  background: rgba(6, 167, 125, 0.22);
}

.profile-unread-badge {
  background: #dc3545;
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-left: 2px;
}

/* Sections */
.profile-section {
  background: var(--cloud-bg2);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.profile-section-title {
  color: var(--text);
  font-size: 1.1rem;
  margin: 0 0 16px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-section-title i {
  opacity: 0.6;
}

/* Stats Grid */
.profile-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.profile-stat {
  text-align: center;
  padding: 12px 8px;
  background: var(--panel-texture-url) center/cover, var(--panel-bg);
  border: 1.5px solid var(--resource-panel-border);
  border-radius: 12px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.profile-stat-value {
  color: #06a77d;
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.profile-stat-label {
  color: var(--text);
  font-size: 0.75rem;
  opacity: 0.7;
}

/* Campaign */
.profile-campaign-total {
  margin-left: auto;
  font-size: 0.85rem;
  font-weight: 600;
  color: #ffc107;
  display: flex;
  align-items: center;
  gap: 4px;
}

.profile-campaign-levels {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.profile-campaign-level {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--panel-texture-url) center/cover, var(--panel-bg);
  border: 1.5px solid var(--resource-panel-border);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.profile-campaign-level.locked {
  opacity: 0.4;
}

.profile-campaign-level-name {
  color: var(--text);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile-campaign-level-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.profile-campaign-stars {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.profile-campaign-stars .star-achieved {
  color: #ffc107;
}

.profile-campaign-stars .star-missed {
  color: rgba(255, 255, 255, 0.15);
}

/* Card Collection */
.profile-card-collection-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Achievements */
.profile-achievements-summary {
  margin-bottom: 12px;
}

.profile-achievements-bar-wrap {
  width: 100%;
  height: 8px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.profile-achievements-bar {
  height: 100%;
  background: linear-gradient(90deg, #06a77d, #04d9a1);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.profile-achievements-count {
  color: var(--text);
  font-size: 0.85rem;
  opacity: 0.8;
}

.profile-achievements-points {
  color: #ffc107;
}

.profile-achievements-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
}

.profile-view-all-link {
  display: block;
  text-align: center;
  margin-top: 12px;
  color: #06a77d;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s;
}

.profile-view-all-link:hover {
  opacity: 0.8;
  text-decoration: underline;
}

/* Match History */
.profile-matches {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.profile-match {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--panel-texture-url) center/cover, var(--panel-bg);
  border: 1.5px solid var(--resource-panel-border);
  border-left: 4px solid var(--resource-panel-border);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.profile-match.win {
  border-left-color: #4caf50;
}

.profile-match.loss {
  border-left-color: #f44336;
}

.profile-match-result {
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.profile-match-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.profile-match-opponent {
  color: var(--text);
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-match-link {
  color: #06a77d;
  cursor: pointer;
  text-decoration: none;
}

.profile-match-link:hover {
  text-decoration: underline;
}

.profile-match-score {
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  opacity: 0.9;
}

.profile-match-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}

.profile-match-duration,
.profile-match-date {
  color: var(--text);
  font-size: 0.75rem;
  opacity: 0.6;
}

.profile-empty {
  text-align: center;
  color: var(--text);
  opacity: 0.5;
  padding: 20px;
  font-size: 0.95rem;
}

/* Popup Modal */
.profile-popup-modal {
  max-width: 500px;
  position: relative;
  padding: 24px 20px 16px;
}

.profile-popup-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text);
  opacity: 0.5;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  transition: opacity 0.15s;
}

.profile-popup-close:hover {
  opacity: 1;
}

.profile-popup-header {
  text-align: center;
  margin-bottom: 16px;
}

.profile-popup-section {
  margin-bottom: 14px;
}

.profile-popup-section-title {
  color: var(--text);
  font-size: 0.9rem;
  margin: 0 0 10px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.profile-popup-section-title i {
  opacity: 0.6;
}

.profile-popup-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.profile-popup-actions .profile-action-btn {
  justify-content: center;
}

/* Notification section in popup */
.profile-notif-section {
  border-top: 1px solid rgba(128, 128, 128, 0.15);
  padding-top: 14px;
  margin-bottom: 0;
}

.profile-notif-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.profile-notif-label {
  color: var(--text);
  font-size: 0.9rem;
  opacity: 0.85;
}

/* Toggle switch */
.profile-notif-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.profile-notif-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.profile-notif-slider {
  position: absolute;
  inset: 0;
  background: rgba(128, 128, 128, 0.3);
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.profile-notif-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.profile-notif-switch input:checked + .profile-notif-slider {
  background: #06a77d;
}

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

.profile-notif-switch input:disabled + .profile-notif-slider {
  opacity: 0.4;
  cursor: default;
}

/* Test / resubscribe button row */
.profile-notif-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.profile-notif-test-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  transition: background 0.15s ease;
}

.profile-notif-test-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.profile-notif-msg {
  margin: 8px 0 0 0;
  font-size: 0.8rem;
  color: var(--text);
  opacity: 0.7;
  min-height: 1em;
}

.profile-notif-msg.notif-msg-ok {
  color: #06a77d;
  opacity: 1;
}

.profile-notif-msg.notif-msg-err {
  color: #dc3545;
  opacity: 1;
}

/* Mobile */
@media (max-width: 600px) {
  .profile-wrapper {
    width: 95%;
    margin: 1em auto;
  }

  .profile-header {
    padding: 18px 16px;
  }

  .profile-name {
    font-size: 1.3rem;
  }

  .profile-stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .profile-stat-value {
    font-size: 1rem;
  }

  .profile-section {
    padding: 16px;
  }

  .profile-match {
    gap: 8px;
    padding: 8px 10px;
  }

  .profile-match-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .profile-rating-actions {
    flex-direction: column;
    gap: 12px;
  }

  .profile-actions {
    width: 100%;
  }

  .profile-rating-row {
    flex-wrap: wrap;
  }

  .profile-actions {
    grid-template-columns: 1fr;
  }

  .profile-popup-actions {
    grid-template-columns: repeat(2, 1fr);
  }

  .profile-popup-modal {
    padding: 20px 14px 12px;
  }
}
