/* ========== 变量 ========== */
:root {
  --bg-color: #f5f0e1;
  --card-bg: #ffffff;
  --radical-bg: #faf8f5;
  --primary-red: #c0392b;
  --primary-indigo: #2c3e50;
  --primary-yellow: #e6b422;
  --success-green: #27ae60;
  --btn-wood: #8b5e3c;
  --text-main: #3e2723;
  --text-sub: #8d6e63;
  --border: #d4c5a9;
  --shadow-light: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-heavy: 0 4px 20px rgba(0, 0, 0, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 48px;
  --tabbar-h: 56px;
  --header-bg: #ffffff;
  --tabbar-bg: #ffffff;
  --text-min: 16px;
  color-scheme: light;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: var(--text-min);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: #fff;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: var(--text-min);
  background: #fff;
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

/* 全站字号底线 ≥ 16px */
input, select, textarea, button, option, label, summary, details {
  font-size: var(--text-min);
}

input::placeholder, textarea::placeholder {
  font-size: var(--text-min);
  color: var(--text-sub);
  opacity: 1;
}

button { font: inherit; cursor: pointer; border: none; background: none; }

a { color: var(--btn-wood); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ========== 主容器 ========== */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: #fff;
}

/* ========== 顶部标题栏 ========== */
.header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: var(--safe-top) 16px 0;
  min-height: calc(var(--header-h) + var(--safe-top));
  background: #fff;
  border-bottom: 1px solid rgba(212, 197, 169, 0.4);
  z-index: 10;
}

.header-spacer { width: 40px; flex-shrink: 0; }

.header-title {
  flex: 1;
  text-align: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-main);
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  border-radius: 10px;
  flex-shrink: 0;
}

.icon-btn:active { background: rgba(0, 0, 0, 0.05); }
.icon-btn.is-muted { opacity: 0.45; }

.header-icon { width: 22px; height: 22px; fill: currentColor; }

/* ========== 主内容区 ========== */
.main-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-color);
}

.main-content {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 16px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.main-content::-webkit-scrollbar { display: none; }

/* 记录 / 教程 / 关于：外层滚动，白卡随内容撑开 */
body[data-tab="record"] .main-content,
body[data-tab="tutorial"] .main-content,
body[data-tab="about"] .main-content {
  padding-left: 0;
  padding-right: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

body[data-tab="record"] .game-screen,
body[data-tab="tutorial"] .game-screen,
body[data-tab="about"] .game-screen {
  display: none;
}

.game-screen {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 8px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.game-screen::-webkit-scrollbar { display: none; }

.page-head {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(0, 0, 0, 0.03);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow-light);
}

.page-head h1 {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.35;
}

.page-head-sub {
  font-size: 16px;
  color: var(--text-sub);
  margin-top: 4px;
}

/* ========== 偏旁卡片 ========== */
.radical-card {
  flex-shrink: 0;
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: var(--shadow-heavy);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.radical-display-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.mizige {
  width: 100px;
  height: 100px;
  background-color: var(--radical-bg);
  border: 2px solid var(--text-sub);
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.mizige::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom, transparent 49%, var(--text-sub) 49%, var(--text-sub) 51%, transparent 51%),
    linear-gradient(to right, transparent 49%, var(--text-sub) 49%, var(--text-sub) 51%, transparent 51%),
    linear-gradient(45deg, transparent 49%, var(--text-sub) 49%, var(--text-sub) 51%, transparent 51%),
    linear-gradient(-45deg, transparent 49%, var(--text-sub) 49%, var(--text-sub) 51%, transparent 51%);
  opacity: 0.2;
  pointer-events: none;
}

.radical-text {
  font-size: 64px;
  font-weight: bold;
  z-index: 1;
}

.radical-desc {
  font-size: 16px;
  color: var(--text-sub);
  text-align: center;
}

.assembled-words-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 80px;
  overflow-y: auto;
  padding: 4px;
}

.assembled-words-list.is-empty::after {
  content: "还没有组字，快输入一个吧";
  color: var(--text-sub);
  font-size: 16px;
  padding: 4px;
}

.word-tag {
  background-color: #e8f5e9;
  color: var(--success-green);
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid #c8e6c9;
  animation: tag-in 0.25s ease;
}

.word-tag svg { width: 14px; height: 14px; fill: var(--success-green); }

@keyframes tag-in {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.input-area {
  display: flex;
  gap: 12px;
}

.char-input {
  flex: 1;
  min-width: 0;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 16px;
  font-size: 20px;
  color: var(--text-main);
  outline: none;
}

.char-input:focus { border-color: var(--primary-yellow); }
.char-input.is-wrong { border-color: var(--primary-red); animation: shake 0.35s; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.submit-btn {
  flex-shrink: 0;
  width: 80px;
  height: 48px;
  background-color: var(--primary-red);
  color: #fff;
  border-radius: 12px;
  font-size: 20px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(192, 57, 43, 0.3);
}

.submit-btn:active { transform: scale(0.96); }
.submit-btn:disabled { opacity: 0.55; }

/* ========== 状态面板 ========== */
.status-panel {
  flex-shrink: 0;
  background: var(--card-bg);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow-light);
}

.status-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 16px;
  font-weight: 500;
}

.status-info span { color: var(--primary-indigo); }
.status-info strong { font-size: var(--text-min); }
.time-urgent { color: var(--primary-red) !important; animation: pulse 1s infinite; }

.progress-bar-container {
  height: 8px;
  background-color: #eee;
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background-color: var(--primary-indigo);
  width: 100%;
  transition: width 1s linear, background-color 0.3s;
}

.progress-bar.urgent { background-color: var(--primary-red); }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.action-buttons {
  flex-shrink: 0;
  display: flex;
  gap: 12px;
}

.action-btn {
  flex: 1;
  height: 44px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--btn-wood);
  font-size: 16px;
  font-weight: 500;
}

