:root {
  --bg: #fff8ec;
  --grass: #cfe8b0;
  --ink: #5b4636;
  --text: #3b2a20;
  --muted: #7a6352;
  --line: #e8d5bd;
  --accent: #ff8a65;
  --gold: #ffd36e;
  --pink: #ff7a8a;
  --rare: #5b8def;
  --epic: #9b6bdf;
  --legend: #e0a800;
  --font: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --hand: "ZCOOL KuaiLe", "Noto Sans SC", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--grass); color: var(--text); font-family: var(--font); }
body { overscroll-behavior: none; touch-action: none; user-select: none; -webkit-user-select: none; }
input { user-select: text; -webkit-user-select: text; }
.hidden { display: none !important; }

#world { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#world.dragging { cursor: grabbing; }

button { font-family: var(--font); color: var(--text); cursor: pointer; }
.btn { height: 44px; padding: 0 18px; border-radius: 999px; border: 2px solid var(--ink); background: #fff; font-weight: 700; font-size: 15px; }
.btn.primary { background: var(--accent); border-width: 3px; }
.btn.gold { background: var(--gold); }
.btn.pinkish { background: #ffe1e6; }
.btn.big { height: 52px; font-size: 16px; width: 100%; }
.btn.small { height: 34px; padding: 0 12px; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:active:not(:disabled) { transform: translateY(1px); }

.tip { padding: 10px 14px; border-radius: 14px; font-size: 13px; line-height: 1.6; }
.tip.green { background: #eef6e4; }
.tip.pink { background: #ffeef1; }
.tip.purple { background: #f1e8ff; }
.hint { font-size: 12px; color: var(--muted); text-align: center; }

/* ---------- 登录 ---------- */
.screen { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; flex-direction: column; align-items: center; overflow-y: auto; }
#login-art { width: 100%; max-width: 520px; height: auto; display: block; }
.brand { margin: 4px 0 0; font-family: var(--hand); font-weight: 400; font-size: 44px; }
.sub { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.login-form { width: 100%; max-width: 420px; padding: 20px 24px 32px; display: flex; flex-direction: column; gap: 12px; }
.login-form label, .birth-panel label { font-weight: 700; font-size: 14px; }
.login-form input, .birth-panel input, .sheet input { height: 50px; padding: 0 16px; border-radius: 16px; border: 3px solid var(--line); background: #fff; font: 400 16px var(--font); color: var(--text); outline: none; }
.login-form input:focus, .birth-panel input:focus, .sheet input:focus { border-color: var(--accent); }

/* ---------- HUD ---------- */
#hud { position: fixed; z-index: 10; top: calc(10px + var(--safe-t)); left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; pointer-events: none; }
#hud > * { pointer-events: auto; }
.me-chip { display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 8px; border-radius: 999px; background: var(--bg); border: 2px solid var(--ink); }
.me-chip .dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--ink); }
.me-name { font-weight: 700; font-size: 14px; line-height: 1.2; }
.me-title { font-size: 11px; color: var(--muted); line-height: 1.2; }
.hud-btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.pill { height: 38px; padding: 0 14px; border-radius: 999px; border: 2px solid var(--ink); background: var(--bg); font-weight: 700; font-size: 14px; }
.pill b { color: #c2562f; }
.pill.icon { width: 38px; padding: 0; display: flex; align-items: center; justify-content: center; }
.online { position: fixed; z-index: 9; top: calc(60px + var(--safe-t)); left: 12px; padding: 4px 10px; border-radius: 999px; background: rgba(255,248,236,0.85); font-size: 12px; color: var(--muted); }

.zoom { position: fixed; z-index: 10; right: 12px; bottom: calc(160px + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; }
.round { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--ink); background: var(--bg); font-size: 22px; font-weight: 700; line-height: 1; padding: 0; }
.round.small { font-size: 12px; }
.minimap { position: fixed; z-index: 10; right: 12px; bottom: calc(12px + var(--safe-b)); width: 200px; height: 134px; border-radius: 14px; border: 2px solid var(--ink); background: #cfe8b0; }

.pick-banner { position: fixed; z-index: 12; left: 50%; transform: translateX(-50%); top: calc(64px + var(--safe-t)); display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 16px; border-radius: 999px; background: #ffe1e6; border: 2px solid var(--ink); font-weight: 700; font-size: 14px; white-space: nowrap; }

/* ---------- 选中卡片 ---------- */
.card { position: fixed; z-index: 11; left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--safe-b)); width: min(560px, calc(100% - 24px)); padding: 12px 14px; border-radius: 22px; background: var(--bg); border: 3px solid var(--ink); display: grid; grid-template-columns: 96px 1fr; gap: 6px 12px; align-items: center; }
#card-art { width: 96px; height: 77px; grid-row: span 1; }
.card-body { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.card-head { display: flex; align-items: center; gap: 8px; padding-right: 24px; }
.card-head b { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px; color: #fff; background: #8a7a6a; white-space: nowrap; }
.tag.rare { background: var(--rare); } .tag.epic { background: var(--epic); } .tag.legendary { background: var(--legend); }
.card-meta { font-size: 12px; color: var(--muted); }
.card-status { font-size: 13px; font-weight: 700; color: #4f7a2e; }
.card-status.warn { color: #a85a00; } .card-status.preg { color: #c2405a; }
.bar { height: 8px; border-radius: 4px; background: #f1ece4; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .3s; }
.card-actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.card-actions .btn { flex: 1 1 auto; height: 42px; font-size: 14px; padding: 0 12px; }
.close { position: absolute; top: 6px; right: 8px; width: 32px; height: 32px; border: 0; background: none; font-size: 24px; color: var(--muted); }

/* ---------- 提示 ---------- */
.toasts { position: fixed; z-index: 30; top: calc(104px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; width: max-content; max-width: calc(100% - 24px); }
.toast { padding: 8px 16px; border-radius: 999px; background: rgba(59,42,32,0.88); color: #fff8ec; font-size: 13px; animation: pop .25s ease-out; text-align: center; }
.announce { position: fixed; z-index: 29; top: calc(64px + var(--safe-t)); left: 50%; transform: translateX(-50%); padding: 8px 18px; border-radius: 16px; border: 2px solid var(--ink); background: #f1e8ff; font-weight: 700; font-size: 14px; max-width: calc(100% - 24px); text-align: center; animation: pop .3s ease-out; }
.announce.legendary { background: #fff3c4; }
@keyframes pop { from { transform: translateX(var(--tx, 0)) scale(.85); opacity: 0; } to { opacity: 1; } }
.ach-pop { position: fixed; z-index: 40; top: calc(14px + var(--safe-t)); left: 50%; transform: translateX(-50%); padding: 10px 16px; border-radius: 16px; background: var(--gold); border: 2px solid var(--ink); font-size: 14px; display: flex; gap: 8px; align-items: center; animation: drop .4s ease-out; width: max-content; max-width: calc(100% - 24px); }
@keyframes drop { from { transform: translate(-50%, -30px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.conn { position: fixed; z-index: 60; left: 50%; bottom: 40%; transform: translateX(-50%); padding: 10px 18px; border-radius: 999px; background: rgba(59,42,32,0.85); color: #fff8ec; font-size: 14px; }

/* ---------- 弹层页面 ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(59,42,32,0.35); display: flex; justify-content: center; align-items: center; }
.sheet-panel { width: min(520px, 100%); height: min(780px, 100%); background: var(--bg); border-radius: 28px; border: 3px solid var(--ink); display: flex; flex-direction: column; overflow: hidden; }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; padding-top: calc(16px + var(--safe-t)); }
.sheet-head h2 { margin: 0; flex-grow: 1; font-family: var(--hand); font-weight: 400; font-size: 26px; }
.sheet-extra { font-weight: 700; }
.back { width: 44px; height: 44px; border-radius: 50%; background: #fff; border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; color: var(--ink); padding: 0; }
.sheet-body { flex: 1; overflow-y: auto; padding: 0 16px 24px; padding-bottom: calc(24px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; touch-action: pan-y; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { height: 34px; padding: 0 12px; border-radius: 999px; border: 2px solid var(--line); background: #fff; font-weight: 700; font-size: 13px; }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.row { padding: 10px 12px; border-radius: 18px; background: #fff; border: 3px solid var(--line); display: flex; align-items: center; gap: 10px; }
.row canvas { width: 64px; height: 51px; flex: none; }
.row .grow { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row .t { font-weight: 700; }
.row .t span { font-weight: 400; font-size: 12px; color: var(--muted); }
.row .s { font-size: 12px; color: var(--muted); }
.row .btn { height: 40px; padding: 0 12px; font-size: 13px; flex: none; }
.row.preg { border-color: #ffb3bf; } .row.hungry { border-color: #f5c48a; } .row.rare { border-color: var(--rare); } .row.epic { border-color: var(--epic); } .row.legendary { border-color: var(--legend); }
.foot-note { margin-top: auto; font-size: 12px; color: var(--muted); padding-top: 8px; }

.dex-progress { height: 12px; border-radius: 6px; background: #f1ece4; border: 2px solid var(--line); overflow: hidden; }
.dex-progress i { display: block; height: 100%; background: var(--accent); }
.tier h3 { margin: 6px 0 8px; font-size: 14px; }
.tier.legendary h3 { color: #8a6500; } .tier.epic h3 { color: #7440c0; } .tier.rare h3 { color: #2f5fc4; }
.grid { display: grid; gap: 8px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cell { padding: 8px 4px; border-radius: 16px; background: #fff; border: 3px dashed var(--line); display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; color: var(--muted); }
.cell canvas { width: 80px; height: 64px; }
.cell.got { border-style: solid; color: var(--text); }
.tier.rare .cell { border-color: #b3c8f2; } .tier.rare .cell.got { border-color: var(--rare); }
.tier.epic .cell { border-color: #c9b3ea; } .tier.epic .cell.got { border-color: var(--epic); }
.tier.legendary .cell { border-color: #e8c766; } .tier.legendary .cell.got { border-color: var(--legend); }

.title-box { padding: 14px 16px; border-radius: 20px; background: var(--gold); border: 3px solid var(--ink); display: flex; align-items: center; gap: 12px; }
.title-box .big { font-family: var(--hand); font-size: 24px; }
.ach { padding: 10px 12px; border-radius: 16px; background: #fff; border: 2px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.ach .top { display: flex; align-items: center; gap: 12px; }
.badge { width: 40px; height: 40px; border-radius: 50%; flex: none; background: #f1ece4; border: 2px dashed #b0a090; display: flex; align-items: center; justify-content: center; }
.badge.done { background: var(--gold); border: 2px solid var(--ink); }
.ach .n { font-weight: 700; }
.ach .d { font-size: 12px; color: var(--muted); }
.ach .p { font-size: 12px; font-weight: 700; white-space: nowrap; }
.ach .p.done { color: #4f7a2e; }
.ach .pb { height: 8px; border-radius: 4px; background: #f1ece4; overflow: hidden; }
.ach .pb i { display: block; height: 100%; border-radius: 4px; }
.titles { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- 邀请 / 出生 ---------- */
.modal { position: fixed; inset: 0; z-index: 35; background: rgba(59,42,32,0.55); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-panel { width: min(400px, 100%); padding: 24px 20px 18px; border-radius: 28px; background: var(--bg); border: 3px solid var(--ink); display: flex; flex-direction: column; gap: 14px; }
.modal-panel h2 { margin: 0; font-family: var(--hand); font-weight: 400; font-size: 24px; text-align: center; }
#inv-art { align-self: center; width: 100%; max-width: 306px; height: auto; }
.pair-cards, .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mini { padding: 10px; border-radius: 16px; background: #fff; border: 2px solid var(--line); }
.mini b { display: block; }
.mini span { font-size: 12px; color: var(--muted); }

.birth { position: fixed; inset: 0; z-index: 36; background: #3d2f4f; overflow: hidden; }
#birth-art { position: absolute; inset: 0; width: 100%; height: 100%; }
.birth-badge { position: absolute; left: 50%; top: 14%; transform: translateX(-50%); padding: 6px 20px; border-radius: 999px; background: #8a7a6a; border: 3px solid var(--bg); font-family: var(--hand); font-size: 22px; color: var(--bg); white-space: nowrap; }
.birth-panel { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(28px + var(--safe-b)); width: min(400px, calc(100% - 40px)); padding: 22px 20px 20px; border-radius: 28px; background: var(--bg); border: 3px solid var(--ink); display: flex; flex-direction: column; gap: 12px; }
.birth-panel h2 { margin: 0; font-family: var(--hand); font-weight: 400; font-size: 24px; text-align: center; }

.menu-list { display: flex; flex-direction: column; gap: 10px; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; background: #fff; border: 2px dashed var(--line); border-radius: 12px; padding: 10px; user-select: text; -webkit-user-select: text; }

.emote-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

/* ---------- 手机 ---------- */
@media (max-width: 720px) {
  #hud { flex-direction: column; align-items: stretch; gap: 6px; }
  .me-chip { align-self: flex-start; }
  .hud-btns { justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto; }
  .pill { height: 36px; padding: 0 12px; font-size: 13px; flex: none; }
  .online { top: auto; bottom: calc(14px + var(--safe-b)); left: 12px; }
  .minimap { width: 120px; height: 80px; top: calc(108px + var(--safe-t)); bottom: auto; }
  .zoom { bottom: calc(14px + var(--safe-b)); }
  body.has-card .zoom { display: none; }
  .pick-banner, .announce { top: calc(110px + var(--safe-t)); }
  .toasts { top: calc(150px + var(--safe-t)); }
  .sheet { align-items: stretch; }
  .sheet-panel { height: 100%; border-radius: 0; border: 0; }
  .card { grid-template-columns: 76px 1fr; bottom: calc(10px + var(--safe-b)); }
  #card-art { width: 76px; height: 61px; }
}
