/* ==========================================================================
   CockView 领钥匙页 —— 一屏：logo / 标题 / 一行副标 / 下载 / 三格表单
   - 零外部资源：系统字体栈，图标全是内联 SVG
   - 颜色收敛：近黑底、白字，彩色只留给公鸡；暖白只在表单「充能」边线上点一下
   - 动效照 emil-design-eng：自定义 ease-out、只动 transform/opacity、按压 0.97、
     hover 只给有鼠标的设备、减少动态效果时只留淡入淡出
   ========================================================================== */

@property --p {
  syntax: '<percentage>';
  inherits: true;
  initial-value: 0%;
}

:root {
  --bg: #050506;
  --fg: #f5f5f7;
  --fg-2: rgba(245, 245, 247, 0.6);
  --fg-3: rgba(245, 245, 247, 0.36);
  --line: rgba(255, 255, 255, 0.1);
  --line-2: rgba(255, 255, 255, 0.16);
  --glass: rgba(255, 255, 255, 0.045);
  --ink: #0b0b0c;
  --accent: #ffd2a6;
  --warn: #f4b860;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "HarmonyOS Sans SC",
    "MiSans", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
}

*,
*::before,
*::after { box-sizing: border-box; }

html {
  background: var(--bg);
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button,
input { font: inherit; color: inherit; }

button { cursor: pointer; background: none; border: 0; padding: 0; }

a { color: inherit; text-decoration: none; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible {
  outline: 2px solid rgba(245, 245, 247, 0.85);
  outline-offset: 3px;
}

/* ———————————————— 背景层 ———————————————— */

.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 500ms var(--ease-out);
}

.has-scene #scene { opacity: 1; }

/* 没有 WebGL 的机器：一张静态公鸡，位置由 JS 对到舞台区 */
.fallback {
  position: absolute;
  background: url("../assets/rooster-map.webp") left center / 200% 100% no-repeat;
  mix-blend-mode: screen;
  opacity: 0;
  transition: opacity 700ms var(--ease-out);
}

.fallback::before {
  content: "";
  position: absolute;
  inset: -30%;
  background: radial-gradient(closest-side, rgba(120, 22, 12, 0.22), transparent 70%);
  mix-blend-mode: screen;
}

/* 图的黑底靠滤色混合融进背景，所以这一层要自己垫一块底色 */
.is-fallback .bg { background: var(--bg); }

.is-fallback .fallback { opacity: 1; }

/* ———————————————— 页面骨架 ———————————————— */

.page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  overflow-x: clip;
  padding: env(safe-area-inset-top) max(24px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(24px, env(safe-area-inset-left));
}

.top {
  height: 64px;
  display: flex;
  align-items: center;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--fg);
}

.brand img {
  width: 24px;
  height: 24px;
  display: block;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  text-align: center;
}

/* 公鸡的舞台：吃掉剩余高度，WebGL 场景按这块区域的位置摆公鸡 */
.stage {
  flex: 1 1 0;
  width: 100%;
  min-height: 150px;
}

.title {
  margin: clamp(-52px, -4.5vh, -20px) 0 0;
  font-size: clamp(36px, 5vw, 68px);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: 0.02em;
  color: var(--fg);
}

.sub {
  margin: 14px 0 0;
  font-size: clamp(14px, 1.25vw, 17px);
  color: var(--fg-2);
}

/* ———————————————— 下载 ———————————————— */

.dl {
  margin-top: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-main {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  height: 46px;
  padding: 0 24px 0 20px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform 160ms var(--ease-out), background-color 160ms ease, color 160ms ease, box-shadow 200ms ease;
}

.btn-main svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.btn-main .ver {
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  opacity: 0.46;
}

.btn-main .ver:empty { display: none; }

#dl-main-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-icon { display: grid; flex: none; }

.btn-main:active { transform: scale(0.97); }

/* 「即将推出」「已选」不是下载动作，降一档，别跟真下载抢 */
.btn-main[data-quiet] {
  background: rgba(255, 255, 255, 0.08);
  color: var(--fg);
  box-shadow: inset 0 0 0 1px var(--line-2);
}

.btn-main[aria-pressed="true"] {
  box-shadow: inset 0 0 0 1px rgba(255, 210, 166, 0.55);
  color: var(--accent);
}

.dl-more {
  display: flex;
  gap: 8px;
}

.icon-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  color: var(--fg-2);
  background: rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: transform 160ms var(--ease-out), color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.icon-btn:active { transform: scale(0.97); }

.icon-btn[aria-pressed="true"] {
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 210, 166, 0.55);
}

