:root {
  --bg: #0f1117;
  --bg-radial: radial-gradient(circle at 50% 0%, #111524 0%, #0f1117 70%);
  --card: rgba(17, 19, 26, 0.65);
  --card-hover: rgba(22, 24, 33, 0.95);
  --text: #ffffff;
  --muted: #8b929e;
  --accent: #4effff;
  --accent-glow: rgba(78, 255, 255, 0.15);
  --danger: #ff5c7a;
  --border: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(255, 255, 255, 0.15);
  --shadow: 0 24px 50px rgba(0, 0, 0, 0.6);
  --input: rgba(12, 13, 18, 0.8);
  --success: #4ade80;
}

body:not(.admin-bar) .tg-wrapper {
  margin-top: 30px;
}

.tg-wrapper {
  position: relative;
  width: 100%;
  min-height: calc(100vh - 100px);
  background: var(--bg);
  /* background-image: var(--bg-radial); */
  color: var(--text);
  font-family: 'Poppins', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body {
  background-color: var(--bg) !important;
}

.tg-wrapper * {
  box-sizing: border-box;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

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

@keyframes pageTransition {
  from {
    opacity: 0;
    transform: scale(0.98) translateY(30px);
  }

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

.animate-up {
  animation: fadeUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.page-enter {
  animation: pageTransition 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.delay-1 {
  animation-delay: 0.1s;
}

.delay-2 {
  animation-delay: 0.2s;
}

.delay-3 {
  animation-delay: 0.3s;
}

.rimuru-app {
  position: relative;
  z-index: 1;
  max-width: 1440px;
  margin: 0 auto;
  padding: 40px 40px 80px;
}

.btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 24px;
  border-radius: 12px;
  transition: all 0.3s;
  backdrop-filter: blur(10px);
}

.btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.btn-primary {
  background: var(--accent-glow);
  border-color: rgba(78, 255, 255, 0.3);
  color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent);
  color: #000;
  box-shadow: 0 0 20px var(--accent-glow);
  border-color: var(--accent);
}

.btn-full {
  width: 100%;
}

.btn:disabled,
.btn-disabled-visual {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.form-control {
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 20px;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.3s;
  outline: none;
  width: 100%;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.form-control:hover {
  border-color: var(--border-highlight);
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
  background: #000;
}

.directory-header {
  text-align: center;
  margin-bottom: 48px;
}

.directory-header h1 {
  font-size: 3rem;
  font-weight: 800;
  margin: 0 0 12px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 2px;
  background: linear-gradient(to right, #fff, #b4e0e0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.directory-header p {
  font-size: 1.1rem;
  color: var(--muted);
  margin: 0;
  max-width: 600px;
  margin: 0 auto;
}

.directory-controls {
  display: flex;
  gap: 16px;
  margin-bottom: 40px;
  flex-wrap: wrap;
  background: var(--card);
  padding: 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.search-box {
  flex-grow: 1;
  position: relative;
  min-width: 250px;
}

.search-box svg {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

.search-box input {
  padding-left: 48px;
}

select.form-control {
  cursor: pointer;
  appearance: none;
  padding-right: 40px;
  width: 220px;
  background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%238b929e%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
  background-repeat: no-repeat;
  background-position: right 16px top 50%;
  background-size: 10px auto;
}

select.form-control option {
  background: #11131a;
}

.guild-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 28px;
}

.guild-card {
  background: #13151c;
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  display: flex;
  flex-direction: column;
  position: relative;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
}

.guild-card:hover {
  border-color: var(--border-highlight);
  transform: translateY(-6px);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--accent-glow);
}

.guild-banner {
  height: 150px;
  background-size: cover;
  background-position: center;
  position: relative;
}

.guild-banner::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent, rgba(19, 21, 28, 0.9))
}

.guild-emblem-wrapper-sm {
  position: absolute;
  top: 100px;
  left: 24px;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  border: 2px solid var(--border-highlight);
  overflow: hidden;
  background: var(--bg);
  z-index: 2;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
  transition: transform 0.3s;
}

.guild-card:hover .guild-emblem-wrapper-sm {
  border-color: var(--accent);
  transform: scale(1.05);
}

.guild-emblem-sm {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.guild-content {
  padding: 44px 24px 24px;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.guild-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 6px;
}

.guild-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
  margin: 0;
  line-height: 1.2;
  word-break: break-word;
}

.guild-motto {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 20px;
  font-style: italic;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  /* min-height: 2.7rem; */
}

.guild-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: auto;
  padding: 16px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  font-weight: 600;
}

.stat-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-value svg {
  color: var(--accent);
  opacity: 0.8;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 56px;
}

.page-btn {
  background: var(--input);
  border: 1px solid var(--border);
  color: var(--text);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  font-family: inherit;
  font-size: 1rem;
}

.page-btn:hover:not(:disabled):not(.active) {
  border-color: var(--border-highlight);
  background: rgba(255, 255, 255, 0.05);
}

.page-btn.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  box-shadow: 0 0 15px var(--accent-glow);
}

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

.page-dots {
  color: var(--muted);
  font-weight: 600;
  padding: 0 8px;
}

#detailView {
  display: none;
  position: relative;
  min-height: 100vh;
  width: 100%;
}

.page-bg-banner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 55vh;
  min-height: 450px;
  background-size: cover;
  background-position: center;
  z-index: 0;
  opacity: 0.35;
  mask-image: linear-gradient(180deg, black 0%, transparent 100%);
  -webkit-mask-image: linear-gradient(180deg, black 0%, transparent 100%);
  transition: background-image 0.5s ease;
}

.manage-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 40px;
  flex-wrap: wrap;
  gap: 24px;
  /* padding-bottom: 24px; */
}

