/* ============================================================================
 * 单词搜索 · 样式（单页自适应 / 暖色纸质风）
 * ==========================================================================*/
:root {
  --bg:          #f5f0e1;   /* 暖米色页面背景 */
  --card:        #ffffff;   /* 卡片白 */
  --grid-bg:     #faf8f5;   /* 网格暖白纸色 */
  --grid-line:   #d4c5a9;   /* 浅木色网格线 */
  --letter:      #2c2416;   /* 字母深棕 */
  --sel-bg:      #fff3cd;   /* 选中淡黄 */
  --drag-bg:     #ffe69c;   /* 拖拽亮黄 */
  --btn:         #8b5e3c;   /* 棕木按钮 */
  --btn-dark:    #6f4a2e;
  --text:        #3e2723;   /* 文字深棕 */
  --text-2:      #8d6e63;   /* 辅助文字 */
  --green:       #27ae60;   /* 正确/提示 */
  --shadow:      0 2px 8px rgba(0, 0, 0, 0.06);
  --topbar-h:    56px;
  --tabbar-h:    56px;
  --font-cn:     "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  --font-mono:   "Courier New", ui-monospace, "SFMono-Regular", Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-cn);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
ul { list-style: none; }

/* ── 顶部导航 ─────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 20px;
  padding-right: 20px;
  background: var(--card);
  border-bottom: 1px solid #ece3d2;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo {
  width: 32px; height: 32px;
  object-fit: contain;
}
.brand .name { font-size: 18px; font-weight: 600; color: var(--text); }
.nav-links { display: flex; gap: 18px; }
.nav-links a { color: var(--text-2); font-size: 15px; }
.nav-links a:hover { color: var(--btn); }

/* ── 游戏主区 ─────────────────────────────────────────────────────────────── */
.game-screen {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
  max-width: 1280px;
  margin: 0 auto;
}

.board-area {
  flex: 1 1 60%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.board-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 16px;
  color: var(--text-2);
}
.board-toolbar .stat { display: flex; align-items: center; gap: 6px; }
.board-toolbar .stat b { color: var(--text); font-variant-numeric: tabular-nums; }

/* 网格容器 */
#gridWrap {
  position: relative;
  width: min(480px, 92vw);
  aspect-ratio: 1 / 1;
  container-type: inline-size;
  background: var(--grid-bg);
  border: 1px solid var(--grid-line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 8px;
  touch-action: none;
}

#grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 10), 1fr);
  grid-template-rows: repeat(var(--rows, 10), 1fr);
  width: 100%;
  height: 100%;
  gap: 0;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: calc(100cqw / var(--cols, 10) * 0.48);
  color: var(--letter);
  border: 1px solid color-mix(in srgb, var(--grid-line) 45%, transparent);
  position: relative;
  z-index: 1;
  transition: background 0.08s;
}
.cell.selecting { background: var(--drag-bg); border-radius: 4px; }
.cell.pending   { background: var(--sel-bg); border-radius: 4px; box-shadow: inset 0 0 0 2px var(--btn); }
.cell.found     { background: color-mix(in srgb, var(--fc, var(--green)) 16%, transparent); font-weight: 700; }
.cell.flash     { animation: flash 0.4s ease-in-out 3; }
@keyframes flash {
  0%, 100% { background: transparent; }
  50%      { background: var(--sel-bg); border-radius: 4px; }
}

/* SVG 连线层（与 #gridWrap 同原点，便于按 wrap 坐标绘制）*/
#lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  overflow: visible;
}

/* 暂停遮罩 */
#gridWrap.paused #grid { filter: blur(8px); opacity: 0.35; }
#gridWrap.paused::after {
  content: "已暂停";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--btn);
  z-index: 5;
}

/* 通关横幅 */
.win-banner {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 12px;
  z-index: 10;
  text-align: center;
  padding: 16px;
}
.win-banner.show { display: flex; }
.win-banner h3 { font-size: 24px; color: var(--green); }
.win-banner p { color: var(--text-2); }
.win-banner .win-time { font-weight: 700; color: var(--text); }

