/* ============ 石铁 RPG 像素风 - 拼图对决 ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-page: #1a1a1a;
  --bg-panel: #2a2a2a;
  --bg-card: #2e2e2e;
  --bg-input: #1a1a1a;
  --bg-btn: #383838;
  --bg-btn-primary: #555;
  --text-primary: #d4c078;
  --text-secondary: #aaa;
  --text-muted: #777;
  --text-gold: #ddaa30;
  --border: #555;
  --border-accent: #ddaa30;
  --red: #cc4444;
  --blue: #4488cc;
  --green: #55aa55;
  --font: -apple-system, "Microsoft YaHei", sans-serif;
  --font-mono: "Courier New", monospace;
}

html, body {
  height: 100%;
  background: var(--bg-page);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ============ 容器 ============ */
.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* ============ 标题 ============ */
.logo {
  text-align: center;
  margin-bottom: 8px;
}
.logo h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-gold);
  letter-spacing: 2px;
  font-family: var(--font);
}
.logo p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ============ 面板 / 卡片 ============ */
.panel {
  background: var(--bg-panel);
  border: 2px solid var(--border);
  padding: 20px;
  margin-bottom: 12px;
}

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  font-size: 14px;
  font-family: var(--font);
  background: var(--bg-btn);
  color: var(--text-gold);
  border: 2px solid var(--border);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-decoration: none;
  user-select: none;
}
.btn:hover { background: #444; border-color: #777; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled:hover { background: var(--bg-btn); border-color: var(--border); }

.btn-primary {
  background: var(--bg-btn-primary);
  border-color: var(--border-accent);
  color: var(--text-gold);
  font-weight: 600;
}
.btn-primary:hover { background: #666; }
.btn-primary:disabled { opacity: 0.4; }
.btn-primary:disabled:hover { background: var(--bg-btn-primary); border-color: var(--border-accent); }

.btn-green { border-color: var(--green); color: var(--green); }
.btn-green:hover { background: #2a3a2a; }

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover { background: #333; }

/* ============ 输入框 ============ */
.input {
  width: 100%;
  padding: 10px 14px;
  font-size: 16px;
  font-family: var(--font);
  background: var(--bg-input);
  color: var(--text-gold);
  border: 2px solid var(--border);
  outline: none;
  text-align: center;
}
.input:focus { border-color: var(--border-accent); }
.input::placeholder { color: var(--text-muted); }

/* ============ 房号 ============ */
.room-code-text {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-gold);
  letter-spacing: 4px;
  font-family: var(--font-mono);
}

/* ============ 难度 & 局数选择器 ============ */
.selector-group {
  display: flex;
  gap: 6px;
}
.selector-group .btn {
  min-width: 60px;
  padding: 6px 12px;
  font-size: 13px;
}
.selector-group .btn.active {
  background: var(--text-gold);
  color: var(--bg-page);
  border-color: var(--text-gold);
  font-weight: 600;
}

/* ============ 上传槽 ============ */
.upload-slot {
  width: 90px;
  height: 90px;
  background: var(--bg-input);
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s;
}
.upload-slot:hover { border-color: var(--border-accent); }
.upload-slot.filled { border-style: solid; border-color: #666; }
.upload-slot img { width: 100%; height: 100%; object-fit: cover; }
.upload-slot .placeholder {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.4;
}
.image-upload-area {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ============ 图片预览（加入方） ============ */
.image-previews { display: flex; gap: 6px; margin-top: 8px; }
.image-previews img {
  width: 60px; height: 60px; object-fit: cover;
  border: 2px solid var(--border);
}

/* ============ 玩家卡片 ============ */
.player-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.player-card .team-badge {
  width: 14px; height: 14px;
  border: 2px solid;
}
.player-card .team-badge.red { border-color: var(--red); background: rgba(204,68,68,0.2); }
.player-card .team-badge.blue { border-color: var(--blue); background: rgba(68,136,204,0.2); }
.player-card .nickname {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}
.player-card .status {
  font-size: 12px;
  font-weight: 600;
}
.player-card .status.ready { color: var(--green); }
.player-card .status.waiting { color: var(--text-muted); }

/* ============ 操作栏 ============ */
.action-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 16px 0;
  flex-wrap: wrap;
}

/* ============ 提示 Toast ============ */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 24px;
  font-size: 14px;
  font-family: var(--font);
  border: 2px solid;
  z-index: 200;
  animation: toastIn 0.3s ease;
}
@keyframes toastIn { from { opacity:0; transform:translateX(-50%) translateY(-10px); } to { opacity:1; transform:translateX(-50%) translateY(0); } }
.toast.error { background: #3a1a1a; border-color: var(--red); color: var(--red); }
.toast.info { background: #1a2a1a; border-color: var(--green); color: var(--green); }

/* ============ 首页 ============ */
.home-form { display: flex; flex-direction: column; gap: 12px; }
.home-form .row { display: flex; gap: 8px; }
.home-form .row .input { flex: 1; text-align: center; }

/* ============ 房间布局 ============ */
.room-layout {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px;
}
.room-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-panel);
  border: 2px solid var(--border);
  margin-bottom: 12px;
}
.room-topbar .room-code-area { display: flex; align-items: center; gap: 12px; }
.room-columns {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 12px;
}
.room-left { display: flex; flex-direction: column; gap: 12px; }
.room-right { display: flex; flex-direction: column; gap: 12px; }
.room-panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-gold);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}

/* ============ 游戏页面 ============ */
.game-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto 1fr auto;
  gap: 8px;
  height: 100%;
  padding: 8px;
}