.action-btn:active { background: var(--radical-bg); }
.action-btn:disabled { opacity: 0.5; }

.stage-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}

.stage-label {
  font-size: 16px;
  color: var(--text-sub);
  flex-shrink: 0;
}

.stage-select {
  flex: 1;
  min-width: 0;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  font-size: 16px;
  background: var(--card-bg);
  color: var(--text-main);
}

/* ========== 广告位（仅 CSS 控制显隐） ========== */
#adSlot {
  display: none;
  flex-shrink: 0;
}

#adSlot:not(:empty) {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  max-height: 60px;
  margin: 4px 0;
  color: var(--text-sub);
  font-size: 16px;
  border-radius: 8px;
  border: 1px dashed #bbb;
  background-color: #f9f9f9;
}

/* ========== 折叠教程 ========== */
.guide-fold {
  flex-shrink: 0;
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: var(--shadow-light);
  border: 1px solid rgba(0, 0, 0, 0.03);
  overflow: hidden;
  margin-bottom: 8px;
}

.guide-fold summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.guide-fold summary::-webkit-details-marker { display: none; }
.guide-fold summary::after { content: "展开"; color: var(--text-sub); font-size: 16px; }
.guide-fold[open] summary::after { content: "收起"; }

.guide-body { padding: 0 16px 16px; }
.guide-body p { color: var(--text-sub); font-size: 16px; line-height: 1.8; margin-bottom: 14px; }
.guide-body h3 { color: var(--primary-indigo); font-size: 16px; font-weight: 600; margin: 18px 0 10px; }
.guide-body ul, .guide-body ol { padding-left: 20px; margin: 0 0 14px; color: var(--text-sub); font-size: 16px; line-height: 1.8; }
.guide-body li { margin-bottom: 8px; font-size: var(--text-min); }

.qa details {
  background: var(--radical-bg);
  border: 1px solid rgba(0, 0, 0, 0.03);
  border-radius: 12px;
  padding: 12px 14px;
  margin-top: 10px;
}

.qa summary { cursor: pointer; font-size: var(--text-min); font-weight: 500; }
.qa p { margin-top: 10px; font-size: var(--text-min); color: var(--text-sub); }

.text-link {
  display: inline;
  color: var(--btn-wood);
  font-size: inherit;
  text-decoration: underline;
  padding: 0;
}

/* ========== 文章视图（记录 / 教程 / 关于） ========== */
.article-view {
  display: none;
  flex: none;
  width: 100%;
  overflow: visible;
  background: var(--card-bg);
  border-radius: 0;
  padding: 24px 16px 36px;
  box-shadow: none;
  font-size: var(--text-min);
  line-height: 1.8;
  margin-top: 0;
  margin-bottom: 0;
}

.article-view.is-active {
  display: block;
}

.article-view h2, .article-view h3 {
  font-size: 22px;
  margin-bottom: 20px;
  padding-left: 12px;
  position: relative;
}

.article-view h2::before, .article-view h3::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 18px;
  background: var(--primary-red);
  border-radius: 2px;
}

.article-view h4 { margin-top: 20px; margin-bottom: 10px; color: var(--primary-indigo); font-size: 18px; }
.article-view p, .article-view ul, .article-view ol { margin-bottom: 16px; color: var(--text-sub); font-size: 16px; }
.article-view ul:not(.history-list), .article-view ol { padding-left: 20px; }
.article-view li { font-size: var(--text-min); }

.panel-sub { font-size: 16px; color: var(--text-sub); margin-bottom: 16px; }

