/* 五子棋 v12 —— 实木温润风(打磨版) */

:root {
  --wood-deep: #2b1d12;
  --wood-mid: #4a3221;
  --wood-warm: #6b4a2f;
  --board-a: #d9a86c;
  --board-b: #c9924f;
  --line: rgba(60, 36, 16, .55);
  --cream: #f4ece0;
  --cream-dim: #cfc2b0;
  --gold: #d8a657;
  --gold-2: #b07a36;
  --ink: #1c1410;
  --ok: #7fb069;
  --off: #6b5c4d;
  --danger: #c1666b;
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, .45);
  --shadow-glow: 0 0 32px rgba(216, 166, 87, .25);
  --radius: 16px;
}

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

html, body {
  margin: 0; min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Noto Sans SC',
               'Microsoft YaHei', 'Segoe UI', sans-serif;
  color: var(--cream);
  background:
    radial-gradient(120% 80% at 50% -10%, #4a3221 0%, transparent 60%),
    linear-gradient(170deg, #2f2116 0%, #1b120b 55%, #150e08 100%);
  background-attachment: fixed;
}

/* 静态星点(夜空感 — 暖色调) */
body::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(1px 1px at 12% 18%, rgba(243, 220, 166, .7), transparent),
    radial-gradient(1px 1px at 24% 62%, rgba(255, 240, 200, .6), transparent),
    radial-gradient(1.5px 1.5px at 36% 28%, rgba(216, 166, 87, .6), transparent),
    radial-gradient(1px 1px at 48% 82%, rgba(243, 220, 166, .5), transparent),
    radial-gradient(1px 1px at 58% 12%, rgba(255, 240, 200, .5), transparent),
    radial-gradient(1.5px 1.5px at 68% 48%, rgba(216, 166, 87, .55), transparent),
    radial-gradient(1px 1px at 78% 78%, rgba(255, 240, 200, .5), transparent),
    radial-gradient(1px 1px at 88% 32%, rgba(243, 220, 166, .6), transparent),
    radial-gradient(1.5px 1.5px at 92% 68%, rgba(216, 166, 87, .5), transparent),
    radial-gradient(1px 1px at 8% 92%, rgba(255, 240, 200, .55), transparent);
  opacity: .85;
}

body { display: flex; flex-direction: column; align-items: center;
  padding: env(safe-area-inset-top) 12px calc(env(safe-area-inset-bottom) + 12px); }

.hidden { display: none !important; }

/* ---------- 入口 ---------- */
.lobby {
  min-height: 100vh; min-height: 100dvh;
  width: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  position: relative; z-index: 1;
  animation: fadeUp 700ms var(--ease-out);
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}
:root { --ease-out: cubic-bezier(0.16, 1, 0.3, 1); }

.lobby-card {
  width: 100%; max-width: 380px;
  padding: 36px 28px 28px;
  border-radius: 22px;
  background: linear-gradient(165deg, rgba(88, 62, 40, .92), rgba(48, 33, 21, .96));
  border: 1px solid rgba(216, 166, 87, .22);
  box-shadow: var(--shadow-lg),
              inset 0 1px 0 rgba(255, 236, 205, .12),
              inset 0 -1px 0 rgba(0, 0, 0, .25);
}

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

.brand h1 {
  margin: 0; font-size: 30px; font-weight: 600; letter-spacing: 6px;
  color: var(--cream); text-shadow: 0 2px 12px rgba(0,0,0,.5);
}
.brand .sub {
  margin: 8px 0 0; font-size: 12.5px; color: var(--cream-dim); letter-spacing: 1px;
}

.field { display: block; margin-bottom: 16px; }
.field span {
  display: block; font-size: 12px; color: var(--cream-dim);
  margin-bottom: 7px; letter-spacing: 1px;
}
.field input {
  width: 100%; padding: 13px 15px; font-size: 15px;
  color: var(--cream);
  background: rgba(20, 13, 8, .55);
  border: 1px solid rgba(216, 166, 87, .2);
  border-radius: 11px; outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
  font-family: inherit;
}
.field input::placeholder { color: #8b7a68; }
.field input:focus {
  border-color: rgba(216, 166, 87, .6);
  background: rgba(30, 20, 13, .65);
  box-shadow: 0 0 0 3px rgba(216, 166, 87, .12);
}

.btn-primary {
  width: 100%; padding: 14px; font-size: 15.5px; font-weight: 600;
  letter-spacing: 2px; color: #2b1d12;
  background: linear-gradient(160deg, #e8be7a, #c99a4e);
  border: none; border-radius: 11px; cursor: pointer;
  box-shadow: 0 6px 18px rgba(201, 154, 78, .3),
              inset 0 1px 0 rgba(255, 230, 180, .5);
  transition: transform .12s, box-shadow .2s, filter .2s;
  font-family: inherit;
  position: relative; overflow: hidden;
}
/* 烫金按钮的高光带 */
.btn-primary::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(115deg, transparent 30%, rgba(255, 240, 200, .35) 48%, rgba(255, 240, 200, .55) 52%, transparent 70%);
  opacity: 0; transition: opacity .3s;
}
.btn-primary:hover { filter: brightness(1.06); box-shadow: 0 8px 22px rgba(201,154,78,.4); }
.btn-primary:hover::before { opacity: 1; }
.btn-primary:active { transform: translateY(1px); }

.hint {
  margin: 18px 0 0; font-size: 11.5px; line-height: 1.9;
  color: #9c8a76; text-align: center;
}

/* ---------- 主界面 ---------- */
.app {
  width: 100%; max-width: 560px;
  display: flex; flex-direction: column; gap: 12px;
  padding-top: 10px; position: relative; z-index: 1;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 4px 0;
}
.room-tag { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.room-label { font-size: 11px; color: #8b7a68; letter-spacing: 2px; }
.room-name {
  font-size: 15px; font-weight: 600; color: var(--gold); letter-spacing: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 180px;
}
.top-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 34px; height: 34px; border-radius: 10px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(216,166,87,.16);
  color: var(--cream-dim); font-size: 14px; cursor: pointer;
  display: grid; place-items: center;
  transition: background .2s, color .2s, border-color .2s, transform .1s;
}
.icon-btn:hover {
  background: rgba(216,166,87,.14); color: var(--cream);
  border-color: rgba(216,166,87,.3);
}
.icon-btn:active { transform: scale(.94); }

/* 玩家条 */
.players {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center;
}
.player {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 11px; border-radius: 13px;
  background: linear-gradient(150deg, rgba(88,62,40,.5), rgba(40,28,18,.55));
  border: 1px solid rgba(216,166,87,.12);
  transition: border-color .35s var(--ease-out), box-shadow .35s var(--ease-out),
              background .35s var(--ease-out), transform .35s var(--ease-out);
  min-width: 0;
}
.player.active {
  border-color: rgba(216,166,87,.55);
  box-shadow: 0 0 0 1px rgba(216,166,87,.25), 0 6px 20px rgba(216,166,87,.18);
  background: linear-gradient(150deg, rgba(112,80,50,.65), rgba(52,36,23,.65));
  transform: translateY(-1px);
}
.player.is-you .pname::after {
  content: '你'; margin-left: 6px; font-size: 10px; padding: 1px 5px;
  border-radius: 5px; background: rgba(216,166,87,.22); color: var(--gold);
  vertical-align: middle;
}

.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto;
  position: relative;
}
.avatar.black {
  background: radial-gradient(circle at 33% 28%, #6f6f6f, #141414 64%);
  box-shadow: 0 3px 8px rgba(0,0,0,.55), inset 0 -2px 4px rgba(0,0,0,.6);
}
.avatar.white {
  background: radial-gradient(circle at 33% 28%, #fff, #cabfae 72%);
  box-shadow: 0 3px 8px rgba(0,0,0,.4), inset 0 -2px 4px rgba(150,138,122,.45);
}
/* 头像高光(动起来更立体) */
.avatar::before {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, rgba(255,255,255,.4), transparent 35%);
  pointer-events: none;
}

.pinfo { flex: 1; min-width: 0; }
.pname {
  font-size: 13.5px; font-weight: 600; color: var(--cream);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pmeta { display: flex; align-items: center; gap: 5px; margin-top: 3px; }
.dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--off);
  transition: background .3s, box-shadow .3s;
}
.player.online .dot { background: var(--ok); box-shadow: 0 0 7px rgba(127,176,105,.8); }
.pstat { font-size: 10.5px; color: #8b7a68; }
.pscore {
  font-size: 19px; font-weight: 600; color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.vs { font-size: 10px; color: #6b5c4d; letter-spacing: 2px; }

/* 棋盘 */
.board-wrap {
  position: relative; width: 100%; aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg),
              inset 0 1px 0 rgba(255,236,205,.1),
              0 0 0 1px rgba(216,166,87,.18);
  transition: box-shadow .4s var(--ease-out);
}
.player.active ~ .board-wrap,
.app[data-turn] .board-wrap {
  /* 活跃对局时棋盘微微发亮 */
  box-shadow: var(--shadow-lg),
              inset 0 1px 0 rgba(255,236,205,.1),
              0 0 0 1px rgba(216,166,87,.3),
              0 0 24px rgba(216,166,87,.12);
}
#board { display: block; width: 100%; height: 100%; touch-action: manipulation; }

.board-mask {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(20,13,8,.72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fadeIn .25s var(--ease-out);
}
.mask-text {
  font-size: 14px; color: var(--cream-dim); letter-spacing: 2px;
  padding: 14px 22px; border-radius: 12px;
  background: rgba(43,29,18,.9);
  border: 1px solid rgba(216,166,87,.2);
  text-align: center; line-height: 1.8;
}

/* 状态条 */
.status {
  text-align: center; font-size: 13px; color: var(--cream-dim);
  letter-spacing: 1px; min-height: 20px;
  transition: color .3s, transform .3s;
}
.status.warn { color: var(--gold); }
.status.err { color: var(--danger); }
.status.win { color: var(--gold); font-weight: 600; transform: scale(1.05); }

/* 工具栏 */
.toolbar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.btn {
  padding: 11px; font-size: 13px; letter-spacing: 1px;
  color: var(--cream);
  background: linear-gradient(155deg, rgba(96,68,44,.6), rgba(48,33,21,.7));
  border: 1px solid rgba(216,166,87,.18);
  border-radius: 11px; cursor: pointer;
  transition: background .2s, border-color .2s, transform .1s;
  font-family: inherit;
}
.btn:hover:not(:disabled) {
  background: linear-gradient(155deg, rgba(120,86,55,.7), rgba(60,42,27,.8));
  border-color: rgba(216,166,87,.35);
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .38; cursor: not-allowed; }

/* 表情 */
.emoji-bar { display: flex; justify-content: center; gap: 6px; }

.hint-row { display: flex; justify-content: center; margin-top: -2px; }
.btn-hint {
  padding: 6px 14px; font-size: 12px;
  color: #8b7a68; letter-spacing: 1px;
  background: transparent;
  border: 1px dashed rgba(216, 166, 87, .2);
  border-radius: 8px; cursor: pointer;
  transition: color .2s, border-color .2s, background .2s;
  font-family: inherit;
}
.btn-hint:hover { color: var(--gold); border-color: rgba(216, 166, 87, .5); background: rgba(216,166,87,.06); }
.btn-hint.active { color: var(--gold); border-style: solid; border-color: rgba(216, 166, 87, .5); }

/* 深度模式: 紫色强调 */
.btn-hint.deep {
  color: #c084fc;
  border-style: solid;
  border-color: rgba(168, 85, 247, .6);
  background: rgba(168, 85, 247, .08);
}
.btn-hint.deep:hover { color: #c084fc; border-color: rgba(168, 85, 247, .8); }
.btn-hint.deep-press {
  color: #c084fc !important;
  border-color: rgba(168, 85, 247, .8) !important;
  background: rgba(168, 85, 247, .12) !important;
  animation: deepPulse 1s ease-in-out infinite;
}
@keyframes deepPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(168, 85, 247, .35); }
  50% { box-shadow: 0 0 0 6px rgba(168, 85, 247, 0); }
}

.emoji-bar button {
  width: 40px; height: 36px; font-size: 18px; cursor: pointer;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(216,166,87,.12);
  border-radius: 10px;
  transition: background .2s, transform .12s;
}
.emoji-bar button:hover { background: rgba(216,166,87,.16); transform: translateY(-2px); }
.emoji-bar button:active { transform: scale(.92); }

/* 弹窗 */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgba(12,8,5,.72);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fadeIn .25s var(--ease-out);
  padding: 20px;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.modal-card {
  width: 100%; max-width: 330px;
  padding: 28px 24px 22px; border-radius: 18px;
  background: linear-gradient(165deg, rgba(96,68,44,.96), rgba(44,30,19,.98));
  border: 1px solid rgba(216,166,87,.26);
  box-shadow: var(--shadow-lg),
              inset 0 1px 0 rgba(255,236,205,.1);
  animation: pop .3s var(--ease-out);
}
@keyframes pop {
  from { transform: scale(.94) translateY(8px); opacity: 0 }
  to { transform: none; opacity: 1 }
}
.modal-card.center { text-align: center; }
.modal-card h3 {
  margin: 0 0 9px; font-size: 18px; font-weight: 600; letter-spacing: 2px;
}
.modal-card p { margin: 0 0 20px; font-size: 13px; color: var(--cream-dim); line-height: 1.7; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* 胜负大图标 + 彩色高光 */
.over-icon {
  font-size: 48px; margin-bottom: 8px;
  animation: bounceIn .6s var(--ease-spring);
}
@keyframes bounceIn {
  0% { transform: scale(0); }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); }
}
.over-icon.win { filter: drop-shadow(0 0 16px rgba(216, 166, 87, .5)); }
.over-icon.lose { filter: grayscale(0.5); opacity: .7; }

/* 提示 */
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translate(-50%, 16px);
  padding: 11px 20px; border-radius: 11px; font-size: 13px;
  background: rgba(43,29,18,.96);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(216,166,87,.28);
  color: var(--cream);
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none;
  transition: opacity .25s var(--ease-out), transform .25s var(--ease-out);
  z-index: 60; max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 表情飘动 */
.emoji-layer { position: fixed; inset: 0; pointer-events: none; z-index: 55; }
.float-emoji {
  position: absolute; font-size: 40px;
  animation: floatUp 1.8s ease-out forwards;
  text-shadow: 0 4px 16px rgba(0,0,0,.4);
}
@keyframes floatUp {
  0%   { opacity: 0; transform: translateY(0) scale(.5); }
  15%  { opacity: 1; transform: translateY(-14px) scale(1.15); }
  100% { opacity: 0; transform: translateY(-140px) scale(1); }
}

/* 胜利粒子 */
.victory-layer {
  position: fixed; inset: 0; pointer-events: none; z-index: 50;
  overflow: hidden;
}
.victory-particle {
  position: absolute; width: 8px; height: 8px;
  border-radius: 50%; pointer-events: none;
  animation: particleFall 2.5s cubic-bezier(0.4, 0, 0.6, 1) forwards;
}
@keyframes particleFall {
  0% { opacity: 0; transform: translateY(-20px) rotate(0deg); }
  10% { opacity: 1; }
  100% {
    opacity: 0;
    transform: translateY(100vh) rotate(720deg);
  }
}

/* 落子高光(玩家刚落子时的金色脉冲) */
.move-glow {
  position: absolute; pointer-events: none;
  width: 24px; height: 24px; margin: -12px;
  border-radius: 50%;
  border: 2px solid rgba(216, 166, 87, .7);
  animation: moveGlow .8s ease-out forwards;
}
@keyframes moveGlow {
  0% { transform: scale(.5); opacity: 1; }
  100% { transform: scale(2.5); opacity: 0; }
}

@media (max-width: 400px) {
  .brand h1 { font-size: 26px; }
  .pscore { font-size: 17px; }
  .emoji-bar button { width: 36px; }
  .lobby-card { padding: 32px 22px 24px; }
}