/* 小图标的名字：悬停/聚焦时冒出来，从按钮方向长出 */
.icon-btn::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  padding: 5px 9px;
  border-radius: 8px;
  background: rgba(28, 28, 30, 0.92);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--fg);
  font-size: 12px;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 4px) scale(0.96);
  transform-origin: bottom center;
  transition: opacity 120ms ease, transform 120ms var(--ease-out);
}

.icon-btn:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

@media (hover: hover) and (pointer: fine) {
  .btn-main:not([data-quiet]):hover { background: #fff; }
  .btn-main[data-quiet]:hover { background: rgba(255, 255, 255, 0.12); }
  .icon-btn:hover {
    color: var(--fg);
    background: rgba(255, 255, 255, 0.1);
  }
  .icon-btn[aria-pressed="true"]:hover { color: var(--accent); }
  .icon-btn:hover::after {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
    transition-delay: 250ms;
  }
}

/* ———————————————— 领钥匙表单 ———————————————— */

.claim {
  position: relative;
  width: min(700px, 100%);
  margin-top: 22px;
}

.claim-fields {
  --p: 0%;
  --mx: 50%;
  --my: 50%;
  position: relative;
  display: flex;
  align-items: stretch;
  height: 58px;
  padding: 6px;
  border-radius: 999px;
  background: var(--glass);
  box-shadow: inset 0 0 0 1px var(--line);
  -webkit-backdrop-filter: blur(22px) saturate(1.3);
  backdrop-filter: blur(22px) saturate(1.3);
  transition: --p 520ms var(--ease-out), box-shadow 300ms ease;
}

/* 充能边线：三格每填好一格，暖白边线向右长三分之一 */
.claim-fields::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(90deg, rgba(255, 210, 166, 0.85) calc(var(--p) - 14%), rgba(255, 210, 166, 0) var(--p));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  pointer-events: none;
}

/* 指针高光：跟着鼠标走的一小片亮 */
.claim-fields::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(180px circle at var(--mx) var(--my), rgba(255, 255, 255, 0.07), transparent 70%);
  opacity: 0;
  transition: opacity 250ms ease;
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  .claim-fields:hover::after { opacity: 1; }
}

.field {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  border-radius: 999px;
  transition: background-color 150ms ease, opacity 180ms ease;
}

.field + .field::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 1px;
  height: 20px;
  margin-top: -10px;
  background: var(--line);
  transition: opacity 150ms ease;
}

.field:focus-within { background: rgba(255, 255, 255, 0.07); }

.field:focus-within::before,
.field:focus-within + .field::before { opacity: 0; }

.field input {
  width: 100%;
  min-width: 0;
  padding: 0 20px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--fg);
  font-size: 15px;
  caret-color: var(--accent);
  border-radius: inherit;
}

.field input::placeholder {
  color: var(--fg-3);
  transition: color 150ms ease;
}

.field:focus-within input::placeholder { color: rgba(245, 245, 247, 0.22); }

.field[data-invalid] input,
.field[data-invalid] input::placeholder { color: var(--warn); }

.field input:-webkit-autofill {
  -webkit-text-fill-color: var(--fg);
  transition: background-color 9999s ease-out;
}

.claim-btn {
  position: relative;
  flex: none;
  min-width: 108px;
  padding: 0 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--fg-2);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform 160ms var(--ease-out), background-color 220ms ease, color 220ms ease, opacity 180ms ease;
}

/* 三格都填好：按钮从灰玻璃变成实心白，等于告诉你「可以点了」 */
.claim[data-ready] .claim-btn {
  background: var(--fg);
  color: var(--ink);
}

.claim-btn:active { transform: scale(0.97); }

@media (hover: hover) and (pointer: fine) {
  .claim-btn:hover { background: rgba(255, 255, 255, 0.16); color: var(--fg); }
  .claim[data-ready] .claim-btn:hover { background: #fff; color: var(--ink); }
}

.claim-btn-label { transition: opacity 150ms ease; }

.dots {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  opacity: 0;
  transition: opacity 150ms ease;
}

.dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.3;
}

