/* ========== 变量 ========== */
:root {
  --bg-page: #f5f0e1;
  --bg-card: #ffffff;
  --red: #c0392b;
  --indigo: #2c3e50;
  --yellow: #e6b422;
  --green: #27ae60;
  --wood: #8b5e3c;
  --text: #3e2723;
  --text-sub: #8d6e63;
  --border: #d4c5a9;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 48px;
  --tabbar-h: 58px;
  --text-min: 16px;
  --content-w: 880px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  background: #fff;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: var(--text-min);
  background: #fff;
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--wood); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; border: none; background: none; }

.ico, .tab-ico { display: block; flex-shrink: 0; }
.ico { width: 22px; height: 22px; }

/* ========== 布局 ========== */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  max-width: 100%;
  margin: 0 auto;
}

.main-wrap {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-page);
}

.main-content {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  padding: 0 16px;
  width: 100%;
}

/* ========== 顶部标题栏 ========== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: var(--safe-top) 12px 0;
  min-height: calc(var(--header-h) + var(--safe-top));
  background: #fff;
  border-bottom: 1px solid rgba(212, 197, 169, 0.4);
  flex-shrink: 0;
  z-index: 10;
}

.app-title {
  flex: 1;
  text-align: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--wood);
  border-radius: 10px;
  flex-shrink: 0;
}

.icon-btn:active { background: rgba(0, 0, 0, 0.05); }

.icon-btn.is-muted { color: var(--text-sub); opacity: 0.72; }
.icon-btn .sound-off { display: none; }
.icon-btn.is-muted .sound-on { display: none; }
.icon-btn.is-muted .sound-off { display: block; }

.pc-nav { display: none; }
.pc-sidebar { display: none; }

/* ========== 游戏区 ========== */
.game-screen {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  gap: 10px;
  padding-top: 8px;
  padding-bottom: 8px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
}

.game-screen::-webkit-scrollbar { display: none; }

body[data-tab="solutions"] .game-screen,
body[data-tab="records"] .game-screen,
body[data-tab="tutorial"] .game-screen {
  flex: 0 0 0;
  overflow: hidden;
  padding: 0;
  min-height: 0;
}

.page-lead {
  text-align: center;
  flex-shrink: 0;
}

.page-lead h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
}

.page-lead-sub {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-sub);
  margin-top: 4px;
}

/* ========== 题目卡片 ========== */
.puzzle-card {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
  transition: box-shadow 0.25s, border-color 0.25s;
  border: 2px solid transparent;
}

.puzzle-card.is-correct {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(39, 174, 96, 0.18), var(--shadow);
  animation: flashGreen 0.6s ease;
}

.puzzle-card.is-wrong {
  border-color: var(--red);
  animation: shake 0.35s ease;
}

@keyframes flashGreen {
  0%, 100% { background: var(--bg-card); }
  40% { background: #e8f8ef; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ========== 扑克牌 ========== */
.cards-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.poker-card {
  position: relative;
  width: 68px;
  height: 96px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.06);
  flex-shrink: 0;
}

.poker-card.is-red { color: var(--red); }
.poker-card.is-black { color: var(--indigo); }

.card-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  gap: 1px;
}

.card-corner-tl { top: 5px; left: 6px; }
.card-corner-br { bottom: 5px; right: 6px; transform: rotate(180deg); }

.card-label {
  font-size: 14px;
  font-weight: 700;
}

.card-suit {
  font-size: 12px;
}

.card-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 700;
}

.goal-tip {
  text-align: center;
  font-size: 14px;
  color: var(--text-sub);
  line-height: 1.5;
}

/* ========== 输入区 ========== */
.input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.expr-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  font-size: 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #faf8f5;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.expr-input:focus {
  border-color: var(--yellow);
  box-shadow: 0 0 0 3px rgba(230, 180, 34, 0.22);
  background: #fff;
}

.btn-verify {
  flex-shrink: 0;
  min-width: 56px;
  height: 48px;
  padding: 0 14px;
  background: var(--red);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  border-radius: 12px;
}

.btn-verify:active { opacity: 0.88; }

.live-result {
  font-size: 16px;
  color: var(--text-sub);
  text-align: center;
  min-height: 24px;
}

.live-result.is-24 { color: var(--green); font-weight: 600; }
.live-result.is-error { color: var(--red); }

