/* ============================================================
   现在就出发 · 出发团消消乐 — 视觉样式
   交互类名（.tile/.avatar/.selected/.hinted/.removing/.no-match/
   .special-bomb/.special-rainbow/.float-score/.combo-banner/.off/
   .hidden）由 game.js 控制，改动时需保留。
   ============================================================ */

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

:root {
  --ink:        #2c3947;
  --ink-soft:   #6b7c8d;
  --ink-faint:  #9fb0bf;

  --accent:     #ff7043;
  --accent-2:   #ffa726;
  --blue:       #3fa2f7;

  --surface:    rgba(255, 255, 255, .86);
  --hairline:   1px solid rgba(255, 255, 255, .95);

  --r-xl: 26px;
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;

  --sh-sm: 0 2px 6px rgba(44, 57, 71, .06);
  --sh-md: 0 6px 18px rgba(44, 57, 71, .09);
  --sh-lg: 0 18px 44px rgba(44, 57, 71, .14);

  --frame-pad: 8px;      /* 棋盘外框内边距，浮动层偏移需与其一致 */
  --frame-border: 3px;   /* 外框描边宽度 */
  --gap: 10px;
}

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(10px + env(safe-area-inset-top))
    calc(10px + env(safe-area-inset-right))
    calc(10px + env(safe-area-inset-bottom))
    calc(10px + env(safe-area-inset-left));
  font-family: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(760px 520px at 10% 4%,  #ffd9c8 0%, rgba(255, 217, 200, 0) 62%),
    radial-gradient(700px 520px at 92% 10%, #cfe7ff 0%, rgba(207, 231, 255, 0) 64%),
    radial-gradient(820px 620px at 50% 108%, #fff1bd 0%, rgba(255, 241, 189, 0) 62%),
    linear-gradient(165deg, #fff8f4 0%, #f5fbff 52%, #fffaf1 100%);
  background-attachment: fixed;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

/* ---------------- 外壳 ---------------- */
.app {
  width: 100%;
  max-width: 560px;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
}

/* ---------------- 顶部栏 ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  background: var(--surface);
  border: var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-md);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.logo {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 13px;
  font-size: 19px; font-weight: 800; color: #fff;
  line-height: 1;
  background: linear-gradient(150deg, #ff8a65 0%, #ff6a3d 55%, #f4511e 100%);
  box-shadow: 0 4px 10px rgba(244, 81, 30, .32), inset 0 1px 0 rgba(255, 255, 255, .5);
  text-shadow: 0 1px 2px rgba(160, 40, 0, .35);
}

.brand-text { min-width: 0; }
.brand-text h1 {
  font-size: clamp(15px, 4.3vw, 18px);
  font-weight: 800;
  letter-spacing: .5px;
  line-height: 1.15;
  white-space: nowrap;
}
.brand-text p {
  margin-top: 2px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2.4px;
  color: var(--ink-faint);
  white-space: nowrap;
}

.top-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  font-size: 16px;
  border: 1px solid rgba(44, 57, 71, .06);
  border-radius: 12px;
  background: #f4f7fa;
  color: var(--ink);
  cursor: pointer;
  transition: transform .14s ease, background .18s ease, box-shadow .18s ease;
}
.icon-btn:hover { background: #eaf0f6; transform: translateY(-1px); box-shadow: var(--sh-sm); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.off { opacity: .42; filter: grayscale(1); }

/* ---------------- 状态区 ---------------- */
.hud {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) 68px;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-md);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
}

.hud-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 0;
}
.hud-cell--wide { align-items: stretch; gap: 6px; }

.hud-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.6px;
  color: var(--ink-faint);
}

.hud-value {
  font-size: clamp(18px, 5.2vw, 21px);
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.hud-cell--moves .hud-value { color: var(--blue); }

.hud-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.hud-score {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.hud-score b { font-size: clamp(14px, 4vw, 16px); color: var(--ink); }
.hud-score i { margin: 0 3px; font-style: normal; color: var(--ink-faint); font-weight: 500; }

.progress-track {
  position: relative;
  height: 9px;
  border-radius: 999px;
  background: #edf1f5;
  box-shadow: inset 0 1px 3px rgba(44, 57, 71, .12);
  overflow: hidden;
}

.progress-fill {
  position: relative;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffc44d 0%, #ff9a3d 45%, #ff6f3d 100%);
  box-shadow: 0 0 10px rgba(255, 138, 61, .45);
  transition: width .45s cubic-bezier(.22, .8, .3, 1);
  overflow: hidden;
}
.progress-fill::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, .65) 50%, transparent 80%);
  transform: translateX(-120%);
  animation: shine 2.6s ease-in-out infinite;
}
@keyframes shine {
  0%, 55% { transform: translateX(-120%); }
  100%    { transform: translateX(120%); }
}