/* ── 控制面板 ─────────────────────────────────────────────────────────────── */
.panel {
  flex: 0 0 320px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.panel-card {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.panel-card h3 {
  font-size: 16px;
  color: var(--text);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 14px; color: var(--text-2); margin-bottom: 6px; }
.field select {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--grid-bg);
  border: 1px solid var(--grid-line);
  border-radius: 8px;
}

/* 待找单词列表 */
.word-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.word-chip {
  font-family: var(--font-mono);
  font-size: 16px;
  letter-spacing: 1px;
  padding: 6px 12px;
  background: var(--grid-bg);
  border: 1px solid var(--grid-line);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}
.word-chip:hover { background: var(--sel-bg); }
.word-chip.done {
  color: var(--text-2);
  text-decoration: line-through;
  opacity: 0.55;
  background: #f3efe6;
  cursor: default;
}

/* 按钮组 */
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
  flex: 1 1 auto;
  min-width: 90px;
  padding: 12px 14px;
  font-size: 16px;
  border-radius: 8px;
  background: var(--btn);
  color: #fff;
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: var(--btn-dark); }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  background: var(--grid-bg);
  color: var(--text);
  border: 1px solid var(--grid-line);
}
.btn.ghost:hover { background: var(--sel-bg); }
.btn.ghost.off { color: var(--text-2); }

/* ── 广告位 ───────────────────────────────────────────────────────────────── */
.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; }

/* ── 内容区 ───────────────────────────────────────────────────────────────── */
.content {
  max-width: 880px;
  margin: 0 auto;
  padding: 16px 20px 40px;
}
.content h1 { font-size: 26px; color: var(--text); margin-bottom: 8px; }
.content .lead {
  font-size: 17px;
  color: #5d5048;
  line-height: 1.8;
  margin-bottom: 24px;
  max-width: 760px;
}

.demo {
  font-family: var(--font-mono);
  background: var(--grid-bg);
  border: 1px solid var(--grid-line);
  border-radius: 6px;
  padding: 2px 8px;
  letter-spacing: 2px;
  color: var(--letter);
  white-space: nowrap;
}

.card-block[id], .game-screen, #panel { scroll-margin-top: calc(var(--topbar-h) + 16px); }

.card-block {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-block h2 { font-size: 20px; color: var(--text); margin-bottom: 12px; }
.card-block h3 { font-size: 17px; color: var(--text); margin: 16px 0 8px; }
.card-block p { color: #5d5048; margin-bottom: 12px; }
.card-block ol, .card-block ul.steps { padding-left: 22px; color: #5d5048; }
.card-block ol li, .card-block ul.steps li { margin-bottom: 10px; }
.card-block ul.steps { list-style: disc; }

.faq-item { border-bottom: 1px solid #f0ebe0; padding: 14px 0; }
.faq-item:last-child { border-bottom: none; }
.faq-q { font-weight: 600; color: var(--text); margin-bottom: 6px; }
.faq-a { color: #5d5048; margin: 0; }

.records-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.records-table th, .records-table td {
  padding: 10px 8px;
  text-align: center;
  border-bottom: 1px solid #f0ebe0;
}
.records-table th { color: var(--text-2); font-weight: 600; }
.records-table td.empty { color: var(--text-2); padding: 24px; }

/* ── 页脚 ─────────────────────────────────────────────────────────────────── */
.footer {
  background: #3e2723;
  color: #e9ded2;
  text-align: center;
  padding: 28px 20px calc(28px + env(safe-area-inset-bottom));
  font-size: 14px;
  line-height: 1.8;
}
.footer a { color: inherit; text-decoration: none; }

/* ── 移动端 TabBar ────────────────────────────────────────────────────────── */
.tabbar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 90;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid #ece3d2;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}
.tabbar-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 12px;
  color: var(--text-2);
}
.tabbar-btn .ico { font-size: 20px; line-height: 1; }
.tabbar-btn.active { color: var(--btn); }

/* ── 响应式：移动端 ───────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .nav-links { display: none; }

  .game-screen {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    padding: 16px 12px;
    min-height: auto;
  }
  .board-area { width: 100%; }
  #gridWrap { width: min(96vw, 460px); }

  .panel { flex: 1 1 auto; width: 100%; }
  .word-list { gap: 6px; }

  body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .tabbar { display: flex; }
}

@media (max-width: 380px) {
  .brand .name { font-size: 16px; }
  .btn { min-width: 72px; font-size: 15px; }
}
