/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f0e8;
  --board-bg: #c4944a;
  --cho: #2d7d46;
  --han: #c0392b;
  --border: #8b6914;
  --accent: #8b4513;
  --text: #333;
  --text-light: #666;
  --white: #fff;
  --shadow: rgba(0, 0, 0, 0.1);
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* === Header === */
.header {
  background: var(--accent);
  color: var(--white);
  padding: 0.5rem 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px var(--shadow);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo { display: flex; align-items: baseline; gap: 0.5rem; }
.logo-title { font-size: 1.5rem; font-weight: bold; font-family: serif; }
.logo-subtitle { font-size: 0.85rem; opacity: 0.8; }

.lang-nav { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.lang-nav a {
  color: var(--white);
  text-decoration: none;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.lang-nav a:hover, .lang-nav a.active { opacity: 1; background: rgba(255,255,255,0.15); }

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--white);
  font-size: 1.5rem;
  cursor: pointer;
}

/* === Ads === */
.ad-container { text-align: center; padding: 0.5rem; max-width: 1200px; margin: 0 auto; }
.ad-top { min-height: 90px; }
.ad-side { min-height: 250px; margin-top: 1rem; }
.ad-bottom { min-height: 90px; }

/* === Main Layout === */
.main-layout {
  max-width: 1200px;
  margin: 1rem auto;
  padding: 0 1rem;
  display: grid;
  grid-template-columns: 200px 1fr 220px;
  gap: 1rem;
  align-items: start;
}

/* === Panels === */
.panel {
  background: var(--white);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 2px 8px var(--shadow);
}

.panel-section { margin-bottom: 1rem; }
.panel-section:last-child { margin-bottom: 0; }
.panel-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Mode tabs */
.mode-tabs { display: flex; gap: 0.25rem; }
.mode-tab {
  flex: 1;
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--white);
  cursor: pointer;
  font-size: 0.85rem;
  text-align: center;
  transition: all 0.2s;
}
.mode-tab.active { background: var(--accent); color: var(--white); border-color: var(--accent); }

/* Radio group */
.radio-group { display: flex; flex-direction: column; gap: 0.3rem; }
.radio-group label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.2rem 0;
}

/* Formation select */
.formation-select {
  width: 100%;
  padding: 0.4rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.85rem;
  background: var(--white);
}

/* Buttons */
.btn {
  display: block;
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: var(--white);
  cursor: pointer;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  transition: all 0.2s;
}
.btn:hover { background: #f0ebe3; }
.btn:last-child { margin-bottom: 0; }
.btn-primary { background: var(--accent); color: var(--white); border-color: var(--accent); }
.btn-primary:hover { background: #6d3710; }
.btn-danger { color: var(--han); border-color: var(--han); }
.btn-danger:hover { background: #ffeaea; }

/* === Board Area === */
.board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.player-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 500px;
  padding: 0.4rem 0.8rem;
  background: var(--white);
  border-radius: 6px;
  font-size: 0.85rem;
  box-shadow: 0 1px 4px var(--shadow);
}
.player-top { margin-bottom: 0.5rem; }
.player-bottom { margin-top: 0.5rem; }
.player-name { font-weight: 600; }
.player-captured { font-size: 0.8rem; color: var(--text-light); }

.board-container {
  width: 100%;
  max-width: 500px;
  aspect-ratio: 9 / 10.3;
}

#gameCanvas { display: block; margin: 0 auto; cursor: pointer; }

.status-bar {
  margin-top: 0.5rem;
  padding: 0.4rem 1rem;
  background: var(--white);
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 1px 4px var(--shadow);
  min-width: 200px;
}
.status-bar.check { color: var(--han); animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* === Move Log === */
.move-log {
  max-height: 300px;
  overflow-y: auto;
  font-size: 0.8rem;
  font-family: 'Courier New', monospace;
  line-height: 1.8;
  color: var(--text-light);
}

/* === Rules Section === */
.rules-section {
  max-width: 800px;
  margin: 2rem auto;
  padding: 2rem;
  background: var(--white);
  border-radius: 8px;
  box-shadow: 0 2px 8px var(--shadow);
  line-height: 1.8;
}
.rules-section h2 { font-size: 1.5rem; color: var(--accent); margin-bottom: 1rem; }
.rules-section h3 { font-size: 1.1rem; color: var(--accent); margin-top: 1.5rem; margin-bottom: 0.5rem; }
.rules-section ul { padding-left: 1.5rem; margin-bottom: 1rem; }
.rules-section li { margin-bottom: 0.5rem; }
.rules-section details { margin-bottom: 0.5rem; }
.rules-section summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.5rem 0;
  color: var(--accent);
}
.rules-section details p { padding: 0.5rem 0 0.5rem 1rem; color: var(--text-light); }

/* === Footer === */
.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-light);
  font-size: 0.85rem;
  border-top: 1px solid #ddd;
  margin-top: 2rem;
}
.footer-inner { display: flex; justify-content: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { text-decoration: underline; }
.footer-copy { font-size: 0.75rem; }

/* === Noscript === */
.noscript-content { max-width: 800px; margin: 2rem auto; padding: 2rem; }

/* === Responsive: Tablet === */
@media (max-width: 1024px) {
  .main-layout {
    grid-template-columns: 1fr;
    max-width: 600px;
  }
  .panel-left {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .panel-left .panel-section { flex: 1; min-width: 140px; margin-bottom: 0; }
  .panel-right { display: flex; gap: 1rem; }
  .panel-right .panel-section { flex: 1; }
  .ad-side { display: none; }
  .lang-nav { display: none; }
  .mobile-menu-btn { display: block; }
}

/* === Responsive: Mobile === */
@media (max-width: 480px) {
  .header { padding: 0.4rem 0.8rem; }
  .logo-title { font-size: 1.2rem; }
  .logo-subtitle { display: none; }

  .main-layout { padding: 0 0.5rem; gap: 0.5rem; }

  .panel { padding: 0.75rem; border-radius: 6px; }
  .panel-left { flex-direction: column; }
  .panel-left .panel-section { min-width: auto; }

  .mode-tabs { width: 100%; }

  .player-bar { font-size: 0.8rem; padding: 0.3rem 0.6rem; }

  .board-container { max-width: 100%; }

  .controls { display: flex; gap: 0.5rem; }
  .controls .btn { margin-bottom: 0; }

  .move-log { max-height: 150px; }

  .rules-section { margin: 1rem; padding: 1rem; }
  .rules-section h2 { font-size: 1.2rem; }

  .ad-top { min-height: 50px; }
  .ad-bottom { min-height: 50px; }
}

/* Mobile menu overlay */
.panel-left.mobile-open {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  background: rgba(245, 240, 232, 0.98);
  padding: 4rem 1.5rem 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.mobile-close-btn {
  position: absolute;
  top: 0.8rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text);
}
