/* ===== 合成国科大 · 样式 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary: #6650b7;
  --primary-dark: #4f3d95;
  --danger: #dc3f4c;
  --ink: #332d26;
  --ink-soft: #7a6f63;
  --card: #ffffff;
  --line: #e8e2da;
  --bg: #f6f4f1;
}

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
  touch-action: manipulation;
}

.app {
  max-width: 460px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 10px 12px 18px;
}

/* ===== 顶栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 2px 10px;
}

.brand {
  flex: 1;
  min-width: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.25;
  color: var(--primary-dark);
  letter-spacing: 1px;
}

.brand p {
  font-size: 10.5px;
  color: var(--ink-soft);
  margin-top: 2px;
  line-height: 1.35;
}

.metrics {
  display: flex;
  gap: 5px;
}

.metric {
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 10px;
  min-width: 46px;
  padding: 4px 5px;
}

.metric span {
  display: block;
  font-size: 9.5px;
  color: var(--ink-soft);
}

.metric strong {
  font-size: 15px;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.metric-ucas {
  border-color: #e9c46a;
  background: #fffaf0;
}

.metric-ucas strong {
  color: #c98a12;
}

.multiplier-chip {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary-dark);
  background: #efeaff;
  border: 1px solid #d9cdf5;
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(101, 80, 183, 0.18);
  z-index: 4;
  pointer-events: none;
}

.multiplier-chip:not(.show) {
  visibility: hidden;
}

.header-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.icon-button {
  width: 34px;
  height: 30px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.sound-icon {
  position: relative;
  width: 14px;
  height: 14px;
}

.sound-icon::before {
  content: "";
  position: absolute;
  left: 0;
  top: 2px;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-right: 8px solid var(--ink);
}

.sound-icon::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 1.5px;
  width: 7px;
  height: 7px;
  border: 2px solid var(--ink);
  border-left: none;
  border-bottom: none;
  border-radius: 0 8px 0 0;
  transform: rotate(0deg);
}

.sound-icon.is-muted::after {
  display: none;
}

.sound-icon.is-muted::before {
  border-right-color: var(--ink-soft);
  opacity: 0.5;
}

.small-button {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}

.small-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.small-button:not(:disabled):active {
  transform: scale(0.96);
}

/* ===== 棋盘 ===== */
.board {
  position: relative;
  width: 100%;
  /* 用 padding-top 比例盒，保证任意浏览器下都是严格的 400:496（游戏区高度为原来的 80%） */
  padding-top: 124%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 6px 22px rgba(70, 55, 40, 0.08);
}

.board canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
}

/* ===== 横幅 ===== */
.banner {
  position: absolute;
  top: 46px;
  left: 50%;
  transform: translateX(-50%) translateY(-14px);
  background: rgba(255, 214, 130, 0.96);
  color: #7a4a00;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(200, 140, 0, 0.3);
  white-space: nowrap;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.28s ease;
  z-index: 5;
}

.banner.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Combo 徽章 ===== */
.combo-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 1px;
  padding: 5px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 3px 10px rgba(40, 30, 20, 0.18);
  opacity: 0;
  transform: scale(0.7);
  transform-origin: left top;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
  z-index: 4;
}

.combo-badge.show {
  opacity: 1;
  transform: scale(1);
}

/* ===== 功能卡（摇晃 / 删除）操作栏 ===== */
.card-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 2px 10px;
  flex-wrap: wrap;
}

.card-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(70, 55, 40, 0.06);
  transition: transform 0.12s ease, opacity 0.18s ease, box-shadow 0.18s ease;
  user-select: none;
}

.card-btn:disabled {
  opacity: 0.42;
  cursor: default;
  box-shadow: none;
}

.card-btn:not(:disabled):active {
  transform: scale(0.95);
}

.card-icon {
  font-size: 14px;
  line-height: 1;
}

