/* ================= 围住小猫 —— 布局与组件 ================= */

* { box-sizing: border-box; }

:root {
  --header-h: 56px;
  --ctrl-h: 76px;
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Noto Sans SC", "Noto Sans JP", "Noto Sans KR", sans-serif;
  --ease: cubic-bezier(.4, 0, .2, 1);
}

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  transition: background-color .25s var(--ease), color .25s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; }

/* ---------------- 顶栏 ---------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 14px;
  background: var(--header-bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
a.brand { text-decoration: none; color: inherit; }
a.brand:hover .brand-title { color: var(--accent-2); }
.brand img { display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-title { font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand-sub { font-size: 11px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.header-actions { display: flex; align-items: center; gap: 8px; }

.lang-select {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 6px 8px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}

.icon-btn {
  width: 34px; height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  transition: transform .15s var(--ease), background-color .2s var(--ease);
}
.icon-btn:hover { transform: translateY(-1px); background: var(--hover); }
.icon-btn:active { transform: scale(.94); }

.auth-area { display: flex; align-items: center; gap: 6px; }

/* 顶栏登录提示（匿名时显示，窄屏隐藏避免挤压） */
.login-hint {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}
@media (max-width: 900px) {
  .login-hint { display: none; }
}

.user-chip {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
  max-width: 160px;
}
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-2);
  color: #fff; font-size: 13px; font-weight: 700;
  display: grid; place-items: center;
}
.user-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- 主区 ---------------- */

.game-layout { flex: 1; min-height: 0; }

.game-stage {
  height: calc(100dvh - var(--header-h) - var(--ctrl-h));
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 10px;
}

.status-line {
  min-height: 26px;
  font-size: 14px;
  color: var(--accent-2);
  font-weight: 600;
  text-align: center;
}

.canvas-wrap {
  flex: 1;
  width: min(92vw, 640px);
  max-height: 100%;
  display: grid;
  place-items: center;
  position: relative;
}
#board { display: block; touch-action: manipulation; }

/* ---------------- 控制栏 ---------------- */

.control-bar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  min-height: var(--ctrl-h);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 18px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--header-bg);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.hud { display: flex; gap: 16px; }
.hud-item {
  display: flex; flex-direction: column; align-items: center;
  font-size: 11px; color: var(--text-2);
  min-width: 52px;
}
.hud-item b { font-size: 19px; color: var(--text); font-variant-numeric: tabular-nums; }

.ctrl-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; justify-content: center; }

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--card);
}
.seg button {
  border: none;
  background: transparent;
  color: var(--text-2);
  padding: 9px 16px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .2s var(--ease), color .2s var(--ease);
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--accent-2); color: #fff; font-weight: 600; }
.seg-sm button { padding: 6px 12px; font-size: 12px; }

.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .15s var(--ease), filter .2s var(--ease), background-color .2s var(--ease);
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-sm { padding: 7px 14px; font-size: 13px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent-2); color: #fff; }
.btn-orange { background: var(--accent); color: #fff; }
.btn-ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); }

/* ---------------- 弹窗 ---------------- */

.modal-mask {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 14, 20, .55);
  display: grid; place-items: center;
  padding: 18px;
  opacity: 0; pointer-events: none;
  visibility: hidden; /* 关闭时从无障碍树移除、不可聚焦 */
  transition: opacity .22s var(--ease), visibility 0s linear .22s;
}
.modal-mask.show {
  opacity: 1; pointer-events: auto;
  visibility: visible;
  transition: opacity .22s var(--ease);
}

.modal {
  width: min(94vw, 420px);
  max-height: 86dvh;
  overflow: auto;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .25);
  padding: 22px;
  position: relative;
  transform: translateY(14px) scale(.97);
  transition: transform .22s var(--ease);
}
.modal-mask.show .modal { transform: none; }
.modal-wide { width: min(94vw, 460px); }

.modal h2 { margin: 0 0 14px; font-size: 19px; }
.modal h2.win { color: var(--ok); }
.modal h2.lose { color: var(--danger); }

.modal-close {
  position: absolute; top: 12px; right: 12px;
  width: 30px; height: 30px;
  border-radius: 9px; border: 1px solid var(--line);
  background: transparent; color: var(--text-2);
  cursor: pointer; font-size: 13px;
}
.modal-close:hover { background: var(--hover); }

.modal-actions {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
  margin-top: 18px;
}

.res-detail { color: var(--text-2); font-size: 14px; line-height: 1.7; text-align: center; }
.res-detail p { margin: 4px 0; }

/* ---------------- 排行榜 ---------------- */

