/* 方案 D · 票根式门禁页（外留白 + 暗色票体 · 固定高度 · 禁滚） */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  /* 固定根字号：电脑/手机用同一套 rem，避免大屏 vmin 把卡片「撑变形」 */
  font-size: 15px;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: var(--font-body);
  color: #1a1a1a;
  background: #e8ecf2;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
  touch-action: manipulation;
}

.env-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  /* 电脑端也按手机宽度居中，卡片视觉比例与手机一致 */
  max-width: 390px;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding:
    calc(1rem + env(safe-area-inset-top, 0px))
    1.1rem
    calc(1rem + env(safe-area-inset-bottom, 0px));
  background: #e8ecf2;
  overflow: hidden;
}

/* ── 票根主体（全态固定高度，不随内容伸缩） ── */
.env-gate__ticket {
  --env-ticket-h: 30.25rem;
  position: relative;
  width: 100%;
  max-width: 21.5rem;
  height: min(
    var(--env-ticket-h),
    calc(
      100dvh
      - 2rem
      - env(safe-area-inset-top, 0px)
      - env(safe-area-inset-bottom, 0px)
    )
  );
  max-height: min(
    var(--env-ticket-h),
    calc(
      100dvh
      - 2rem
      - env(safe-area-inset-top, 0px)
      - env(safe-area-inset-bottom, 0px)
    )
  );
  isolation: isolate;
  border-radius: 14px;
  background: #0a0b0f;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.07) inset,
    0 22px 48px rgba(15, 23, 42, 0.14),
    0 6px 16px rgba(15, 23, 42, 0.08);
  overflow: hidden;
  flex-shrink: 0;
}

.env-gate__ticket-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.5;
  pointer-events: none;
}

.env-gate__ticket-bg .hero-bg {
  position: absolute;
  inset: 0;
}

.env-gate__ticket-body {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: 1.35rem 1.25rem 1.25rem;
  color: #e8eaed;
  box-sizing: border-box;
}

/* ── 报头 ── */
.env-gate__masthead {
  flex-shrink: 0;
}

.env-gate__kicker {
  margin-bottom: 1.15rem;
  font-family: ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, monospace;
  font-size: 0.56rem;
  font-weight: 500;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: rgba(232, 234, 237, 0.4);
}

.env-gate__title {
  display: flex;
  flex-direction: column;
  gap: 0.05em;
  margin-bottom: 0;
  font-size: 2.55rem;
  font-weight: 600;
  line-height: 0.98;
  letter-spacing: 0.06em;
  color: #f4f6f8;
}

.env-gate__title-line {
  display: block;
}

.env-gate__title-line--sub,
.env-gate__title-line:last-child {
  margin-top: 0.35em;
  font-size: 0.48em;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: 0.08em;
  color: #fff;
}

.env-gate__lede {
  display: none;
}

/* ── 票根下段（占满中间剩余高度，全态不撑破票根） ── */
.env-gate__status {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.85rem 0 0;
}

.env-gate__verify {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  height: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

/* 检测中：label + detail + 剩余区留给 actions */
.env-gate__status[data-state='idle'] .env-gate__verify,
.env-gate__status[data-state='active'] .env-gate__verify {
  grid-template-rows: 1rem 3.2rem minmax(0, 1fr);
}

.env-gate__status[data-state='idle'] .env-gate__enter-slot,
.env-gate__status[data-state='active'] .env-gate__enter-slot {
  grid-row: 3;
}

/* 欢迎：左侧二维码；下方恢复入口 + 进入按钮 */
.env-gate__status[data-state='welcome'] {
  --env-side: 6.1rem;
}

.env-gate__status[data-state='welcome'] .env-gate__verify {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  overflow: hidden;
}

.env-gate__status[data-state='welcome'] .env-gate__label {
  flex: 0 0 auto;
}

.env-gate__status[data-state='welcome'] .env-gate__detail {
  flex: 0 0 auto;
  font-size: 1.24rem;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.06em;
  color: #fff;
  padding-top: 0.1rem;
  overflow: hidden;
}

.env-gate__status[data-state='welcome'] .env-gate__key {
  flex: 0 0 auto;
  padding-top: 0.1rem;
  padding-bottom: 0.1rem;
  column-gap: 0.7rem;
}

.env-gate__status[data-state='welcome'] .env-gate__enter-slot {
  flex: 0 0 auto;
  margin-top: auto;
}

/* 失败：文案固定，二维码区吃满剩余高度并保持正方形 */
.env-gate__status[data-state='fail'] .env-gate__verify {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  overflow: hidden;
}

.env-gate__status[data-state='fail'] .env-gate__label {
  flex: 0 0 auto;
}

.env-gate__status[data-state='fail'] .env-gate__detail {
  flex: 0 0 auto;
  overflow: hidden;
  font-size: 1.12rem;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: 0.02em;
  color: rgba(255, 163, 158, 0.98);
  padding-top: 0.1rem;
}

.env-gate__status[data-state='fail'] .env-gate__enter-slot {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  padding-top: 0.25rem;
}

.env-gate__status[data-state='idle'] .env-gate__key,
.env-gate__status[data-state='active'] .env-gate__key,
.env-gate__status[data-state='fail'] .env-gate__key {
  display: none;
}

.env-gate__label {
  min-height: 0;
  font-family: ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, monospace;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: rgba(105, 177, 255, 0.88);
  transition: color 0.35s ease;
}

.env-gate__status[data-state='fail'] .env-gate__label {
  color: rgba(255, 120, 117, 0.92);
}

.env-gate__status[data-state='welcome'] .env-gate__label {
  color: rgba(148, 210, 255, 0.95);
}

.env-gate__detail {
  min-height: 0;
  margin: 0;
  padding-top: 0.3rem;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0.02em;
  color: rgba(232, 234, 237, 0.5);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.4s ease, transform 0.4s ease, color 0.35s ease;
  overflow: hidden;
}

.env-gate__detail.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.env-gate__detail--multiline {
  white-space: pre-line;
}

.env-gate__invite {
  font-weight: 700;
  font-family: ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, monospace;
  font-size: 1em;
  letter-spacing: 0.08em;
  color: #6eb6ff;
}

.env-gate__key {
  display: grid;
  grid-template-columns: var(--env-side, 5.7rem) 1fr;
  align-items: center;
  column-gap: 0.55rem;
  min-height: 0;
  margin: 0;
  padding: 0.1rem 0 0;
  overflow: hidden;
}

.env-gate__key[hidden] {
  display: none;
}

.env-gate__key-tip {
  min-width: 0;
  margin: 0;
  display: block;
  text-align: left;
  font-size: 1.12rem;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: 0.02em;
  color: rgba(255, 186, 120, 0.98);
}

.env-gate__key-tip-line {
  display: inline;
}

.env-gate__key-qr {
  margin: 0;
  justify-self: stretch;
  width: var(--env-side, 5.7rem);
  height: var(--env-side, 5.7rem);
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: #fff;
  cursor: zoom-in;
}

.env-gate__key-qr img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.env-gate__enter-slot {
  position: relative;
  min-height: 0;
  margin: 0;
  padding-top: 0.35rem;
  height: 100%;
  box-sizing: border-box;
}

.env-gate__actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  height: 100%;
}

