/* ============= 全局 ============= */
* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  margin: 0;
  background: #f5f6f8;
  color: #2a2a2a;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
h1, h2, h3 { margin: 0 0 12px; }
h1 { font-size: 20px; }
h2 { font-size: 16px; color: #1b2838; }
.hidden { display: none !important; }

/* ============= 顶栏 ============= */
.topbar {
  background: #1b2838;
  color: white;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.topbar h1 { color: white; font-size: 18px; }

.tabs { display: flex; gap: 4px; }
.tab-btn {
  background: transparent;
  color: #c0c8d0;
  border: none;
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 5px;
  font-size: 14px;
  font-family: inherit;
  transition: background-color 150ms ease, color 150ms ease;
}
.tab-btn:hover { background: rgba(255,255,255,0.12); color: white; }
.tab-btn.active { background: #66c0f4; color: #1b2838; font-weight: 600; }

.tabs-bottom { display: none; }

/* ============= 内容区 ============= */
.tab-page {
  max-width: 1100px;
  margin: 16px auto;
  padding: 0 16px;
  /* tab 切换动效 */
  animation: tabFadeIn 200ms ease-out;
}
@keyframes tabFadeIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.card {
  background: white;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 6px rgba(20, 30, 50, 0.05);
}

/* ============= 表单 ============= */
label {
  display: block;
  margin: 10px 0 4px;
  font-size: 13px;
  color: #555;
  font-weight: 500;
}
label.inline { display: inline-flex; align-items: center; gap: 4px; margin: 0; }
.hint.inline { display: inline; }

input[type="text"], input[type="password"], input[type="number"], select {
  padding: 8px 10px;
  border: 1px solid #d0d4d8;
  border-radius: 5px;
  font-size: 14px;
  font-family: inherit;
  background: white;
  width: 100%;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
input[type="number"] { width: auto; min-width: 60px; }

label.inline input { width: auto; min-width: 60px; }

input:focus, select:focus {
  outline: none;
  border-color: #66c0f4;
  box-shadow: 0 0 0 3px rgba(102, 192, 244, 0.18);
}
.hint {
  font-size: 12px;
  color: #888;
  margin: 4px 0 8px;
}
.hint a { color: #1976d2; }
.empty-hint, .empty-hint-small {
  text-align: center;
  color: #888;
  padding: 30px 16px;
  font-size: 14px;
}
.empty-hint-small { padding: 12px; font-size: 13px; }

/* ============= 按钮 ============= */
button {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 16px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  margin: 4px 4px 4px 0;
  transition: background-color 150ms ease, transform 80ms ease, box-shadow 150ms ease;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:active:not(:disabled) { transform: translateY(1px); }

.btn-primary {
  background: #1b2838;
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: #2a3f5f;
  box-shadow: 0 2px 6px rgba(27, 40, 56, 0.25);
}
.btn-secondary {
  background: #e8eaed;
  color: #1a1a1a;
}
.btn-secondary:hover:not(:disabled) { background: #d8dadd; }
.btn-danger { background: #d9534f; color: white; }
.btn-danger:hover:not(:disabled) {
  background: #c9302c;
  box-shadow: 0 2px 6px rgba(217, 83, 79, 0.3);
}

/* 大抽奖按钮 */
.btn-roulette {
  width: 100%;
  background: linear-gradient(180deg, #2a3f5f 0%, #1b2838 100%);
  color: white;
  font-size: 18px;
  font-weight: 600;
  padding: 18px 24px;
  margin: 12px 0;
  border-radius: 12px;
  letter-spacing: 4px;
  box-shadow: 0 3px 10px rgba(27, 40, 56, 0.25);
  transition: transform 100ms ease, box-shadow 200ms ease, background 200ms ease;
}
.btn-roulette:hover:not(:disabled) {
  background: linear-gradient(180deg, #3a4f6f 0%, #2b3848 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(27, 40, 56, 0.35);
}
.btn-roulette:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 2px 6px rgba(27, 40, 56, 0.25);
}
.btn-roulette:disabled {
  background: linear-gradient(180deg, #4a5a7f 0%, #3a4f6f 100%);
  letter-spacing: 6px;
  cursor: wait;
  opacity: 1;
}

/* 摇骰子时的小动效（图标摇晃） */
.btn-roulette.rolling .dice-icon {
  display: inline-block;
  animation: diceShake 250ms ease-in-out infinite;
}
@keyframes diceShake {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-15deg); }
  75% { transform: rotate(15deg); }
}

/* ============= 筛选区 ============= */
.filter-card { padding: 12px 16px; }

.selected-groups {
  background: #fafbfc;
  border: 1px solid #e8eaed;
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 10px;
  min-height: 40px;
}
.tag-group-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}
.tag-group-label {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  color: white;
  cursor: pointer;
  user-select: none;
  transition: opacity 150ms ease;
}
.tag-group-label:hover { opacity: 0.85; }
.tag-group-label.current::before { content: "▶ "; }
.tag-group-row .chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: #e8eaed;
  border-radius: 3px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  transition: background-color 150ms ease;
}
.tag-group-row .chip:hover { background: #d0d4d8; }
.tag-group-row .chip::after {
  content: "✕";
  font-size: 10px;
  opacity: 0.5;
}
.tag-group-row .group-or {
  color: #888;
  font-size: 11px;
  padding: 0 2px;
}
.tag-group-row .group-delete {
  color: #999;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  transition: color 150ms ease;
}
.tag-group-row .group-delete:hover { color: #d9534f; }

.group-and-sep {
  text-align: center;
  color: #555;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 0;
}

.exclude-row {
  border-top: 1px dashed #d0d4d8;
  margin-top: 4px;
  padding-top: 8px;
}
.exclude-row .tag-group-label { background: #d9534f; }
.exclude-row .chip { background: #f5d0d0; }
.exclude-row .chip:hover { background: #ecbcbc; }

.add-group-btn, .clear-all-btn {
  background: transparent;
  border: 1px dashed #ccc;
  color: #666;
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
  border-radius: 4px;
  margin-top: 4px;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}
.add-group-btn:hover, .clear-all-btn:hover {
  background: #f0f0f0;
  color: #333;
  border-color: #999;
}
.clear-all-btn { float: right; }

/* 基础筛选行 */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  margin: 10px 0;
  font-size: 13px;
  color: #555;
}
.filter-row label.inline input { width: 70px; }

/* 标签云 */
.tag-cloud-wrap {
  border-top: 1px solid #eee;
  padding-top: 10px;
}
.tag-cloud-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.tag-cloud-header input { flex: 1; max-width: 240px; }

.tag-cloud {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px;
  border: 1px solid #f0f0f0;
  border-radius: 5px;
  background: #fafbfc;
}
.tag-chip {
  display: inline-block;
  padding: 3px 8px;
  border: 1px solid #d0d4d8;
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-size: 12px;
  user-select: none;
  /* 颜色 / 边框过渡，让状态切换平滑 */
  transition: background-color 180ms ease, color 180ms ease,
              border-color 180ms ease, transform 100ms ease;
}
.tag-chip:hover {
  background: #f0f4f8;
  transform: translateY(-1px);
}
.tag-chip:active { transform: translateY(0); }
.tag-chip .count {
  color: #999;
  margin-left: 3px;
  font-size: 10px;
}

/* ============= 抽奖结果 ============= */
.result-area {
  background: white;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 6px rgba(20, 30, 50, 0.05);
}
.result-card {
  border-left: 3px solid #66c0f4;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: #fafbfc;
  border-radius: 0 6px 6px 0;

  /* 滑入 + 淡入动效 */
  opacity: 0;
  animation: resultSlideIn 320ms cubic-bezier(0.2, 0.8, 0.4, 1) forwards;
}
@keyframes resultSlideIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
/* 多个结果时,逐个出现 */
.result-card:nth-child(1) { animation-delay: 0ms; }
.result-card:nth-child(2) { animation-delay: 100ms; }
.result-card:nth-child(3) { animation-delay: 200ms; }
.result-card:nth-child(4) { animation-delay: 300ms; }
.result-card:nth-child(5) { animation-delay: 400ms; }
.result-card:nth-child(6) { animation-delay: 500ms; }
.result-card:nth-child(7) { animation-delay: 600ms; }
.result-card:nth-child(8) { animation-delay: 700ms; }
.result-card:nth-child(9) { animation-delay: 800ms; }
.result-card:nth-child(10) { animation-delay: 900ms; }

.result-card:last-child { margin-bottom: 0; }
.result-name {
  font-size: 16px;
  font-weight: 600;
  color: #1b2838;
  margin-bottom: 4px;
}
.result-tags {
  font-size: 13px;
  color: #555;
  margin-bottom: 4px;
  line-height: 1.7;
}
.result-tag-hit {
  background: #fff3a0;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
}
.result-meta { font-size: 12px; color: #888; }
.result-actions { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.result-actions button { font-size: 12px; padding: 4px 10px; margin: 0; }

/* ============= 库列表 ============= */
.stats-card { padding: 12px 16px; }
.stats-row {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  font-size: 14px;
  color: #555;
}
.stats-row strong {
  color: #1b2838;
  font-size: 18px;
  margin-right: 4px;
}

.library-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.library-controls input { flex: 1; }
.library-controls select { width: auto; min-width: 100px; }

.library-list { max-height: 65vh; overflow-y: auto; }
.game-item {
  padding: 10px 12px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background-color 120ms ease;
}
.game-item:hover { background: #f3f6f9; }
.game-item:last-child { border-bottom: none; }
.game-name {
  font-weight: 500;
  font-size: 14px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.game-tags {
  font-size: 12px;
  color: #777;
  flex: 2;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.game-meta { font-size: 12px; color: #999; white-space: nowrap; }

/* ============= 历史 ============= */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.history-list { max-height: 65vh; overflow-y: auto; }
.history-item {
  padding: 10px 12px;
  border-bottom: 1px solid #eee;
}
.history-item:last-child { border-bottom: none; }
.history-time { font-size: 11px; color: #888; }
.history-filters { font-size: 12px; color: #666; margin: 2px 0; }
.history-results {
  font-size: 14px;
  color: #1b2838;
  font-weight: 500;
}

/* ============= 进度 ============= */
progress {
  width: 100%;
  height: 6px;
  margin: 8px 0;
}
progress::-webkit-progress-bar { background: #e8eaed; border-radius: 3px; }
progress::-webkit-progress-value {
  background: #66c0f4;
  border-radius: 3px;
  transition: width 300ms ease;
}

/* ============= 危险区 ============= */
.danger-zone { border-left: 3px solid #d9534f; }

/* ============= Toast ============= */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  background: #1a1a1a;
  color: white;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  z-index: 1000;
  max-width: 90%;

  /* 滑入 + 淡入动效 */
  transform: translateX(-50%) translateY(0);
  animation: toastIn 240ms cubic-bezier(0.2, 0.8, 0.4, 1);
}
.toast.hidden {
  display: none;
}
.toast.closing {
  /* 消失：淡出下滑 */
  animation: toastOut 200ms ease-in forwards;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(30px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to   { opacity: 0; transform: translateX(-50%) translateY(30px); }
}
.toast.error { background: #c62828; }
.toast.success { background: #2e7d32; }

/* ============= 模态/详情窗 ============= */
.modal-mask {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(20, 30, 50, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  /* 蒙层淡入 */
  animation: maskFadeIn 180ms ease-out;
}
.modal-mask.closing { animation: maskFadeOut 160ms ease-in forwards; }
@keyframes maskFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes maskFadeOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

.modal {
  background: white;
  border-radius: 10px;
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 22px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  /* 弹出动效：缩放 + 上浮 */
  animation: modalIn 220ms cubic-bezier(0.2, 0.8, 0.4, 1);
}
.modal-mask.closing .modal { animation: modalOut 160ms ease-in forwards; }
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes modalOut {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.96); }
}
.modal h3 { margin-top: 0; font-size: 18px; color: #1b2838; }
.modal-section { margin: 12px 0; }
.modal-section-label { font-size: 13px; color: #555; font-weight: 600; margin-bottom: 4px; }
.modal-tag-chip {
  display: inline-block;
  padding: 2px 8px;
  margin: 2px;
  background: #e8eaed;
  border-radius: 3px;
  font-size: 12px;
}
.modal-tag-chip.custom {
  background: #fff3cd;
  cursor: pointer;
  transition: background-color 150ms ease;
}
.modal-tag-chip.custom:hover { background: #ffe898; }
.modal-tag-chip.custom::after { content: " ✕"; font-size: 10px; opacity: 0.5; }
.modal-actions {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid #eee;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

/* ============= 移动端 ============= */
@media (max-width: 700px) {
  .topbar h1 { font-size: 16px; }
  .topbar { padding: 10px 12px; }
  .tabs-top { display: none; }

  .tabs-bottom {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #e0e0e0;
    z-index: 10;
    padding: 4px 0;
    padding-bottom: env(safe-area-inset-bottom, 4px);
    box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
  }
  .tabs-bottom .tab-btn {
    flex: 1;
    flex-direction: column;
    padding: 8px 0;
    font-size: 18px;
    color: #888;
    border-radius: 0;
  }
  .tabs-bottom .tab-btn span {
    font-size: 11px;
    display: block;
    margin-top: 2px;
  }
  .tabs-bottom .tab-btn:hover { background: transparent; }
  .tabs-bottom .tab-btn.active {
    background: transparent;
    color: #1b2838;
    font-weight: 600;
  }
  .tabs-bottom .tab-btn.active span { color: #1b2838; }

  body { padding-bottom: 64px; }

  .tab-page { padding: 0 10px; margin-top: 10px; }
  .card { padding: 14px; }
  .stats-row { gap: 12px; font-size: 12px; }
  .stats-row strong { font-size: 14px; }

  .filter-row { gap: 10px; font-size: 12px; }
  .filter-row label.inline input { width: 56px; }

  .tag-cloud { max-height: 180px; }

  /* 移动端按钮稍微大一点点更好按 */
  button { padding: 10px 16px; }
  .btn-roulette {
    font-size: 16px;
    padding: 16px;
    letter-spacing: 2px;
  }
  .tag-chip { padding: 5px 10px; font-size: 13px; }
  .modal-tag-chip { padding: 4px 10px; font-size: 13px; }

  .game-tags { display: none; }

  /* 详情窗手机上稍微调整 */
  .modal { padding: 18px; }
}

/* 用户偏好"减少动效"时,关掉所有动画 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
