/* ========== 基础重置与变量 ========== */
:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --bg-hover: #334155;
  --text-main: #f1f5f9;
  --text-sub: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --border-focus: #60a5fa;
  --green: #22c55e;
  --yellow: #eab308;
  --gray: #475569;
  --arrow-up: #60a5fa;
  --arrow-down: #fb923c;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -2px rgba(0,0,0,0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.3), 0 4px 6px -2px rgba(0,0,0,0.2);
  --cell-size: 52px;
  --accent: #60a5fa;
  --accent-hover: #3b82f6;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text-main);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ========== 顶部导航 ========== */
.top-nav {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(10px);
}
.nav-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.logo {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-main);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-icon {
  font-size: 22px;
}
.logo-text {
  background: linear-gradient(135deg, #60a5fa, #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.mode-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg);
  padding: 4px;
  border-radius: 999px;
}
.mode-btn {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-sub);
  transition: all .2s;
  font-weight: 500;
}
.mode-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 600;
}
.mode-btn:hover:not(.active) {
  color: var(--text-main);
  background: var(--bg-hover);
}
.user-info {
  font-size: 13px;
  color: var(--text-sub);
  display: flex;
  gap: 10px;
  align-items: center;
}
#elo-display {
  background: var(--bg-input);
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  color: var(--accent);
}

/* ========== 主内容区 ========== */
.main-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--text-sub);
}
#mode-label { 
  font-weight: 700; 
  color: var(--text-main);
  font-size: 16px;
}
#guess-counter {
  background: var(--bg-card);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}
#timer { font-weight: 800; color: var(--arrow-down); font-size: 16px; }

/* ========== 输入区域 ========== */
.input-area {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  align-items: stretch;
}
.autocomplete-wrap {
  position: relative;
  flex: 1;
}
#guess-input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  outline: none;
  transition: all .2s;
  background: var(--bg-input);
  color: var(--text-main);
}
#guess-input:focus { 
  border-color: var(--accent); 
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}
#guess-input::placeholder {
  color: var(--text-muted);
}

.suggestions-list {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 4px;
  max-height: 300px;
  overflow-y: auto;
  list-style: none;
  z-index: 40;
  box-shadow: var(--shadow-lg);
}
.suggestion-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background .15s;
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover, .suggestion-item.active {
  background: var(--bg-hover);
}
.suggest-name {
  font-weight: 600;
  color: var(--text-main);
}
.suggest-anime {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 999px;
}

.primary-btn, .secondary-btn {
  border: none;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 15px;
  cursor: pointer;
  transition: all .2s;
  font-weight: 600;
  white-space: nowrap;
}
.primary-btn {
  background: linear-gradient(135deg, #60a5fa, #3b82f6);
  color: #fff;
  box-shadow: var(--shadow);
}
.primary-btn:hover {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}
.secondary-btn {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border);
}
.secondary-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}
.primary-btn:active, .secondary-btn:active { 
  transform: scale(0.98); 
}