.env-gate__status[data-state='welcome'] .env-gate__enter-slot {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  align-items: stretch;
  padding-top: 0.35rem;
  height: auto;
  flex: 0 0 auto;
  flex-shrink: 0;
  --env-btn-h: 2.75rem;
}

.env-gate__status[data-state='welcome'] .env-gate__actions {
  min-width: 0;
  height: var(--env-btn-h);
  flex: 0 0 var(--env-btn-h);
}

.env-gate__status[data-state='welcome'] .env-gate__enter {
  height: var(--env-btn-h);
  max-height: var(--env-btn-h);
  min-height: var(--env-btn-h);
  font-size: 0.88rem;
  letter-spacing: 0.04em;
  text-transform: none;
  box-sizing: border-box;
}

.env-gate__status[data-state='fail'] .env-gate__actions {
  display: none;
}

.env-gate__enter {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  max-height: 2.5rem;
  padding: 0 0.55rem;
  font-family: ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, monospace;
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #0a0b0f;
  background: #f0f4ff;
  border: 1px solid #f0f4ff;
  border-radius: 3px;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition:
    background 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease,
    opacity 0.4s ease;
}

.env-gate__enter.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.env-gate__enter:hover:not(:disabled) {
  background: #fff;
  border-color: #fff;
}

.env-gate__enter:active:not(:disabled) {
  background: #dce8ff;
}

.env-gate__enter:disabled {
  opacity: 0;
  pointer-events: none;
  cursor: not-allowed;
}

.env-gate__recover-file {
  display: none;
}

.env-gate__recover-btn {
  display: none;
  flex: 0 0 auto;
  height: 2.1rem;
  padding: 0 0.7rem;
  border-radius: 3px;
  border: 1px solid rgba(240, 244, 255, 0.35);
  background: rgba(240, 244, 255, 0.12);
  color: rgba(240, 244, 255, 0.92);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  cursor: pointer;
  white-space: nowrap;
}

.env-gate__status[data-state='welcome'] .env-gate__recover-btn:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
  order: -1;
  width: 100%;
  max-width: none;
  height: var(--env-btn-h);
  min-height: var(--env-btn-h);
  max-height: var(--env-btn-h);
  box-sizing: border-box;
  padding: 0 0.55rem;
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

/* 未通过页不展示密钥登陆按钮，避免挡住加群二维码 */
.env-gate__status[data-state='fail'] .env-gate__recover-btn {
  display: none !important;
}

.env-gate__fail-help {
  position: relative;
  inset: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: stretch;
  min-height: 0;
  height: 100%;
}

.env-gate__fail-help[hidden] {
  display: none;
}

.env-gate__fail-qrs {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.env-gate__fail-qr {
  margin: 0;
  flex: 0 1 auto;
  width: auto;
  height: 100%;
  max-width: calc((100% - 0.55rem) / 2);
  aspect-ratio: 1;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.92);
}

.env-gate__fail-qr img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── 票根页脚 ── */
.env-gate__colophon {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 0.35rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-family: ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, monospace;
  font-size: 0.5rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(232, 234, 237, 0.26);
}

@media (max-width: 360px) {
  html {
    font-size: 14px;
  }

  .env-gate {
    padding-inline: 0.85rem;
  }

  .env-gate__ticket-body {
    padding-inline: 1.1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .env-gate__detail,
  .env-gate__enter {
    transition: none;
  }
}
