/* 卡一把 · 离线版样式(与在线版 Blast 暗色主题保持一致) */
:root {
  color-scheme: dark;
  --bg: #160a13;
  --card: #281520;
  --card-soft: #20101a;
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(218, 255, 61, 0.42);
  --text: #f8f5f7;
  --text-sec: #c9bac5;
  --text-light: #95818f;
  --input-bg: #170b13;
  --primary: #d9ff3f;
  --primary-hover: #c5eb2e;
  --primary-soft: rgba(217, 255, 63, 0.11);
  --success: #51d795;
  --warning: #ffad49;
  --danger: #ff6578;
  --accent: #a281ff;
  --correct: #38bd78;
  --close: #d59632;
  --wrong: #675563;
  --radius: 4px;
  --radius-sm: 3px;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 28px 80px rgba(0, 0, 0, 0.48);
}

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

html, body { width: 100%; max-width: 100%; overflow-x: hidden; }

body {
  min-width: 320px;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background:
    radial-gradient(circle at 82% -12%, rgba(118, 47, 91, 0.3), transparent 34rem),
    radial-gradient(circle at 4% 88%, rgba(83, 31, 65, 0.24), transparent 28rem),
    repeating-linear-gradient(118deg, transparent 0 92px, rgba(255, 255, 255, 0.018) 92px 93px),
    var(--bg);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: 0;
  content: '';
  pointer-events: none;
  background:
    radial-gradient(circle at 28% 34%, rgba(217, 255, 63, 0.045), transparent 26%),
    radial-gradient(circle at 72% 62%, rgba(162, 129, 255, 0.075), transparent 30%);
}

button, input { font: inherit; }
button, a { touch-action: manipulation; }
::selection { background: rgba(217, 255, 63, 0.45); }

* { scrollbar-color: rgba(217, 255, 63, 0.42) rgba(255, 255, 255, 0.04); scrollbar-width: thin; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.04); }
*::-webkit-scrollbar-thumb { background: rgba(217, 255, 63, 0.38); }

.screen { position: relative; z-index: 1; min-height: 100dvh; display: flex; flex-direction: column; }
.screen.hidden { display: none; }

/* ---------- 顶栏(与在线版 header-bar 一致) ---------- */
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px clamp(1rem, 4vw, 3.25rem);
  background: rgba(22, 10, 19, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.11);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.24);
}
.topbar::after {
  position: absolute;
  right: clamp(1rem, 4vw, 3.25rem);
  bottom: -1px;
  width: clamp(48px, 9vw, 120px);
  height: 2px;
  content: '';
  background: var(--primary);
  box-shadow: 0 0 20px rgba(217, 255, 63, 0.55);
}
.brand {
  color: #fff;
  font-family: Bahnschrift, 'Arial Narrow', 'Microsoft YaHei', sans-serif;
  font-style: italic;
  font-weight: 800;
  letter-spacing: 0.045em;
  font-size: 1.15rem;
}
.brand::before { content: "//"; color: var(--primary); margin-right: 8px; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 按钮(与在线版 controls.css 一致) ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  min-height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 8px 16px rgba(0, 0, 0, 0.24); }
.btn:active:not(:disabled) { transform: translateY(0); box-shadow: none; }
.btn:disabled { opacity: 0.52; cursor: not-allowed; box-shadow: none; }
.btn-sm { padding: 7px 12px; font-size: 0.85rem; min-height: 34px; }
.btn-lg { padding: 13px 26px; font-size: 1.05rem; }
.btn-green { background: var(--success); border-color: transparent; }
.btn-green:hover:not(:disabled) { background: #117448; }
.btn-warning { background: transparent; border-color: var(--warning); color: var(--warning); }
.btn-warning:hover:not(:disabled) { background: rgba(255, 173, 73, 0.12); border-color: var(--warning); color: var(--warning); box-shadow: none; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(255, 101, 120, 0.12); border-color: var(--danger); color: var(--danger); box-shadow: none; }
.link-btn { background: none; border: none; color: var(--text-light); text-decoration: underline; font-size: 0.9rem; margin-top: 6px; cursor: pointer; }

/* ---------- 开始页 ---------- */
.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px clamp(1rem, 4vw, 3.25rem);
  gap: 18px;
  animation: surface-enter 0.52s cubic-bezier(0.2, 0.72, 0.25, 1) both;
}
@keyframes surface-enter {
  from { opacity: 0; transform: translate3d(0, 16px, 0); }
  to { opacity: 1; transform: translate3d(0, 0, 0); }
}
.kicker {
  letter-spacing: 0.35em;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
}
.hero h1 {
  font-size: 3rem;
  letter-spacing: 0.14em;
  font-family: Bahnschrift, 'Arial Narrow', 'Microsoft YaHei', sans-serif;
  font-style: italic;
  font-weight: 800;
  color: #fff;
}
.subtitle { color: var(--text-light); max-width: 34rem; }
.hero .btn-green { margin-top: 12px; }
.footer { text-align: center; color: var(--text-light); font-size: 0.78rem; padding: 16px; }
.footer-links {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
}
.footer-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-light);
  text-decoration: none;
  transition: color 0.15s ease;
}
.footer-link:hover { color: var(--primary); }

