.shahnameh-auth-wrap {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
}

.shahnameh-auth-wrap.is-tree-corner {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(8px, calc(50vw - 556px));
  z-index: 950;
}

body.immersive .shahnameh-auth-wrap.is-tree-corner {
  display: none !important;
}

.shahnameh-auth-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--box-border, #6b3a22) 28%, transparent);
  background: color-mix(in srgb, var(--box-fill, #fbf3e1) 70%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: color-mix(in srgb, var(--ink, #362415) 82%, transparent);
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.shahnameh-auth-btn:hover {
  background: var(--box-elevated, #fff8e8);
  border-color: color-mix(in srgb, var(--gold, #b9902e) 65%, transparent);
  color: var(--maroon, #8c2f2f);
}

.shahnameh-auth-btn.open,
.shahnameh-auth-btn:focus-visible {
  outline: none;
  border-color: var(--gold, #b9902e);
  box-shadow: 0 0 0 2.5px rgba(185, 144, 46, 0.22);
}

.shahnameh-auth-btn.is-logged-in {
  height: 30px;
  padding: 0 10px 0 9px;
  border-color: color-mix(in srgb, var(--gold, #b9902e) 55%, transparent);
  color: var(--ink, #362415);
}

.shahnameh-auth-btn:not(.is-logged-in) .shahnameh-auth-icon {
  display: none;
}

.shahnameh-auth-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--maroon, #8c2f2f);
  flex-shrink: 0;
}

.shahnameh-auth-icon svg {
  width: 14px;
  height: 14px;
  display: block;
}

.shahnameh-auth-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2f855a;
  flex-shrink: 0;
  pointer-events: none;
}

.shahnameh-auth-label {
  font-size: 0.74rem;
  font-weight: 500;
  white-space: nowrap;
}

.shahnameh-auth-name {
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.74rem;
  font-weight: 600;
}

.shahnameh-auth-wrap.is-char-mode .shahnameh-auth-btn {
  height: 34px;
  padding: 0 11px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--box-fill, #fbf3e1) 72%, transparent);
}

.shahnameh-auth-wrap.is-char-mode .shahnameh-auth-btn.is-logged-in {
  padding: 0 9px;
}

@media (max-width: 640px) {
  .shahnameh-auth-wrap.is-tree-corner {
    top: max(8px, env(safe-area-inset-top));
    left: 8px;
  }

  body.has-auth-corner header {
    padding-top: 26px;
  }

  .shahnameh-auth-btn {
    height: 27px;
    padding: 0 9px;
    font-size: 0.71rem;
  }

  .shahnameh-auth-label {
    font-size: 0.71rem;
  }

  .shahnameh-auth-name {
    display: none;
  }

  .shahnameh-auth-btn.is-logged-in {
    height: 27px;
    padding: 0 8px;
    gap: 4px;
  }

  .shahnameh-auth-wrap.is-char-mode .shahnameh-auth-btn {
    height: 32px;
    padding: 0 8px;
  }
}

.shahnameh-auth-dropdown {
  position: absolute;
  top: calc(100% + 7px);
  left: 0;
  right: auto;
  min-width: 215px;
  max-width: min(270px, calc(100vw - 20px));
  padding: 10px 12px;
  background: var(--box-elevated, var(--box-fill, #fbf3e1));
  color: var(--ink, #362415);
  border: 1.5px solid var(--box-border, #6b3a22);
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.22);
  z-index: 1200;
  direction: rtl;
  text-align: right;
  font-family: 'Vazirmatn', Tahoma, sans-serif;
}

.shahnameh-auth-dropdown[hidden] {
  display: none;
}

.auth-dropdown-user {
  padding: 3px 2px 8px;
}

.auth-dropdown-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.auth-dropdown-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink, #362415);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-dropdown-role {
  flex: 0 0 auto;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  background: rgba(185, 144, 46, 0.16);
  color: var(--maroon, #8c2f2f);
  border: 1px solid rgba(185, 144, 46, 0.42);
}

.auth-dropdown-handle {
  font-size: 0.77rem;
  color: var(--ink, #362415);
  opacity: 0.62;
  direction: ltr;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.auth-dropdown-sep {
  height: 1px;
  margin: 4px 0 8px;
  background: color-mix(in srgb, var(--box-border, #6b3a22) 22%, transparent);
}

.auth-dropdown-action {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--box-border, #6b3a22) 28%, transparent);
  background: transparent;
  color: var(--ink, #362415);
  font-family: inherit;
  font-size: 0.81rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.auth-dropdown-action:hover {
  background: rgba(185, 144, 46, 0.14);
  border-color: var(--gold, #b9902e);
  color: var(--maroon, #8c2f2f);
}

.auth-dropdown-action--panel {
  border-color: color-mix(in srgb, var(--gold, #b9902e) 48%, transparent);
  background: rgba(185, 144, 46, 0.1);
  color: var(--maroon, #8c2f2f);
  font-weight: 600;
}

.auth-dropdown-logout {
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid rgba(140, 47, 47, 0.42);
  background: rgba(140, 47, 47, 0.08);
  color: var(--maroon, #8c2f2f);
  font-family: inherit;
  font-size: 0.81rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.auth-dropdown-logout:hover {
  background: var(--maroon, #8c2f2f);
  color: #fdf8ec;
}

.auth-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 25000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(24, 15, 8, 0.62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  direction: rtl;
  font-family: 'Vazirmatn', Tahoma, sans-serif;
}

.auth-modal-overlay[hidden] {
  display: none;
}

.auth-modal-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--box-fill, #fbf3e1);
  color: var(--ink, #362415);
  border: 2px solid var(--box-border, #6b3a22);
  border-radius: 14px;
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.34), inset 0 0 0 1px rgba(185, 144, 46, 0.25);
  padding: 22px 22px 20px;
  text-align: right;
  line-height: 1.7;
}

.auth-modal-close {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid rgba(107, 58, 34, 0.28);
  background: transparent;
  color: var(--ink, #362415);
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.auth-modal-close:hover {
  background: rgba(185, 144, 46, 0.16);
  border-color: var(--gold, #b9902e);
}

.auth-modal-title {
  margin: 0 0 14px;
  font-size: 1.14rem;
  font-weight: 700;
  color: var(--maroon, #8c2f2f);
  padding-left: 36px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  margin-bottom: 16px;
  border-radius: 10px;
  background: rgba(107, 58, 34, 0.08);
  border: 1px solid rgba(107, 58, 34, 0.2);
}

.auth-tab {
  padding: 7px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--ink, #362415);
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.auth-tab.is-active {
  background: var(--box-fill, #fbf3e1);
  color: var(--maroon, #8c2f2f);
  box-shadow: 0 2px 8px rgba(54, 36, 21, 0.12);
  border: 1px solid rgba(185, 144, 46, 0.45);
}

.auth-field {
  margin-bottom: 12px;
}

.auth-field label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink, #362415);
}

.auth-input-wrap {
  position: relative;
}

.auth-field input {
  width: 100%;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--ink, #362415);
  background: var(--parchment, #efe3c4);
  border: 1.5px solid var(--box-border, #6b3a22);
  border-radius: 9px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

@media (max-width: 600px) {
  .auth-field input {
    font-size: 16px;
  }
}

.auth-field input:focus {
  border-color: var(--gold, #b9902e);
  box-shadow: 0 0 0 3px rgba(185, 144, 46, 0.22);
}

.auth-pass-toggle {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--ink, #362415);
  opacity: 0.65;
  cursor: pointer;
  padding: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.auth-pass-toggle:hover {
  opacity: 1;
}

.auth-input-wrap input {
  padding-left: 36px;
}

.auth-error {
  margin: 0 0 12px;
  padding: 8px 11px;
  border-radius: 8px;
  background: rgba(140, 47, 47, 0.12);
  border: 1px solid rgba(140, 47, 47, 0.42);
  color: var(--maroon, #8c2f2f);
  font-size: 0.82rem;
  font-weight: 500;
}

.auth-error[hidden] {
  display: none;
}

.auth-submit-btn {
  width: 100%;
  margin-top: 4px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--gold, #b9902e);
  background: var(--maroon, #8c2f2f);
  color: #fdf8ec;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.15s ease;
}

.auth-submit-btn:hover:not(:disabled) {
  filter: brightness(1.08);
}

.auth-submit-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}
