/* ============================================
   MahjongGuide.com - Global Stylesheet
   Colors: Mahjong Green #1E8C45 | China Red #D82E2F
   Backgrounds: Cream #F8F9F5 | Text: Dark Brown #332E29
   ============================================ */

/* --- CSS Variables --- */
:root {
  --green: #1E8C45;
  --green-dark: #166f38;
  --green-light: #E8F5EE;
  --red: #D82E2F;
  --red-dark: #b52425;
  --bg: #F8F9F5;
  --bg-card: #ffffff;
  --text: #332E29;
  --text-light: #6b5e55;
  --title: #000000;
  --border: #d8d4cf;
  --header-height: 60px;
  --max-width: 1100px;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-hover: 0 4px 16px rgba(0,0,0,0.12);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --transition: 0.25s ease;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.8;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--green); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--green-dark); }
img { max-width: 100%; height: auto; display: block; }
ul, ol { padding-left: 20px; }
li { margin-bottom: 6px; }

/* --- Site Header / Navigation --- */
.site-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--header-height);
  background: var(--green);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.nav-container {
  max-width: var(--max-width); margin: 0 auto;
  padding: 0 20px; height: 100%;
  display: flex; align-items: center; justify-content: space-between;
}
.logo {
  display: flex; align-items: center; gap: 8px;
  font-size: 1.2rem; font-weight: 700; color: #fff;
  white-space: nowrap;
}
.logo:hover { color: #fff; opacity: 0.9; }
.logo-icon { font-size: 1.4rem; }

.nav-links {
  display: flex; align-items: center; gap: 0;
  list-style: none; padding: 0; margin: 0; height: 100%;
}
.nav-links li { margin: 0; height: 100%; }
.nav-links a {
  display: flex; align-items: center; padding: 0 16px;
  color: rgba(255,255,255,0.85); font-size: 0.9rem;
  transition: background var(--transition), color var(--transition);
  height: 100%; white-space: nowrap;
}
.nav-links a:hover { background: rgba(255,255,255,0.12); color: #fff; }
.nav-links a.active { background: rgba(255,255,255,0.18); color: #fff; font-weight: 600; }

/* Hamburger */
.hamburger {
  display: none; background: none; border: none; cursor: pointer;
  flex-direction: column; gap: 5px; padding: 4px;
}
.hamburger-line {
  display: block; width: 24px; height: 2.5px;
  background: #fff; border-radius: 2px;
  transition: var(--transition);
}
.hamburger.active .hamburger-line:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.hamburger.active .hamburger-line:nth-child(2) { opacity: 0; }
.hamburger.active .hamburger-line:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

/* --- Main Layout --- */
main { flex: 1; padding-top: var(--header-height); }
.container {
  max-width: var(--max-width); margin: 0 auto; padding: 24px 20px;
}

/* --- Footer --- */
.site-footer {
  background: var(--green); color: rgba(255,255,255,0.9);
  padding: 32px 20px 20px;
  margin-top: auto;
}
.footer-inner {
  max-width: var(--max-width); margin: 0 auto;
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px;
}
.footer-col h4 { color: #fff; font-size: 0.95rem; margin-bottom: 12px; }
.footer-col p, .footer-col a { font-size: 0.85rem; color: rgba(255,255,255,0.8); }
.footer-col a:hover { color: #fff; }
.footer-col ul { list-style: none; padding: 0; }
.footer-col li { margin-bottom: 6px; }
.footer-bottom {
  max-width: var(--max-width); margin: 20px auto 0;
  padding-top: 16px; border-top: 1px solid rgba(255,255,255,0.2);
  text-align: center; font-size: 0.8rem; opacity: 0.7;
}

/* --- Headings --- */
h1 { font-size: 24px; font-weight: 700; color: var(--title); margin-bottom: 16px; }
h2 { font-size: 20px; font-weight: 700; color: var(--title); margin-bottom: 12px; margin-top: 28px; }
h3 { font-size: 18px; font-weight: 700; color: var(--title); margin-bottom: 10px; margin-top: 20px; }
p { margin-bottom: 14px; }

/* --- Banner --- */
.banner {
  text-align: center; padding: 48px 20px 36px;
  background: linear-gradient(135deg, var(--green-light) 0%, #f0f7f2 50%, var(--green-light) 100%);
  border-bottom: 3px solid var(--green);
}
.banner h1 { font-size: 28px; margin-bottom: 10px; }
.banner h1 .highlight { color: var(--red); }
.banner p { font-size: 17px; color: var(--text-light); max-width: 640px; margin: 0 auto; }

/* --- Card Grid --- */
.card-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px; margin: 24px 0;
}

.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-hover); }
.card h3 { margin-top: 0; font-size: 18px; }
.card p { color: var(--text-light); font-size: 0.9rem; line-height: 1.6; }
.card .card-meta { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }

.tag {
  display: inline-block; padding: 3px 12px; border-radius: 20px;
  font-size: 0.78rem; font-weight: 600;
}
.tag-easy { background: #e8f5e9; color: #2e7d32; }
.tag-medium { background: #fff3e0; color: #e65100; }
.tag-hard { background: #fce4ec; color: #c62828; }

.card-link {
  display: inline-block; margin-top: 12px;
  padding: 8px 22px;
  background: var(--green); color: #fff; border-radius: var(--radius);
  font-size: 0.9rem; font-weight: 600;
  transition: background var(--transition);
}
.card-link:hover { background: var(--green-dark); color: #fff; }

/* --- Intro Section --- */
.intro-section {
  background: var(--bg-card); border-radius: var(--radius);
  padding: 28px; margin: 24px 0; border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.intro-section h2 { margin-top: 0; }
.intro-section ul, .intro-section ol { padding-left: 24px; }
.intro-section li { margin-bottom: 8px; }

.section-title {
  font-size: 20px; font-weight: 700; margin: 32px 0 16px;
  padding-left: 14px; border-left: 4px solid var(--green);
}

/* --- Teaching Page --- */
.teaching-page { max-width: var(--max-width); margin: 0 auto; padding: 24px 20px 40px; }
.teaching-page h1 {
  font-size: 24px; margin-bottom: 20px;
  padding-bottom: 12px; border-bottom: 3px solid var(--green);
}

/* Module Card */
.module {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.module h2 {
  margin-top: 0; margin-bottom: 16px;
  padding-bottom: 10px; border-bottom: 2px solid var(--green-light);
}
.module h2 .module-num {
  display: inline-block; margin-right: 8px;
  background: var(--green); color: #fff;
  width: 28px; height: 28px; line-height: 28px; text-align: center;
  border-radius: 50%; font-size: 0.85rem;
}
.module h3 { margin-top: 16px; color: var(--green-dark); }
.module ul, .module ol { padding-left: 24px; margin-bottom: 10px; }
.module li { margin-bottom: 8px; line-height: 1.7; }
.module li strong { color: var(--red); }

/* Highlight Box */
.highlight-box {
  background: var(--green-light); border-left: 4px solid var(--green);
  padding: 16px 20px; margin: 14px 0; border-radius: 0 var(--radius) var(--radius) 0;
}
.highlight-box p { margin-bottom: 0; }
.highlight-box strong { color: var(--red); }
.highlight-box.highlight-red { border-left-color: var(--red); background: #fdf0f0; }

/* Rhyme Box */
.rhyme-box {
  background: linear-gradient(135deg, var(--green-light), #f0f7f2);
  border: 2px solid var(--green); border-radius: var(--radius);
  padding: 24px; margin: 14px 0; text-align: center;
}
.rhyme-box p { font-size: 17px; line-height: 2; color: var(--title); margin-bottom: 0; }

/* Table */
table {
  width: 100%; border-collapse: collapse; margin: 14px 0;
  font-size: 0.9rem;
}
th, td {
  padding: 10px 14px; text-align: left;
  border: 1px solid var(--border);
}
th { background: var(--green); color: #fff; font-weight: 600; }
td { background: var(--bg-card); }
tr:nth-child(even) td { background: #f5f7f5; }

/* --- FAQ Accordion --- */
.faq-section { margin: 24px 0; }
.faq-section h2 { margin-bottom: 16px; }
.faq-item {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 10px;
  overflow: hidden;
}
.faq-question {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; cursor: pointer; font-weight: 600;
  font-size: 1rem; color: var(--title);
  transition: background var(--transition);
  user-select: none;
}
.faq-question:hover { background: var(--green-light); }
.faq-question::after {
  content: '+'; font-size: 1.4rem; font-weight: 300;
  color: var(--green); transition: transform var(--transition);
  flex-shrink: 0; margin-left: 12px;
}
.faq-item.open .faq-question::after { transform: rotate(45deg); }
.faq-answer {
  max-height: 0; overflow: hidden;
  transition: max-height 0.35s ease, padding 0.35s ease;
  padding: 0 20px;
}
.faq-item.open .faq-answer {
  max-height: 600px; padding: 0 20px 16px;
}
.faq-answer p { color: var(--text-light); line-height: 1.7; }

/* --- Related Games Cards --- */
.related-games {
  margin: 40px 0 24px; padding-top: 24px;
  border-top: 2px solid var(--green-light);
}
.related-games h2 { margin-top: 0; }
.related-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px; margin-top: 16px;
}
.related-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  text-align: center; transition: transform var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow);
}
.related-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.related-card h3 { font-size: 1rem; margin: 8px 0 4px; }
.related-card p { font-size: 0.82rem; color: var(--text-light); margin-bottom: 10px; }
.related-card .card-link { font-size: 0.82rem; padding: 6px 16px; }
.related-card .tag { margin-bottom: 8px; }

/* --- Back to Top --- */
#back-to-top {
  position: fixed; bottom: 30px; right: 30px; z-index: 999;
  width: 44px; height: 44px;
  background: var(--green); color: #fff; border: none; border-radius: 50%;
  font-size: 1.2rem; cursor: pointer;
  box-shadow: var(--shadow); opacity: 0; visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition), background var(--transition);
}
#back-to-top.show { opacity: 1; visibility: visible; }
#back-to-top:hover { background: var(--green-dark); }

/* --- Anchor offset --- */
.anchor { display: block; position: relative; top: calc(-1 * var(--header-height) - 16px); visibility: hidden; }

/* --- Why Learn Section --- */
.why-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px; margin: 16px 0;
}
.why-item {
  text-align: center; padding: 20px;
  background: var(--bg-card); border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow);
}
.why-item .why-icon { font-size: 2rem; margin-bottom: 8px; }
.why-item h3 { font-size: 1rem; margin: 0 0 6px; }
.why-item p { font-size: 0.85rem; color: var(--text-light); margin: 0; }

/* --- TOC (Table of Contents) --- */
.toc {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px; margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.toc h3 { margin: 0 0 10px; font-size: 0.95rem; color: var(--green-dark); }
.toc ol { padding-left: 20px; margin: 0; }
.toc li { margin-bottom: 4px; font-size: 0.9rem; }
.toc a { color: var(--text); }
.toc a:hover { color: var(--green); }

/* --- 404 Page --- */
.page-404 {
  text-align: center; padding: 80px 20px;
  min-height: 60vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.page-404 h1 { font-size: 4rem; color: var(--green); }
.page-404 p { font-size: 1.1rem; color: var(--text-light); max-width: 500px; }

/* --- Responsive --- */
@media (max-width: 768px) {
  .hamburger { display: flex; }

  .nav-links {
    position: fixed; top: var(--header-height); left: 0; right: 0;
    background: var(--green); flex-direction: column;
    height: auto; padding: 0;
    transform: translateY(-100%); opacity: 0;
    transition: transform 0.35s cubic-bezier(0.16,1,0.3,1), opacity 0.35s ease;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  }
  .nav-links.open {
    transform: translateY(0); opacity: 1;
    pointer-events: auto;
  }
  .nav-links li { height: auto; width: 100%; }
  .nav-links a { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,0.12); }

  .banner h1 { font-size: 22px; }
  .card-grid { grid-template-columns: 1fr; }
  .related-grid { grid-template-columns: 1fr 1fr; }
  .footer-inner { grid-template-columns: 1fr; gap: 16px; }
  .why-grid { grid-template-columns: 1fr 1fr; }

  .module { padding: 20px; }
  .module h2 { font-size: 18px; }

  #back-to-top { bottom: 16px; right: 16px; width: 40px; height: 40px; font-size: 1rem; }
}

@media (max-width: 480px) {
  .banner { padding: 36px 16px 28px; }
  .banner h1 { font-size: 20px; }
  .container { padding: 16px 14px; }
  .teaching-page { padding: 16px 14px 30px; }
  .module { padding: 16px; }
  .related-grid { grid-template-columns: 1fr; }
  .why-grid { grid-template-columns: 1fr; }
  table { font-size: 0.82rem; }
  th, td { padding: 8px 10px; }
}

/* --- Print --- */
@media print {
  .site-header, .site-footer, #back-to-top, .hamburger, .toc { display: none !important; }
  main { padding-top: 0; }
  .anchor { display: none; }
  .module { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }
  .card { break-inside: avoid; box-shadow: none; }
  body { background: #fff; }
}

/* ============================================
   Language Switcher & Game UI Styles
   ============================================ */

/* --- Language Switcher --- */
.lang-switcher {
  display: flex;
  align-items: center;
  height: 100%;
  position: relative;
  margin-left: 12px;
}

.lang-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  transition: background var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}

.lang-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.lang-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  min-width: 140px;
  z-index: 1001;
  display: none;
}

.lang-dropdown.show {
  display: block;
}

.lang-option {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
  transition: background var(--transition);
}

.lang-option:hover {
  background: var(--green-light);
}

.lang-option.active {
  background: var(--green);
  color: #fff;
}

/* --- Game Tiles --- */
.tile {
  width: 44px;
  height: 60px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  user-select: none;
  margin: 2px;
  /* Image containers: padding creates inner area for tile art */
  padding: 3px;
  background: white;
  border: 1px solid #ccc;
}

.tile-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none; /* prevent image from intercepting clicks */
  border-radius: 4px;
  display: block;
}

/* Suit-specific backgrounds (visible around image if any transparent pixels) */
.tile-wan  { border-color: #b8d4b8; }
.tile-tong { border-color: #d4b8b8; }
.tile-tiao { border-color: #b8d4b8; }

.tile-hongzhong {
  background: linear-gradient(180deg, #D82E2F 0%, #a02020 100%);
  border: 2px solid #8B0000;
}

.tile-wind {
  background: linear-gradient(180deg, #34495e 0%, #2c3e50 100%);
}

.tile-dragon {
  background: linear-gradient(180deg, #9b59b6 0%, #8e44ad 100%);
}

.tile-flower {
  background: linear-gradient(180deg, #f1c40f 0%, #f39c12 100%);
}

.tile-back {
  background: linear-gradient(135deg, #1E8C45 0%, #145a32 100%);
  color: white;
  font-size: 20px;
}

.tile:hover:not(.tile-disabled) {
  transform: translateY(-4px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.tile-selected {
  transform: translateY(-8px) scale(1.05);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
  border-color: #1E8C45;
}

/* 正确状态 - 绿色边框和发光效果 */
.tile-correct {
  border: 3px solid #27ae60 !important;
  box-shadow: 0 0 12px rgba(39, 174, 96, 0.6);
}

/* 错误状态 - 红色边框和发光效果 */
.tile-wrong {
  border: 3px solid #e74c3c !important;
  box-shadow: 0 0 12px rgba(231, 76, 60, 0.6);
}

/* 保持图片原样，不使用 filter */
.tile-correct .tile-image,
.tile-wrong .tile-image {
  /* 不修改图片显示 */
}

.tile-disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* --- Try It Section --- */
.try-section {
  background: #f8f9f5;
  border: 2px solid #1E8C45;
  border-radius: 12px;
  padding: 24px;
  margin: 32px 0;
}

.try-section h2 {
  color: #1E8C45;
  margin-bottom: 16px;
  margin-top: 0;
}

.try-instruction {
  font-size: 1.05rem;
  color: var(--text-light);
  margin-bottom: 20px;
  padding: 12px;
  background: white;
  border-radius: var(--radius);
  border-left: 4px solid #1E8C45;
}

.game-area {
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin: 24px 0;
}

.hand-display,
.options-display {
  background: white;
  padding: 16px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.hand-display h3,
.options-display h3 {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: 1rem;
  color: var(--green-dark);
}

.tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

/* --- Game Buttons --- */
.btn-action {
  background: #1E8C45;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 600;
}

.btn-action:hover {
  background: #145a32;
  transform: translateY(-2px);
}

.btn-suit {
  background: #fff;
  border: 2px solid #1E8C45;
  color: #1E8C45;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 600;
  margin: 4px;
}

.btn-suit:hover {
  background: #1E8C45;
  color: white;
}

/* --- Score Board --- */
.score-board {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: #1E8C45;
  color: white;
  border-radius: 8px;
  margin-top: 16px;
  font-weight: 600;
}

/* --- Result Messages --- */
.result-message {
  padding: 12px;
  border-radius: 8px;
  text-align: center;
  font-weight: bold;
  margin-top: 12px;
  font-size: 1rem;
}

.result-message.success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.result-message.error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.result-message.info {
  background: #d1ecf1;
  color: #0c5460;
  border: 1px solid #bee5eb;
}

/* --- Hint Box --- */
.hint-box {
  background: linear-gradient(135deg, #fff9e6 0%, #fff3cd 100%);
  border: 2px solid #ffc107;
  border-radius: var(--radius);
  padding: 16px;
  margin: 16px 0;
  font-size: 0.95rem;
}

.hint-box p {
  margin: 0;
}

/* --- Suit Buttons Container --- */
.suit-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

/* --- Responsive Game UI --- */
@media (max-width: 768px) {
  .tile {
    width: 38px;
    height: 52px;
    font-size: 14px;
  }

  .try-section {
    padding: 16px;
  }

  .lang-switcher {
    margin-left: 0;
    margin-top: 8px;
  }

  .lang-dropdown {
    right: auto;
    left: 0;
  }
}

@media (max-width: 480px) {
  .tile {
    width: 34px;
    height: 48px;
    font-size: 13px;
  }

  .btn-action {
    padding: 10px 18px;
    font-size: 14px;
  }
}