.card-count {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.card-shake {
  border-color: #b7d4f5;
  color: #1b6bb0;
  background: #f2f8ff;
}

.card-shake:not(:disabled).hungry {
  animation: card-glow 1.8s ease-in-out infinite;
  border-color: #6aa9e8;
}

.card-delete {
  border-color: #f5b6c0;
  color: #e04a5f;
  background: #fff;
}

.card-delete.active {
  background: #ffe9ed;
  box-shadow: 0 4px 16px rgba(224, 74, 95, 0.4);
}

.card-delete:not(:disabled).hungry {
  animation: card-glow 1.8s ease-in-out infinite;
  border-color: #f18fa0;
}

@keyframes card-glow {
  0%, 100% { box-shadow: 0 2px 8px rgba(70, 55, 40, 0.06); }
  50% { box-shadow: 0 4px 16px rgba(101, 80, 183, 0.45); }
}

.card-tip {
  font-size: 10.5px;
  color: var(--ink-soft);
  line-height: 1.3;
}

.delete-hint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(20, 28, 44, 0.86);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 6;
}

.delete-hint.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== 遮罩 ===== */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(38, 30, 22, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  background: var(--card);
  border-radius: 18px;
  padding: 22px 24px;
  width: 100%;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(40, 30, 20, 0.25);
}

.eyebrow {
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 2px;
  margin-bottom: 6px;
}

.game-over-card h2 {
  font-size: 19px;
  color: var(--ink);
  margin-bottom: 16px;
}

.result-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: stretch;
  margin-bottom: 14px;
}

.result-score,
.result-highest {
  flex: 1;
  background: #faf8f5;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 8px;
}

.result-score span,
.result-highest span {
  display: block;
  font-size: 11px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.result-score strong {
  font-size: 24px;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.highest-item {
  width: 58px;
  height: 58px;
  margin: 0 auto 4px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #fdfbfb, #e9ebed);
  overflow: hidden;
}

.highest-item img {
  max-width: 86%;
  max-height: 86%;
  display: block;
}

.result-highest p {
  font-size: 11px;
  color: var(--ink-soft);
  line-height: 1.3;
}

.new-record {
  color: #c0561f;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 10px;
}

.primary-button {
  width: 100%;
  font-size: 15px;
  font-weight: 700;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #7c66d8, #55409f);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(101, 80, 183, 0.35);
}

.primary-button:active {
  transform: scale(0.98);
}

/* ===== 合成顺序栏 ===== */
.chain-section {
  margin-top: 14px;
}

.chain-title {
  font-size: 12.5px;
  color: var(--ink-soft);
  font-weight: 600;
  margin-bottom: 8px;
  text-align: center;
}

.chain-strip {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  overflow-x: auto;
  padding: 8px 4px 10px;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.chain-cell {
  flex: 0 0 auto;
  width: 66px;
  text-align: center;
  padding: 6px 2px 4px;
  border-radius: 10px;
  border: 1.5px solid transparent;
  transition: all 0.2s ease;
  background: var(--card);
}

.chain-cell.reached {
  border-color: #d9cdf5;
  background: #f6f2ff;
}

.chain-cell.current {
  border-color: var(--primary);
  background: #efeaff;
  box-shadow: 0 2px 10px rgba(101, 80, 183, 0.25);
}

.chain-badge {
  width: 40px;
  height: 40px;
  margin: 0 auto 3px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #fdfbfb, #eceef0);
}

.chain-badge img {
  max-width: 84%;
  max-height: 84%;
  display: block;
}

.chain-name {
  font-size: 10px;
  color: var(--ink);
  line-height: 1.25;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.chain-rank {
  font-size: 9px;
  color: var(--ink-soft);
  margin-top: 2px;
}

.chain-arrow {
  flex: 0 0 auto;
  align-self: center;
  font-size: 14px;
  color: var(--ink-soft);
  padding-top: 22px;
}

.chain-hint {
  text-align: center;
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 2px;
}

/* ===== 页脚 ===== */
.footer {
  margin-top: 14px;
  text-align: center;
  font-size: 10.5px;
  color: #a89c8e;
  line-height: 1.6;
}

.footer a {
  color: #8b7bbd;
  text-decoration: none;
}

@media (max-width: 380px) {
  .brand h1 {
    font-size: 17px;
  }

  .metric {
    min-width: 48px;
    padding: 4px 7px;
  }

  .chain-cell {
    width: 60px;
  }
}