/* ========== 快捷输入 ========== */
.quick-pad {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.quick-btn {
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-page);
  color: var(--text);
}

.quick-btn.num-btn {
  background: #fff;
  color: var(--wood);
  font-size: 18px;
  min-width: 44px;
}

.quick-btn.op-btn { color: var(--indigo); }
.quick-btn.util-btn { color: var(--text-sub); }

.quick-btn:active { background: rgba(139, 94, 60, 0.1); }

/* ========== 状态栏 ========== */
.status-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 12px;
  flex-shrink: 0;
}

.stat-chip {
  font-size: 16px;
  color: var(--text-sub);
}

.stat-chip b { color: var(--text); font-weight: 700; }

.combo-badge {
  font-size: 16px;
  font-weight: 700;
  color: var(--yellow);
  background: rgba(230, 180, 34, 0.18);
  padding: 2px 10px;
  border-radius: 12px;
  animation: popIn 0.3s ease;
}

.combo-badge[hidden] { display: none; }

@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ========== AI 解法折叠 ========== */
.ai-solutions-fold {
  border: 1px solid rgba(212, 197, 169, 0.5);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  overflow: hidden;
  flex-shrink: 0;
}

.ai-solutions-fold summary {
  padding: 12px 14px;
  font-size: 16px;
  font-weight: 600;
  color: var(--wood);
  cursor: pointer;
  list-style: none;
}

.ai-solutions-fold summary::-webkit-details-marker { display: none; }

.ai-solutions-body {
  padding: 0 14px 14px;
}

.optimal-path,
.optimal-banner {
  font-size: 16px;
  color: var(--green);
  font-weight: 600;
  margin-bottom: 8px;
  padding: 8px 10px;
  background: rgba(39, 174, 96, 0.08);
  border-radius: 8px;
}

.solution-list-inline,
.solution-list-full,
.solution-list-sidebar {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.solution-item {
  font-size: 14px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid rgba(212, 197, 169, 0.45);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  word-break: break-all;
  line-height: 1.45;
}

.solution-item[hidden] { display: none; }

.solution-item:active { background: rgba(139, 94, 60, 0.06); }

.solution-item.is-optimal {
  border-color: var(--green);
  background: rgba(39, 174, 96, 0.06);
}

.solution-item.is-optimal::before {
  content: "推荐 · ";
  color: var(--green);
  font-weight: 600;
}

.solution-item.is-user {
  border-color: var(--yellow);
  background: rgba(230, 180, 34, 0.12);
}

.solution-item.is-user::after {
  content: " ← 你的解法";
  color: var(--wood);
  font-weight: 600;
}

.solution-more {
  font-size: 16px;
  color: var(--text-sub);
  text-align: center;
  margin-top: 8px;
}

.solution-more[hidden] { display: none; }

/* ========== 操作按钮 ========== */
.action-row {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-action {
  flex: 1 1 0;
  min-width: 0;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--wood);
  font-size: 16px;
  font-weight: 500;
}

.btn-action:active { background: rgba(139, 94, 60, 0.06); }

/* ========== 提示面板 ========== */
.hint-panel {
  background: rgba(230, 180, 34, 0.12);
  border: 1px solid rgba(230, 180, 34, 0.45);
  border-radius: 10px;
  padding: 12px 14px;
  flex-shrink: 0;
}

.hint-panel[hidden] { display: none; }

.hint-panel-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  font-weight: 600;
  color: var(--wood);
  margin-bottom: 6px;
}

.hint-count {
  margin-left: auto;
  font-size: 16px;
  color: var(--text-sub);
  font-weight: 500;
}

.hint-line {
  font-size: 16px;
  color: var(--text);
  line-height: 1.55;
}

.hint-line[hidden] { display: none; }

/* ========== 说明区块 ========== */
.info-block {
  font-size: 16px;
  color: var(--text-sub);
  line-height: 1.75;
  padding: 8px 4px 4px;
  flex-shrink: 0;
}

.info-block strong { color: var(--text); font-weight: 600; }

.page-guide {
  border: 1px solid rgba(212, 197, 169, 0.45);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
  overflow: hidden;
  flex-shrink: 0;
}

.page-guide summary {
  padding: 12px 14px;
  font-size: 16px;
  font-weight: 600;
  color: var(--wood);
  cursor: pointer;
  list-style: none;
}

