:root {
  --ink: #14100c;
  --ink-2: #1d1813;
  --surface: #221c16;
  --surface-2: #2b241c;
  --line: rgba(198, 161, 91, 0.18);
  --gold: #c6a15b;
  --gold-soft: #e2c98d;
  --gold-dim: rgba(198, 161, 91, 0.55);
  --text: #f2ece2;
  --text-2: #a89d8c;
  --text-3: #6f6659;
  --ok: #7fbf8a;
  --danger: #e0736b;
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --serif: "Noto Serif SC", "Songti SC", "SimSun", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

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

html, body {
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
  /* 禁止长按选中/拖拽，配合 JS 阻断长按保存 */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(198, 161, 91, 0.13), transparent 70%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(198, 161, 91, 0.06), transparent 70%);
  background-attachment: fixed;
}

img {
  display: block;
  -webkit-user-drag: none;
  user-drag: none;
  pointer-events: none;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input { font: inherit; }

.screen { display: none; }
.screen.active { display: block; }

/* ====================== 登录页 ====================== */
#login {
  min-height: 100dvh;
  display: none;
  flex-direction: column;
  justify-content: center;
  padding: calc(var(--safe-t) + 32px) 24px calc(var(--safe-b) + 32px);
}
#login.active { display: flex; }

.brand { text-align: center; margin-bottom: 40px; }

.brand-seal {
  width: 62px; height: 62px;
  margin: 0 auto 20px;
  border: 1.5px solid var(--gold-dim);
  border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--serif);
  font-size: 26px;
  color: var(--gold);
  letter-spacing: 1px;
  position: relative;
  background: linear-gradient(160deg, rgba(198,161,91,.12), transparent);
}
.brand-seal::after {
  content: "";
  position: absolute; inset: -7px;
  border: 1px solid rgba(198, 161, 91, 0.14);
  border-radius: 50%;
}

.brand h1 {
  font-family: var(--serif);
  font-size: 27px;
  font-weight: 600;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  color: var(--text);
}
.brand .sub {
  margin-top: 14px;
  font-size: 12.5px;
  letter-spacing: 0.22em;
  color: var(--text-3);
}

.rule {
  display: flex; align-items: center; gap: 12px;
  margin: 0 auto 34px; max-width: 240px;
}
.rule span { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--line), transparent); }
.rule i { color: var(--gold-dim); font-size: 9px; font-style: normal; }

.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 11.5px;
  letter-spacing: 0.2em;
  color: var(--text-3);
  margin-bottom: 10px;
}

#nameInput {
  width: 100%;
  padding: 17px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 20px;
  font-family: var(--serif);
  letter-spacing: 0.22em;
  text-align: center;
  outline: none;
  transition: border-color .22s, box-shadow .22s, background .22s;
  -webkit-user-select: text;
  user-select: text;
}
#nameInput::placeholder { color: var(--text-3); letter-spacing: 0.2em; font-size: 17px; }
#nameInput:focus {
  border-color: var(--gold-dim);
  background: var(--surface-2);
  box-shadow: 0 0 0 4px rgba(198, 161, 91, 0.09);
}

.counter {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 9px; font-size: 11px; color: var(--text-3); letter-spacing: .1em;
}
.counter b { color: var(--gold); font-weight: 600; }

.btn-primary {
  width: 100%;
  padding: 17px;
  margin-top: 10px;
  background: linear-gradient(150deg, var(--gold), #a8863f);
  color: #1a1409;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
  border-radius: var(--r-md);
  transition: transform .18s, box-shadow .22s, opacity .2s;
  box-shadow: 0 10px 30px -12px rgba(198, 161, 91, 0.75);
}
.btn-primary:active { transform: scale(.982); }
.btn-primary:disabled { opacity: .5; box-shadow: none; }

.hint {
  margin-top: 26px;
  font-size: 11.5px;
  line-height: 2;
  color: var(--text-3);
  text-align: center;
}
.hint b { color: var(--gold-dim); font-weight: 500; }

.err {
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--danger);
  text-align: center;
  min-height: 18px;
  letter-spacing: .05em;
}

