* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  min-height: 100vh;
  color: #fff;
}

.container {
  max-width: 400px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
}

.page {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 40px);
  text-align: center;
}

.page.active {
  display: flex;
}

h1 {
  font-size: 2rem;
  margin-bottom: 10px;
}

h2 {
  font-size: 1.5rem;
  margin-bottom: 20px;
}

.subtitle {
  color: #888;
  margin-bottom: 40px;
}

.hint {
  color: #666;
  font-size: 0.9rem;
  margin: 10px 0;
}

.buttons {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.btn {
  padding: 16px 32px;
  font-size: 1.1rem;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  font-weight: 600;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
}

.btn.secondary {
  background: #2d2d44;
  color: #fff;
}

.divider {
  color: #666;
  font-size: 0.9rem;
}

/* 好友对战页 */
.friend-buttons {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.friend-buttons input {
  letter-spacing: 8px;
  font-size: 1.3rem;
}

input[type="text"] {
  padding: 16px;
  font-size: 1.2rem;
  border: 2px solid #333;
  border-radius: 12px;
  background: #1a1a2e;
  color: #fff;
  text-align: center;
  width: 100%;
  letter-spacing: 8px;
}

input[type="text"]:focus {
  outline: none;
  border-color: #667eea;
}

.big-input {
  font-size: 2rem;
  padding: 20px;
  letter-spacing: 15px;
  margin-bottom: 20px;
}

/* 等待页 */
.room-code {
  background: #2d2d44;
  padding: 30px 50px;
  border-radius: 16px;
  margin: 20px 0;
}

.room-code h1 {
  font-size: 3rem;
  letter-spacing: 10px;
  color: #667eea;
}

.loader {
  width: 40px;
  height: 40px;
  border: 4px solid #333;
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-top: 30px;
}

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

/* 游戏页 */
.game-info-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 15px;
}

.my-number-display {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 1rem;
  letter-spacing: 1px;
}

.my-number-display span {
  font-family: monospace;
  font-size: 1.2rem;
  font-weight: bold;
  letter-spacing: 4px;
}

.round-display {
  background: #2d2d44;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
}

.round-display span {
  color: #4ade80;
  font-size: 1.3rem;
}

.game-header {
  width: 100%;
  margin-bottom: 20px;
}

.turn-indicator {
  display: inline-block;
  padding: 10px 20px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 1rem;
}

.turn-indicator.my-turn {
  background: #4ade80;
  color: #000;
}

.turn-indicator.waiting {
  background: #fbbf24;
  color: #000;
}

.history-container {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-bottom: 20px;
  flex: 1;
  max-height: 300px;
}

.history-panel {
  flex: 1;
  background: #2d2d44;
  border-radius: 12px;
  padding: 15px;
  overflow-y: auto;
}

.history-panel h3 {
  font-size: 0.9rem;
  color: #888;
  margin-bottom: 10px;
}

.history-panel ul {
  list-style: none;
}

.history-panel li {
  padding: 8px;
  margin: 5px 0;
  background: #1a1a2e;
  border-radius: 8px;
  font-family: monospace;
  font-size: 1.1rem;
}

.history-panel li .result {
  color: #4ade80;
  font-weight: bold;
}

.guess-area {
  width: 100%;
}

/* 结果页 */
.reveal {
  background: #2d2d44;
  padding: 20px 40px;
  border-radius: 12px;
  margin: 20px 0;
}

.reveal strong {
  font-size: 2rem;
  color: #667eea;
  letter-spacing: 8px;
}

#resultText {
  font-size: 2rem;
}

#resultText.win {
  color: #4ade80;
}

#resultText.lose {
  color: #f87171;
}

#resultText.draw {
  color: #fbbf24;
}

.result-rounds {
  color: #888;
  margin-top: 10px;
  font-size: 1.1rem;
}

/* 对局回放 */
.replay-area {
  width: 100%;
  margin: 15px 0;
}

.replay-container {
  display: flex;
  gap: 10px;
  width: 100%;
}

.replay-panel {
  flex: 1;
  background: #2d2d44;
  border-radius: 12px;
  padding: 12px;
  max-height: 200px;
  overflow-y: auto;
}

.replay-panel h4 {
  font-size: 0.85rem;
  color: #888;
  margin-bottom: 8px;
  text-align: center;
}

.replay-panel ul {
  list-style: none;
}

.replay-panel li {
  padding: 6px 8px;
  margin: 4px 0;
  background: #1a1a2e;
  border-radius: 6px;
  font-family: monospace;
  font-size: 0.95rem;
  display: flex;
  justify-content: space-between;
}

.replay-panel li .round-num {
  color: #666;
  font-size: 0.8rem;
}

.replay-panel li .result {
  color: #4ade80;
  font-weight: bold;
}

