:root {
  --bg: #14171d;
  --panel: #1b1f28;
  --panel-raised: #222733;
  --line: #2c3140;
  --text: #e7e5dd;
  --muted: #8b93a3;
  --gold: #d3a543;
  --gold-soft: rgba(211, 165, 67, 0.16);
  --active: #5fb682;
  --inactive: #c4583f;
  --font-display: 'Spectral', serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 15% 0%, rgba(211,165,67,0.07), transparent 40%),
    radial-gradient(circle at 85% 10%, rgba(95,182,130,0.05), transparent 35%);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
}

#app { max-width: 1080px; margin: 0 auto; padding: 28px 24px 60px; }

/* Header */
.hall-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.hall-brand { display: flex; align-items: center; gap: 14px; }
.sigil svg { width: 38px; height: 38px; }
.sigil polygon { fill: var(--gold-soft); stroke: var(--gold); stroke-width: 1.5; }
.hall-header h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.7rem;
  margin: 0;
  letter-spacing: 0.01em;
}
.hall-sub { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }
#clanPicker {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: var(--font-body);
  font-size: 0.9rem;
}

/* Stat strip */
.home-stat-strip {
  grid-template-columns: repeat(2, 1fr) !important;
  width: 100%;
  max-width: 360px;
  margin: 0 0 36px;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  background: var(--line);
  border-radius: 12px;
  overflow: hidden;
  margin: 22px 0;
  border: 1px solid var(--line);
}
.stat {
  background: var(--panel);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--gold);
}
.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.citadel-stat .stat-value { color: #8fc6a8; }

/* Tabs */
.tabbar { display: flex; gap: 4px; margin-bottom: 18px; }
.tab {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 9px 16px;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.86rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.tab:hover { color: var(--text); border-color: #3a4150; }
.tab.active { background: var(--gold-soft); border-color: var(--gold); color: var(--gold); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Toolbar */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.86rem;
}
#searchInput { flex: 1; min-width: 180px; }

/* Table */
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
thead th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; transition: background 0.12s ease; }
tbody tr:hover { background: var(--panel-raised); }
.clanmate-name { font-weight: 600; }
.mono { font-family: var(--font-mono); }

.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: capitalize;
}
.status-pill.active { background: rgba(95,182,130,0.15); color: var(--active); }
.status-pill.inactive { background: rgba(196,88,63,0.15); color: var(--inactive); }

.progress-cell { min-width: 140px; }
.progress-bar { background: var(--line); border-radius: 999px; height: 6px; overflow: hidden; margin-bottom: 4px; }
.progress-fill { background: var(--gold); height: 100%; border-radius: 999px; }
.progress-label { font-size: 0.72rem; color: var(--muted); }

.empty-state { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 0.9rem; }

/* Activity feed */
.activity-feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.activity-feed li {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
}
.activity-feed .a-top { display: flex; justify-content: space-between; gap: 12px; font-size: 0.85rem; }
.activity-feed .a-user { font-weight: 600; color: var(--gold); text-decoration: none; }
.activity-feed .a-user:hover { text-decoration: underline; }
.activity-feed .a-when { color: var(--muted); font-family: var(--font-mono); font-size: 0.75rem; }
.activity-feed .a-text { margin-top: 4px; font-size: 0.85rem; color: var(--text); }

@media (max-width: 720px) {
  .stat-strip { grid-template-columns: repeat(2, 1fr); }
  thead th:nth-child(4), tbody td:nth-child(4) { display: none; }
}

/* ---------- Homepage ---------- */
.home {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  text-align: center;
}
.home-sigil svg { width: 64px; height: 64px; margin-bottom: 18px; }
.home-sigil polygon { fill: var(--gold-soft); stroke: var(--gold); stroke-width: 1.4; }
.home h1 {
  font-family: var(--font-display);
  font-size: 2.4rem;
  margin: 0 0 6px;
  letter-spacing: 0.01em;
}
.home p.tag {
  color: var(--muted);
  margin: 0 0 40px;
  font-size: 0.95rem;
}
.search-rows {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
  max-width: 480px;
}
.search-box { position: relative; text-align: left; }
.search-box label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
  padding-left: 2px;
}
.search-box input {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 13px 16px;
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 0.95rem;
}
.search-box input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  z-index: 10;
  max-height: 280px;
  overflow-y: auto;
  display: none;
}
.search-results.open { display: block; }
.search-results .result {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  cursor: pointer;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.search-results .result:last-child { border-bottom: none; }
.search-results .result:hover { background: var(--gold-soft); }
.search-results .result .r-name { font-weight: 600; }
.search-results .result .r-meta { color: var(--muted); font-size: 0.78rem; }
.search-results .result-empty {
  padding: 14px 16px; color: var(--muted); font-size: 0.85rem; cursor: default;
}
.search-results .result-empty:hover { background: none; }

.add-clan-btn {
  display: block;
  width: 100%;
  background: var(--gold-soft);
  border: none;
  border-top: 1px solid var(--line);
  color: var(--gold);
  padding: 12px 16px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}
.add-clan-btn:hover { background: rgba(211, 165, 67, 0.26); }
.add-clan-btn:disabled {
  color: var(--muted);
  background: var(--panel);
  cursor: default;
}

.home-footnote { margin-top: 36px; color: var(--muted); font-size: 0.8rem; }
.home-footnote a { color: var(--gold); text-decoration: none; }
.home-footnote a:hover { text-decoration: underline; }

/* Back link used on inner pages */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.82rem;
  margin-bottom: 16px;
}
.back-link:hover { color: var(--gold); }

/* 404 */
.notfound {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: 10px;
}
.notfound h1 { font-family: var(--font-display); font-size: 2rem; margin: 0; }
.notfound a { color: var(--gold); }