/* ====================== 主页面 ====================== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  padding: calc(var(--safe-t) + 13px) 18px 13px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: rgba(20, 16, 12, 0.82);
  backdrop-filter: saturate(150%) blur(16px);
  -webkit-backdrop-filter: saturate(150%) blur(16px);
  border-bottom: 1px solid var(--line);
}
.topbar .who { min-width: 0; }
.topbar .who .nm {
  font-family: var(--serif);
  font-size: 16px; letter-spacing: .16em; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .who .st { margin-top: 3px; font-size: 10.5px; letter-spacing: .12em; color: var(--text-3); }

.chip {
  flex: none;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: .1em;
  color: var(--gold-soft);
  background: rgba(198, 161, 91, .07);
}
.chip.mine { color: #1a1409; background: linear-gradient(150deg, var(--gold), #a8863f); border-color: transparent; font-weight: 600; }

.notice {
  margin: 16px 16px 4px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: linear-gradient(160deg, rgba(198,161,91,.09), rgba(198,161,91,.02));
  font-size: 12.5px;
  line-height: 1.85;
  color: var(--text-2);
}
.notice b { color: var(--gold-soft); font-weight: 600; }
.notice.done { border-color: rgba(127,191,138,.3); background: linear-gradient(160deg, rgba(127,191,138,.1), transparent); }
.notice.done b { color: var(--ok); }

/* 交错瀑布流：CSS columns 天然错落 */
.grid {
  column-count: 2;
  column-gap: 10px;
  padding: 14px 12px calc(var(--safe-b) + 92px);
}
@media (min-width: 560px) { .grid { column-count: 3; column-gap: 13px; padding-inline: 16px; } }
@media (min-width: 900px) { .grid { column-count: 4; } }

.card {
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 10px;
  border-radius: var(--r-md);
  overflow: hidden;
  position: relative;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.045);
  transition: transform .24s cubic-bezier(.22,1,.36,1), box-shadow .24s, border-color .24s;
  animation: rise .5s cubic-bezier(.22,1,.36,1) backwards;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.97); } }

.card:active { transform: scale(.975); }

.card.is-mine {
  border-color: var(--gold-dim);
  box-shadow: 0 0 0 1px rgba(198,161,91,.35), 0 14px 34px -16px rgba(198,161,91,.5);
}

.card .ph {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
  background: var(--surface-2);
}

.card .veil {
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(10,8,6,.86) 0%, rgba(10,8,6,.24) 45%, transparent 72%);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px 9px;
  opacity: 0; transition: opacity .25s;
}
.card:active .veil { opacity: 1; }

.card .veil .act {
  font-size: 11.5px; letter-spacing: .16em; color: var(--gold-soft);
  padding: 8px 14px; border: 1px solid var(--gold-dim); border-radius: 999px;
  background: rgba(20,16,12,.66); backdrop-filter: blur(6px); white-space: nowrap;
}

