* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #009688;
  --btn-primary: #0baf85;
  --primary-dark: #00796b;
  --link: #1677ff;
  --primary-light: #b2dfdb;
  --text: #1f2937;
  --text-light: #6b7280;
  --border: #e5e7eb;
  --bg: #ffffff;
  --hover-bg: #f3f4f6;
  --error: #dc2626;
  --success: #16a34a;
  --card-bg: #ffffff;
  --input-bg: #ffffff;
  --footer-bg: #f5f5f5;
  --dropdown-bg: #fff;
  --carousel-dot-bg: #fff;
  --lsprite-rows: 7;
  --lsprite-columns: 6;
  --background-image: url('/image/BG-light.svg') center/cover no-repeat fixed;
  --ft-card-bg: #ffffff;
  --ft-card-border: #e2e8f0;
  --ft-card-shadow: rgba(0,0,0,0.08);
  --ft-avatar-border: #e2e8f0;
  --ft-status-online: #22c55e;
  --ft-status-offline: #d2d2d2;
  --ft-status-busy: #ef4444;
  --ft-status-border: #ffffff;
  --ft-name-color: #1e293b;
  --ft-relation-color: #94a3b8;
  --ft-edge-color: #cbd5e1;
  --ft-highlight-bg: #dcfce7;
  --ft-highlight-text: #065f46;
  --ft-highlight-rel: #047857;
  #sunIcon { display: block; }
  #moonIcon { display: none; }
}

/* Dark Theme */
body.dark-theme {
  --text: #e5e7eb;
  --text-light: #9ca3af;
  --border: transparent;
  --bg: transparent;
  --hover-bg: #393939;
  --card-bg: #393939;
  --input-bg: #4d4f53;
  --footer-bg: #000;
  --dropdown-bg: #424242;
  --carousel-dot-bg: #8e8e8e;
  --background-image: url('image/BG-dark.jpg') center/cover no-repeat fixed;
  --ft-card-bg: #222;
  --ft-card-border: #4d4f53;
  --ft-card-shadow: rgba(0,0,0,0.08);
  --ft-avatar-border: #4d4f53;
  --ft-status-border: #ffffff;
  --ft-name-color: #e5e7eb;
  --ft-relation-color: #c0c8d4;
  --ft-edge-color: #a1a5ab;
  --ft-highlight-bg: #0baf85;
  --ft-highlight-text: #ffffff;
  --ft-highlight-rel: #d1fae5;
  --ft-dead-bg: #5e5e5e;
  --ft-dead-name: #9ca3af;
  --ft-dead-relation: #6b7280;
  --ft-dead-hatch: #989ca5;
  #sunIcon { display: none; }
  #moonIcon { display: block; }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  background: var(--background-image);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.flex-row { display: flex; }
.gap5 { gap: 1rem; }
.gap10 { gap: 2rem; }

.ellipses {
  text-overflow: ellipsis;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
}

.txt-right { text-align: right; }

/* Server Banner */
.server-banner {
  background: #fff1f0;
  font-size: 0.85rem;
  color: #a8071a;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  overflow: hidden;
  height: 45px;
  margin-top: -45px;
  transition: margin-top 0.4s ease-in-out;
}

.server-banner.show {
  margin-top: 0;
}

.server-banner-text {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 0;
}

.server-banner-icon { width: 16px; height: 16px; stroke: #faad14; color: #faad14; flex-shrink: 0; }

.server-banner-retry {
  background: none;
  border: none;
  color: var(--link);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  padding: 0;
  white-space: nowrap;
}

.server-banner-retry:hover { text-decoration: underline; }

body.dark-theme .server-banner {
  background: #2a1215;
  border-bottom-color: #58181c;
  color: #ff7875;
}

body.dark-theme .server-banner-icon { stroke: #faad14; }

/* Header */
header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0.8rem 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo { height: 2.5rem; }

/* Language Selector */
.language-selector { position: relative; }

.language-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  color: var(--text);
  transition: color 0.2s, transform 0.2s;
  border-radius: 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.language-toggle:hover {
  color: var(--primary);
  background: var(--hover-bg);
}

.language-toggle:active { transform: scale(0.95); }

.language-icon { width: 18px; height: 18px; }

.language-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.5rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 1000;
  min-width: 160px;
  padding: 0.5rem 0;
}

.language-option {
  width: 100%;
  padding: 0.625rem 1rem;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text);
  transition: background 0.2s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.language-option:hover { background: var(--hover-bg); }

.language-option.active {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 600;
}

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: color 0.2s, transform 0.2s;
  border-radius: 0.375rem;
}

.theme-toggle:hover {
  color: var(--primary);
  background: var(--hover-bg);
}

.theme-toggle:active { transform: scale(0.95); }

.theme-icon { width: 20px; height: 20px; }

.app-link {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
  transition: opacity 0.2s;
}

.app-link:hover { opacity: 0.7; }

/* Main Container */
main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 3rem;
  padding: 2rem;
}

/* Carousel */
.carousel {
  max-width: 40rem;
  width: 100%;
  overflow: hidden;
  border-radius: 0.75rem;
}