/* ---------------- 棋盘 ---------------- */
.board-wrap {
  position: relative;
  width: min(100%, max(258px, calc(100dvh - 250px)));
  margin: 0 auto;
}

.board-frame {
  padding: var(--frame-pad);
  border-radius: var(--r-xl);
  border: var(--frame-border) solid #fff;
  background: linear-gradient(155deg, #fffdfa 0%, #fff4e8 55%, #ffeede 100%);
  box-shadow:
    var(--sh-lg),
    inset 0 2px 0 rgba(255, 255, 255, .9),
    inset 0 -3px 10px rgba(214, 160, 110, .16);
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 17px;
  background: transparent;   /* 透出外框底色，避免左右留白不对称被看见 */
  overflow: hidden;
  touch-action: manipulation;
}

/* ---------------- 棋子 ---------------- */
.tile {
  position: absolute;
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: transform .22s cubic-bezier(.2, .9, .3, 1.2), opacity .2s ease;
  will-change: transform, opacity;
}

.tile .avatar {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 15px;
  background: var(--tile-bg, #fff);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, .82),
    0 2px 4px rgba(44, 57, 71, .12);
  transition: box-shadow .18s ease, transform .18s cubic-bezier(.2, .9, .3, 1.4);
  pointer-events: none;
}

.tile .avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  -webkit-user-drag: none;
  user-select: none;
}

.tile.selected .avatar {
  transform: scale(1.07);
  box-shadow:
    0 0 0 3px #fff,
    0 0 0 6px var(--accent),
    0 6px 14px rgba(255, 112, 67, .4);
}

.tile.hinted .avatar { animation: hintPulse 1s ease-in-out infinite; }
@keyframes hintPulse {
  0%, 100% {
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .8),
                0 0 0 2px rgba(255, 193, 7, .9),
                0 0 0 2px rgba(255, 193, 7, 0);
  }
  50% {
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .8),
                0 0 0 2px rgba(255, 193, 7, .9),
                0 0 0 8px rgba(255, 193, 7, 0);
  }
}

.tile.special-bomb .avatar::after,
.tile.special-rainbow .avatar::after {
  position: absolute;
  top: 2px; right: 3px;
  font-size: clamp(9px, 2.6vw, 13px);
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .35));
}
.tile.special-bomb .avatar::after { content: "💥"; }
.tile.special-rainbow .avatar::after { content: "🌈"; }

.tile.removing { opacity: 0; transform: scale(.28) rotate(22deg); }

.tile.no-match .avatar { animation: shake .34s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}

/* ---------------- 浮动文字层 ---------------- */
.floating-layer {
  position: absolute;
  inset: calc(var(--frame-pad) + var(--frame-border)); /* 与外框内边距 + 描边对齐 */
  border-radius: 17px;
  overflow: hidden;
  pointer-events: none;
}

.float-score {
  position: absolute;
  font-size: 19px;
  font-weight: 900;
  color: #fff;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 #e2571f, 0 0 12px rgba(255, 196, 77, .85);
  animation: floatUp 1s ease-out forwards;
  white-space: nowrap;
}
@keyframes floatUp {
  0%   { opacity: 0; transform: translate(-50%, 0) scale(.6); }
  22%  { opacity: 1; transform: translate(-50%, -16px) scale(1.14); }
  100% { opacity: 0; transform: translate(-50%, -58px) scale(1); }
}

.combo-banner {
  position: absolute;
  left: 50%; top: 44%;
  transform: translate(-50%, -50%);
  font-size: clamp(24px, 8vw, 32px);
  font-weight: 900;
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 3px 0 #e2571f, 0 0 20px rgba(255, 196, 77, .95);
  animation: comboPop 1.1s ease-out forwards;
  white-space: nowrap;
}
@keyframes comboPop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(.3) rotate(-12deg); }
  28%  { opacity: 1; transform: translate(-50%, -50%) scale(1.18) rotate(4deg); }
  70%  { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0); }
  100% { opacity: 0; transform: translate(-50%, -96%) scale(.92); }
}

