/* UNO Online — 深绿呢绒牌桌主题 */
:root {
  --felt-1: #1a6b40;
  --felt-2: #12502f;
  --felt-3: #0d3b22;
  --accent: #7c5cff;
  --ink: #1c1c1c;
  --card-w: 74px;
  --card-h: 110px;
  --red: #e23b2e;
  --yellow: #f6c61c;
  --green: #2fa84f;
  --blue: #2f6fd0;
  --orange: #f08a24;
  --pink: #e8559b;
  --teal: #26a69a;
  --purple: #8e44ad;
  --dark: #141414;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #fff; user-select: none;
}
body {
  background:
    radial-gradient(ellipse at 50% 26%, #17336b, #0e2148 55%, #08142c 100%);
}
/* 绿呢绒 / Flip 暗紫只属于牌桌视图 */
#view-game {
  background:
    radial-gradient(ellipse at 50% 40%, var(--felt-1), var(--felt-2) 55%, var(--felt-3) 100%);
  transition: background 1s;
}
body.darkside #view-game {
  background:
    radial-gradient(ellipse at 50% 40%, #4a2b6b, #331d4d 55%, #1c0f2e 100%);
}
.hidden { display: none !important; }

/* 顶部身份条 */
#identity-bar {
  position: fixed; top: 0; left: 0; right: 0; height: 48px; z-index: 50;
  display: flex; align-items: center; gap: 8px; padding: 0 10px;
  background: rgba(0,0,0,.35); backdrop-filter: blur(6px);
}
.avatar-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--accent);
  background: #fff3; font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0; line-height: 1;
}
#nick-input {
  flex: 0 0 140px; height: 32px; border-radius: 8px; border: 1px solid #fff4;
  background: #0006; color: #fff; padding: 0 10px; font-size: 14px;
}
.conn-dot { width: 10px; height: 10px; border-radius: 50%; background: #888; margin-left: auto; }
.conn-dot.on { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
.conn-dot.off { background: #ef4444; }

/* 视图切换 */
.view { display: none; position: absolute; inset: 48px 0 0 0; }
.view.active { display: block; }

/* 按钮：高对比纯色块 */
.btn {
  border: none; border-radius: 10px; padding: 10px 16px; font-size: 15px;
  background: #2f5fbf; color: #fff; cursor: pointer; font-weight: 700;
  transition: transform .08s, filter .15s; box-shadow: 0 2px 6px rgba(0,0,0,.35);
}
.btn:active { transform: scale(.96); }
.btn:hover { filter: brightness(1.12); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; color: #fff; border: 1.5px solid rgba(255,255,255,.55); box-shadow: none; }
.btn-ghost:hover { background: rgba(255,255,255,.12); filter: none; }
.btn-lg { padding: 14px 22px; font-size: 17px; }
.btn-xs { padding: 6px 10px; font-size: 13px; }
.btn-uno { background: #e23b2e; color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.06)} }

/* ---------- 大厅 ---------- */
#view-lobby { display: none; }
#view-lobby.active { display: flex; align-items: center; justify-content: center; }
.lobby-card {
  width: min(420px, 92vw); background: rgba(8, 18, 38, .55); border: 1px solid #ffffff26;
  border-radius: 20px; padding: 28px 24px; text-align: center; backdrop-filter: blur(6px);
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
}
/* LOGO：UNO 三字母做成微缩 UNO 牌 */
.logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0; flex-wrap: wrap; }
.logo .lt {
  display: inline-flex; align-items: center; justify-content: center; position: relative;
  width: 62px; height: 86px; border-radius: 12px; color: #fff;
  box-shadow: 0 6px 16px rgba(0,0,0,.45), inset 0 -4px 0 rgba(0,0,0,.22);
}
/* 字母与椭圆环同角度旋转，作为整体居中 */
.logo .lt i {
  font-style: italic; font-weight: 900; font-family: "Arial Black", sans-serif;
  font-size: 31px; line-height: 1; transform: rotate(-14deg); display: block;
}
.logo .lt::after {
  content: ''; position: absolute; inset: 7px; border: 3px solid #ffffffd9;
  border-radius: 50%; transform: rotate(-14deg);
}
.logo .lt-r { background: var(--red); transform: rotate(-6deg); }
.logo .lt-y { background: var(--yellow); color: #4a3a00; transform: rotate(2deg) translateY(-5px); }
.logo .lt-o { background: var(--green); transform: rotate(7deg); }
.logo-sub { width: 100%; font-size: 15px; letter-spacing: 8px; color: var(--accent); font-weight: 700; margin-top: 12px; }
.tagline { color: #ffffffaa; font-size: 13px; margin: 8px 0 22px; }
.lobby-actions { display: flex; flex-direction: column; gap: 12px; }
.join-row { display: flex; gap: 8px; }
.join-row input {
  flex: 1 1 0; min-width: 0; width: 100%; height: 48px; border-radius: 10px; border: 1px solid #fff4; background: #0006;
  color: #fff; text-align: center; font-size: 20px; letter-spacing: 5px; text-transform: uppercase;
}
.join-row .btn { flex: 0 0 auto; }
.mode-picker h3 { margin: 4px 0 12px; }
.mode-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.mode-opt {
  text-align: left; padding: 12px; border-radius: 12px; border: 2px solid #ffffff22;
  background: #14243f; cursor: pointer;
}
.mode-opt.sel { border-color: var(--accent); background: #1d3157; }
.mode-opt b { font-size: 15px; }
.mode-opt small { display: block; color: #ffffffb3; font-size: 12px; margin-top: 3px; }
.timer-row { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 18px; }
.timer-opts { display: flex; gap: 6px; }
.timer-opts button { padding: 7px 10px; border-radius: 8px; border: 1px solid #ffffff33; background: #22304a; color: #fff; cursor: pointer; font-size: 13px; font-weight: 600; }
.timer-opts button.sel { background: var(--accent); color: #fff; border-color: transparent; }

/* ---------- 房间 ---------- */
.room-wrap { max-width: 900px; margin: 0 auto; padding: 12px; height: 100%; overflow-y: auto; }
.room-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.room-code-label { font-size: 12px; color: #fffa; }
.room-code { font-size: 30px; font-weight: 900; letter-spacing: 4px; color: var(--accent); }
.room-body { display: grid; grid-template-columns: 1fr 320px; gap: 14px; }
.seats-panel h3 { font-size: 14px; color: #fffc; margin: 10px 0 6px; }
.seats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px,1fr)); gap: 8px; }
.seat {
  background: rgba(8, 18, 38, .5); border: 1px solid #ffffff22; border-radius: 12px; padding: 8px; text-align: center;
  position: relative; min-height: 78px;
}
.seat.host::after { content: "👑"; position: absolute; top: -8px; right: -4px; font-size: 16px; }
.seat.disconnected { opacity: .45; }
.seat .av { font-size: 26px; }
.seat .nm { font-size: 12px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .bot-tag { position:absolute; bottom:2px; left:0; right:0; font-size:10px; color: var(--accent); }
.room-side { display: flex; flex-direction: column; gap: 12px; }
.settings-panel { background: rgba(8, 18, 38, .5); border: 1px solid #ffffff22; border-radius: 12px; padding: 12px; }
.room-mode { font-size: 18px; font-weight: 800; color: var(--accent); }
.room-mode-desc { font-size: 12px; color: #fffb; margin: 4px 0 8px; min-height: 32px; }
.host-controls label { font-size: 12px; color: #fffa; display: block; margin: 8px 0 3px; }
.host-controls select { width: 100%; height: 36px; border-radius: 8px; background: #0008; color: #fff; border: 1px solid #fff3; padding: 0 8px; }
.room-actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.hint { font-size: 12px; color: #fffa; text-align: center; margin: 4px 0; }
.chat-box { background: rgba(8, 18, 38, .5); border: 1px solid #ffffff22; border-radius: 12px; padding: 8px; display: flex; flex-direction: column; }
.chat-log { height: 140px; overflow-y: auto; font-size: 13px; display: flex; flex-direction: column; gap: 4px; padding: 4px; }
.chat-log .sys { color: var(--accent); font-size: 12px; opacity: .85; }
.chat-log .msg b { color: #9ee7ff; }
.chat-quick { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.chat-quick button { font-size: 11px; padding: 4px 8px; border-radius: 20px; background: #22304a; border: 1px solid #ffffff33; color: #fff; cursor: pointer; }
.chat-input-row { display: flex; gap: 6px; }
.chat-input-row input { flex: 1; height: 34px; border-radius: 8px; border: 1px solid #fff3; background: #0006; color: #fff; padding: 0 10px; }

/* ---------- 牌桌 ---------- */
.table { position: absolute; inset: 0; }
.opponents {
  position: absolute; top: 4px; left: 0; right: 0; height: 96px;
  display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: wrap; padding: 0 6px;
}
.opp {
  width: 64px; text-align: center; position: relative; padding: 4px 2px; border-radius: 10px;
  transition: box-shadow .2s, transform .2s;
}
.opp.turn { box-shadow: 0 0 0 2px var(--accent), 0 0 16px #7c5cff66; transform: translateY(3px); }
.opp.eliminated { opacity: .35; filter: grayscale(1); }
.opp .av { font-size: 26px; }
.opp .nm { font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opp .cnt {
  display: inline-block; min-width: 22px; margin-top: 2px; padding: 1px 5px; border-radius: 10px;
  background: #0008; font-size: 12px; font-weight: 700;
}
.opp .cnt.uno { background: var(--red); animation: pulse .8s infinite; }
.opp .voice-on::after { content:"🔊"; position:absolute; top:-2px; right:-2px; font-size:12px; }
.opp .mic { position:absolute; top:-2px; right:-2px; font-size:11px; }

.table-center { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-58%); text-align: center; }
.pile-area {
  display: flex; gap: 20px; align-items: center; justify-content: center;
  transform: perspective(800px) rotateX(24deg); transform-origin: 50% 88%;
}
.pile { position: relative; width: var(--card-w); height: var(--card-h); }
.draw-pile { cursor: pointer; }
.draw-pile:active { transform: scale(.95); }
/* 动态厚度：--stk 由 JS 按剩余牌数设置，模拟一叠牌的侧面 */
.draw-pile::before {
  content: ''; position: absolute; left: 1px; right: 1px; top: 10px;
  height: calc(var(--card-h) - 10px + var(--stk, 8px));
  background: repeating-linear-gradient(to bottom, #f2f2f2 0 2px, #bdbdbd 2px 4px);
  border-radius: 9px; z-index: 0;
  box-shadow: 0 12px 22px rgba(0,0,0,.55);
}
.draw-pile .card { position: relative; z-index: 1; box-shadow: 0 2px 4px rgba(0,0,0,.4); }
.discard-pile::before {
  content: ''; position: absolute; left: 1px; right: 1px; top: 8px;
  height: calc(var(--card-h) - 8px + 6px);
  background: repeating-linear-gradient(to bottom, #f2f2f2 0 2px, #c4c4c4 2px 4px);
  border-radius: 9px; z-index: 0;
  box-shadow: 0 10px 18px rgba(0,0,0,.5);
}
.discard-pile .card { position: relative; z-index: 1; box-shadow: 0 2px 4px rgba(0,0,0,.4); }
/* 深色面（Flip）下牌堆叠层改用暗色牌边，避免与暗紫背景冲突 */
body.darkside .draw-pile::before,
body.darkside .discard-pile::before {
  background: repeating-linear-gradient(to bottom, #47474f 0 2px, #232329 2px 4px);
  box-shadow: 0 12px 22px rgba(0,0,0,.65);
}
/* 摸牌落定：揭示时的轻微回弹 */
.card.just-drawn { animation: settle .16s ease-out; }
@keyframes settle {
  from { transform: rotate(var(--rot, 0deg)) scale(1.15); }
  to { transform: rotate(var(--rot, 0deg)) scale(1); }
}
.pile-count { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 12px; color: #fffd; }
.center-info { margin-top: 26px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.color-chip { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff8; box-shadow: 0 0 10px #0006; }
.turn-indicator { font-size: 13px; color: #fff; background: #0006; padding: 3px 12px; border-radius: 20px; }
.timer-ring { width: 40px; height: 40px; border-radius: 50%; display:flex; align-items:center; justify-content:center;
  font-weight: 800; font-size: 15px; border: 3px solid var(--accent); }
.timer-ring.urgent { border-color: var(--red); color: var(--red); animation: pulse .5s infinite; }
.pending-badge { background: var(--red); padding: 3px 12px; border-radius: 20px; font-weight: 800; font-size: 14px; }

.my-area { position: absolute; bottom: 0; left: 0; right: 0; padding: 6px 8px 10px; }
.my-info { text-align: center; font-size: 13px; margin-bottom: 4px; color: #fffd; }
.hand {
  display: flex; justify-content: flex-start; align-items: flex-end; min-height: calc(var(--card-h) + 36px);
  flex-wrap: nowrap; overflow-x: auto; padding: 30px 4px 8px; scrollbar-width: thin;
}
/* 用首尾 auto 外边距实现"可滚动时不裁切"的居中（id 特异性确保不被覆盖） */
#my-hand .card:first-child { margin-left: auto; }
#my-hand .card:last-child { margin-right: auto; }
.hand .card { margin: 0 -6px; transition: transform .12s, margin .12s; cursor: pointer; flex: 0 0 auto; transform: rotate(var(--rot, 0deg)); }
.hand.crowded .card { margin: 0 -10px; }
.hand .card:hover { transform: rotate(var(--rot, 0deg)) translateY(-10px); z-index: 20; }
.hand .card.playable { box-shadow: 0 0 0 2px var(--accent), 0 4px 10px #0008; }
.hand .card.selected { transform: rotate(var(--rot, 0deg)) translateY(-16px); z-index: 30; }
.hand .card:not(.playable) { filter: brightness(.85) saturate(.9); }
.my-controls { display: flex; gap: 10px; justify-content: center; margin-top: 4px; }

/* ---------- 卡牌 ---------- */
.card {
  width: var(--card-w); height: var(--card-h); border-radius: 9px; position: relative;
  background: #fff; box-shadow: 0 2px 6px #0006; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.card .inner {
  position: absolute; inset: 4px; border-radius: 6px;
  transform: rotate(0deg);
}
.card .inner::before {
  content: ''; position: absolute; inset: 14% 4%;
  border: 5px solid #ffffffee; border-radius: 50%;
  transform: rotate(-16deg);
}
.card .val {
  position: relative; z-index: 2; font-size: 28px; font-weight: 900; font-style: italic;
  color: #fff; text-shadow: 0 2px 3px rgba(0,0,0,.4); font-family: "Arial Black", sans-serif;
  line-height: 1; white-space: nowrap;
}
.card .val.glyph { font-size: 21px; font-style: normal; }
.card .corner { position: absolute; z-index: 3; font-size: 12px; font-weight: 900; color: #fff; text-shadow: 1px 1px 0 #0006; font-style: italic; line-height: 1; }
.card .corner.tl { top: 8px; left: 9px; }
.card .corner.br { bottom: 8px; right: 9px; transform: rotate(180deg); }
.card.red .inner { background: var(--red); }
.card.yellow .inner { background: var(--yellow); }
.card.green .inner { background: var(--green); }
.card.blue .inner { background: var(--blue); }
.card.orange .inner { background: var(--orange); }
.card.pink .inner { background: var(--pink); }
.card.teal .inner { background: var(--teal); }
.card.purple .inner { background: var(--purple); }
.card.wild .inner, .card.black .inner { background: var(--dark); }
.card.yellow .val, .card.yellow .corner { color: #4a3a00; text-shadow: 0 1px 0 #fff8; }
.card.yellow .inner::before { border-color: #fff; }
.card-back { background: repeating-linear-gradient(45deg,#b8202f,#b8202f 8px,#8f1622 8px,#8f1622 16px); display:flex; align-items:center; justify-content:center; }
.card-back span { background:#e23b2e; color:#fff; font-weight:900; font-style:italic; padding:4px 8px; border-radius:20px; transform:rotate(-18deg); box-shadow:0 2px 4px #0006; font-size:18px; }

/* flip 牌背面小标记 */
.card .side-tag { position:absolute; bottom:2px; left:50%; transform:translateX(-50%); font-size:9px; z-index:4; opacity:.8; }

/* 发牌/出牌动画 */
.card.dealing { animation: dealIn .3s ease-out; }
@keyframes dealIn { from { transform: translateY(-40vh) scale(.5); opacity:0 } to { transform:none; opacity:1 } }
#top-card-slot .card.played { animation: playIn .28s ease-out; }
@keyframes playIn { from { transform: scale(.4) rotate(-30deg); opacity:.4 } to { transform:none; opacity:1 } }

/* 工具条 */
#game-toolbar { position: fixed; top: 52px; right: 8px; z-index: 40; display: flex; gap: 6px; }
.tool-btn { position: relative; width: 40px; height: 40px; border-radius: 50%; border: 1px solid #fff3; background: #0006; font-size: 18px; cursor: pointer; color:#fff; }
.tool-btn .tool-badge { position:absolute; bottom:-2px; right:-2px; width:12px; height:12px; border-radius:50%; }
.tool-btn .tool-badge.on { background:#4ade80; }
.tool-btn .tool-badge.off { background:#ef4444; }
.game-chat { position: fixed; top: 96px; right: 8px; width: 260px; z-index: 40; background: #000a; border:1px solid #fff2; border-radius: 12px; padding: 8px; }
.game-chat .chat-log { height: 160px; }

/* 弹层 */
.modal { position: fixed; inset: 48px 0 0 0; background: #000a; z-index: 60; display: flex; align-items: center; justify-content: center; }
.modal-box { background: #101c30; border: 1px solid #ffffff33; border-radius: 16px; padding: 22px; text-align: center; max-width: 92vw; box-shadow: 0 16px 50px rgba(0,0,0,.6); }
.color-choices { display: flex; gap: 12px; justify-content: center; margin-top: 16px; }
.color-choices button { width: 62px; height: 62px; border-radius: 14px; border: 3px solid #fff6; cursor: pointer; font-size: 11px; color:#fff; font-weight:700; }
.target-choices, .avatar-choices { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; max-width: 320px; }
.target-choices button { padding: 8px 12px; border-radius: 10px; border: 1px solid #ffffff33; background: #22304a; color: #fff; cursor: pointer; }
.target-choices button:hover { background: #2d3f60; }
.avatar-choices button { width: 46px; height: 46px; font-size: 24px; border-radius: 10px; border: 2px solid #ffffff33; background: #1b2a44; cursor: pointer; }
.avatar-choices button.sel { border-color: var(--accent); background: #24365c; }
.result-box h2 { color: var(--accent); margin: 0 0 14px; }
.rankings { text-align: left; margin: 0 auto 16px; padding-left: 26px; max-width: 260px; }
.rankings li { padding: 4px 0; font-size: 15px; }
.rankings li.win { color: var(--accent); font-weight: 800; }
.result-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* toast */
.toast { position: fixed; bottom: 130px; left: 50%; transform: translateX(-50%); background: #000d; border:1px solid #fff3;
  padding: 10px 18px; border-radius: 20px; z-index: 80; font-size: 14px; }

/* ---------- 手机适配 ---------- */
@media (max-width: 640px) {
  :root { --card-w: 56px; --card-h: 84px; }
  .card .val { font-size: 21px; }
  .card .val.glyph { font-size: 16px; }
  .card .corner { font-size: 10px; }
  .card .corner.tl { top: 6px; left: 7px; }
  .card .corner.br { bottom: 6px; right: 7px; }
  .room-body { grid-template-columns: 1fr; }
  .opponents { height: 84px; }
  .opp { width: 52px; }
  .hand .card { margin: 0 -4px; }
  .hand.crowded .card { margin: 0 -8px; }
  .hand { padding-top: 24px; min-height: calc(var(--card-h) + 30px); }
  .logo .lt { width: 46px; height: 64px; border-radius: 9px; }
  .logo .lt i { font-size: 22px; }
  .logo .lt::after { inset: 5px; border-width: 2px; }
  .logo-sub { font-size: 12px; letter-spacing: 6px; }
  .table-center { transform: translate(-50%,-54%); }
  #nick-input { flex-basis: 100px; }
}
@media (max-height: 560px) {
  .table-center { transform: translate(-50%,-52%); }
  .opponents { height: 72px; }
}
