/* ========== 变量 ========== */
:root {
  --bg-color: #f5f0e1;
  --card-bg: #ffffff;
  --card-inner: #faf8f5;
  --primary-red: #c0392b;
  --primary-indigo: #2c3e50;
  --primary-yellow: #e6b422;
  --success-green: #27ae60;
  --error-red: #e74c3c;
  --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: 52px;
  --header-bg: rgba(255, 255, 255, 0.92);
  --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: #ffffff;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: var(--text-min);
  background: #ffffff;
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100dvh;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

input, select, textarea, button, option, label, summary, details {
  font-size: var(--text-min);
}

button { font: inherit; cursor: pointer; border: none; background: none; }

a { color: var(--btn-wood); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ========== 主容器 ========== */
.app-container {
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-color);
  background-image:
    radial-gradient(ellipse 120% 80% at 50% -20%, rgba(230, 180, 34, 0.12), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40'%3E%3Cpath d='M0 20c10-8 20-8 30 0s20 8 30 0' fill='none' stroke='%23e6b422' stroke-width='0.6' opacity='0.15'/%3E%3C/svg%3E");
  background-size: auto, 80px 40px;
  overflow: hidden;
  position: relative;
}

/* ========== 顶部标题栏（对齐汉字拆解 app-header 安全区方案） ========== */
.header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--safe-top) 12px 0;
  min-height: calc(var(--header-h) + var(--safe-top));
  box-sizing: border-box;
  background: #ffffff;
  border-bottom: 1px solid rgba(212, 197, 169, 0.45);
  z-index: 10;
}

.header-brand {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

.header-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 6px;
}

.header-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.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-x: hidden;
  overflow-y: auto;
  padding: 0 16px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.main-content::-webkit-scrollbar {
  display: none;
}

.main-content.is-article-mode .game-screen {
  flex: 0 0 0;
  overflow: hidden;
  padding: 0;
  min-height: 0;
  opacity: 0;
  pointer-events: none;
}

.game-screen {
  flex: 0 0 auto;
  min-height: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 8px;
  padding-bottom: 8px;
  overflow: visible;
}

.page-head {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(212, 197, 169, 0.35);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow-light);
}

.page-head h1 {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text-main);
}

.page-head-sub {
  font-size: 16px;
  font-weight: 400;
  color: var(--text-sub);
  margin-top: 4px;
}

/* ========== 谜语卡片 ========== */
.riddle-card {
  flex-shrink: 0;
  position: relative;
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: var(--shadow-heavy);
  padding: 20px 16px 16px;
  border: 1px solid rgba(212, 197, 169, 0.3);
  overflow: hidden;
}

.card-deco {
  position: absolute;
  left: 0;
  right: 0;
  height: 6px;
  background: repeating-linear-gradient(
    90deg,
    var(--primary-yellow) 0,
    var(--primary-yellow) 8px,
    transparent 8px,
    transparent 16px
  );
  opacity: 0.35;
}

.card-deco-top { top: 0; }
.card-deco-bottom { bottom: 0; opacity: 0.2; }

.type-tag {
  display: inline-block;
  background: var(--primary-yellow);
  color: var(--text-main);
  font-size: 16px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 20px;
  margin-bottom: 14px;
}

.riddle-body {
  text-align: center;
  padding: 8px 4px 16px;
}

.riddle-question {
  font-size: 22px;
  line-height: 1.6;
  color: var(--text-main);
  font-weight: 500;
}

.riddle-prompt {
  font-size: 16px;
  color: var(--text-sub);
  margin-top: 8px;
}

/* ========== 选项区 ========== */
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.option-btn {
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-main);
  font-size: 16px;
  padding: 0 10px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.option-btn:active:not(:disabled) { transform: scale(0.97); }

.option-btn:disabled {
  cursor: default;
  opacity: 0.85;
}

.option-btn.is-correct {
  background: rgba(39, 174, 96, 0.15);
  border-color: var(--success-green);
  color: var(--success-green);
  font-weight: 600;
}