/* ---------- 游戏页 ---------- */
.game-wrap {
  flex: 1;
  width: 100%;
  max-width: 73.75rem;
  margin: 0 auto;
  padding: 16px clamp(1rem, 4vw, 3.25rem) 24px;
  animation: surface-enter 0.52s cubic-bezier(0.2, 0.72, 0.25, 1) both;
}
.status-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  color: var(--text-sec);
  font-size: 0.85rem;
}
.progress-dots { display: inline-flex; align-items: center; gap: 4px; }
.progress-dots i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: transparent;
}
.progress-dots i.used { border-color: var(--primary); background: var(--primary); }

/* 棋盘(与在线版 game-table 一致:圆角色块 + 间距) */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-soft);
  padding: 10px;
}
table.board { width: 100%; border-collapse: separate; border-spacing: 6px 5px; font-size: 0.9rem; }
.board th {
  color: var(--text-sec);
  font-weight: 600;
  font-size: 0.8rem;
  padding: 6px 8px;
  text-align: center;
  white-space: nowrap;
}
.board td {
  padding: 9px 10px;
  text-align: center;
  border-radius: 9px;
  background: var(--card);
  border: 1px solid transparent;
  white-space: nowrap;
}
.board td.name { font-weight: 700; text-align: left; }
/* 注意:td 必须保持 table-cell,直接给 td 设 display:flex 会让它脱离表格布局、
   整行列位错乱。所以头像与名字的横向对齐放在内层 .name-cell 上。 */
.name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}
.name-text { min-width: 0; overflow-wrap: anywhere; }
.board th:nth-child(1), .board td:nth-child(1) { width: 18%; }
.board th:nth-child(2), .board td:nth-child(2) { width: 12%; }
.board th:nth-child(3), .board td:nth-child(3) { width: 12%; }
.board th:nth-child(4), .board td:nth-child(4) { width: 10%; }
.board th:nth-child(5), .board td:nth-child(5) { width: 12%; }
.board th:nth-child(6), .board td:nth-child(6) { width: 10%; }
.board th:nth-child(7), .board td:nth-child(7) { width: 12%; }
.board th:nth-child(8), .board td:nth-child(8) { width: 14%; }
.board td.correct { background: var(--correct); border-color: var(--correct); color: #fff; }
.board td.close { background: var(--close); border-color: var(--close); color: #fff; }
.board td.wrong { background: var(--wrong); border-color: var(--wrong); color: #fff; }
.board td .dir { display: inline-flex; vertical-align: -2px; margin-left: 3px; }
.board tr.row-latest td { border-color: var(--primary); }
.board tr.row-correct td { background: var(--primary-soft); }
.board tr.row-correct td.correct { background: var(--correct); }

/* 图例 */
.legend {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin-top: 14px;
  color: var(--text-light);
  font-size: 0.8rem;
  flex-wrap: wrap;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}
.legend .legend-correct { background: var(--correct); }
.legend .legend-close { background: var(--close); }
.legend .legend-wrong { background: var(--wrong); }

/* 输入栏(与在线版 input-bar 一致) */
.input-bar {
  display: flex;
  gap: 10px;
  width: 100%;
  min-width: 0;
  max-width: 56.25rem;
  margin: 14px auto 0;
}
.input-bar input {
  flex: 1;
  min-width: 0;
  font-size: 1.05rem;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--input-bg);
  color: var(--text);
  outline: none;
}
.input-bar input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(217, 255, 63, 0.14); }
.input-bar .btn { flex-shrink: 0; white-space: nowrap; }

.autocomplete { position: relative; max-width: 56.25rem; margin: 0 auto; }
.suggestions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 4px);
  z-index: 10;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 320px;
  overflow-y: auto;
  display: none;
  list-style: none;
  padding: 6px;
}
.suggestions.open { display: block; }
.suggestions li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
}
.suggestions li.active, .suggestions li:hover { background: var(--primary-soft); color: var(--primary-hover); }

