/* ==========================================================================
   五子棋 · 在线对弈  ——  极简木质棋院风 / 移动端 App 壳
   ========================================================================== */

:root {
  --page-bg: #ece3d6;
  --paper: #f7f3ec;
  --paper-2: #fffdf8;
  --wood: #e3c08d;
  --wood-light: #eecfa3;
  --wood-dark: #d2a96f;
  --line: #8a6a3b;
  --ink: #1f1b16;
  --white-stone: #fdfcf9;
  --accent: #c0392b;
  --accent-dark: #9b2d22;
  --accent-soft: #f7e2dd;
  --text: #3a322a;
  --muted: #8c7e6c;
  --border: #e3d8c7;
  --win: #2f7d5a;
  --draw: #a98a4b;
  --shadow-phone: 0 30px 70px rgba(58, 50, 42, 0.34), 0 4px 14px rgba(58, 50, 42, 0.18);
  --font-sans: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --font-serif: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--text);
  font-family: var(--font-sans);
  background:
    radial-gradient(circle at 50% -10%, #fbf7f0 0%, #ece3d6 46%, #e0d4c1 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  background-image:
    repeating-linear-gradient(96deg, rgba(138, 106, 59, 0.05) 0 2px, transparent 2px 7px),
    repeating-linear-gradient(4deg, rgba(138, 106, 59, 0.035) 0 3px, transparent 3px 11px);
}

/* ------------------------------- 手机外框 -------------------------------- */