.option-btn.is-wrong {
  background: rgba(231, 76, 60, 0.12);
  border-color: var(--error-red);
  color: var(--error-red);
  animation: shake 0.45s ease;
}

.option-btn.is-eliminated {
  opacity: 0.35;
  text-decoration: line-through;
  pointer-events: none;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.hint-link {
  display: block;
  width: 100%;
  text-align: center;
  font-size: 16px;
  color: var(--btn-wood);
  text-decoration: underline;
  padding: 6px 0;
}

.hint-link:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  text-decoration: none;
}

/* ========== 状态栏 ========== */
.status-bar {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 16px;
  color: var(--text-sub);
  border: 1px solid rgba(212, 197, 169, 0.3);
  box-shadow: var(--shadow-light);
}

.status-bar strong {
  color: var(--primary-red);
  font-size: 18px;
  margin-left: 2px;
}

.combo-badge {
  margin-left: 4px;
  color: var(--primary-red);
  font-weight: 600;
  font-size: 16px;
}

.combo-badge:not([hidden]) {
  display: inline;
  animation: pulse 0.8s ease infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

/* ========== 操作按钮 ========== */
.action-buttons {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
}

.action-btn {
  flex: 1;
  height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-main);
  font-size: 16px;
  font-weight: 500;
}

.action-btn:active {
  background: var(--card-inner);
}

/* ========== 每日挑战标识 ========== */
.daily-badge {
  flex-shrink: 0;
  text-align: center;
  font-size: 16px;
  color: var(--btn-wood);
  background: rgba(230, 180, 34, 0.15);
  border: 1px dashed rgba(230, 180, 34, 0.5);
  border-radius: 8px;
  padding: 8px 12px;
}

.daily-badge.is-done {
  color: var(--success-green);
  background: rgba(39, 174, 96, 0.1);
  border-color: rgba(39, 174, 96, 0.35);
}

/* ========== 广告位（仅 CSS 控制显隐） ========== */
.ad-slot {
  display: none;
  min-height: 60px;
  max-height: 60px;
  margin: 10px 0;
  color: #999;
  font-size: 14px;
  border-radius: 8px;
  border: 1px dashed #ccc;
  background: #fafafa;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.ad-slot:not(:empty) {
  display: flex;
  flex: 0 0 60px;
}

/* ========== 折叠教程 ========== */
.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(--card-inner);
  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); }

/* ========== 文章视图（记录 / 教程 / 关于） ========== */
.article-view {
  display: none;
  flex: 0 0 auto;
  overflow: visible;
  background: transparent;
  border-radius: 0;
  padding: 8px 0 16px;
  box-shadow: none;
  font-size: var(--text-min);
  line-height: 1.8;
  margin: 0;
}

.article-view.is-active {
  display: block;
}

.article-view h2 {
  font-size: 22px;
  margin-bottom: 20px;
  padding-left: 12px;
  position: relative;
}

.article-view h2::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:not(.history-list), .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;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  padding: 0;
}

.history-empty {
  text-align: center;
  color: var(--text-sub);
  font-size: 16px;
  padding: 24px 0;
}

.history-list li {
  background: var(--card-inner);
  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-icon {
  width: 48px;
  height: 48px;
  background: #fff;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  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(--card-inner);
  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; }

.about-site-links {
  margin-top: 12px;
  font-size: 16px;
}

.about-site-links a { color: var(--btn-wood); }

/* ========== 底部 TabBar ========== */
.tab-bar {
  order: 999;
  flex-shrink: 0;
  display: flex;
  align-items: stretch;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  box-sizing: border-box;
  background: #ffffff;
  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;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-sub);
  min-height: var(--tabbar-h);
  padding: 7px 0 5px;
}

.tab-item.active { color: var(--primary-red); }
.tab-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  fill: currentColor;
}
.tab-text { font-size: 14px; line-height: 1.2; }

/* ========== PC 侧栏 ========== */
.pc-side-panel { display: none; }