.claim[data-state="loading"] .claim-btn-label { opacity: 0; }
.claim[data-state="loading"] .dots { opacity: 1; }
.claim[data-state="loading"] .dots i { animation: dot 1s ease-in-out infinite; }
.claim[data-state="loading"] .dots i:nth-child(2) { animation-delay: 140ms; }
.claim[data-state="loading"] .dots i:nth-child(3) { animation-delay: 280ms; }
.claim[data-state="loading"] .field { opacity: 0.5; pointer-events: none; }

@keyframes dot {
  0%, 100% { opacity: 0.3; }
  40% { opacity: 1; }
}

.claim[data-state="locked"] .field,
.claim[data-state="locked"] .claim-btn {
  opacity: 0.38;
  pointer-events: none;
}

/* 完成态：三格和按钮淡出，同一个胶囊里换成一行结果 */
.claim-done {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 22px;
  font-size: 15px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 160ms ease, transform 160ms var(--ease-out), visibility 0s 160ms;
}

.claim-done svg {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--accent);
}

.done-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.done-actions {
  display: flex;
  gap: 2px;
  margin-left: 6px;
}

.link-btn {
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--fg-2);
  font-size: 13px;
  white-space: nowrap;
  transition: color 150ms ease, transform 160ms var(--ease-out);
}

.link-btn:active { transform: scale(0.97); }
.link-btn:disabled { color: var(--fg-3); cursor: default; }

@media (hover: hover) and (pointer: fine) {
  .link-btn:not(:disabled):hover { color: var(--fg); }
}

.claim[data-state="done"] .field,
.claim[data-state="done"] .claim-btn {
  opacity: 0;
  visibility: hidden;
  transition: opacity 160ms ease, visibility 0s 160ms;
}

.claim[data-state="done"] .claim-done {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 280ms ease 140ms, transform 280ms var(--ease-out) 140ms, visibility 0s;
}

.claim[data-state="done"] .claim-fields { --p: 100%; }

/* 钥匙粒子落进表单的那一下：边线亮一圈再收回去 */
.claim.is-landed .claim-fields { animation: landed 1100ms var(--ease-out); }

@keyframes landed {
  0% { box-shadow: inset 0 0 0 1px var(--line), 0 0 0 0 rgba(255, 200, 150, 0); }
  18% { box-shadow: inset 0 0 0 1px rgba(255, 220, 185, 0.9), 0 0 46px 2px rgba(255, 170, 110, 0.34); }
  100% { box-shadow: inset 0 0 0 1px var(--line), 0 0 60px 0 rgba(255, 170, 110, 0); }
}

/* 表单下面唯一一行小字：报错、名额告急、iPhone/安卓的一句话说明，同一时间只出现一种 */
.note {
  min-height: 20px;
  margin: 12px 0 0;
  font-size: 13px;
  line-height: 20px;
  color: var(--fg-2);
  transition: opacity 180ms ease;
}

.note:empty { opacity: 0; }
.note[data-kind="error"] { color: var(--warn); }

.note .link-btn {
  padding: 2px 6px;
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--fg-3);
}

/* ———————————————— 页脚 ———————————————— */

.foot {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.help {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  color: var(--fg-3);
  transition: color 150ms ease, transform 160ms var(--ease-out);
}

.help:active { transform: scale(0.97); }

@media (hover: hover) and (pointer: fine) {
  .help:hover { color: var(--fg-2); }
}

/* ———————————————— 帮助弹层 ———————————————— */

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 160ms ease, visibility 0s 160ms;
}

.modal[data-open] {
  opacity: 1;
  visibility: visible;
  transition: opacity 220ms ease, visibility 0s;
}

.modal-panel {
  width: min(400px, 100%);
  padding: 24px 24px 20px;
  border-radius: 20px;
  background: #121214;
  box-shadow: inset 0 0 0 1px var(--line), 0 30px 80px rgba(0, 0, 0, 0.6);
  text-align: left;
  transform: translateY(8px) scale(0.96);
  transition: transform 160ms var(--ease-out);
}

.modal[data-open] .modal-panel {
  transform: none;
  transition: transform 260ms var(--ease-out);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: -6px -8px -6px 0;
  border-radius: 50%;
  color: var(--fg-2);
  transition: background-color 150ms ease, color 150ms ease, transform 160ms var(--ease-out);
}

.modal-close svg { width: 14px; height: 14px; }
.modal-close:active { transform: scale(0.97); }

@media (hover: hover) and (pointer: fine) {
  .modal-close:hover { background: rgba(255, 255, 255, 0.08); color: var(--fg); }
}