.stage {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.phone {
  width: 390px;
  height: 844px;
  flex: none;
  padding: 11px;
  border-radius: 52px;
  background: linear-gradient(160deg, #38332b 0%, #211d18 52%, #332d26 100%);
  box-shadow: var(--shadow-phone), inset 0 0 0 2px rgba(255, 255, 255, 0.06);
  transform: scale(var(--phone-scale, 1));
  transform-origin: center center;
}

.phone__inner {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 42px;
  background: var(--paper);
}

/* 顶部状态栏 */
.statusbar {
  flex: none;
  height: 44px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
  background: transparent;
  user-select: none;
}

.statusbar__icons { display: flex; align-items: center; gap: 5px; }
.statusbar__icons svg { display: block; }

/* 屏幕内容 */
.screen {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.view {
  position: absolute;
  inset: 0;
  padding: 14px 18px 20px;
  overflow-y: auto;
  overflow-x: hidden;
  opacity: 0;
  transform: translateY(10px) scale(0.995);
  pointer-events: none;
  transition: opacity 0.26s ease, transform 0.3s cubic-bezier(0.22, 0.8, 0.3, 1);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.view::-webkit-scrollbar { display: none; }

.view.is-active {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* ------------------------------- 底部 Tab -------------------------------- */

.tabbar {
  flex: none;
  height: 66px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  padding: 0 10px 6px;
  background: rgba(255, 253, 248, 0.94);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(12px);
  z-index: 30;
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 56px;
  border-radius: 14px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease;
}

.tab svg { width: 22px; height: 22px; }
.tab.is-active { color: var(--accent); background: var(--accent-soft); }
.tab:active { transform: scale(0.96); }

/* ------------------------------- 通用组件 -------------------------------- */

.btn {
  appearance: none;
  border: 0;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border-radius: 14px;
  padding: 12px 16px;
  color: var(--text);
  background: var(--paper-2);
  border: 1px solid var(--border);
  transition: transform 0.12s ease, background 0.16s ease, box-shadow 0.16s ease, color 0.16s ease;
}

.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn--primary {
  background: linear-gradient(180deg, #cb4433 0%, var(--accent) 60%, var(--accent-dark) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 18px rgba(192, 57, 43, 0.26);
}

.btn--ghost { background: var(--paper-2); }

.btn--text {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 8px;
}

.btn--xl {
  padding: 16px 18px;
  border-radius: 18px;
  font-size: 16.5px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.btn--xl .btn__icon {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.2);
  font-size: 20px;
}

.btn--ghost.btn--xl .btn__icon { background: #f0e6d6; }

.btn__txt { display: flex; flex-direction: column; gap: 2px; }
.btn__txt small { font-weight: 500; font-size: 11.5px; opacity: 0.72; letter-spacing: 0.01em; }

.card {
  background: var(--paper-2);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px;
}

.muted { color: var(--muted); }
.serif { font-family: var(--font-serif); }

/* ------------------------------- 首页 ------------------------------------ */

.home__head { padding: 6px 2px 14px; display: flex; align-items: center; justify-content: space-between; }

.brand { display: flex; align-items: center; gap: 12px; }

.brand__seal {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, #cb4433, var(--accent-dark));
  box-shadow: 0 6px 14px rgba(192, 57, 43, 0.28);
}

.brand h1 { margin: 0; font-family: var(--font-serif); font-size: 25px; letter-spacing: 0.06em; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); letter-spacing: 0.14em; }

.home__me {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  background: linear-gradient(120deg, #fffdf8, #f5ecdd);
}

.avatar {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 21px;
  background: radial-gradient(circle at 32% 28%, #fbf4e7, #e8d8be);
  border: 1px solid var(--border);
  position: relative;
  user-select: none;
}

.avatar--sm { width: 34px; height: 34px; font-size: 17px; }
.avatar--lg { width: 72px; height: 72px; font-size: 36px; border-width: 2px; }

.avatar__dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--paper-2);
  display: none;
}

.is-turn .avatar__dot { display: block; }

.home__me-info { min-width: 0; flex: 1; }
.home__me-info b { display: block; font-size: 15px; }
.home__me-info span { font-size: 12px; color: var(--muted); }

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

.home__last { margin-top: 18px; display: flex; align-items: center; gap: 12px; }
.last__seal {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-family: var(--font-serif);
  font-weight: 700;
  background: #f2e8d8;
  color: var(--text);
}
.last__seal.win { background: #e2f0e8; color: var(--win); }
.last__seal.lose { background: var(--accent-soft); color: var(--accent); }
.last__seal.draw { background: #f3ecd9; color: var(--draw); }
.last__body { flex: 1; min-width: 0; }
.last__body b { display: block; font-size: 14px; }
.last__body span { font-size: 11.5px; color: var(--muted); }

.home__tip {
  margin-top: 18px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px dashed var(--border);
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
  background: rgba(255, 253, 248, 0.6);
}

.home__tip b { color: var(--text); }

/* ------------------------------ 子页头部 --------------------------------- */

.subhead {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.subhead h2 { margin: 0; font-family: var(--font-serif); font-size: 18px; letter-spacing: 0.04em; }

.iconbtn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--paper-2);
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 18px;
  color: var(--text);
  flex: none;
}
.iconbtn:active { transform: scale(0.94); }

/* ------------------------------ 创建房间 --------------------------------- */

.create__code { text-align: center; padding: 22px 16px; }
.create__code > p { margin: 0 0 10px; font-size: 12.5px; color: var(--muted); }

.code-display {
  font-family: var(--font-serif);
  font-size: 46px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 6px;
  text-shadow: 0 2px 0 rgba(192, 57, 43, 0.1);
}

.code-sub { font-size: 11.5px; color: var(--muted); margin-bottom: 16px; }

.create__row { display: flex; gap: 10px; }
.create__row .btn { flex: 1; }

.create__wait { margin-top: 14px; text-align: center; padding: 20px 16px; }
.create__wait p { margin: 10px 0 0; font-size: 14px; font-weight: 600; }

.spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid #eadfce;
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
.spinner--sm { width: 14px; height: 14px; border-width: 2px; }

@keyframes spin { to { transform: rotate(360deg); } }

.share-link {
  margin-top: 14px;
  font-size: 11px;
  color: var(--muted);
  word-break: break-all;
  background: #f3ecdf;
  border-radius: 10px;
  padding: 9px 11px;
  text-align: left;
  line-height: 1.5;
}

/* ------------------------------ 对局页 ----------------------------------- */

.view[data-view="game"] { display: flex; flex-direction: column; overflow: hidden; padding: 12px 16px 16px; }

.gamebar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0 10px;
}

.player { display: flex; align-items: center; gap: 8px; flex: 1 1 0; min-width: 0; }
.player--opp { flex-direction: row-reverse; text-align: right; }

.player__info { min-width: 0; }
.player__info b {
  display: block;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 82px;
}
.player__info span { font-size: 10.5px; color: var(--muted); }

.roomchip {
  flex: none;
  text-align: center;
  padding: 5px 9px;
  border-radius: 11px;
  background: #f0e7d8;
  border: 1px solid var(--border);
}
.roomchip b { display: block; font-size: 13px; letter-spacing: 0.1em; font-family: var(--font-serif); }
.roomchip span { font-size: 9.5px; color: var(--muted); }

.statusline {
  flex: none;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  transition: color 0.2s ease;
}
.statusline.is-me { color: var(--accent); }
.statusline.is-opp { color: var(--muted); }
.statusline.is-result { color: var(--text); }

.boardbox {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px 0;
}

.board-svg { width: 100%; height: 100%; display: block; touch-action: manipulation; cursor: pointer; }
.board-svg.is-locked { cursor: default; }
.board-svg.shake { animation: boardshake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97); }

@keyframes boardshake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}

.metaRow {
  flex: none;
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 11.5px;
  color: var(--muted);
  padding: 8px 0 10px;
}
.metaRow b { color: var(--text); font-variant-numeric: tabular-nums; }

.gameactions { flex: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.gameactions .btn { padding: 13px 6px; font-size: 13.5px; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.gameactions .btn svg { width: 18px; height: 18px; }

.offline-tip {
  position: absolute;
  left: 50%;
  top: 98px;
  transform: translateX(-50%) translateY(-6px);
  background: rgba(58, 50, 42, 0.92);
  color: #fff;
  font-size: 11.5px;
  padding: 7px 12px;
  border-radius: 999px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 35;
}
.offline-tip.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 棋子动画由 SVG 内部完成 */
.stone--drop { animation: drop 0.24s ease-out; transform-box: fill-box; transform-origin: center; }
@keyframes drop {
  0% { transform: scale(1.55); opacity: 0; }
  65% { transform: scale(0.94); opacity: 1; }
  100% { transform: scale(1); }
}
.winring { animation: pulse 1.3s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }

/* ------------------------------ 战绩页 ----------------------------------- */

.page-title { font-family: var(--font-serif); font-size: 22px; margin: 6px 2px 14px; letter-spacing: 0.04em; }

.statgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.statcard {
  background: var(--paper-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 6px;
  text-align: center;
}
.statcard b { display: block; font-family: var(--font-serif); font-size: 23px; line-height: 1.2; }
.statcard span { font-size: 11px; color: var(--muted); }

.record {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px;
  border-radius: 15px;
  background: var(--paper-2);
  border: 1px solid var(--border);
  margin-bottom: 9px;
}
.record__main { flex: 1; min-width: 0; }
.record__main b { display: block; font-size: 14px; }
.record__main span { font-size: 11px; color: var(--muted); }
.tag {
  flex: none;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 11px;
  border-radius: 999px;
}
.tag.win { background: #e2f0e8; color: var(--win); }
.tag.lose { background: var(--accent-soft); color: var(--accent); }
.tag.draw { background: #f3ecd9; color: var(--draw); }

/* 全局排名 */
.rank-note { font-weight: 400; font-size: 10.5px; color: var(--muted); margin-left: 6px; }

.ranklist { margin-bottom: 4px; }

.rank-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 15px;
  background: var(--paper-2);
  border: 1px solid var(--border);
  margin-bottom: 9px;
}
.rank-row.is-me { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.rank-no {
  flex: none;
  width: 26px;
  text-align: center;
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.rank-no.is-gold { color: #c9a227; }
.rank-no.is-silver { color: #9aa0a6; }
.rank-no.is-bronze { color: #b07d43; }

.rank-main { flex: 1; min-width: 0; }
.rank-main b {
  display: block;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rank-main span { font-size: 11px; color: var(--muted); }

.rank-meta { flex: none; text-align: right; }
.rank-meta b {
  display: block;
  font-family: var(--font-serif);
  font-size: 17px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.rank-meta span { font-size: 10.5px; color: var(--muted); }

.rank-empty {
  padding: 20px 14px;
  margin-bottom: 9px;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--paper-2);
  border: 1px dashed var(--border);
  border-radius: 15px;
}

.empty {
  text-align: center;
  padding: 46px 18px;
  color: var(--muted);
}
.empty__icon { display: flex; justify-content: center; margin-bottom: 14px; opacity: 0.92; }
.empty__icon svg { display: block; filter: drop-shadow(0 6px 12px rgba(58, 50, 42, 0.16)); }
.empty p { margin: 0 0 16px; font-size: 13.5px; }

/* ------------------------------ 我的页 ----------------------------------- */

.section-label { font-size: 12px; font-weight: 700; color: var(--muted); margin: 18px 4px 8px; letter-spacing: 0.05em; }

.avatar-picker { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; }
.avatar-choice {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid transparent;
  background: radial-gradient(circle at 32% 28%, #fbf4e7, #e8d8be);
  display: grid;
  place-items: center;
  font-size: 21px;
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease;
}
.avatar-choice:active { transform: scale(0.93); }
.avatar-choice.is-active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.field { display: flex; align-items: center; gap: 10px; }
.field input[type="text"] {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  padding: 12px 13px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: var(--paper-2);
  outline: none;
}
.field input[type="text"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 14px;
  background: var(--paper-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 9px;
}
.switch-row__txt b { display: block; font-size: 14px; font-weight: 700; }
.switch-row__txt span { font-size: 11.5px; color: var(--muted); }

.switch { position: relative; width: 46px; height: 27px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch__track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #ddd2c0;
  transition: background 0.2s ease;
  pointer-events: none;
}
.switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.18);
  transition: transform 0.2s ease;
}
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(19px); }

.list-row {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  text-align: left;
  padding: 14px;
  border-radius: 14px;
  background: var(--paper-2);
  border: 1px solid var(--border);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 9px;
}
.list-row .arrow { margin-left: auto; color: var(--muted); font-size: 16px; }

.rowico {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: #f0e6d6;
  color: var(--accent);
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
}

/* 布局容器：默认单列堆叠，PC 媒体查询里再改成多栏 */
.home__side { display: block; }
.create__grid { display: block; }
.profile__grid { display: block; }
.profile__me { display: flex; align-items: center; gap: 14px; }
.profile__note { font-size: 11px; text-align: center; margin: 22px 0 6px; line-height: 1.7; }

/* ------------------------------ 弹层/浮层 --------------------------------- */

.sheet {
  position: absolute;
  inset: 44px 0 0 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  background: rgba(31, 27, 22, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease;
}
.sheet.is-open { opacity: 1; pointer-events: auto; }

.sheet__panel {
  width: 100%;
  max-height: 90%;
  overflow-y: auto;
  background: var(--paper-2);
  border-radius: 26px 26px 0 0;
  padding: 20px 18px 24px;
  transform: translateY(40px);
  transition: transform 0.32s cubic-bezier(0.22, 0.8, 0.3, 1);
}
.sheet.is-open .sheet__panel { transform: none; }
.sheet__title { font-family: var(--font-serif); font-size: 18px; margin: 0 0 4px; text-align: center; }
.sheet__hint { text-align: center; font-size: 12px; color: var(--muted); margin: 0 0 16px; }

.code-cells { display: flex; justify-content: center; gap: 8px; margin: 6px 0 4px; }
.code-cell {
  width: 42px;
  height: 52px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: #f7f1e6;
  display: grid;
  place-items: center;
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  transition: border-color 0.15s ease;
}
.code-cell.is-focus { border-color: var(--accent); background: #fff; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0 6px; }
.key {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--paper-2);
  border-radius: 13px;
  padding: 13px 0;
  font: inherit;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
}
.key:active { background: #f1e8d8; transform: scale(0.97); }
.key--wide { grid-column: span 1; font-size: 14px; font-weight: 600; color: var(--muted); }

.sheet__actions { display: flex; gap: 10px; margin-top: 12px; }
.sheet__actions .btn { flex: 1; }

.overlay {
  position: absolute;
  inset: 44px 0 0 0;
  z-index: 55;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(31, 27, 22, 0.55);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease;
}
.overlay.is-open { opacity: 1; pointer-events: auto; }

.dialog-card {
  width: 100%;
  background: var(--paper-2);
  border-radius: 22px;
  padding: 22px 20px;
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.34);
  transform: translateY(12px) scale(0.97);
  transition: transform 0.28s cubic-bezier(0.22, 0.8, 0.3, 1);
}
.overlay.is-open .dialog-card { transform: none; }
.dialog-card h3 { margin: 0 0 8px; font-family: var(--font-serif); font-size: 18px; text-align: center; }
.dialog-card .dialog-body { margin: 0 0 18px; font-size: 13.5px; line-height: 1.7; color: var(--muted); text-align: center; }
.dialog-actions { display: flex; gap: 10px; }
.dialog-actions .btn { flex: 1; }

/* 结算层 */
.result-card {
  width: 100%;
  background: var(--paper-2);
  border-radius: 26px;
  padding: 26px 20px 22px;
  text-align: center;
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.34);
  transform: translateY(14px) scale(0.96);
  transition: transform 0.32s cubic-bezier(0.22, 0.8, 0.3, 1);
}
.overlay.is-open .result-card { transform: none; }

.result-seal {
  width: 68px;
  height: 68px;
  margin: 0 auto 14px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-family: var(--font-serif);
  font-size: 34px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, #cb4433, var(--accent-dark));
  box-shadow: 0 10px 22px rgba(192, 57, 43, 0.32);
}
.result-seal.is-draw { background: linear-gradient(180deg, #b99a5c, #8f7440); box-shadow: 0 10px 22px rgba(143, 116, 64, 0.3); }
.result-seal.is-lose { background: linear-gradient(180deg, #55504a, #2c2822); box-shadow: 0 10px 22px rgba(44, 40, 34, 0.3); }

.result-card h2 { margin: 0 0 6px; font-family: var(--font-serif); font-size: 24px; letter-spacing: 0.06em; }
.result-meta { margin: 0 0 18px; font-size: 12.5px; color: var(--muted); }
.result-actions { display: flex; flex-direction: column; gap: 9px; }
.result-wait { min-height: 16px; margin: 10px 0 0; font-size: 11.5px; color: var(--accent); }

/* Toast */
.toast-wrap {
  position: absolute;
  left: 0;
  right: 0;
  top: 54px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.toast {
  max-width: 84%;
  background: rgba(31, 27, 22, 0.92);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.5;
  padding: 9px 14px;
  border-radius: 11px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  animation: toastin 0.24s ease-out;
}
.toast.is-out { animation: toastout 0.3s ease forwards; }
@keyframes toastin { from { opacity: 0; transform: translateY(-8px); } }
@keyframes toastout { to { opacity: 0; transform: translateY(-8px); } }

/* 旁观标识 */
.spectator-badge {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: var(--muted);
  border-radius: 999px;
  padding: 2px 7px;
  vertical-align: middle;
}

/* 桌面提示 */
.stage-hint {
  color: #7d6f5d;
  font-size: 12px;
  letter-spacing: 0.03em;
  opacity: 0.85;
  text-align: center;
}
.stage-hint b { color: var(--accent); }

/* 小屏微调 */
@media (max-height: 700px) {
  .stage-hint { display: none; }
}

/* ---------------------- 手机端全屏（去掉手机外壳） ----------------------- */
/* 手机上：内容铺满整个视口，不再显示圆角机身与两侧留白；
   PC / 宽屏：保持居中的 390×844 手机壳预览。 */
@media (max-width: 640px), (max-width: 960px) and (hover: none) and (pointer: coarse) {
  html, body { height: 100%; }

  body {
    display: block;
    min-height: 100dvh;
    overflow: hidden;
    background: var(--paper);
  }

  /* 木纹底纹在满屏时容易显脏，手机端去掉 */
  body::before { display: none; }

  .stage {
    display: block;
    width: 100%;
    height: 100dvh;
    gap: 0;
  }

  .phone {
    width: 100%;
    height: 100dvh;
    padding: 0;
    border-radius: 0;
    background: var(--paper);
    box-shadow: none;
    transform: none;
    transform-origin: top left;
  }

  /* 手机自带系统状态栏，去掉原型里的仿真状态栏 */
  .statusbar { display: none; }

  .phone__inner {
    border-radius: 0;
    /* 状态栏隐藏后，用安全区为内容让出刘海/挖孔 */
    padding-top: env(safe-area-inset-top, 0px);
  }

  /* 底部 Tab 让出手势条安全区 */
  .tabbar {
    height: calc(66px + env(safe-area-inset-bottom, 0px));
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  }

  /* 状态栏已隐藏，弹层铺满整屏 */
  .sheet,
  .overlay {
    inset: 0;
  }

  /* 顶部提示避开刘海 */
  .toast-wrap { top: calc(12px + env(safe-area-inset-top, 0px)); }

  /* 全屏后底部没有外壳，列表页多留出安全区 */
  .view { padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
  /* 对局页收窄左右留白，让棋盘尽量大 */
  .view[data-view="game"] { padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px)); }

  .stage-hint { display: none; }
}

/* 手机横屏：外壳也没意义，保持满屏铺满 */
@media (max-height: 520px) and (hover: none) and (pointer: coarse) {
  .stage-hint { display: none; }
}

/* ==========================================================================
   PC 网页端适配（非移动端）
   --------------------------------------------------------------------------
   命中条件与上面的「手机端全屏」互补：窗口宽度 > 640px 且主指针不是触屏
   （即 PC / 鼠标触控板设备）。此时不再是居中的手机壳，而是铺满窗口的网页端布局：
   左侧固定导航 + 右侧内容区；宽屏再自动分栏（首页 / 对局 / 战绩）。
   ========================================================================== */
@media (min-width: 641px) and (not (pointer: coarse)) {
  html, body { height: 100%; }

  body {
    display: block;
    min-height: 100dvh;
    overflow: hidden;
    background:
      radial-gradient(circle at 50% -10%, #fbf7f0 0%, #ece3d6 46%, #e0d4c1 100%);
  }

  .stage {
    display: block;
    width: 100%;
    height: 100dvh;
    gap: 0;
  }

  /* 去掉手机外壳，让应用铺满窗口 */
  .phone {
    width: 100%;
    height: 100dvh;
    padding: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    transform: none;
    transform-origin: top left;
  }

  .phone__inner {
    display: grid;
    grid-template-columns: 236px minmax(0, 1fr);
    grid-template-areas: "nav main";
    width: 100%;
    height: 100dvh;
    border-radius: 0;
    background: transparent;
    overflow: hidden;
  }

  /* 桌面端用系统窗口自带的状态栏，不需要仿真状态栏 */
  .statusbar { display: none; }

  /* ---------------------------- 左侧导航 ---------------------------- */
  .tabbar {
    grid-area: nav;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 6px;
    padding: 30px 16px 22px;
    background: linear-gradient(180deg, #fffdf8 0%, #f3ebde 100%);
    border-top: 0;
    border-right: 1px solid var(--border);
    backdrop-filter: none;
    z-index: 30;
  }

  .tabbar::before {
    content: "棋";
    align-self: flex-start;
    width: 48px;
    height: 48px;
    margin: 0 0 4px 6px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-family: var(--font-serif);
    font-size: 27px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(180deg, #cb4433, var(--accent-dark));
    box-shadow: 0 8px 18px rgba(192, 57, 43, 0.3);
  }

  /* 导航底部的一句话说明，填补桌面端侧栏留白 */
  .tabbar::after {
    content: "把房间号发给朋友\A点开即玩，无需注册";
    white-space: pre-line;
    margin-top: auto;
    padding: 16px 10px 8px;
    border-top: 1px dashed var(--border);
    text-align: center;
    font-size: 11px;
    line-height: 1.7;
    letter-spacing: 0.04em;
    color: var(--muted);
  }

  .tab {
    flex: none;
    height: 48px;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 0 14px;
    border-radius: 12px;
    font-size: 14.5px;
    position: relative;
  }
  .tab svg { width: 20px; height: 20px; }
  .tab:hover { background: #f2e8d8; color: var(--text); }
  .tab.is-active { box-shadow: inset 0 0 0 1px rgba(192, 57, 43, 0.16); }
  .tab.is-active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    width: 3px;
    height: 22px;
    border-radius: 0 3px 3px 0;
    background: var(--accent);
    transform: translateY(-50%);
  }
  .tab.is-active:hover { background: var(--accent-soft); color: var(--accent); }

  /* ---------------------------- 主内容区 ---------------------------- */
  .screen {
    grid-area: main;
    background:
      radial-gradient(circle at 88% -12%, rgba(227, 192, 141, 0.24), transparent 46%),
      var(--paper);
  }

  /* 桌面端显示可用的细滚动条 */
  .view { scrollbar-width: thin; scrollbar-color: #ddd0ba transparent; }
  .view::-webkit-scrollbar { display: block; width: 8px; }
  .view::-webkit-scrollbar-thumb { background: #ddd0ba; border-radius: 999px; }
  .view::-webkit-scrollbar-track { background: transparent; }

  /* 首页 / 战绩 / 我的 / 创建：窄桌面先用居中的单列 */
  .view[data-view="home"],
  .view[data-view="records"],
  .view[data-view="profile"],
  .view[data-view="create"] {
    max-width: 780px;
    margin: 0 auto;
    padding: 40px 44px 52px;
  }

  .page-title { font-size: 27px; }

  /* 头像选择：PC 上限制尺寸，避免圆圈被拉得过大 */
  .avatar-picker { max-width: 380px; }
  .avatar-choice { font-size: 20px; }

  /* 对局页：窄桌面棋盘在上、信息与操作在下 */
  .view[data-view="game"] {
    max-width: 860px;
    margin: 0 auto;
    padding: 26px 36px 34px;
  }
  .boardbox { min-height: 320px; }

  /* 弹层在桌面改为居中卡片，不再从底部滑出 */
  .sheet,
  .overlay { inset: 0; }
  .sheet {
    align-items: center;
    justify-content: center;
    padding: 24px;
  }
  .sheet__panel {
    width: min(420px, 100%);
    max-height: 88%;
    border-radius: 24px;
    transform: translateY(12px) scale(0.98);
  }
  .overlay { padding: 24px; }
  .dialog-card,
  .result-card { width: min(420px, 100%); }

  .toast-wrap { top: 18px; }

  .stage-hint { display: none; }

  /* ------------------------- 桌面端交互细节 ------------------------- */
  .card { box-shadow: 0 12px 28px rgba(58, 50, 42, 0.06); }
  .statcard { box-shadow: 0 12px 26px rgba(58, 50, 42, 0.06); }
  .btn:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(58, 50, 42, 0.13); }
  .btn--primary:hover { box-shadow: 0 14px 26px rgba(192, 57, 43, 0.32); }
  .btn:active { transform: translateY(1px); }
  .btn--text:hover { box-shadow: none; transform: none; color: var(--accent); }
  .btn:focus-visible,
  .tab:focus-visible,
  .key:focus-visible,
  .avatar-choice:focus-visible { outline: 3px solid rgba(192, 57, 43, 0.35); outline-offset: 2px; }
}

/* ---------------------- 宽屏桌面：自动分栏布局 ------------------------- */
@media (min-width: 1120px) and (not (pointer: coarse)) {
  /* 首页：左侧身份与战绩、右侧行动面板 */
  .view[data-view="home"] {
    max-width: 1080px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(340px, 400px);
    grid-template-rows: auto auto auto auto;
    grid-template-areas:
      "head   head"
      "me     side"
      "last   side"
      "tip    side";
    column-gap: 52px;
    row-gap: 16px;
    padding: 48px 52px 56px;
    align-content: safe center;
  }
  .home__head { grid-area: head; margin-bottom: 4px; }
  .home__me { grid-area: me; margin-bottom: 0; }
  .home__last { grid-area: last; margin-top: 0; }
  .home__tip { grid-area: tip; align-self: start; margin-top: 0; }
  .home__side {
    grid-area: side;
    align-self: start;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 20px;
    border-radius: 22px;
    border: 1px solid var(--border);
    background: linear-gradient(165deg, #fffdf8 0%, #f6efe2 100%);
    box-shadow: 0 20px 44px rgba(58, 50, 42, 0.1);
  }
  .home__side::before {
    content: "开始对局";
    display: block;
    margin: -2px 2px 2px;
    font-family: var(--font-serif);
    font-size: 15px;
    letter-spacing: 0.08em;
    color: var(--text);
  }
  .home__side .home__actions { gap: 14px; }
  #btnResume { margin-top: 0 !important; }
  #btnLocalDemo { margin-top: 0 !important; }

  /* 战绩：左侧统计 + 我的对局，右侧全局排名 */
  .view[data-view="records"] {
    max-width: 1080px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas:
      "title title"
      "stats ranklabel"
      "mine  ranklist"
      "recs  ranklist";
    column-gap: 52px;
    padding: 48px 52px 56px;
    align-content: start;
  }
  .view[data-view="records"] .page-title { grid-area: title; }
  .view[data-view="records"] .statgrid { grid-area: stats; }
  #rankLabel { grid-area: ranklabel; }
  #rankList {
    grid-area: ranklist;
    display: flex;
    flex-direction: column;
    min-height: 300px;
    padding: 12px;
    border-radius: 20px;
    background: linear-gradient(180deg, #fffdf8, #f7f1e6);
    border: 1px solid var(--border);
    box-shadow: 0 16px 34px rgba(58, 50, 42, 0.07);
  }
  #rankList > .rank-empty { margin: auto; width: 100%; }
  #mineLabel { grid-area: mine; }
  #recordList { grid-area: recs; }

  /* 创建房间：房间卡 + 等待卡并排 */
  .view[data-view="create"] {
    max-width: 900px;
    display: block;
    padding: 48px 52px 56px;
  }
  .create__grid {
    display: grid;
    grid-template-columns: minmax(0, 1.12fr) minmax(0, 0.88fr);
    gap: 22px;
    align-items: stretch;
  }
  .create__wait { margin-top: 0; display: flex; flex-direction: column; justify-content: center; }

  /* 我的：左「资料/头像」右「音效/关于」两栏 */
  .view[data-view="profile"] {
    max-width: 1000px;
    margin: 0 auto;
    padding: 48px 52px 56px;
  }
  .profile__grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 52px;
    align-items: start;
  }
  .avatar-picker { max-width: 340px; }
  .avatar-choice { font-size: 19px; }
  .profile__note { text-align: left; margin-top: 26px; }
}

/* ------------- 超宽桌面：对局页左侧大棋盘 + 右侧信息栏 ------------------ */
/* 窗口不够宽时，棋盘改为居中单列展示，避免棋盘被右侧栏挤小。 */
@media (min-width: 1300px) and (not (pointer: coarse)) {
  .view[data-view="game"] {
    max-width: 1360px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas:
      "bar    bar"
      "board  status"
      "board  meta"
      "board  actions";
    column-gap: 30px;
    padding: 24px 30px 30px;
    align-content: start;
  }
  .gamebar {
    grid-area: bar;
    background: var(--paper-2);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 12px 20px;
    box-shadow: 0 14px 30px rgba(58, 50, 42, 0.07);
  }
  .player__info b { max-width: 150px; }
  .boardbox { grid-area: board; min-height: 0; }
  .statusline {
    grid-area: status;
    height: auto;
    margin-top: 16px;
    justify-content: flex-start;
    padding: 15px 18px;
    border-radius: 16px;
    background: linear-gradient(120deg, #fffdf8, #f7efe2);
    border: 1px solid var(--border);
  }
  .metaRow {
    grid-area: meta;
    align-self: start;
    justify-content: flex-start;
    gap: 26px;
    margin-top: 14px;
    padding: 13px 18px;
    border-radius: 16px;
    background: var(--paper-2);
    border: 1px solid var(--border);
    font-size: 12.5px;
  }
  .gameactions { grid-area: actions; align-self: start; margin-top: 14px; }
  .gameactions .btn { padding: 18px 6px; font-size: 14px; }

  /* 右侧操作区下方的淡淡竖排题字，填补留白 */
  .view[data-view="game"]::after {
    content: "落子无悔 · 观棋不语";
    grid-area: actions;
    align-self: end;
    justify-self: center;
    margin-bottom: 10px;
    writing-mode: vertical-rl;
    font-family: var(--font-serif);
    font-size: 13px;
    letter-spacing: 0.42em;
    color: rgba(138, 106, 59, 0.34);
    pointer-events: none;
  }
}