/* ========== 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: 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); }
.toast.hint { background: rgba(139, 94, 60, 0.95); }

/* ========== 移动端：全屏贴边，内容自然撑满 ========== */
@media (max-width: 859px) {
  html,
  body {
    height: 100dvh;
    overflow: hidden;
  }

  body {
    align-items: stretch;
    width: 100%;
  }

  .app-container {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    min-height: 100dvh;
  }

  .legal-body {
    height: 100dvh;
    overflow: hidden;
  }

  .legal-body .app-container {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    min-height: 100dvh;
  }

  .guide-fold {
    margin-bottom: 8px;
  }

  .tab-icon {
    width: 23px;
    height: 23px;
  }

  .tab-text {
    font-size: 15px;
  }
}

/* ========== PC 适配 ========== */
@media (min-width: 860px) {
  body {
    align-items: stretch;
    padding: 0;
    min-height: 100dvh;
    height: 100dvh;
    overflow: hidden;
  }

  .app-container {
    width: 100%;
    max-width: none;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }

  .header {
    padding-top: 0;
    min-height: var(--header-h);
  }

  .legal-header {
    padding-top: 0;
    min-height: var(--header-h);
    padding-bottom: 0;
  }

  .main-wrap {
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: row;
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
    border-bottom: 1px dashed rgba(0, 0, 0, 0.08);
  }

  .main-content {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 480px;
    margin: 0 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .pc-side-panel {
    display: flex;
    flex-direction: column;
    width: 280px;
    flex-shrink: 0;
    min-height: 0;
    background: var(--card-inner);
    padding: 20px;
    overflow-y: auto;
  }

  .tab-bar {
    order: 0;
    flex-shrink: 0;
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
    height: var(--tabbar-h);
    padding-bottom: 0;
  }

  .tab-item {
    min-height: var(--tabbar-h);
    flex-direction: row;
    gap: 6px;
  }

  .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; }
}

/* ========== 法律单页（隐私政策等，对齐汉字拆解 + 主站 Safari 安全区方案） ========== */
.legal-body {
  background: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  width: 100%;
  min-height: 100dvh;
}

.legal-body .app-container {
  background-color: var(--bg-color);
  background-image: none;
  max-width: 100%;
  width: 100%;
}

.legal-main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px 16px;
}

.legal-main::-webkit-scrollbar { display: none; }

.legal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  padding: var(--safe-top) 16px 0;
  min-height: calc(var(--header-h) + var(--safe-top));
  box-sizing: border-box;
  background: #ffffff;
  border-bottom: 1px solid rgba(212, 197, 169, 0.45);
  z-index: 10;
}

.legal-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  text-decoration: none;
}

.legal-brand:hover { opacity: 0.9; text-decoration: none; }

.legal-back {
  font-size: 16px;
  color: var(--btn-wood);
  text-decoration: none;
  white-space: nowrap;
}

.legal-back:hover { text-decoration: underline; }

.legal-main h1 {
  font-size: 26px;
  color: var(--text-main);
  margin-bottom: 8px;
}

.legal-updated {
  font-size: 16px;
  color: var(--text-sub);
  margin-bottom: 20px;
}

.legal-lead {
  font-size: 16px;
  line-height: 1.8;
  color: var(--text-sub);
  margin-bottom: 24px;
}

.legal-section {
  margin-bottom: 28px;
}

.legal-section h2 {
  font-size: 18px;
  color: var(--text-main);
  margin-bottom: 12px;
}

.legal-section p,
.legal-section li {
  font-size: 16px;
  line-height: 1.8;
  color: var(--text-sub);
  margin-bottom: 10px;
}

.legal-section ul {
  padding-left: 1.25em;
  margin-bottom: 10px;
}

.legal-section code {
  font-size: 16px;
  background: rgba(212, 197, 169, 0.25);
  padding: 2px 6px;
  border-radius: 4px;
}

.legal-section a { color: var(--btn-wood); }

.legal-icp {
  margin-top: 16px;
  font-size: 16px;
  color: var(--text-sub);
}

.legal-footer {
  padding: 20px 0;
  border-top: 1px solid rgba(212, 197, 169, 0.45);
  text-align: center;
  font-size: 16px;
  color: var(--text-sub);
}

.legal-footer a { color: var(--btn-wood); }
