/* ===== 基础布局 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f5f1e8;
  --bg-alt: #fffdf7;
  --primary: #2e7d32;
  --primary-dark: #1b5e20;
  --accent: #c62828;
  --text: #2c2c2c;
  --muted: #6b6b6b;
  --border: #d9d2bf;
  --tile-bg: #fdfaf0;
  --tile-shadow: rgba(0,0,0,0.18);
}
body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}
.app-header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  padding: 16px 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.app-header h1 { font-size: 1.6rem; }
.subtitle { font-size: 0.85rem; opacity: 0.9; margin-top: 4px; }

/* ===== 标签导航 ===== */
.tab-nav {
  display: flex;
  background: var(--bg-alt);
  border-bottom: 2px solid var(--border);
  padding: 0 16px;
  flex-wrap: wrap;
}
.tab-btn {
  background: none;
  border: none;
  padding: 12px 20px;
  font-size: 1rem;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* ===== 标签内容 ===== */
.tab-content { padding: 20px; max-width: 1200px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== 按钮 ===== */
.btn {
  background: #e8e2d0;
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text);
  transition: background 0.15s;
}
.btn:hover { background: #ddd5be; }
.btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-dark);
}
.btn.primary:hover { background: var(--primary-dark); }

/* ===== 知识库 ===== */
.panel-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 20px;
}
.kb-sidebar {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  height: fit-content;
}
.kb-sidebar h3 { margin-bottom: 8px; color: var(--primary-dark); }
.kb-category-list { list-style: none; }
.kb-category-list li {
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.95rem;
  margin: 2px 0;
}
.kb-category-list li:hover { background: #eef3e9; }
.kb-category-list li.active { background: var(--primary); color: #fff; }
.kb-article {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 24px;
  min-height: 400px;
}
.kb-article h2 { color: var(--primary-dark); margin-bottom: 12px; border-bottom: 2px solid var(--border); padding-bottom: 6px; }
.kb-article h3 { color: var(--primary); margin: 14px 0 6px; }
.kb-article p { margin-bottom: 10px; }
.kb-article ul, .kb-article ol { margin: 6px 0 12px 22px; }
.kb-article .tip {
  background: #fff8e1;
  border-left: 4px solid #ffb300;
  padding: 8px 12px;
  margin: 10px 0;
  border-radius: 0 4px 4px 0;
}
.kb-empty { color: var(--muted); font-style: italic; }

/* ===== 麻将牌 ===== */
.tile {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 64px;
  margin: 3px;
  background: linear-gradient(180deg, #fff 0%, #f4ecd6 100%);
  border: 1px solid #c9b98a;
  border-radius: 6px;
  box-shadow: 0 2px 3px var(--tile-shadow), inset 0 1px 0 rgba(255,255,255,0.6);
  cursor: pointer;
  user-select: none;
  font-weight: 700;
  vertical-align: middle;
  transition: transform 0.1s, box-shadow 0.1s;
  position: relative;
}
.tile:hover { transform: translateY(-2px); box-shadow: 0 4px 6px var(--tile-shadow); }
.tile.disabled { opacity: 0.4; cursor: not-allowed; }
.tile.selected { box-shadow: 0 0 0 3px var(--accent); }

/* 万子: 数字 + 萬字(红色印章样式) */
.tile.wan { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.tile.wan .num { font-size: 1.25rem; line-height: 1; color: #c62828; font-family: "KaiTi", "STKaiti", serif; }
.tile.wan .suit { font-size: 0.8rem; line-height: 1; margin-top: 3px; color: #c62828; font-family: "KaiTi", "STKaiti", serif; }

/* 饼子: 圆点图案 */
.tile.dots { display: grid; padding: 6px; gap: 3px; align-content: center; justify-items: center; }
.tile.dots-1 { grid-template: 1fr / 1fr; }
.tile.dots-2 { grid-template: 1fr 1fr / 1fr; }
.tile.dots-3 { grid-template: 1fr 1fr 1fr / 1fr; }
.tile.dots-4 { grid-template: 1fr 1fr / 1fr 1fr; }
.tile.dots-5 { grid-template: 1fr 1fr 1fr / 1fr 1fr; }
.tile.dots-5 .dot:nth-child(1) { grid-column: 1 / span 2; }
.tile.dots-6 { grid-template: 1fr 1fr 1fr / 1fr 1fr; }
.tile.dots-7 { grid-template: 1fr 1fr 1fr / 1fr 1fr 1fr; }
.tile.dots-7 .dot:nth-child(1) { grid-column: 1 / span 3; }
.tile.dots-8 { grid-template: 1fr 1fr 1fr 1fr / 1fr 1fr; }
.tile.dots-9 { grid-template: 1fr 1fr 1fr / 1fr 1fr 1fr; }
.tile .dot {
  width: 9px; height: 9px;
  background: radial-gradient(circle at 35% 35%, #6aa6e8 0%, #1565c0 65%, #0d47a1 100%);
  border: 1px solid #0b3d91;
  border-radius: 50%;
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.4);
}
.tile.dots-1 .dot { width: 22px; height: 22px; }

/* 条子: 1条=鸟图案, 2-9条=竹竿图案 */
.tile.bams { display: grid; padding: 6px; gap: 3px; align-content: center; justify-items: center; }
.tile.bams-2 { grid-template: 1fr / 1fr 1fr; }
.tile.bams-3 { grid-template: 1fr / 1fr 1fr 1fr; }
.tile.bams-4 { grid-template: 1fr 1fr / 1fr 1fr; }
.tile.bams-5 { grid-template: 1fr 1fr 1fr / 1fr 1fr; }
.tile.bams-5 .bam:nth-child(1) { grid-column: 1 / span 2; }
.tile.bams-6 { grid-template: 1fr 1fr 1fr / 1fr 1fr; }
.tile.bams-7 { grid-template: 1fr 1fr 1fr / 1fr 1fr 1fr; }
.tile.bams-7 .bam:nth-child(1) { grid-column: 1 / span 3; }
.tile.bams-8 { grid-template: 1fr 1fr 1fr 1fr / 1fr 1fr; }
.tile.bams-9 { grid-template: 1fr 1fr 1fr / 1fr 1fr 1fr; }
.tile .bam {
  width: 5px;
  height: 100%;
  min-height: 40px;
  background: linear-gradient(to right, #1b5e20 0%, #43a047 30%, #66bb6a 50%, #43a047 70%, #1b5e20 100%);
  border-radius: 2px;
  position: relative;
}
.tile .bam::before, .tile .bam::after {
  content: '';
  position: absolute;
  left: -1px; right: -1px;
  height: 3px;
  background: #1b5e20;
  border-radius: 1px;
}
.tile .bam::before { top: 25%; }
.tile .bam::after { top: 70%; }
.tile.bird { display: flex; align-items: center; justify-content: center; }
.tile .bird-icon { font-size: 1.5rem; line-height: 1; }

/* 风牌: 大字 */
.tile.feng { display: flex; align-items: center; justify-content: center; }
.tile.feng .char { font-size: 1.5rem; color: #2c2c2c; font-family: "KaiTi", "STKaiti", serif; }

/* 箭牌: 中/發/白 */
.tile.jian { display: flex; align-items: center; justify-content: center; }
.tile.jian .char { font-size: 1.5rem; font-family: "KaiTi", "STKaiti", serif; font-weight: 700; }
.tile.jian.zhong .char { color: #c62828; }
.tile.jian.fa .char { color: #2e7d32; }
.tile.jian.bai { align-items: center; justify-content: center; }
.tile .bai-frame {
  width: 70%; height: 60%;
  border: 2px solid #424242;
  border-radius: 3px;
  background: transparent;
}

/* 小尺寸牌 */
.tile.small { width: 32px; height: 44px; margin: 2px; }
.tile.small.wan .num { font-size: 0.95rem; }
.tile.small.wan .suit { font-size: 0.6rem; }
.tile.small .dot { width: 6px; height: 6px; }
.tile.small.dots-1 .dot { width: 16px; height: 16px; }
.tile.small .bam { width: 4px; min-height: 28px; }
.tile.small .bam::before, .tile.small .bam::after { height: 2px; }
.tile.small .bird-icon { font-size: 1rem; }
.tile.small.feng .char, .tile.small.jian .char { font-size: 1.1rem; }
.tile.small .bai-frame { width: 65%; height: 55%; }

/* ===== 题库 ===== */
.quiz-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
  background: var(--bg-alt);
  padding: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.quiz-controls label { font-size: 0.9rem; }
.quiz-controls select { padding: 4px 8px; border-radius: 4px; border: 1px solid var(--border); }
.quiz-progress { margin-left: auto; color: var(--muted); }
.quiz-area {
  background: var(--bg-alt);
  padding: 20px;
  border-radius: 6px;
  border: 1px solid var(--border);
  min-height: 300px;
}
.quiz-question { font-size: 1.05rem; margin-bottom: 12px; }
.quiz-hand-display { margin: 12px 0; padding: 12px; background: #f7f3e8; border-radius: 4px; }
.quiz-options { margin-top: 12px; }
.quiz-options button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  margin: 6px 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
}
.quiz-options button:hover { background: #f0f7ed; }
.quiz-options button.correct { background: #c8e6c9; border-color: var(--primary); }
.quiz-options button.wrong { background: #ffcdd2; border-color: var(--accent); }
.quiz-feedback { margin-top: 14px; padding: 12px; border-radius: 4px; background: #e8f5e9; border-left: 4px solid var(--primary); }

/* ===== 分析 ===== */
.analysis-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
  background: var(--bg-alt);
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.ana-count { margin-left: auto; font-weight: 600; color: var(--primary-dark); }
.ana-tilepool {
  background: var(--bg-alt);
  padding: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
}
.ana-tilepool .pool-section { margin-bottom: 8px; }
.ana-tilepool .pool-label { font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.ana-hand {
  min-height: 80px;
  background: #e3f2e6;
  border: 2px dashed var(--primary);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 16px;
}
.ana-result { background: var(--bg-alt); border: 1px solid var(--border); border-radius: 6px; padding: 16px; }
.ana-result .result-block { margin-bottom: 14px; }
.ana-result h4 { color: var(--primary-dark); margin-bottom: 6px; }
.ana-result .stat-row { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 8px; }
.ana-result .stat { background: #fff8e1; padding: 6px 12px; border-radius: 4px; font-weight: 600; }
.ana-result .highlight { color: var(--accent); font-weight: 700; }

/* ===== 算番表 ===== */
.score-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  background: var(--bg-alt);
  border-radius: 6px;
  overflow: hidden;
}
.score-table th, .score-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.score-table th { background: var(--primary); color: #fff; }
.score-table tr:last-child td { border-bottom: none; }
.score-table .score-val { font-weight: 700; color: var(--accent); }
.scoring-sim {
  background: var(--bg-alt);
  padding: 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  align-items: center;
}
.scoring-sim label { font-size: 0.9rem; }
.scoring-sim input[type="number"] { width: 60px; padding: 4px; }
.sc-result { grid-column: 1 / -1; margin-top: 10px; padding: 12px; background: #fff8e1; border-radius: 4px; font-size: 1.1rem; font-weight: 700; }

/* ===== 页脚 ===== */
.app-footer {
  text-align: center;
  padding: 16px;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  margin-top: 20px;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .panel-layout { grid-template-columns: 1fr; }
  .tile { width: 38px; height: 54px; }
  .tile .num { font-size: 1rem; }
  .tab-btn { padding: 10px 14px; font-size: 0.9rem; }
}
