/* ============================================================
   Idmanos 登录 / 注册面板（首页右侧内嵌 + 移动端底部弹层）
   ============================================================ */

/* ---------- 基础 ---------- */
.auth-panel {
  width: 100%;
  max-width: 340px;
  box-sizing: border-box;
  color: #333;
}

.auth-panel[hidden] { display: none !important; }

.auth-panel .ap-title {
  margin: 0 0 4px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .04em;
}

.auth-panel .ap-sub {
  margin: 0 0 18px;
  font-size: .78rem;
  font-weight: 400;
  opacity: .55;
  line-height: 1.5;
}

/* ---------- 切换 Tab ---------- */
.auth-panel .ap-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(0, 0, 0, .12);
}

.auth-panel .ap-tabs button {
  flex: 1;
  appearance: none;
  border: 0;
  background: none;
  padding: 8px 0 9px;
  font: inherit;
  font-size: .82rem;
  color: inherit;
  opacity: .45;
  cursor: pointer;
  position: relative;
  transition: opacity .2s ease;
}

.auth-panel .ap-tabs button.on {
  opacity: 1;
  font-weight: 600;
}

.auth-panel .ap-tabs button.on::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: currentColor;
}

/* ---------- OAuth 按钮 ---------- */
.auth-panel .ap-oauth {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.auth-panel .ap-oauth button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  appearance: none;
  border: 1px solid rgba(0, 0, 0, .18);
  background: transparent;
  color: inherit;
  border-radius: 999px;
  padding: 10px 14px;
  font: inherit;
  font-size: .82rem;
  cursor: pointer;
  transition: background-color .2s ease, border-color .2s ease;
}

.auth-panel .ap-oauth button:hover {
  border-color: rgba(0, 0, 0, .45);
  background: rgba(0, 0, 0, .035);
}

.auth-panel .ap-oauth button svg { flex: none; }

/* ---------- 分隔线 ---------- */
.auth-panel .ap-or {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  font-size: .7rem;
  opacity: .38;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.auth-panel .ap-or::before,
.auth-panel .ap-or::after {
  content: '';
  flex: 1;
  height: 1px;
  background: currentColor;
  opacity: .5;
}

/* ---------- 表单 ---------- */
.auth-panel .ap-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-panel .ap-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.auth-panel .ap-field label {
  font-size: .7rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  opacity: .5;
}

.auth-panel .ap-field input {
  appearance: none;
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(0, 0, 0, .18);
  background: transparent;
  color: inherit;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: .84rem;
  transition: border-color .2s ease;
}

.auth-panel .ap-field input:focus {
  outline: none;
  border-color: rgba(0, 0, 0, .6);
}

.auth-panel .ap-submit {
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: #1a1a1a;
  color: #f7f7f7;
  padding: 11px 14px;
  font: inherit;
  font-size: .84rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  transition: opacity .2s ease;
}

.auth-panel .ap-submit:hover { opacity: .82; }
.auth-panel .ap-submit:disabled { opacity: .4; cursor: default; }

.auth-panel .ap-msg {
  min-height: 18px;
  font-size: .74rem;
  line-height: 1.4;
  color: #c0392b;
}

.auth-panel .ap-msg.ok { color: #2e7d32; }

.auth-panel .ap-links {
  margin-top: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  font-size: .75rem;
  opacity: .6;
}

.auth-panel .ap-links button {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.auth-panel .ap-legal {
  margin: 14px 0 0;
  font-size: .68rem;
  line-height: 1.6;
  opacity: .4;
}

/* ---------- 遮罩（仅移动端弹层使用） ---------- */
.ap-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .28);
  z-index: 999998;
}

/* ============================================================
   桌面：内嵌在首页右栏
   ============================================================ */
@media (min-width: 1025px) and (orientation: landscape), (orientation: landscape) and (min-height: 500px) {
  body.needs-auth .ap-backdrop { display: none !important; }
}

/* ============================================================
   移动端：从底部升起
   ============================================================ */
@media (max-width: 1024px), (max-height: 499px) {
  /* 只有弹层打开时才显示遮罩，关闭后必须让页面可交互 */
  .ap-backdrop.show { display: block; }

  /* 关闭状态：面板彻底移出屏幕，且不接收任何点击 */
  body.needs-auth .auth-panel:not(.ap-open) { pointer-events: none; }

  body.needs-auth .auth-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    max-width: none;
    max-height: 88vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #f7f7f7;
    color: #333;
    border-radius: 20px 20px 0 0;
    padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
    box-shadow: 0 -8px 40px rgba(0, 0, 0, .18);
    z-index: 999999;
    transform: translateY(100%);
    transition: transform .32s cubic-bezier(.32, .72, 0, 1);
    box-sizing: border-box;
  }

  body.needs-auth .auth-panel.ap-open { transform: translateY(0); }

  /* 关闭按钮 */
  body.needs-auth .auth-panel .ap-close {
    position: absolute;
    top: 14px;
    right: 16px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    appearance: none;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, .06);
    color: inherit;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
  }

  /* 顶部小把手 */
  body.needs-auth .auth-panel::before {
    content: '';
    display: block;
    width: 38px;
    height: 4px;
    border-radius: 2px;
    background: rgba(0, 0, 0, .16);
    margin: 0 auto 16px;
  }

}

/* ============================================================
   桌面：未登录时用面板替换右栏内容
   ============================================================ */
@media (min-width: 1025px) and (orientation: landscape), (orientation: landscape) and (min-height: 500px) {
  body.needs-auth .editor-info > *:not(#authPanel) { display: none !important; }

  body.needs-auth .editor-info {
    justify-content: center;
    align-items: center;      /* 面板居中 */
    text-align: left;
    padding-left: 3vw;
    padding-right: 3vw;
  }

  body.needs-auth .auth-panel {
    max-width: 340px;
    width: 100%;
    margin: 0 auto;           /* 水平居中 */
    animation: apFadeIn .5s ease forwards;
  }
}

@keyframes apFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- 深色模式 ---------- */
@media (prefers-color-scheme: dark) {
  .auth-panel { color: #f2f2f2; }

  .auth-panel .ap-tabs { border-bottom-color: rgba(255, 255, 255, .16); }

  .auth-panel .ap-oauth button,
  .auth-panel .ap-field input {
    border-color: rgba(255, 255, 255, .24);
  }

  .auth-panel .ap-oauth button:hover {
    border-color: rgba(255, 255, 255, .55);
    background: rgba(255, 255, 255, .06);
  }

  .auth-panel .ap-field input:focus { border-color: rgba(255, 255, 255, .7); }

  .auth-panel .ap-submit {
    background: #f2f2f2;
    color: #1a1a1a;
  }

  .auth-panel .ap-msg { color: #ff8a80; }
  .auth-panel .ap-msg.ok { color: #81c784; }

  @media (max-width: 1024px), (max-height: 499px) {
    body.needs-auth .auth-panel {
      background: #232323;
      color: #f2f2f2;
    }
    body.needs-auth .auth-panel::before { background: rgba(255, 255, 255, .2); }
  }
}