/* ========== 历史记录 ========== */
.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-empty {
  text-align: center;
  color: var(--text-sub);
  font-size: 16px;
  padding: 24px 0;
}

.history-list li {
  background: var(--radical-bg);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid rgba(0, 0, 0, 0.03);
}

.history-left { display: flex; align-items: center; gap: 14px; }

.history-radical {
  width: 48px;
  height: 48px;
  background: #fff;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: bold;
  color: var(--btn-wood);
  box-shadow: 0 2px 8px rgba(139, 94, 60, 0.15);
  border: 1px solid #f0e6d2;
  flex-shrink: 0;
}

.history-info { display: flex; flex-direction: column; gap: 4px; }
.history-title { font-size: 16px; font-weight: 500; color: var(--text-main); }
.history-date { font-size: 16px; color: #aaa; }
.history-score { text-align: right; }
.history-score-num { display: block; font-size: 20px; font-weight: bold; color: var(--primary-red); }
.history-score-label { font-size: 16px; color: var(--text-sub); }

.site-footnote {
  background: var(--radical-bg);
  color: var(--text-sub);
  padding: 20px;
  font-size: 16px;
  text-align: center;
  line-height: 1.8;
  margin-top: 24px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.04);
}

.site-footnote a { color: var(--text-main); text-decoration: none; border-bottom: 1px solid rgba(0, 0, 0, 0.1); }
.site-footnote a:hover { color: var(--primary-red); border-bottom-color: var(--primary-red); }
.site-footnote p { margin-bottom: 8px; font-size: 16px; }
.site-footnote p:last-child { margin-bottom: 0; opacity: 0.8; }

/* ========== 底部 TabBar ========== */
.tab-bar {
  order: 999;
  flex-shrink: 0;
  display: flex;
  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-item {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-sub);
  padding: 4px 0 2px;
}

.tab-item.active { color: var(--primary-red); }
.tab-icon { width: 20px; height: 20px; fill: currentColor; }
.tab-text { font-size: 16px; }

/* ========== PC 侧栏 ========== */
.pc-side-panel { display: none; }

/* ========== 轮次结束遮罩 ========== */
.round-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.round-overlay.is-show {
  opacity: 1;
  pointer-events: auto;
}

.round-modal {
  width: 100%;
  max-width: 360px;
  background: var(--card-bg);
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: var(--shadow-heavy);
}

.round-modal h3 { font-size: 22px; margin-bottom: 12px; }
.round-modal p,
#roundDetail { font-size: var(--text-min); color: var(--text-sub); margin-bottom: 8px; }
.round-stat { font-size: 28px; font-weight: bold; color: var(--primary-red); margin: 16px 0; }
.round-modal .submit-btn { width: 100%; margin-top: 16px; }

/* ========== Toast ========== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: rgba(62, 39, 35, 0.92);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 16px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90%;
  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.95); }

/* ========== 平板居中（与汉字拆解一致） ========== */
@media (min-width: 768px) {
  .app-container {
    max-width: 480px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.06);
  }
}

/* ========== PC 适配 ========== */
@media (min-width: 860px) {
  body {
    min-height: 100dvh;
    height: 100dvh;
    overflow: hidden;
  }

  .app-container {
    max-width: none;
    height: 100dvh;
    box-shadow: none;
  }

  .header {
    padding-top: 0;
    min-height: var(--header-h);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  }

  .main-wrap {
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: row;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    border-bottom: 1px dashed rgba(0, 0, 0, 0.08);
  }

  .main-content {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    border-right: 1px dashed rgba(0, 0, 0, 0.08);
  }

  .pc-side-panel {
    display: flex;
    flex-direction: column;
    width: 300px;
    flex-shrink: 0;
    min-height: 0;
    background: var(--radical-bg);
    padding: 20px;
    overflow-y: auto;
  }

  .tab-bar {
    order: 0;
    flex-shrink: 0;
    flex-direction: row;
    height: var(--tabbar-h);
    padding-bottom: 0;
    border-top: 1px solid rgba(212, 197, 169, 0.45);
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
  }

  .tab-item {
    flex: 1;
    padding: 8px 0;
  }

  .pc-panel-title {
    font-size: 18px;
    color: var(--primary-indigo);
    margin-bottom: 12px;
    padding-left: 12px;
    position: relative;
  }

  .pc-panel-title::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 16px;
    background: var(--primary-red);
    border-radius: 2px;
  }

  .pc-tip-card {
    background: var(--card-bg);
    padding: 14px;
    border-radius: 12px;
    box-shadow: var(--shadow-light);
    font-size: 16px;
    line-height: 1.7;
    color: var(--text-main);
    margin-bottom: 20px;
  }

  .pc-side-panel .history-list { margin-top: 8px; }

  .page-head h1 { font-size: 20px; }
}