.carousel-track {
  display: flex;
  transition: transform 1.4s ease-in-out;
}

.carousel-slide {
  min-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.carousel-caption {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 2rem 0;
}

.carousel-dots {
  display: flex;
  justify-content: center;
  gap: 1.25rem;
}

.dot {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  border: none;
  background: var(--carousel-dot-bg);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: background 0.3s;
}

.dot.active { background: var(--primary); }

/* Form Card */
.form-card {
  width: 364px;
  /* min-height (not a fixed height) so the card grows to fit its fields on
     short viewports (e.g. DevTools docked at the bottom) instead of clipping
     them; on tall screens it still fills 60vh and space-around spreads it out. */
  min-height: 60vh;
  background: var(--card-bg);
  border-radius: 0.5rem;
  padding: 2rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}

.form-title {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.back-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  color: var(--text-light);
  transition: color 0.2s;
}

.back-btn:hover { color: var(--primary); }

.divider {
  display: flex;
  align-items: center;
  margin: 0.5rem 0;
  color: var(--text-light);
  font-size: 0.75rem;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border);
}

.divider span { padding: 0 0.75rem; white-space: nowrap; }

/* Form */
form {
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  margin-bottom: 1.4rem;
  align-items: center;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

/* Password field with a show/hide eye toggle */
.password-group {
  position: relative;
}

.password-group input {
  padding-right: 2.75rem;
  width: 100%;
}

.password-toggle {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 2.6rem;
  /* Hidden until the field has a value — shown via :not(:placeholder-shown)
     below (this also handles programmatic clears on view switch). */
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  padding: 0;
}

.password-group input:not(:placeholder-shown) ~ .password-toggle {
  display: flex;
}

.password-toggle:hover {
  color: var(--text);
}

.password-toggle svg {
  width: 1.15rem;
  height: 1.15rem;
}

/* Phone Input with Country Code */
.phone-input-wrapper {
  display: flex;
  gap: 0.5rem;
  position: relative;
}

.phone-input-wrapper input[name=mobile] {
  position: absolute;
  width: 100%;
  text-indent: 90px;
}

.country-select-wrapper {
  position: relative;
  flex-shrink: 0;
  z-index: 1;
  margin: 1px;
}

.country-select {
  padding: 0.625rem 1.5rem 0.625rem 0.75rem;
  border: none;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
  cursor: pointer;
  appearance: none;
  min-width: 90px;
  transition: border-color 0.2s;
}

.country-select:focus {
  outline: none;
  border-color: var(--primary);
}

.country-select-arrow {
  margin-left: 7px;
  margin-bottom: -3px;
  width: 12px;
  pointer-events: none;
  color: var(--text-light);
}

input {
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  flex: 1;
}

input:focus {
  outline: none;
  border-color: var(--primary);
}

input:disabled { cursor: not-allowed; }

.login-action-container { padding: 0 3px; }

/* Checkbox */
.checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
}

.checkbox-wrapper input[type="checkbox"] {
  width: auto;
  cursor: pointer;
  margin: 0;
  accent-color: var(--primary);
}

/* Signup consent: optional DOB + 16+/terms checkboxes */
.signup-consent {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
}

/* DOB field: label sits above the input (matches the other form fields). */
.dob-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: stretch;
}

.dob-label {
  font-size: 0.8125rem;
  color: var(--text-secondary, #6b7280);
}

.dob-optional {
  color: #9aa0a6;
  font-weight: 400;
}

.dob-input {
  width: 100%;
}

/* INVITE_ONLY: the invite code is server-supplied — render it clearly non-editable. */
.invite-code-input {
  width: 100%;
}
.invite-code-input[readonly] {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-secondary, #6b7280);
  cursor: not-allowed;
}

/* Placeholder look: the native dd/mm/yyyy text is grey (#999) until a date is
   picked, then it switches to the normal input colour. The date sub-fields inherit
   the input's `color`, so we drive it off the input element. `has-value` is toggled
   in JS since a non-required date input has no reliable empty-state selector. */
.dob-input:not(.has-value) {
  color: #999;
}

.dob-input.has-value {
  color: var(--text);
}

.dob-input::-webkit-calendar-picker-indicator {
  opacity: 0.6;
  cursor: pointer;
}
.dob-input input::placeholder{
  color: #eee;
}

/* The terms label wraps to two lines — keep the checkbox pinned to the first. */
.signup-consent .checkbox-wrapper {
  align-items: flex-start;
  line-height: 1.35;
  cursor: pointer;
}

.signup-consent .checkbox-wrapper input[type="checkbox"] {
  margin-top: 2px;
  flex: none;
}

.signup-consent .checkbox-wrapper a {
  padding: 0;
}

.form-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  width: 100%;
}

.btn {
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 0.275rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 0.5rem;
  width: fit-content;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}

.btn-primary { background: var(--btn-primary); color: white; }
.btn-primary:disabled { background: #b0bec5; cursor: not-allowed; }
.btn-primary:active { transform: scale(0.98); }

/* Loading Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Form Footer */
.form-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  font-size: 0.875rem;
  color: var(--text-light);
  text-align: center;
}