.modal-body dl { margin: 0; }

.modal-body dt {
  margin-top: 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
}

.modal-body dt:first-child { margin-top: 0; }

.modal-body dd {
  margin: 3px 0 0;
  font-size: 14px;
  color: var(--fg-2);
}

.modal-body p {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--fg-2);
}

.modal-body code {
  display: block;
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--fg);
  word-break: break-all;
  user-select: all;
}

.modal-meta {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--fg-3);
  font-variant-numeric: tabular-nums;
}

.modal-meta:empty { display: none; }

/* ———————————————— 入场：文字逐行浮上来 ———————————————— */

.js .rise {
  opacity: 0;
  transform: translateY(10px);
  filter: blur(6px);
}

.js .is-ready .rise {
  opacity: 1;
  transform: none;
  filter: none;
  transition: opacity 800ms var(--ease-out), transform 800ms var(--ease-out), filter 800ms var(--ease-out);
  transition-delay: calc(var(--i, 0) * 70ms + 120ms);
}

/* ———————————————— 手机：表单竖排成一张卡 ———————————————— */

@media (max-width: 719px) {
  .page {
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
  }

  .top { height: 54px; }

  .stage { min-height: 130px; }

  .title { margin-top: -14px; font-size: clamp(32px, 9.4vw, 42px); }

  .sub { margin-top: 10px; }

  .dl { margin-top: 22px; width: 100%; gap: 8px; }

  .btn-main { flex: 1 1 0; min-width: 0; height: 48px; padding: 0 14px; gap: 8px; }

  .btn-main .ver { display: none; }

  .icon-btn { width: 46px; height: 46px; flex: none; }

  /* 最右一枚的名字靠右对齐，免得顶出屏幕 */
  .icon-btn:last-child::after {
    left: auto;
    right: 0;
    transform: translate(0, 4px) scale(0.96);
    transform-origin: bottom right;
  }

  .icon-btn:last-child:hover::after,
  .icon-btn:last-child:focus-visible::after { transform: translate(0, 0) scale(1); }

  .claim { margin-top: 14px; }

  .claim-fields {
    flex-direction: column;
    height: auto;
    padding: 6px;
    border-radius: 20px;
  }

  .field {
    flex: none;
    height: 48px;
    border-radius: 14px;
  }

  .field + .field::before {
    left: 16px;
    right: 16px;
    top: 0;
    width: auto;
    height: 1px;
    margin: 0;
  }

  /* 16px 起步，免得 iOS 聚焦输入框时自动放大页面 */
  .field input { font-size: 16px; padding: 0 16px; }

  .claim-btn {
    height: 48px;
    margin-top: 6px;
    border-radius: 14px;
    font-size: 16px;
  }

  .claim-done {
    flex-direction: column;
    gap: 6px;
  }

  .claim-done svg { width: 22px; height: 22px; }

  .done-text { white-space: normal; text-align: center; }

  .done-actions { margin: 2px 0 0; }

  .note { margin-top: 8px; }

  .foot { height: 44px; }
}

/* 矮屏（横屏手机、被压扁的窗口）：收紧间距，装不下就允许滚动 */
@media (max-width: 340px) {
  .dl { gap: 6px; }
  .btn-main { padding: 0 10px; gap: 6px; font-size: 14px; }
  .btn-main .btn-icon { display: none; }
  .icon-btn { width: 40px; height: 40px; }
}

@media (max-height: 640px) {
  .top { height: 46px; }
  .stage { min-height: 110px; }
  .dl { margin-top: 16px; }
  .claim { margin-top: 12px; }
  .foot { height: 40px; }
}

/* ———————————————— 减少动态效果：只留淡入淡出 ———————————————— */

@media (prefers-reduced-motion: reduce) {
  .js .rise {
    transform: none;
    filter: none;
  }

  .js .is-ready .rise {
    transition: opacity 300ms ease;
    transition-delay: 0s;
  }

  .claim-fields { transition: box-shadow 300ms ease; }

  .claim.is-landed .claim-fields { animation: none; }

  .claim[data-state="loading"] .dots i { animation: none; opacity: 0.7; }

  .claim-done,
  .modal-panel { transform: none; }

  .btn-main:active,
  .icon-btn:active,
  .claim-btn:active,
  .link-btn:active,
  .help:active,
  .modal-close:active { transform: none; }
}