.page-guide summary::-webkit-details-marker { display: none; }

.page-guide-body {
  padding: 0 14px 14px;
  font-size: 16px;
  color: var(--text-sub);
  line-height: 1.75;
}

.guide-steps {
  padding-left: 20px;
}

.guide-steps li { margin-bottom: 6px; }

/* ========== Tab 面板 ========== */
.tab-pane {
  display: none;
  flex: 1 1 auto;
  overflow-y: auto;
  padding-bottom: 12px;
  min-height: 0;
}

.tab-pane::-webkit-scrollbar { width: 0; height: 0; }

body[data-tab="solutions"] .solutions-pane,
body[data-tab="records"] .records-pane,
body[data-tab="tutorial"] .tutorial-pane {
  display: block;
}

.pane-inner {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 8px;
}

.pane-title {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

.pane-title h2 {
  font-size: 20px;
  color: var(--text);
  line-height: 1.35;
}

.pane-title p {
  margin-top: 6px;
  color: var(--text-sub);
  font-size: 16px;
}

.pane-h3 {
  font-size: 18px;
  color: var(--text);
  font-weight: 600;
}

.tutorial-steps,
.tutorial-tips,
.combo-list,
.faq-list {
  font-size: 16px;
  color: var(--text-sub);
  padding-left: 20px;
}

.tutorial-tips,
.combo-list { list-style: none; padding-left: 0; }

.tutorial-tips li,
.combo-list li {
  padding: 10px 14px;
  background: var(--bg-card);
  border-radius: 10px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
}

.combo-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.combo-list li span:last-child {
  color: var(--red);
  font-weight: 600;
}

.faq-list { padding-left: 0; list-style: none; }

.faq-list dt {
  font-weight: 600;
  color: var(--text);
  margin-top: 12px;
}

.faq-list dd {
  margin-top: 4px;
  line-height: 1.65;
}

/* ========== 记录列表 ========== */
.record-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.record-empty {
  text-align: center;
  padding: 24px 16px;
  color: var(--text-sub);
  background: rgba(255, 255, 255, 0.75);
  border-radius: 12px;
}

.record-item {
  padding: 12px 14px;
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  font-size: 16px;
  color: var(--text-sub);
  line-height: 1.5;
}

.record-item[hidden] { display: none; }

.record-item b { color: var(--text); }

.record-item.is-solved { border-left: 3px solid var(--green); }
.record-item.is-skipped { border-left: 3px solid var(--text-sub); }

.record-stats {
  text-align: center;
  font-size: 16px;
  color: var(--text-sub);
}

.record-stats b { color: var(--wood); }

/* ========== 广告位 ========== */
.ad-slot {
  display: none;
  min-height: 60px;
  max-height: 60px;
  margin: 10px 16px;
  color: #999;
  font-size: 14px;
  border-radius: 8px;
  border: 1px dashed #ccc;
  background: #fafafa;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.ad-slot:not(:empty) {
  display: flex;
  flex: 0 0 60px;
}

/* ========== 底部 TabBar ========== */
.tab-bar {
  display: flex;
  order: 999;
  flex-shrink: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: #fff;
  border-top: 1px solid rgba(212, 197, 169, 0.45);
  box-shadow: 0 -2px 12px rgba(62, 39, 35, 0.04);
  z-index: 20;
}

.tab-btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  color: var(--text-sub);
  font-size: 16px;
  padding: 6px 8px 4px;
  transition: color 0.15s;
}

.tab-ico {
  width: 24px;
  height: 24px;
}

.tab-btn span {
  line-height: 1.1;
  letter-spacing: 0.02em;
}

.tab-btn.active {
  color: var(--red);
  font-weight: 600;
}

.tab-btn.active .tab-ico {
  transform: translateY(-1px);
}

.tab-btn:active { background: rgba(0, 0, 0, 0.03); }

/* ========== 页脚 ========== */
.site-footer {
  display: none;
  text-align: center;
  font-size: 16px;
  line-height: 1.7;
  background: var(--text);
  color: rgba(255, 255, 255, 0.88);
  padding: 20px 24px;
}

.site-footer p + p { margin-top: 6px; }

.site-footer a {
  color: #d4c5a9;
  text-decoration: none;
}

.site-footer a:hover { text-decoration: underline; }