.link-btn {
  background: none;
  border: none;
  color: var(--link);
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-decoration: none;
  transition: color 0.2s;
}

.link-btn:hover:not(:disabled) { text-decoration: underline; }
.link-btn:disabled { color: #9e9e9e; cursor: not-allowed; }

.small { font-size: 0.8rem; }

.terms-text {
  font-size: 0.75rem;
  text-align: center;
  max-width: 300px;
  line-height: 1.5;
}

/* OTP Timer */
.otp-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.otp-timer-wrapper {
  display: flex;
  flex-direction: column;
  align-items: end;
  width: 100%;
}

.otp-timer-wrapper input { width: 100%; }

.timer-btn {
  font-size: 0.75rem;
  white-space: nowrap;
  padding: 0.25rem 0.5rem;
}

.timer-btn:disabled { opacity: 0.6; }

/* View Content */
.view-content {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  height: 100%;
}

/* Alert */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 0.375rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  display: none;
}

.alert.show { display: block; }

.alert-error {
  background: #fee2e2;
  color: var(--error);
  border: 1px solid #fecaca;
}

.alert-success {
  background: #dcfce7;
  color: var(--success);
  border: 1px solid #bbf7d0;
}

/* Footer */
footer {
  border-top: 1px solid var(--border);
  padding: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  height: 52px;
  background-color: var(--footer-bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}

#view {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  height: inherit;
}

#view.login .view-signup, #view.login .view-reset, #view.login .view-signupConflict,
#view.signup .view-login, #view.signup .view-reset, #view.signup .view-signupConflict,
#view.reset .view-login, #view.reset .view-signup, #view.reset .view-signupConflict,
#view.signupConflict .view-login, #view.signupConflict .view-signup, #view.signupConflict .view-reset {
  display: none;
}

/* Signup Conflict View */
.conflict-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding: 1rem 0 0.5rem;
}

.conflict-avatar-wrap {
  display: flex;
  justify-content: center;
}

.conflict-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border, #e5e7eb);
  background: #f3f4f6;
}

.conflict-identity {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.conflict-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.conflict-loginid {
  font-size: 0.875rem;
  color: var(--text-muted, #6b7280);
}

.conflict-message {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  text-align: center;
}

/* ── Confirm dialog (signup conflict → "No, I'm not") ─────────────────────── */
/* `hidden` sets display:none via the UA sheet, but the rule below sets
   display:flex and wins on specificity — without this the dialog rendered over
   the landing page from first paint. Higher specificity, so it beats it back. */
.confirm-backdrop[hidden] {
  display: none;
}

.confirm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgb(15 23 42 / 45%);
}

.confirm-card {
  width: 100%;
  max-width: 380px;
  background: var(--card-bg, #fff);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 12px 32px rgb(0 0 0 / 18%);
  text-align: center;
}

.confirm-title {
  margin: 0 0 0.75rem;
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
}

.confirm-body {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text-muted, #6b7280);
}

.confirm-body strong {
  color: var(--text);
  font-weight: 600;
}

.confirm-prompt {
  margin: 0 0 1.25rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.confirm-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.confirm-actions .btn {
  flex: 1;
  max-width: 160px;
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border, #e5e7eb);
}

.btn-ghost:hover:not(:disabled) {
  background: rgb(0 0 0 / 4%);
}

.conflict-createdby {
  font-size: 0.8125rem;
  color: var(--text-muted, #6b7280);
  margin: -0.75rem 0 0;
  text-align: center;
}

.conflict-createdby strong {
  color: var(--text);
  font-weight: 600;
}

/* Creator's photo, inline with their name. Sized to sit on the text baseline of
   the "Added by ..." line rather than dominate it — the owner's own 96px avatar
   above stays the focus of the card. Hidden by auth.js when there is no picture,
   so the line collapses back to name-only. */
.conflict-createdby-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: -6px;
  margin: 0 0.25rem;
  border: 1px solid var(--border, #e5e7eb);
  background: #f3f4f6;
}

.conflict-actions {
  display: flex;
  gap: 0.75rem;
  width: 100%;
  justify-content: center;
}

.conflict-actions .btn {
  flex: 1;
  max-width: 160px;
}

.btn-danger {
  background: #ef4444;
  color: #fff;
  border: 1px solid #ef4444;
}
.btn-danger:hover:not(:disabled) {
  background: #dc2626;
  border-color: #dc2626;
}

/* Responsive */
@media (max-width: 1024px) {
  main { flex-direction: column; gap: 2rem; }
  .carousel { max-width: 100%; }
  .form-card { width: 100%; max-width: 400px; }
}

@media (max-width: 640px) {
  .server-banner { font-size: 0.75rem; padding: 0 0.75rem; gap: 0.5rem; }
  header { padding: 0.75rem 1rem; }
  .logo { height: 2rem; }
  .app-link span { display: none; }
  main { padding: 1rem; }
  .form-card { padding: 1.5rem; }
  .carousel-caption { font-size: 0.75rem; margin: 1rem 0; }
  .carousel { display: none; }
}