/* ---------- Member page ---------- */
.drawer-list { list-style: none; margin: 0; padding: 0; font-size: 0.85rem; }
.drawer-list li { padding: 7px 0; border-bottom: 1px solid var(--line); color: var(--muted); }
.drawer-list li:last-child { border-bottom: none; }
.drawer-list .hl { color: var(--text); }
.member-main { display: flex; flex-direction: column; gap: 18px; }
.panel-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
}
.clan-description h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 12px;
}
.panel-block h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 12px;
}


.clanmate-name img.skill-icon {
  vertical-align: middle;
  margin-right: 6px;
}

.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 720px) {
  .panel-grid { grid-template-columns: 1fr; }
}
#progressBlock .progress-bar { height: 8px; margin-bottom: 8px; }
#progressBlock .progress-label { font-size: 0.85rem; color: var(--text); }
#progressBlock .max-rank { color: var(--gold); font-size: 0.9rem; }
.gains-meta { font-size: 0.7rem; text-transform: none; letter-spacing: normal; color: var(--muted); font-weight: 400; }
.gain-positive { color: var(--active); font-weight: 600; }
.gain-zero { color: var(--muted); }

/* ---------- Header Layout Alignment ---------- */
.hall-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end; /* Aligns button with the bottom elements (the status pill) */
}

/* ---------- Sleek, Smaller Activate Button ---------- */
.activate-btn {
  background: var(--active);
  color: var(--panel);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 12px;
  font-family: var(--font-body);
  font-size: 0.78rem; /* Matches the visual weight of small status pills */
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  height: max-content;
  margin-bottom: 2px; /* Fine-tunes baseline alignment with text */
}

/* Hover state */
.activate-btn:hover {
  background: #6fc492;
  box-shadow: 0 0 0 3px rgba(95, 182, 130, 0.2);
}

/* Click feedback */
.activate-btn:active {
  transform: scale(0.97);
}

/* Disabled state */
.activate-btn:disabled {
  background: var(--line);
  color: var(--muted);
  cursor: default;
  transform: none;
  box-shadow: none;
}

  .modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 16, 0.65);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
  }
  .modal-overlay.open { display: flex; }

  .modal-box {
    background: var(--panel-raised);
    border: 1px solid var(--line);
    border-radius: 14px;
    width: 100%;
    max-width: 420px;
    padding: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  }
  .modal-box h2 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    margin: 0 0 6px;
    color: var(--text);
  }
  .modal-box p.modal-sub {
    color: var(--muted);
    font-size: 0.85rem;
    margin: 0 0 18px;
  }
  .modal-box input {
    width: 100%;
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 11px 14px;
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 0.92rem;
    margin-bottom: 8px;
  }
  .modal-box input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-soft);
  }
  .modal-error {
    color: var(--inactive);
    font-size: 0.8rem;
    min-height: 18px;
    margin-bottom: 10px;
  }
  .modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 6px;
  }
  .modal-btn {
    padding: 9px 16px;
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
  }
  .modal-btn:hover { color: var(--text); border-color: #3a4150; }
  .modal-btn.primary {
    background: var(--gold-soft);
    border-color: var(--gold);
    color: var(--gold);
  }
  .modal-btn.primary:hover { background: rgba(211, 165, 67, 0.26); }
  .modal-btn:disabled {
    opacity: 0.5;
    cursor: default;
  }
  .modal-spinner {
    display: inline-block;
    width: 12px; height: 12px;
    border: 2px solid rgba(211,165,67,0.3);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin-right: 6px;
    vertical-align: -2px;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  .toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--panel-raised);
    border: 1px solid var(--line);
    border-left: 3px solid var(--active);
    border-radius: 10px;
    padding: 12px 18px;
    font-size: 0.85rem;
    color: var(--text);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 200;
    max-width: 90vw;
  }
  .toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
  }
  .toast.error { border-left-color: var(--inactive); }

/* Dashboard settings/config fields */
.field-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  align-items: center;
}
.field-row label {
  flex: 1 1 160px;
  font-size: 0.85rem;
  color: var(--muted);
}
.field-row input[type="text"],
.field-row input[type="number"],
.field-row input[type="datetime-local"] {
  flex: 2 1 220px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: inherit;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}
.field-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

/* Add-row fields (threshold/schedule forms) */
.add-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  align-items: flex-end;
}
.add-form .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.add-form .field label {
  font-size: 0.72rem;
  color: var(--muted);
}
.add-form .field input {
  width: 130px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: inherit;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

#thRank { width: 110px; }
#thNextRank { width: 110px; }
#thXp { width: 100px; text-align: right; }
#schDay { width: 80px; text-align: center; }
#schChannel { width: 160px; }

.desc-field {
  width: 100%;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: inherit;
  font-family: var(--font-body);
  font-size: 0.88rem;
  line-height: 1.5;
  resize: vertical;
  min-height: 120px;
}
.desc-field:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
.desc-counter {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: right;
  margin-top: 4px;
}
.desc-counter.warn { color: var(--inactive); }

/* ---------- Clan description (landing content above the tabs) ---------- */
.clan-description {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px 24px;
  margin: 22px 0;
}
.clan-description h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--gold);
  margin: 0 0 8px;
}
.clan-description p {
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.6;
  margin: 0;
  white-space: pre-line; /* preserves user's line breaks without needing HTML */
}
.clan-description:empty,
.clan-description[hidden] {
  display: none;
}

.info-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 720px) {
  .info-layout { grid-template-columns: 1fr; }
}
#highestRanksPanel .drawer-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.info-layout .clan-description {
  margin: 0;
}
.info-layout .panel-block {
  margin-top: 0;
}

.rank-entry {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.rank-icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
}