.rank-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.rank-tabs button {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--card); color: var(--text-2);
  border-radius: 10px; padding: 8px 0; font-size: 13px; cursor: pointer;
}
.rank-tabs button.active { background: var(--accent-2); color: #fff; border-color: var(--accent-2); font-weight: 600; }

.rank-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

.rank-notice { font-size: 12px; color: var(--text-3); min-height: 16px; margin-bottom: 4px; }

.rank-list { max-height: 46dvh; overflow-y: auto; overscroll-behavior: contain; }

/* 列表头（与行同列宽） */
.rank-head {
  display: flex; align-items: center; gap: 10px;
  padding: 2px 6px 6px;
  font-size: 11px; color: var(--text-3);
}
.rank-head .rk { width: 38px; text-align: center; flex-shrink: 0; }
.rank-head .nm { flex: 1; min-width: 0; }
.rank-head .du, .rank-row .du { width: 46px; text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.rank-head .st { width: 56px; text-align: right; flex-shrink: 0; }

.rank-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.rank-row .rk { width: 38px; text-align: center; font-weight: 700; color: var(--text-2); flex-shrink: 0; }
.rank-row.top0 .rk, .rank-row.top1 .rk, .rank-row.top2 .rk { font-size: 16px; }
.rank-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.rank-row .flag { margin-right: 5px; }
.rank-row .du { color: var(--text-2); font-size: 12px; }
.rank-row .st { color: var(--accent-2); font-weight: 700; flex-shrink: 0; width: 56px; text-align: right; }
.rank-row.local .nm { color: var(--accent); }

.rank-empty { text-align: center; color: var(--text-3); padding: 26px 0; font-size: 13px; }

.rank-me {
  display: flex; align-items: center; gap: 10px;
  border-top: 2px solid var(--line);
  margin-top: 4px; padding-top: 10px;
  font-size: 13px; font-weight: 600;
}
.rank-me .rk { color: var(--accent); }
.rank-me .nm { flex: 1; }
.rank-me .st { color: var(--accent-2); }

.rank-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 10px; font-size: 12px; color: var(--text-3);
}

/* ---------------- 认证表单 ---------------- */

.auth-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.auth-tabs button {
  flex: 1;
  border: 1px solid var(--line);
  background: transparent; color: var(--text-2);
  border-radius: 10px; padding: 7px 0; font-size: 12px; cursor: pointer;
}
.auth-tabs button.active { background: var(--accent-2); color: #fff; border-color: var(--accent-2); font-weight: 600; }

.auth-form { display: flex; flex-direction: column; gap: 12px; }

/* 登录/注册弹窗顶部动机提示 */
.auth-banner {
  background: linear-gradient(135deg, rgba(255, 140, 66, .12), rgba(46, 134, 171, .12));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text-2);
  text-align: center;
  margin-bottom: 14px;
}
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-2); }
.auth-form input {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color .2s var(--ease);
}
.auth-form input:focus { border-color: var(--accent-2); }

.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; min-width: 0; letter-spacing: 4px; }

.field-tip { font-size: 11px; color: var(--text-3); margin-top: -2px; }
.auth-error { color: var(--danger); font-size: 13px; min-height: 18px; }

.auth-links { display: flex; justify-content: center; gap: 14px; }
.linklike {
  border: none; background: none; color: var(--accent-2);
  font-size: 12px; cursor: pointer; padding: 2px;
}

/* ---------------- 引导 / Toast ---------------- */

.guide-list { margin: 0; padding-left: 20px; color: var(--text-2); font-size: 14px; line-height: 2; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--ctrl-h) + 18px);
  transform: translate(-50%, 12px);
  background: var(--toast-bg); color: #fff;
  padding: 10px 18px; border-radius: 12px;
  font-size: 13px;
  opacity: 0; pointer-events: none;
  transition: opacity .25s var(--ease), transform .25s var(--ease);
  z-index: 80;
  max-width: 86vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- 桌面双栏（≥1200px 预留侧栏空间） ---------------- */

@media (min-width: 1200px) {
  .canvas-wrap { width: min(70vw, 760px); }
  .brand-sub { font-size: 12px; }
}

/* ---------------- 移动端 ---------------- */

/* 移动端顶栏只留图标 */
@media (max-width: 768px) {
  .brand-text { display: none; }
}

@media (max-width: 480px) {
  .lang-select { max-width: 96px; }
  .btn { padding: 9px 14px; font-size: 13px; }
  .hud { gap: 10px; }
}

/* 减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* 焦点可见性（无障碍） */
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