.empty-hint { color: var(--text-light); text-align: center; padding: 60px 16px; }

/* ---------- 弹窗(与在线版 overlay 一致) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(10, 5, 9, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.overlay.show { display: flex; }
.overlay-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 26px;
  max-width: 440px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: surface-enter 0.32s cubic-bezier(0.2, 0.72, 0.25, 1) both;
}
.overlay-card h2 { margin-bottom: 10px; font-size: 1.25rem; }
.overlay-card.win { border-color: var(--correct); }
.overlay-card.lose { border-color: var(--danger); }
.answer-name {
  font-size: 1.9rem;
  font-weight: 800;
  font-family: Bahnschrift, 'Arial Narrow', 'Microsoft YaHei', sans-serif;
  font-style: italic;
  margin: 6px 0 14px;
  color: #fff;
}
.info-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.info-table td { padding: 8px 6px; border-bottom: 1px solid var(--border); }
.info-table td.label { color: var(--text-light); width: 40%; }
.muted { color: var(--text-light); font-size: 0.85rem; margin: 8px 0; }
.overlay-actions { display: flex; gap: 8px; margin-top: 18px; }
.overlay-actions .btn { flex: 1; }

/* 规则 */
.rules-body { font-size: 0.9rem; line-height: 1.75; color: var(--text-sec); }
.rules-body h3 { color: var(--text); margin: 14px 0 6px; font-size: 0.95rem; }
.rules-body ul { padding-left: 18px; }
.rules-body li { margin: 3px 0; }
.rule-close {
  float: right;
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}
.rule-close:hover { color: var(--text); }

/* ---------- 输入坞(底部固定,手机端粘底) ---------- */
.input-dock {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  padding: 12px 0 14px;
  background: linear-gradient(180deg, transparent, var(--bg) 22%);
  z-index: 5;
}
.input-dock .autocomplete { position: relative; max-width: 56.25rem; margin: 0 auto; }
.input-dock .input-bar { margin-top: 0; }

/* 提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%) translateY(20px);
  background: var(--card);
  border: 1px solid var(--warning);
  color: var(--warning);
  padding: 10px 18px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s;
  z-index: 100;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 图片(头像 / 立绘) ---------- */
/* 猜测行小头像:默认 40px,保证在棋盘上也一眼认得出是谁 */
.row-avatar {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
}

/* 候选列表小头像 */
.sug-avatar {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
}
.sug-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 1rem;
}

.result-portrait-wrap {
  display: flex;
  justify-content: center;
  margin: 2px 0 14px;
}
.result-portrait-wrap.hidden { display: none; }
.result-portrait {
  max-width: 100%;
  max-height: 44vh;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.01));
}

/* ---------- 平板 / 小笔记本(641 ~ 1024px) ---------- */
@media (min-width: 641px) and (max-width: 1024px) {
  .row-avatar { width: 36px; height: 36px; }
  .sug-avatar { width: 36px; height: 36px; }
  .suggestions li { min-height: 52px; }
  .result-portrait { max-height: 40vh; }
}

/* ---------- 横屏手机 / 矮视口:收一收纵向占用,别让内容被挤没 ---------- */
@media (max-height: 480px) and (orientation: landscape) {
  .hero { gap: 10px; padding: 14px 1rem; }
  .hero h1 { font-size: 1.8rem; }
  .status-line { padding: 4px; }
  .suggestions { max-height: 62dvh; }
  .overlay-card { padding: 16px; }
  .result-portrait { max-height: 56vh; }
  .result-portrait-wrap { margin-bottom: 8px; }
}