.game-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 8px 16px;
  background: var(--bg-panel);
  border: 2px solid var(--border);
}

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
}

.vs-timer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.timer-display {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-gold);
  font-family: var(--font-mono);
}
.round-indicator {
  font-size: 13px;
  color: var(--text-secondary);
}
.opponent-done-banner {
  font-size: 14px;
  font-weight: 600;
  color: var(--green);
  padding: 4px 12px;
  border: 2px solid var(--green);
  background: rgba(85,170,85,0.1);
}

.puzzle-area {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: var(--bg-panel);
  border: 2px solid var(--border);
}

.puzzle-grid {
  display: grid;
  gap: 2px;
  border: 2px solid var(--border);
  padding: 2px;
  position: relative;
  touch-action: none;
}

.puzzle-piece {
  position: relative;
  cursor: grab;
  background-size: cover;
  background-repeat: no-repeat;
  border: 1px solid rgba(255,255,255,0.06);
  transition: filter 0.3s ease;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  will-change: transform;
  filter: brightness(0.75) saturate(0.85);
}
.puzzle-piece:hover {
  border-color: rgba(255,255,255,0.2);
  z-index: 2;
}
.puzzle-piece.dragging {
  opacity: 0.85;
  cursor: grabbing;
  z-index: 10;
  transform: scale(1.08);
  box-shadow: 0 8px 25px rgba(0,0,0,0.5);
  filter: brightness(0.6) saturate(0.7);
}
.puzzle-piece.correct {
  filter: brightness(1) saturate(1);
  border: 2px solid rgba(85,170,85,0.7);
  box-shadow: 0 0 8px rgba(85,170,85,0.2), inset 0 0 6px rgba(85,170,85,0.1);
  cursor: default;
  pointer-events: none;
}
.puzzle-piece.swap-target {
  border-color: var(--text-gold);
  box-shadow: 0 0 10px rgba(221,170,48,0.3);
}

/* ============ 完成盖章 ============ */
.complete-stamp {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-15deg) scale(0);
  font-size: 36px;
  font-weight: 900;
  color: rgba(85,170,85,0.85);
  text-shadow: 3px 3px 0 rgba(0,0,0,0.5);
  letter-spacing: 4px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 20;
  font-family: var(--font);
  animation: stampIn 0.5s cubic-bezier(0.34,1.56,0.64,1) forwards;
}
@keyframes stampIn {
  0% { transform: translate(-50%,-50%) rotate(-15deg) scale(3); opacity:0; }
  60% { transform: translate(-50%,-50%) rotate(-15deg) scale(0.9); opacity:1; }
  100% { transform: translate(-50%,-50%) rotate(-15deg) scale(1); opacity:1; }
}
.puzzle-grid.completed::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(85,170,85,0.15);
  pointer-events: none;
  z-index: 15;
}

/* ============ 烟花 ============ */
.firework-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 150;
  overflow: hidden;
}
.firework-spark {
  position: absolute;
  width: 4px;
  height: 4px;
  animation: fireworkExplode 1s ease-out forwards;
}
@keyframes fireworkExplode {
  0% { transform: translate(0,0) scale(1); opacity:1; }
  100% { transform: translate(var(--dx),var(--dy)) scale(0); opacity:0; }
}

/* ============ 覆盖层 ============ */
.countdown-overlay,
.transition-overlay,
.result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.countdown-number {
  font-size: 100px;
  font-weight: 700;
  color: var(--red);
  font-family: var(--font);
}
.countdown-go {
  font-size: 60px;
  font-weight: 700;
  color: var(--green);
  font-family: var(--font);
}

.transition-overlay { flex-direction: column; gap: 16px; }
.round-text { font-size: 20px; font-weight: 600; color: var(--text-primary); }
.countdown-text { font-size: 48px; font-weight: 700; color: var(--text-gold); }

/* ============ 结果面板 ============ */
.result-panel {
  background: var(--bg-panel);
  border: 2px solid var(--border-accent);
  padding: 24px 32px;
  min-width: 340px;
  text-align: center;
}
.result-panel h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-gold);
  margin-bottom: 16px;
}
.result-summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
}
.result-player { text-align: center; }
.result-player .win-count {
  font-size: 40px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
}
.result-player .win-count.winner { color: var(--text-gold); }
.result-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}
.result-table th, .result-table td {
  padding: 6px 10px;
  font-size: 13px;
  text-align: center;
  border: 1px solid var(--border);
}
.result-table th { font-weight: 600; color: var(--text-gold); background: var(--bg-card); }
.result-verdict {
  font-size: 18px;
  font-weight: 700;
  padding: 8px;
  margin-bottom: 16px;
}
.result-verdict.red-win { color: var(--red); }
.result-verdict.blue-win { color: var(--blue); }
.result-verdict.draw { color: var(--text-muted); }

/* ============ 徽章 ============ */
.badge-red, .badge-blue {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border: 2px solid;
}
.badge-red { color: var(--red); border-color: var(--red); }
.badge-blue { color: var(--blue); border-color: var(--blue); }

/* ============ 状态点 ============ */
.status-dot {
  width: 10px; height: 10px;
  display: inline-block;
  border: 2px solid;
}
.status-dot.ready { background: var(--green); border-color: var(--green); }
.status-dot.not-ready { background: transparent; border-color: var(--text-muted); }

/* ============ 响应式 ============ */
@media (max-width: 768px) {
  .room-columns { grid-template-columns: 1fr; }
  .game-layout { grid-template-columns: 1fr; grid-template-rows: auto auto auto auto; }
  .game-header { flex-wrap: wrap; gap: 8px; }
  .puzzle-area { grid-column: 1; }
}
