/* ============================================================
   简单拼图 — 样式（Chrome 61 基线层）
   约束：无 flex gap / aspect-ratio / clamp / inset / 逻辑属性 / :has
   主题：空间感知 · 天蓝/青色系（主色 #2f80ed / #4aa8ff，浅蓝渐变背景）
   ============================================================ */

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
               "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #e8f4ff;
  background: -webkit-linear-gradient(180deg, #e8f4ff 0%, #d9ecff 100%);
  background: linear-gradient(180deg, #e8f4ff 0%, #d9ecff 100%);
  color: #1f2329;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-flex-direction: column;
  flex-direction: column;
  height: 100vh;
  height: calc(var(--app-height, 100vh));
}

/* ---------- 顶栏 ---------- */
.app-header {
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  padding-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  background: #ffffff;
  border-bottom: 1px solid #dcebfa;
}

.header-brand {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  padding: 10px 16px;
}

.header-icon {
  width: 32px;
  height: 32px;
  margin-right: 8px;
  border-radius: 8px;
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
}

.header-title { font-size: 17px; font-weight: 600; }

.header-ver {
  margin-left: 6px;
  font-size: 10px;
  color: #c9cdd4;
}

/* ---------- 主体 ---------- */
.app-main {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

.view {
  padding: 12px 16px;
  max-width: 480px; /* PC 打开居中、拼图网格不超宽 */
  margin: 0 auto;
  min-width: 0;
}

/* ---------- 通用按钮 ---------- */
.btn {
  min-height: 48px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  color: #2f80ed;
  background: #dceeff;
  cursor: pointer;
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
}

.btn:active { opacity: 0.75; }
.btn-primary { background: #4aa8ff; color: #ffffff; }

/* ---------- 首页：选难度 ---------- */
.page-title {
  font-size: 16px;
  font-weight: 600;
  margin: 8px 0 12px;
  text-align: center;
}

.home-hint {
  font-size: 12px;
  color: #7a8aa0;
  text-align: center;
  margin: -4px 0 12px;
}

.home-list { margin-top: 4px; }

.diff-card {
  background: #ffffff;
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(47, 128, 237, 0.1);
}

.diff-btn {
  width: 100%;
  min-height: 56px;
  border: none;
  border-radius: 10px;
  font-size: 18px;
  font-weight: 600;
  color: #1f2329;
  background: #e3f0ff;
  cursor: pointer;
}

.diff-btn:active { opacity: 0.7; }

.diff-meta {
  margin-top: 8px;
  font-size: 12px;
  color: #7a8aa0;
  text-align: center;
}

/* ---------- 游戏页：顶部状态栏 ---------- */
.game-top {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  margin-bottom: 12px;
  min-height: 36px;
}

.game-back {
  border: none;
  background: none;
  color: #2f80ed;
  font-size: 14px;
  min-height: 36px;
  padding: 0 8px;
  cursor: pointer;
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
}

.game-name {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  color: #4e5969;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.game-timer {
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  font-size: 14px;
  font-weight: 700;
  color: #2f80ed;
  min-width: 62px;
  text-align: center;
}

.game-solved {
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  color: #12b76a;
  min-width: 62px;
  text-align: right;
}

/* ---------- 游戏页：参照图 ---------- */
.ref-row {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  margin-bottom: 10px;
  min-height: 90px;
}

.ref-thumb {
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(47, 128, 237, 0.12);
  line-height: 0;
  overflow: hidden;
}

.ref-thumb.hide { display: none; }

.ref-thumb .ref-svg {
  display: block;
  width: 90px;
  height: 90px;
}

.btn-ref {
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 16px;
  margin-left: 12px;
  font-size: 14px;
  background: #ffffff;
  color: #2f80ed;
  border: 1px solid #b8d9f8;
  box-shadow: 0 1px 4px rgba(47, 128, 237, 0.12);
}

/* ---------- 游戏页：拼图网格 ---------- */
/* 正方形碎片：width 与 padding-bottom 同为网格宽度的百分比
   （2×2→50%、3×3→33.33%、4×4→25%） */
.puzzle-grid {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  width: 100%;
  background: #eef6ff;
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(47, 128, 237, 0.14);
  padding: 6px;
}

.piece {
  position: relative;
  width: 50%;
  padding-bottom: 50%;
  min-width: 0;
  cursor: pointer;
}

.puzzle-grid.grid-3 .piece {
  width: 33.3333%;
  padding-bottom: 33.3333%;
}

.puzzle-grid.grid-4 .piece {
  width: 25%;
  padding-bottom: 25%;
}

/* 块间缝隙（不用 flex gap）：内层比块小 4px，形成间隔 */
.piece-inner {
  position: absolute;
  left: 4px;
  top: 4px;
  right: 4px;
  bottom: 4px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(43, 64, 92, 0.08);
}

.piece-svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* 选中：紫色高亮描边 */
.piece.selected .piece-inner {
  outline: 3px solid #8b5cf6;
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

/* 全部归位：绿色边框 + 一次闪烁动画（400ms） */
.piece.solved .piece-inner {
  outline: 3px solid #12b76a;
  -webkit-animation: solvedFlash 0.4s ease-out;
  animation: solvedFlash 0.4s ease-out;
}

@-webkit-keyframes solvedFlash {
  0% { box-shadow: 0 0 0 0 rgba(18, 183, 106, 0.55); }
  100% { box-shadow: 0 0 0 14px rgba(18, 183, 106, 0); }
}

@keyframes solvedFlash {
  0% { box-shadow: 0 0 0 0 rgba(18, 183, 106, 0.55); }
  100% { box-shadow: 0 0 0 14px rgba(18, 183, 106, 0); }
}

/* ---------- 游戏页：底部状态 + 重新开始 ---------- */
.game-status {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  margin-top: 10px;
  min-height: 22px;
}

.game-moves {
  font-size: 13px;
  font-weight: 700;
  color: #4e5969;
}

.btn-row {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  margin-top: 12px;
}

.btn-row > * + * { margin-left: 10px; }

/* ---------- 成绩列表 ---------- */
.point-list { margin-top: 4px; }

.point-item {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  padding: 14px 16px;
  background: #ffffff;
  border-radius: 10px;
  margin-bottom: 8px;
  box-shadow: 0 1px 4px rgba(47, 128, 237, 0.1);
}

.point-name { font-size: 15px; font-weight: 600; }

.point-meta { font-size: 12px; color: #7a8aa0; margin-top: 3px; }

.point-right { text-align: right; }

.point-time { font-size: 16px; font-weight: 700; color: #2f80ed; }

.point-stars { font-size: 13px; color: #f5a623; margin-top: 3px; }

/* ---------- 打卡日历 ---------- */
.calendar {
  background: #ffffff;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(47, 128, 237, 0.12);
}

.calendar-grid {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  margin-top: 8px;
}

.calendar-grid > * { width: 14.28%; padding: 4px; }

.cal-day {
  width: 100%;
  padding: 8px 0;
  text-align: center;
  font-size: 13px;
  border-radius: 6px;
  color: #7a8aa0;
  background: #f0f6fd;
}

.cal-day.done { background: #ff9c1a; color: #ffffff; font-weight: 700; }

.cal-day.today { outline: 2px solid #2f80ed; }

.streak-info { text-align: center; margin-top: 10px; font-size: 14px; color: #4e5969; }
.streak-info b { color: #ff9c1a; }

/* ---------- 结果浮层 ---------- */
.result-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 999;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  padding: 24px;
}

.result-box {
  background: #ffffff;
  border-radius: 16px;
  padding: 24px 20px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.result-title { font-size: 14px; color: #4e5969; }

.result-time {
  font-size: 44px;
  font-weight: 800;
  color: #2f80ed;
  margin-top: 4px;
}

.result-stats {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  margin-top: 14px;
}

.result-stat {
  margin: 0 14px;
  font-size: 13px;
  color: #4e5969;
  text-align: center;
}

.result-stat b { display: block; font-size: 18px; color: #1f2329; }

.result-stars {
  font-size: 22px;
  color: #f5a623;
  margin-top: 10px;
  letter-spacing: 4px;
}

.result-record {
  margin-top: 10px;
  font-size: 15px;
  font-weight: 700;
  color: #12b76a;
}

.result-box .btn {
  display: block;
  width: 100%;
  margin-top: 10px;
}

/* ---------- 参照大图浮层（看原图，3 秒自动关） ---------- */
.ref-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(15, 23, 42, 0.75);
  z-index: 998;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  padding: 24px;
}

.ref-box {
  width: 320px;
  height: 320px;
  max-width: 90vw;
  max-height: 70vh;
  line-height: 0;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  background: #ffffff;
}

.ref-box .ref-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.ref-hint {
  margin-top: 14px;
  font-size: 13px;
  color: #dceeff;
  text-align: center;
}

/* ---------- 底栏 ---------- */
.app-footer {
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  background: #ffffff;
  border-top: 1px solid #dcebfa;
  padding-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
}

.footer-nav {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  padding: 8px 12px 10px;
}

.footer-nav > * + * { margin-left: 10px; }

.footer-btn {
  min-width: 64px;
  padding: 9px 0;
  font-size: 13px;
  color: #2f80ed;
  text-align: center;
  border-radius: 8px;
  background: #eef6ff;
}

/* ---------- 安全区增强 ---------- */
@supports ((padding-bottom: var(--safe-area-inset-bottom)) or (padding-bottom: env(safe-area-inset-bottom))) {
  .app-header { padding-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px)); }
  .app-footer { padding-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)); }
}
