/* ============================================================
   看图说话排序 — 样式（Chrome 61 基线，语言维度·清新绿系）
   主题：语言/故事子系列用清新绿（#f2f9f0 背景 / #45ae72 主色），
         排序工具增加绿色点缀（#2FBF9E 步数/进度）；选中/提示用橙色
   规范：
   - 无 flex gap / aspect-ratio / clamp() / inset / 逻辑属性 / :has / dvh
   - 动画双写 @-webkit-keyframes + @keyframes；温和（<=400ms，无频闪；
     提示脉冲 1.2s 一次呼吸）
   - flex 三重前缀（-webkit-box / -webkit-flex / flex）；子项 min-width:0
   - 正方形卡片：.caus-card 用 width 与 padding-bottom 同百分比
     （3/5 步→33.3333%、4 步→25%），内层 .caus-card-inner absolute 撑满
   - 安全区 env(safe-area-inset-*) 组合；按钮 hit area >= 48x48
   ============================================================ */

*, *::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: #f2f9f0;
  color: #2a3a4a;
  -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));
  overflow: hidden;
}

/* ---------- 三段式骨架 ---------- */

.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 #d8e9dc;
}

.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: 8px 16px;
}

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

.header-title { font-size: 17px; font-weight: 700; color: #2a3a4a; }

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

.app-main {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.app-footer {
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  padding: 6px 16px calc(8px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  text-align: center;
}

.view {
  max-width: 480px;
  margin: 0 auto;
  padding: 6px 16px 20px;
  width: 100%;
  min-width: 0;
}

/* ---------- 顶栏 ---------- */

.topbar {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  margin-bottom: 10px;
  min-height: 44px;
}

.topbar .level-title {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  color: #2a3a4a;
  min-width: 0;
}

.topbar .level-title small {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #8fa596;
}

.top-timer {
  font-size: 13px;
  font-weight: 700;
  color: #e76f51;
  min-width: 54px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.btn-ghost-sm {
  padding: 8px 14px;
  min-height: 36px;
  border: none;
  border-radius: 10px;
  background: #d7efe0;
  color: #2f7d58;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-ghost-sm:active { background: #c2e6d2; }

/* ---------- 题面标题 ---------- */

.caus-title {
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  color: #2a3a4a;
  margin: 2px 0 12px;
}

/* ---------- 卡片网格（正方形卡：width + padding-bottom %） ---------- */

.caus-grid {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  width: 100%;
  background: #eef8ef;
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(69, 174, 114, 0.12);
  padding: 6px;
}

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

/* 3 步 / 5 步：一行 3 张（5 步两行 3+2）；4 步：一行 4 张 */
.caus-grid.grid-3 .caus-card,
.caus-grid.grid-5 .caus-card {
  width: 33.3333%;
  padding-bottom: 33.3333%;
}

.caus-grid.grid-4 .caus-card {
  width: 25%;
  padding-bottom: 25%;
}

/* 卡片内层（块间缝隙用内层 inset，无 flex gap） */
.caus-card-inner {
  position: absolute;
  left: 4px;
  top: 4px;
  right: 4px;
  bottom: 4px;
  border-radius: 12px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(43, 64, 92, 0.1);
  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;
  -webkit-transition: -webkit-transform 0.22s ease;
  transition: -webkit-transform 0.22s ease;
  transition: transform 0.22s ease;
  transition: transform 0.22s ease, -webkit-transform 0.22s ease;
}

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

/* 选中：橙色描边 + 轻微抬起 */
.caus-card.selected .caus-card-inner {
  outline: 3px solid #ff9f43;
  box-shadow: 0 6px 16px rgba(69, 174, 114, 0.25);
  -webkit-transform: translateY(-3px);
  transform: translateY(-3px);
}

/* 交换弹跳动画（280ms，无频闪） */
.caus-card.swap-anim .caus-card-inner {
  -webkit-animation: cardSwap 0.28s ease;
  animation: cardSwap 0.28s ease;
}

@-webkit-keyframes cardSwap {
  0% { -webkit-transform: scale(1); transform: scale(1); }
  40% { -webkit-transform: scale(0.92); transform: scale(0.92); }
  100% { -webkit-transform: scale(1); transform: scale(1); }
}
@keyframes cardSwap {
  0% { -webkit-transform: scale(1); transform: scale(1); }
  40% { -webkit-transform: scale(0.92); transform: scale(0.92); }
  100% { -webkit-transform: scale(1); transform: scale(1); }
}

/* 全部归位：绿色边框 + 一次闪烁（400ms） */
.caus-card.solved .caus-card-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); }
}

/* 提示脉冲：橙色描边 + 缓慢呼吸 1.2s（一次呼吸，温和） */
.caus-card.hinting .caus-card-inner {
  outline: 3px solid #ff9f43;
  -webkit-animation: hintPulse 1.2s ease-in-out 1;
  animation: hintPulse 1.2s ease-in-out 1;
}

@-webkit-keyframes hintPulse {
  0%, 100% { -webkit-transform: scale(1); transform: scale(1); }
  50% { -webkit-transform: scale(1.06); transform: scale(1.06); }
}
@keyframes hintPulse {
  0%, 100% { -webkit-transform: scale(1); transform: scale(1); }
  50% { -webkit-transform: scale(1.06); transform: scale(1.06); }
}

/* ---------- 操作行：提示 + 步数/提示统计 ---------- */

.status-row {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  margin-top: 12px;
}

.tool-btn {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-width: 0;
  height: 52px;
  margin: 4px 3px;
  border: 2px solid #d8e9dc;
  border-radius: 12px;
  background: #ffffff;
  color: #2f7d58;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.tool-btn:active { background: #e0f3e8; }
.tool-btn:disabled { opacity: 0.45; cursor: default; }

.status-row .hint-btn {
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  width: 132px;
  height: 48px;
}

.status-text {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-width: 0;
  text-align: right;
  font-size: 15px;
  font-weight: 800;
  color: #2FBF9E;
  padding-right: 6px;
}

/* ---------- 游戏页底栏 ---------- */

.game-footer {
  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;
}

.game-footer .btn-ghost-sm {
  margin: 0 5px;
  min-height: 40px;
}

.footer-moves {
  margin-left: 10px;
  font-size: 15px;
  font-weight: 800;
  color: #2FBF9E;
  min-width: 60px;
  text-align: left;
}

/* ---------- 首页：选难度 ---------- */

.page-title {
  font-size: 16px;
  font-weight: 700;
  margin: 8px 0 12px;
  text-align: center;
  color: #2a3a4a;
}

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

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

.diff-btn {
  display: block;
  width: 100%;
  min-height: 68px;
  border: none;
  border-radius: 14px;
  background: #ffffff;
  padding: 12px 18px;
  margin-bottom: 12px;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(69, 174, 114, 0.12);
}

.diff-btn:active { background: #e0f3e8; }

.diff-head {
  display: block;
  font-size: 17px;
  font-weight: 800;
  color: #2a3a4a;
}

.diff-sub {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  color: #7c9484;
  font-weight: 600;
}

.diff-tag {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: #2f9f68;
  font-weight: 600;
}

/* 底栏：打卡入口 / 返回 */

.btn-checkin {
  display: block;
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: 12px;
  background: #45ae72;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.btn-checkin:active { background: #36985f; }

/* ---------- 结算浮层 ---------- */

.overlay {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.5);
  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;
  z-index: 50;
  padding: 24px;
}

.overlay-card {
  background: #ffffff;
  border-radius: 16px;
  padding: 26px 24px 24px;
  text-align: center;
  width: 100%;
  max-width: 340px;
  -webkit-animation: cardIn 0.25s ease;
  animation: cardIn 0.25s ease;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

@-webkit-keyframes cardIn {
  0% { -webkit-transform: scale(0.92); transform: scale(0.92); opacity: 0; }
  100% { -webkit-transform: scale(1); transform: scale(1); opacity: 1; }
}
@keyframes cardIn {
  0% { -webkit-transform: scale(0.92); transform: scale(0.92); opacity: 0; }
  100% { -webkit-transform: scale(1); transform: scale(1); opacity: 1; }
}

.overlay-title {
  font-size: 26px;
  font-weight: 800;
  color: #2a3a4a;
}

.overlay-sub {
  margin-top: 6px;
  font-size: 14px;
  color: #7c9484;
}

.summary {
  margin: 16px 0 18px;
}

.summary .stars-line {
  font-size: 34px;
  letter-spacing: 6px;
  color: #f5a623;
  margin-bottom: 8px;
  -webkit-animation: starPop 0.35s ease;
  animation: starPop 0.35s ease;
}

@-webkit-keyframes starPop {
  0% { -webkit-transform: scale(0.4); transform: scale(0.4); opacity: 0; }
  60% { -webkit-transform: scale(1.25); transform: scale(1.25); }
  100% { -webkit-transform: scale(1); transform: scale(1); opacity: 1; }
}
@keyframes starPop {
  0% { -webkit-transform: scale(0.4); transform: scale(0.4); opacity: 0; }
  60% { -webkit-transform: scale(1.25); transform: scale(1.25); }
  100% { -webkit-transform: scale(1); transform: scale(1); opacity: 1; }
}

.summary .checkin-line {
  margin-top: 6px;
  font-size: 13px;
  color: #2f9f68;
  font-weight: 600;
}

.summary .record-badge {
  margin-top: 6px;
  font-size: 15px;
  font-weight: 800;
  color: #12b76a;
}

.overlay-btns {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
}

.overlay-btns > * {
  margin: 4px 5px;
}

.btn-main {
  padding: 12px 30px;
  min-height: 48px;
  border: none;
  border-radius: 12px;
  background: #45ae72;
  color: #ffffff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.btn-main:active { background: #36985f; }

.btn-ghost {
  padding: 10px 22px;
  min-height: 48px;
  border: none;
  border-radius: 12px;
  background: #e0f3e8;
  color: #2f7d58;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn-ghost:active { background: #cbe9d8; }

/* ---------- 打卡日历 ---------- */

.calendar {
  background: #ffffff;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(69, 174, 114, 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: #7c9484;
  background: #eef6ef;
}

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

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

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

/* ---------- 响应式：大屏微调 ---------- */

@media (min-width: 400px) {
  .topbar .level-title { font-size: 18px; }
}

/* ---------- 安全区增强 ---------- */
@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: calc(8px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))); }
}