.card .tag {
  position: absolute; top: 9px; left: 9px;
  padding: 5px 11px;
  font-size: 10.5px; letter-spacing: .14em; font-weight: 600;
  border-radius: 999px;
  background: linear-gradient(150deg, var(--gold), #a8863f);
  color: #1a1409;
  box-shadow: 0 5px 16px -6px rgba(198,161,91,.9);
}
.card .tag.taken {
  background: rgba(14, 11, 8, 0.86);
  color: #d9cfbe;
  border: 1px solid rgba(255, 255, 255, 0.16);
  font-weight: 500;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
/* 前置对勾，一眼区分"已领取"和编号 */
.card .tag.taken::before {
  content: "✓";
  margin-right: 4px;
  font-size: 10px;
  opacity: .85;
}

.card.taken .ph { filter: grayscale(.6) brightness(.5); }
/* 已被领走的卡不再响应点击反馈，避免误以为可领 */
.card.taken:active { transform: none; }
.card.taken .veil .act { color: var(--text-3); border-color: rgba(255,255,255,.14); }

/* 已领取高亮卡 */
.card.mine .tag { background: linear-gradient(150deg, #8fd39b, #5fa76d); color: #0d1a10; }

/* ====================== 底部已领取条 ====================== */
.dock {
  position: fixed;
  left: 0; right: 0; bottom: 0; z-index: 60;
  padding: 12px 16px calc(var(--safe-b) + 12px);
  display: flex; align-items: center; gap: 13px;
  background: rgba(24, 19, 14, 0.93);
  backdrop-filter: saturate(150%) blur(18px);
  -webkit-backdrop-filter: saturate(150%) blur(18px);
  border-top: 1px solid var(--line);
  transform: translateY(115%);
  transition: transform .4s cubic-bezier(.22,1,.36,1);
}
.dock.show { transform: translateY(0); }

.dock .pic {
  width: 52px; height: 52px; flex: none;
  border-radius: var(--r-sm); object-fit: cover;
  border: 1px solid var(--gold-dim);
}
.dock .txt { flex: 1; min-width: 0; }
.dock .txt .t1 {
  font-family: var(--serif); font-size: 14px; letter-spacing: .12em; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dock .txt .t2 { margin-top: 4px; font-size: 10.5px; letter-spacing: .1em; color: var(--text-3); }

.btn-dl {
  flex: none;
  padding: 12px 19px;
  border-radius: 999px;
  background: linear-gradient(150deg, var(--gold), #a8863f);
  color: #1a1409;
  font-size: 13px; font-weight: 600; letter-spacing: .1em;
  box-shadow: 0 8px 24px -10px rgba(198,161,91,.85);
  transition: transform .18s;
}
.btn-dl:active { transform: scale(.96); }
.btn-dl:disabled { opacity: .6; box-shadow: none; }

/* ====================== 弹层 ====================== */
.mask {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(8, 6, 4, 0.82);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  display: flex; align-items: center; justify-content: center;
  padding: 26px;
  opacity: 0; pointer-events: none;
  transition: opacity .28s;
}
.mask.show { opacity: 1; pointer-events: auto; }

.dialog {
  width: 100%; max-width: 330px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 26px 22px 20px;
  text-align: center;
  transform: scale(.93) translateY(10px);
  transition: transform .32s cubic-bezier(.22,1,.36,1);
}
.mask.show .dialog { transform: scale(1) translateY(0); }

.dialog .thumb-wrap {
  width: 100%; aspect-ratio: 1; border-radius: var(--r-md); overflow: hidden;
  margin-bottom: 18px; background: var(--surface-2);
  border: 1px solid rgba(255,255,255,.05);
}
.dialog .thumb-wrap img { width: 100%; height: 100%; object-fit: cover; }

.dialog h3 {
  font-family: var(--serif); font-size: 17.5px; font-weight: 600;
  letter-spacing: .14em; color: var(--text); margin-bottom: 9px;
}
.dialog p { font-size: 12.5px; line-height: 1.85; color: var(--text-2); }
.dialog p b { color: var(--gold-soft); }

.dialog .acts { display: flex; gap: 10px; margin-top: 21px; }
.dialog .acts button {
  flex: 1; padding: 13px; border-radius: var(--r-sm);
  font-size: 13.5px; letter-spacing: .12em; transition: transform .18s, background .2s;
}
.dialog .acts button:active { transform: scale(.97); }
.btn-ghost { border: 1px solid var(--line); color: var(--text-2); background: rgba(255,255,255,.02); }
.btn-solid { background: linear-gradient(150deg, var(--gold), #a8863f); color: #1a1409; font-weight: 600; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 104px); z-index: 300;
  transform: translate(-50%, 16px);
  padding: 12px 22px;
  background: rgba(38, 31, 24, .97);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px; letter-spacing: .06em; color: var(--text);
  opacity: 0; pointer-events: none;
  transition: opacity .26s, transform .26s;
  max-width: calc(100vw - 48px);
  text-align: center;
  box-shadow: 0 14px 40px -14px rgba(0,0,0,.9);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 骨架屏 */
.skeleton { padding: 14px 12px; column-count: 2; column-gap: 10px; }
.skeleton i {
  display: block; break-inside: avoid; margin-bottom: 10px;
  border-radius: var(--r-md);
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.35s linear infinite;
}
@keyframes shimmer { to { background-position: -220% 0; } }

.spin {
  width: 15px; height: 15px;
  border: 2px solid rgba(26,20,9,.32);
  border-top-color: #1a1409;
  border-radius: 50%;
  display: inline-block; vertical-align: -2px; margin-right: 8px;
  animation: sp .7s linear infinite;
}
@keyframes sp { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