/* ---------- 手机端(与在线版 responsive.css 一致) ---------- */
@media (max-width: 640px) {
  body { padding-bottom: env(safe-area-inset-bottom); }

  .topbar {
    gap: 8px;
    padding: calc(10px + env(safe-area-inset-top)) 0.875rem 10px;
  }
  .topbar::after { right: 0.875rem; }
  .topbar .actions { gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .topbar .actions .btn { padding: 7px 10px; font-size: 0.82rem; min-height: 36px; }

  .hero { padding: 28px 1rem; gap: 14px; }
  .hero h1 { font-size: 2rem; letter-spacing: 0.1em; }
  .kicker { font-size: 0.7rem; }
  .hero .btn-lg { min-height: 46px; padding: 12px 26px; }

  .game-wrap { padding: 10px 0.875rem 0; }

  .btn { min-height: 40px; padding: 9px 14px; }
  .btn-lg { min-height: 44px; padding: 11px 19px; }
  .input-bar .input { min-height: 46px; font-size: 1rem; padding: 10px 12px; }
  .input-bar .btn { min-height: 46px; padding-inline: 14px; }

  .status-line { padding: 8px 4px; font-size: 0.8rem; }

  /* 棋盘:固定布局 + 紧凑单元格(在线版同款) */
  .table-wrap { overflow-x: hidden; border-radius: 10px; padding: 6px; }
  table.board {
    min-width: 0;
    table-layout: fixed;
    border-spacing: 2px;
    font-size: 0.72rem;
  }
  .board th {
    padding: 5px 1px;
    font-size: 0.68rem;
    line-height: 1.12;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .board td {
    padding: 6px 2px;
    border-radius: 4px;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.15;
  }
  .board td .dir { margin-left: 1px; font-size: 8px; }

  .input-dock {
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  }
  /* 键盘弹起时隐藏顶栏与状态行,并让屏幕高度跟随视觉视口(与在线版 keyboard-active 一致) */
  #game-screen.keyboard-active .topbar,
  #game-screen.keyboard-active .status-line { display: none; }
  #game-screen.keyboard-active { height: var(--visual-viewport-height, 100dvh); min-height: 0; }
  .autocomplete { left: 0; right: 0; }
  .suggestions {
    left: 14px;
    right: 14px;
    max-height: 48dvh;
  }

  .legend { gap: 10px; font-size: 0.72rem; margin-top: 10px; }
  .legend i { width: 10px; height: 10px; }

  .overlay { padding: 12px; }
  .overlay-card { padding: 20px 16px; border-radius: 16px; }
  .answer-name { font-size: 1.5rem; }
  .overlay-actions { flex-direction: column; }
  .overlay-actions .btn { width: 100%; min-height: 44px; }
  .info-table td { padding: 7px 4px; font-size: 0.84rem; }

  /* 手机端:头像缩小但仍保持辨识度;角色名列加宽,避免头像与名字挤在一起 */
  .board th:nth-child(1), .board td:nth-child(1) { width: 24%; }
  .board th:nth-child(2), .board td:nth-child(2) { width: 11%; }
  .board th:nth-child(3), .board td:nth-child(3) { width: 11%; }
  .board th:nth-child(4), .board td:nth-child(4) { width: 9%; }
  .board th:nth-child(5), .board td:nth-child(5) { width: 11%; }
  .board th:nth-child(6), .board td:nth-child(6) { width: 9%; }
  .board th:nth-child(7), .board td:nth-child(7) { width: 11%; }
  .board th:nth-child(8), .board td:nth-child(8) { width: 14%; }
  .name-cell { gap: 6px; }
  .row-avatar { width: 32px; height: 32px; }
  .sug-avatar { width: 36px; height: 36px; }
  .suggestions li { min-height: 52px; padding: 6px 10px; }
  .result-portrait { max-height: 40vh; border-radius: 10px; }

  .footer { font-size: 0.7rem; padding: 10px; }
}

@media (max-width: 400px) {
  table.board { border-spacing: 1px; }
  .board th { padding: 4px 0; font-size: 0.62rem; }
  .board td { padding: 5px 1px; font-size: 0.66rem; }
  .board td .dir { font-size: 7px; }
  .topbar .actions .btn { padding: 6px 8px; font-size: 0.76rem; }
  .row-avatar { width: 28px; height: 28px; }
  .sug-avatar { width: 32px; height: 32px; }
  .suggestions li { min-height: 48px; }
}