/* ========== Toast ========== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: rgba(62, 39, 35, 0.92);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 90;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success { background: rgba(39, 174, 96, 0.95); }
.toast.error { background: rgba(192, 57, 43, 0.92); }

/* ========== PC 适配（主体 880px，导航/页脚通栏） ========== */
@media (min-width: 768px) {
  html {
    overflow-y: auto;
    background: var(--bg-page);
  }

  body {
    overflow-y: auto;
    min-height: 100dvh;
    background:
      radial-gradient(ellipse 680px 680px at 88% 12%, rgba(212, 197, 169, 0.16), transparent),
      radial-gradient(ellipse 520px 520px at 8% 88%, rgba(141, 110, 99, 0.09), transparent),
      var(--bg-page);
  }

  .app-container {
    max-width: var(--content-w);
    width: 100%;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
    margin: 0 auto;
    background: transparent;
    box-shadow: none;
  }

  .app-header { display: none; }

  .tab-bar { display: none; }

  /* 顶部导航通栏 */
  .pc-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100vw;
    margin-left: calc(50% - 50vw);
    padding: 14px calc(50vw - 50% + 24px);
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid rgba(212, 197, 169, 0.45);
    flex-shrink: 0;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
  }

  .pc-nav-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin-right: auto;
    text-decoration: none;
  }

  .pc-nav-brand:hover { text-decoration: none; opacity: 0.9; }

  .pc-nav-link {
    font-size: 16px;
    color: var(--text-sub);
    padding: 8px 14px;
    border-radius: 10px;
    transition: background 0.15s, color 0.15s;
  }

  .pc-nav-link.active { color: var(--red); font-weight: 600; }
  .pc-nav-link:hover { background: rgba(139, 94, 60, 0.06); }

  .pc-nav-sound { padding: 8px 10px; }
  .pc-nav-sound .sound-off { display: none; }
  .pc-nav-sound.is-muted { color: var(--text-sub); opacity: 0.72; }
  .pc-nav-sound.is-muted .sound-on { display: none; }
  .pc-nav-sound.is-muted .sound-off { display: block; }

  .main-wrap {
    flex: 1 1 auto;
    min-height: 0;
    overflow: visible;
    padding: 20px 24px 28px;
    background: transparent;
  }

  .main-content {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 24px;
    padding: 0;
    overflow: visible;
    min-height: 0;
  }

  .game-screen {
    flex: 1 1 auto;
    min-width: 0;
    max-height: none;
    overflow-y: visible;
    padding-bottom: 0;
  }

  body[data-tab="solutions"] .game-screen,
  body[data-tab="records"] .game-screen,
  body[data-tab="tutorial"] .game-screen {
    display: none;
  }

  .tab-pane {
    flex: 1 1 auto;
    min-width: 0;
    max-height: none;
  }

  body[data-tab="game"] .tab-pane { display: none !important; }

  .pc-sidebar {
    display: block;
    flex: 0 0 300px;
    width: 300px;
    background: var(--bg-card);
    border-radius: 16px;
    padding: 18px 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(212, 197, 169, 0.45);
    position: sticky;
    top: 16px;
    max-height: calc(100dvh - 180px);
    overflow-y: auto;
  }

  body[data-tab="solutions"] .pc-sidebar,
  body[data-tab="records"] .pc-sidebar,
  body[data-tab="tutorial"] .pc-sidebar {
    display: none;
  }

  body[data-tab="game"] .ai-solutions-fold {
    display: none;
  }

  .pc-sidebar h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--text);
  }

  .sidebar-meta {
    font-size: 16px;
    color: var(--text-sub);
    margin-bottom: 12px;
  }

  .page-lead h1 { font-size: 22px; }

  .puzzle-card { padding: 22px 20px 16px; }

  .poker-card { width: 76px; height: 106px; }

  .cards-row { gap: 10px; }

  .action-row .btn-action { height: 46px; }

  .ad-slot:not(:empty) {
    margin-left: 24px;
    margin-right: 24px;
  }

  /* 页脚通栏 */
  .site-footer {
    display: block;
    flex-shrink: 0;
    width: 100vw;
    margin-left: calc(50% - 50vw);
    padding: 24px calc(50vw - 50% + 24px);
    margin-top: auto;
  }

  .toast { bottom: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