/* ========== 表头与猜测网格 ========== */
.grid-header, .guess-row {
  display: grid;
  grid-template-columns: 110px repeat(11, 1fr);
  gap: 5px;
  margin-bottom: 5px;
}
.header-cell, .cell {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 11px;
  padding: 8px 4px;
  min-height: var(--cell-size);
  font-weight: 600;
  color: var(--text-sub);
  word-break: keep-all;
  transition: all .2s;
}
.header-cell {
  background: var(--bg-card);
  border-color: var(--border);
}
.name-cell {
  background: var(--bg-card);
  color: var(--text-main);
  font-weight: 700;
}
.cell {
  font-weight: 700;
  color: #fff;
  border: none;
  transition: transform .15s, box-shadow .15s;
}
.cell:hover { 
  transform: translateY(-2px); 
  box-shadow: var(--shadow); 
}
.cell.correct   { background: var(--green); }
.cell.partial   { background: var(--yellow); color: #1e293b; }
.cell.wrong     { background: var(--gray); }
.cell .arrow {
  margin-left: 4px;
  font-weight: 900;
}
.cell .arrow.up { color: var(--arrow-up); }
.cell .arrow.down { color: var(--arrow-down); }

.guess-row .name-cell {
  color: var(--text-main);
  font-weight: 700;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

/* 对手面板：仅色块，文字隐藏 */
.board-col.opponent .cell .cell-text { display: none; }
.board-col.opponent .cell { color: transparent; }

/* ========== 结果覆盖层 ========== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  backdrop-filter: blur(4px);
}
.overlay-content {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 0;
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

/* 结果卡片 */
.result-card {
  display: flex;
  flex-direction: column;
}
.card-header {
  padding: 28px;
  border-radius: 20px 20px 0 0;
  color: white;
}
.card-header.win { background: linear-gradient(135deg, #22c55e, #16a34a); }
.card-header.lose { background: linear-gradient(135deg, #475569, #334155); }
.card-icon { font-size: 48px; margin-bottom: 12px; }
.card-title { font-size: 24px; font-weight: 800; margin-bottom: 4px; }
.card-subtitle { font-size: 15px; opacity: 0.9; }

.card-body { padding: 24px; }
.char-name {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.char-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.info-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.info-row .label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.info-row .value {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

.card-footer {
  padding: 20px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
}
.card-footer button { flex: 1; margin: 0; }

/* ========== 底部功能栏 ========== */
.bottom-bar {
  max-width: 960px;
  margin: 24px auto;
  padding: 0 16px;
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}
.text-btn {
  background: transparent;
  border: none;
  color: var(--text-sub);
  font-size: 14px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: all .2s;
  font-weight: 500;
}
.text-btn:hover { 
  color: var(--text-main); 
  background: var(--bg-card);
}

/* ========== 弹窗 ========== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
}
.modal-content {
  position: relative;
  background: var(--bg-card);
  border-radius: 20px;
  padding: 28px;
  max-width: 500px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  z-index: 2;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.modal-content.small { max-width: 340px; }
.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  background: var(--bg);
  border: none;
  font-size: 20px;
  color: var(--text-sub);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
}
.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}
.modal-content h2 { 
  margin-bottom: 16px; 
  font-size: 20px;
  color: var(--text-main);
}

/* 玩法说明 */
.help-body p { margin-bottom: 12px; font-size: 14px; line-height: 1.7; color: var(--text-sub); }
.color-legend { margin: 16px 0; }
.color-legend div { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 14px; color: var(--text-sub); }
.legend-box { width: 20px; height: 20px; border-radius: 6px; display: inline-block; }
.legend-box.correct { background: var(--green); }
.legend-box.partial { background: var(--yellow); }
.legend-box.wrong   { background: var(--gray); }

/* 排行榜 */
.leaderboard-body { font-size: 14px; }
.leaderboard-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.leaderboard-row:last-child { border-bottom: none; }
.leaderboard-row span { color: var(--text-sub); }
.leaderboard-row strong { color: var(--text-main); font-weight: 700; }

/* 番剧池选择 */
.pool-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pool-list label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
  border: 1px solid transparent;
}
.pool-list label:hover { 
  background: var(--bg);
  border-color: var(--border);
}
.pool-list label:has(input:checked) {
  background: rgba(96, 165, 250, 0.1);
  border-color: var(--accent);
}
.pool-list input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}
.pool-list label span {
  color: var(--text-main);
}

/* PVP 菜单 */
.pvp-menu, .pvp-room { text-align: center; }
.or-divider { margin: 16px 0; color: var(--text-muted); font-size: 13px; }
#room-code-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  text-align: center;
  font-size: 16px;
  letter-spacing: 2px;
  background: var(--bg-input);
  color: var(--text-main);
}
#room-code-input::placeholder {
  color: var(--text-muted);
}

/* ========== PVP 对局面板 ========== */
#pvp-board {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}
.pvp-input-area {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}
.pvp-input-area #pvp-guess-input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  outline: none;
  transition: all .2s;
  background: var(--bg-input);
  color: var(--text-main);
}
.pvp-input-area #pvp-guess-input:focus { 
  border-color: var(--accent); 
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}
.board-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
}
.player-panel { text-align: center; }
.player-name { font-size: 14px; color: var(--text-sub); }
.player-score { font-size: 32px; font-weight: 800; color: var(--text-main); }
.match-info { text-align: center; }
.match-round { font-size: 13px; color: var(--text-sub); }
.match-timer { font-size: 24px; font-weight: 800; color: var(--arrow-down); }
.board-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.board-col .col-title {
  text-align: center;
  font-size: 14px;
  color: var(--text-sub);
  margin-bottom: 10px;
  font-weight: 600;
}

/* ========== 响应式 ========== */
@media (max-width: 900px) {
  :root { --cell-size: 44px; }
  .grid-header, .guess-row {
    grid-template-columns: 90px repeat(11, 1fr);
    gap: 4px;
  }
  .header-cell, .cell { 
    font-size: 10px; 
    padding: 6px 2px; 
    min-height: var(--cell-size); 
  }
}

@media (max-width: 768px) {
  :root { --cell-size: 40px; }
  .nav-inner { padding: 10px 12px; }
  .mode-btn { padding: 5px 10px; font-size: 13px; }
  .grid-header, .guess-row {
    grid-template-columns: 80px repeat(11, 1fr);
    gap: 3px;
  }
  .header-cell, .cell { 
    font-size: 9px; 
    padding: 5px 2px; 
    min-height: var(--cell-size); 
    border-radius: 6px;
  }
  .input-area { flex-wrap: wrap; }
  #guess-btn, #giveup-btn { width: 100%; }
  .board-body { grid-template-columns: 1fr; }
  .player-score { font-size: 24px; }
  .match-timer { font-size: 20px; }
}

@media (max-width: 480px) {
  :root { --cell-size: 36px; }
  .grid-header, .guess-row {
    grid-template-columns: 65px repeat(11, 1fr);
    gap: 2px;
  }
  .header-cell, .cell { 
    font-size: 8px; 
    padding: 4px 1px; 
    border-radius: 5px;
  }
  .suggest-anime {
    display: none;
  }
}

/* ========== 滚动条美化 ========== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