.guild-profile-header {
  display: flex;
  align-items: flex-end;
  gap: 32px;
  position: relative;
}

.emblem-wrapper {
  position: relative;
  width: 150px;
  height: 150px;
  border-radius: 28px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), inset 0 0 0 4px var(--card);
  border: 2px solid var(--border-highlight);
  background: var(--card);
  overflow: hidden;
}

.guild-profile-emblem {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.level-badge-cyan {
  background: rgba(78, 255, 255, 0.1);
  color: var(--accent);
  border: 1px solid rgba(78, 255, 255, 0.3);
  font-size: 0.85rem;
  font-weight: 800;
  padding: 6px 14px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  letter-spacing: 1.5px;
  box-shadow: 0 0 15px var(--accent-glow);
}

.guild-profile-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.guild-profile-info h1 {
  font-size: 3.2rem;
  font-weight: 800;
  margin: 0 0 8px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
  background: linear-gradient(to right, #fff, #b4e0e0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.guild-profile-info p {
  font-size: 1.05rem;
  color: var(--accent);
  margin: 0;
  font-weight: 600;
  font-style: italic;
  letter-spacing: 1px;
}

.unified-profile-container {
  background: var(--card);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 48px;
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 64px;
  box-shadow: var(--shadow);
}

.profile-section-title {
  font-size: 1.3rem;
  color: #fff;
  margin: 0 0 24px 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile-section-title svg {
  color: var(--accent);
}

.desc-text {
  color: var(--muted);
  line-height: 1.8;
  font-size: 1rem;
  margin: 0;
  white-space: pre-line;
}

.stats-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 40px;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
}

.stat-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.stat-item .stat-label {
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

.stat-item .stat-value {
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-item .stat-value svg {
  color: var(--accent);
  opacity: 0.8;
  width: 16px;
  height: 16px;
}

.join-btn {
  padding: 18px;
  font-size: 1.15rem;
  border-radius: 16px;
  letter-spacing: 1px;
}

.directory-roster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

.roster-member-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  padding: 14px 16px;
  border-radius: 16px;
  transition: all 0.3s;
}

.roster-member-card:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-highlight);
  transform: translateX(4px);
}

.member-avatar {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--input);
  display: flex;
  align-items: center;
  justify-content: center;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid transparent;
}

.avatar-glow {
  border-color: var(--accent);
  background: var(--accent-glow);
  box-shadow: 0 0 15px var(--accent-glow);
}

.member-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.member-name {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.5px;
  color: #fff;
}

.role-badge-pill {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
  width: fit-content;
  border: 1px solid transparent;
}

.role-leader {
  background: rgba(255, 215, 0, 0.1);
  color: #ffd700;
  border-color: rgba(255, 215, 0, 0.3);
}

.role-officer {
  background: rgba(187, 134, 252, 0.1);
  color: #bb86fc;
  border-color: rgba(187, 134, 252, 0.3);
}

.role-member {
  background: rgba(139, 146, 158, 0.1);
  color: var(--muted);
  border-color: rgba(139, 146, 158, 0.3);
}

.role-initiate {
  background: rgba(74, 222, 128, 0.1);
  color: var(--success);
  border-color: rgba(74, 222, 128, 0.3);
}

/* --- Modal System --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  padding: 20px;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal-content {
  background: var(--bg);
  background-image: var(--bg-radial);
  border: 1px solid var(--border-highlight);
  border-radius: 20px;
  padding: 32px;
  width: 100%;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
  transform: scale(0.95) translateY(10px);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: flex;
  flex-direction: column;
}

.modal-overlay.active .modal-content {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
  margin-bottom: 16px;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.btn-icon {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  border-color: var(--border-highlight);
}

#toast-container {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.toast {
  background: var(--card);
  border: 1px solid var(--border-highlight);
  padding: 16px 24px;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  gap: 14px;
  transform: translateX(120%);
  opacity: 0;
  backdrop-filter: blur(10px);
  transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast svg {
  color: var(--success);
  flex-shrink: 0;
}

@media (max-width: 1024px) {
  .unified-profile-container {
    grid-template-columns: 1fr;
    gap: 40px;
  }
}

@media (max-width: 768px) {
  body:not(.admin-bar) .tg-wrapper {
    margin-top: 0; 
}
  .rimuru-app {
    padding: 40px 20px 60px;
  }
  #detailView { padding-top: 50px; }
  .directory-header h1 {
    font-size: 2.2rem;
  }

  .search-box {
    min-width: 100%;
  }

  select.form-control {
    width: 100%;
  }

  .guild-grid {
    grid-template-columns: 1fr;
  }

  .manage-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .guild-profile-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .emblem-wrapper {
    width: 100px;
    height: 100px;
    border-radius: 20px;
  }

  .guild-profile-info h1 {
    font-size: 2.2rem;
  }

  .unified-profile-container {
    padding: 8px;
    background: transparent;
    border: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: none;
  }

  .btn {
    width: 100%;
  }

  #toast-container {
    bottom: 20px;
    right: 20px;
    left: 20px;
  }

  .modal-actions {
    flex-direction: column;
  }
}

/* Guild Ledger Expedition Badges */
.exp-badge {
  font-size: 0.75rem;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--input);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* S-Tier: Gold */
.exp-s { 
  color: #ffd700; 
  border-color: rgba(255, 215, 0, 0.4); 
  background: rgba(255, 215, 0, 0.08); 
}

/* A-Tier: Purple */
.exp-a { 
  color: #bb86fc; 
  border-color: rgba(187, 134, 252, 0.4); 
  background: rgba(187, 134, 252, 0.08); 
}

/* C-Tier: Green */
.exp-c { 
  color: var(--success); 
  border-color: rgba(74, 222, 128, 0.4); 
  background: rgba(74, 222, 128, 0.08); 
}