.replay-panel li.winner {
  background: linear-gradient(135deg, #166534 0%, #15803d 100%);
}

#showReplayBtn {
  margin-bottom: 10px;
}

/* 聊天区域 */
.chat-area {
  width: 100%;
  margin-top: 15px;
  border-top: 1px solid #333;
  padding-top: 10px;
}

.chat-messages {
  max-height: 120px;
  overflow-y: auto;
  margin-bottom: 10px;
}

.chat-message {
  padding: 6px 10px;
  margin: 4px 0;
  border-radius: 8px;
  font-size: 0.9rem;
  max-width: 80%;
}

.chat-message.self {
  background: #667eea;
  margin-left: auto;
  text-align: right;
}

.chat-message.other {
  background: #2d2d44;
}

.chat-message .sender {
  font-size: 0.75rem;
  color: #aaa;
  margin-bottom: 2px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
}

.chat-input-row input {
  flex: 1;
  padding: 10px;
  font-size: 0.9rem;
  letter-spacing: normal;
}

.chat-input-row .btn {
  padding: 10px 16px;
  font-size: 0.9rem;
}

/* 难度选择 */
.difficulty-buttons {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.diff-btn {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  text-align: left;
  gap: 15px;
}

.diff-icon {
  font-size: 2rem;
}

.diff-name {
  font-size: 1.2rem;
  font-weight: 600;
}

.diff-desc {
  font-size: 0.85rem;
  color: #aaa;
  margin-left: auto;
}

.diff-btn.practice {
  background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
}

.diff-btn.easy {
  background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
}

.diff-btn.normal {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  color: #000;
}

.diff-btn.normal .diff-desc {
  color: #444;
}

.diff-btn.hard {
  background: linear-gradient(135deg, #f87171 0%, #ef4444 100%);
}

/* 用户栏 */
.user-bar {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #2d2d44;
  padding: 8px 12px;
  border-radius: 20px;
}

.user-bar span {
  font-size: 0.9rem;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-icon {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
}

.btn-back {
  position: absolute;
  top: 15px;
  left: 15px;
  background: rgba(255,255,255,0.1);
  border: none;
  color: #aaa;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-back:hover {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

/* 战绩页 */
.stats-section {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border-radius: 16px;
  padding: 15px;
  margin-bottom: 15px;
}

.stats-section h3 {
  font-size: 1rem;
  color: #aaa;
  margin-bottom: 10px;
  text-align: left;
}

.stats-summary {
  display: flex;
  justify-content: space-around;
  width: 100%;
  margin: 10px 0;
}

.stats-summary.compact {
  justify-content: center;
  gap: 15px;
}

.stat-item {
  text-align: center;
  background: #2d2d44;
  padding: 15px 20px;
  border-radius: 12px;
  min-width: 60px;
}

.stat-value {
  display: block;
  font-size: 1.8rem;
  font-weight: bold;
}

.stat-label {
  font-size: 0.8rem;
  color: #888;
}

.stat-item.win .stat-value { color: #4ade80; }
.stat-item.draw .stat-value { color: #fbbf24; }
.stat-item.lose .stat-value { color: #f87171; }

.stats-extra {
  text-align: center;
  margin-bottom: 20px;
  color: #888;
}

.stats-extra strong {
  color: #fff;
}

.record-list {
  list-style: none;
  width: 100%;
  max-height: 250px;
  overflow-y: auto;
  margin-bottom: 20px;
}

.record-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: #2d2d44;
  margin: 6px 0;
  border-radius: 8px;
  font-size: 0.9rem;
}

.record-list .mode {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
}

.record-list .mode.pvp {
  background: #667eea;
  color: #fff;
}

.record-list .mode.solo {
  background: #444;
  color: #aaa;
}

.record-list .result {
  font-weight: bold;
  padding: 4px 10px;
  border-radius: 4px;
}

.record-list .result.win { background: #166534; color: #4ade80; }
.record-list .result.draw { background: #854d0e; color: #fbbf24; }
.record-list .result.lose { background: #991b1b; color: #f87171; }

/* 弹窗 */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.7);
  justify-content: center;
  align-items: center;
  z-index: 200;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: #2d2d44;
  padding: 30px;
  border-radius: 16px;
  text-align: center;
  width: 280px;
}

.modal-content h3 {
  margin-bottom: 20px;
}

.modal-content input {
  margin-bottom: 20px;
}

.modal-buttons {
  display: flex;
  gap: 10px;
}

.modal-buttons .btn {
  flex: 1;
  padding: 12px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #f87171;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  transition: transform 0.3s;
  z-index: 100;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* 状态文字 */
.status {
  color: #888;
  margin-top: 15px;
}

.status.ready {
  color: #4ade80;
}