/* ---------------- 结算弹层 ---------------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  border-radius: var(--r-xl);
  background: rgba(38, 51, 63, .42);
  backdrop-filter: blur(6px) saturate(1.2);
  -webkit-backdrop-filter: blur(6px) saturate(1.2);
}
.overlay.hidden { display: none; }

.overlay-card {
  width: 100%;
  max-width: 300px;
  padding: 24px 20px 20px;
  text-align: center;
  border-radius: var(--r-xl);
  background: linear-gradient(170deg, #ffffff 0%, #fffaf0 100%);
  border: 3px solid #fff;
  box-shadow: var(--sh-lg), 0 0 0 1px rgba(255, 154, 61, .18);
  animation: cardIn .42s cubic-bezier(.2, .9, .3, 1.32);
}
@keyframes cardIn {
  from { opacity: 0; transform: scale(.74) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.overlay-emoji {
  font-size: 48px;
  line-height: 1;
  filter: drop-shadow(0 6px 10px rgba(44, 57, 71, .18));
}

.overlay-card h2 {
  margin-top: 10px;
  font-size: 23px;
  font-weight: 800;
  letter-spacing: .5px;
  color: var(--accent);
}

.overlay-card p {
  margin: 8px 0 18px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-soft);
}

.overlay-buttons { display: flex; gap: 10px; justify-content: center; }

.btn {
  flex: 1 1 0;
  min-height: 44px;
  padding: 0 16px;
  border: none;
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .14s ease, box-shadow .18s ease, filter .18s ease;
}
.btn:active { transform: scale(.96); }

.btn-primary {
  color: #fff;
  background: linear-gradient(150deg, #ff8a5c, #ff6a3d 60%, #f4511e);
  box-shadow: 0 6px 14px rgba(244, 81, 30, .34), inset 0 1px 0 rgba(255, 255, 255, .45);
}
.btn-primary:hover { filter: brightness(1.04); }

.btn-ghost {
  color: var(--ink-soft);
  background: #eef2f6;
  box-shadow: inset 0 0 0 1px rgba(44, 57, 71, .05);
}
.btn-ghost:hover { background: #e5ebf1; }

/* ---------------- 底部提示 ---------------- */
.hintbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px 9px 14px;
  background: var(--surface);
  border: var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-md);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
}

.hintbar p {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink-soft);
}

.hint-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.text-btn {
  min-height: 34px;
  padding: 0 11px;
  border: none;
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: #e2632a;
  background: #fff2e8;
  white-space: nowrap;
  cursor: pointer;
  transition: background .18s ease, transform .14s ease;
}
.text-btn:hover { background: #ffe6d5; }
.text-btn:active { transform: scale(.95); }

/* ---------------- 移动端适配 ---------------- */
@media (max-width: 400px) {
  :root { --gap: 8px; --frame-pad: 7px; }
  .topbar { padding: 8px 10px; }
  .hud { grid-template-columns: 54px minmax(0, 1fr) 60px; gap: 8px; padding: 9px 10px; }
  .brand-text p { letter-spacing: 1.8px; }
  .icon-btn { width: 34px; height: 34px; font-size: 15px; border-radius: 11px; }
  .logo { width: 35px; height: 35px; font-size: 17px; border-radius: 12px; }
  .hintbar { padding: 8px 9px 8px 12px; }
  .hintbar p { font-size: 11px; }
  .text-btn { padding: 0 9px; font-size: 11px; min-height: 32px; }
}

@media (max-width: 340px) {
  .brand-text p { display: none; }
  .hud { grid-template-columns: 48px minmax(0, 1fr) 54px; }
}

/* 横屏 / 很矮的屏幕：压缩上下元素，把空间留给棋盘 */
@media (max-height: 640px) {
  :root { --gap: 7px; }
  .topbar { padding: 6px 10px; }
  .logo { width: 32px; height: 32px; font-size: 16px; }
  .brand-text p { display: none; }
  .hud { padding: 7px 10px; }
  .hintbar p { font-size: 11px; }
  .board-wrap { width: min(100%, max(220px, calc(100dvh - 190px))); }
}

@media (prefers-reduced-motion: reduce) {
  .progress-fill::after { animation: none; }
  .tile.hinted .avatar { animation: none; }
  * { transition-duration: .01ms !important; }
}
