* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: #0a0e14;
  color: #c8d6e5;
  font-family: "Segoe UI", "Hiragino Sans", "Meiryo", sans-serif;
  min-height: 100vh;
}

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  padding-top: 60px;
}

/* --- Sticky ヘッダー（trivia-master 準拠） --- */
/* ── 日本語 / 英語 ──
 *
 * 両方の文言を HTML に置き、要らないほうを伏せる。`<html lang>` は i18n.js が
 * `<head>` で決めるので、**描画される前**に片方だけになる（ちらつかない）。
 *
 * 画面側で組み立てないのは **クローラに両方を拾わせる**ため。
 * `[lang]` を直接見ているのは、印を二重に持たないから — 読み上げソフトも
 * この属性で言語を切り替えるので、意味のうえでも正しい。 */
html[lang="ja"] [lang="en"],
html[lang="en"] [lang="ja"] {
  display: none;
}

/* ── 言語切り替え。他アプリと同じくヘッダーの右端 ── */
.langbar {
  margin-left: auto;
  display: flex;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 100px;
  overflow: hidden;
  flex-shrink: 0;
}

.langbar button {
  font: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  /* 指で押す的。高さ 23〜28px しか無かった */
  min-height: 32px;
  padding: 3px 12px;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.langbar button:hover {
  color: rgba(255, 255, 255, 0.8);
}

html[lang="ja"] .langbar button[data-set-lang="ja"],
html[lang="en"] .langbar button[data-set-lang="en"] {
  background: rgba(123, 237, 159, 0.16);
  color: #7bed9f;
}

#site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(10, 14, 20, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(123, 237, 159, 0.15);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.apps-link {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.35);
  text-decoration: none;
  transition: color 0.2s;
  flex-shrink: 0;
}

.apps-link:hover {
  color: rgba(255, 255, 255, 0.7);
}

.header-logo {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, #7bed9f, #2ed573);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 12px rgba(123, 237, 159, 0.4));
  transition: filter 0.2s;
}

.header-logo:hover {
  filter: drop-shadow(0 0 20px rgba(123, 237, 159, 0.7));
}

.title-area {
  text-align: center;
  margin-bottom: 16px;
}

.title-area h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0 0 6px;
  color: #dfe6ec;
}

.subtitle {
  font-size: 0.85rem;
  color: #576574;
}

#main-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

#canvas-wrapper {
  position: relative;
  flex: 1;
  min-width: 0;
}

#world {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #0d1a08;
  border-radius: 12px;
  border: 2px solid #1e3a1e;
  display: block;
  cursor: crosshair;
}

#overlay-stats {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 14px;
  font-size: 0.85rem;
  background: rgba(0, 0, 0, 0.65);
  padding: 6px 12px;
  border-radius: 8px;
  pointer-events: none;
}

#stat-grass { color: #7bed9f; }
#stat-herbivore { color: #70a1ff; }
#stat-predator { color: #ff6b6b; }
#stat-generation { color: #ffa502; }
#stat-time { color: #f8e71c; }
#stat-season { color: #ff9ff3; }
#stat-bugs { color: #a3cb38; }
#stat-hawks { color: #c89666; }

#creature-tooltip {
  position: absolute;
  display: none;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.75rem;
  color: #dfe6e9;
  pointer-events: none;
  z-index: 15;
  line-height: 1.5;
  white-space: nowrap;
}

#creature-tooltip.show {
  display: block;
}

.tooltip-title {
  font-weight: bold;
  font-size: 0.85rem;
  margin-bottom: 2px;
}

.tooltip-bar {
  height: 4px;
  border-radius: 2px;
  background: #2d3a4a;
  margin: 3px 0;
  overflow: hidden;
}

.tooltip-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.2s;
}

#place-mode-bar {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(0, 0, 0, 0.7);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
}

.place-row {
  display: flex;
  gap: 5px;
  align-items: center;
  justify-content: center;
}

#place-mode-bar span {
  color: #a0aec0;
  font-size: 0.72rem;
  white-space: nowrap;
}

.place-btn {
  padding: 4px 8px;
  border: 1px solid #2d3a4a;
  background: #1a2332;
  color: #c8d6e5;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.78rem;
  transition: all 0.15s;
}

.place-row .disaster-btn {
  padding: 4px 6px;
  font-size: 0.85rem;
  line-height: 1;
}

.place-btn:hover {
  background: #243447;
}

.place-btn.active {
  background: #2d4a3e;
  border-color: #7bed9f;
  color: #7bed9f;
}

.inspect-btn.active {
  background: #3a3a20;
  border-color: #f8e71c;
  color: #f8e71c;
}

#controls {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-section {
  background: #141a22;
  border-radius: 10px;
  padding: 12px;
  border: 1px solid #1e2a3a;
}

.control-section h3 {
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: #dfe6e9;
}

.control-section label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  margin-bottom: 5px;
  color: #a0aec0;
}

.control-section label input[type="range"] {
  flex: 1;
  accent-color: #7bed9f;
  cursor: pointer;
}

.value {
  min-width: 20px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.button-row {
  display: flex;
  gap: 5px;
}

.button-row button {
  flex: 1;
  padding: 7px 4px;
  border: 1px solid #2d3a4a;
  background: #1a2332;
  color: #c8d6e5;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.76rem;
  transition: background 0.2s;
}

.button-row button:hover:not(:disabled) {
  background: #243447;
}

.button-row button:disabled {
  opacity: 0.4;
  cursor: default;
}

.speed-row {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-top: 8px;
  font-size: 0.78rem;
  color: #a0aec0;
}

.speed-btn {
  padding: 4px 8px;
  border: 1px solid #2d3a4a;
  background: #1a2332;
  color: #c8d6e5;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.74rem;
  transition: all 0.15s;
}

.speed-btn:hover {
  background: #243447;
}

.speed-btn.active {
  background: #2d4a3e;
  border-color: #7bed9f;
  color: #7bed9f;
}

.presets, .disasters {
  flex-wrap: wrap;
}

.presets button, .disasters button {
  flex: 1 1 45%;
  font-size: 0.76rem;
}


.disaster-btn.active {
  background: #4a2332;
  border-color: #ff6b6b;
  color: #ff6b6b;
}

.disaster-trigger {
  transition: transform 0.1s;
}

.disaster-trigger:active {
  transform: scale(0.95);
}

#event-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.6rem;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 20px rgba(0,0,0,0.8), 0 0 40px rgba(0,0,0,0.5);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 10;
  white-space: nowrap;
}

#event-toast.show {
  opacity: 1;
}

#canvas-wrapper.shake {
  animation: shake 0.4s ease-out;
}

@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-6px, -4px); }
  20% { transform: translate(5px, 6px); }
  30% { transform: translate(-7px, 2px); }
  40% { transform: translate(4px, -5px); }
  50% { transform: translate(-3px, 5px); }
  60% { transform: translate(6px, -2px); }
  70% { transform: translate(-4px, 3px); }
  80% { transform: translate(3px, -4px); }
  90% { transform: translate(-2px, 2px); }
}

.control-section label input[type="checkbox"] {
  accent-color: #ff6b6b;
  cursor: pointer;
}

#achievement-popup {
  position: absolute;
  top: 45px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 20;
}

.achievement-toast {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.25), rgba(255, 165, 0, 0.18));
  border: 1px solid rgba(255, 215, 0, 0.5);
  border-radius: 8px;
  padding: 8px 14px;
  color: #ffd700;
  font-size: 0.8rem;
  font-weight: bold;
  white-space: nowrap;
  animation: achieveIn 0.4s ease-out, achieveOut 0.5s ease-in 3s forwards;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}

@keyframes achieveIn {
  from { transform: translateX(60px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes achieveOut {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-10px); }
}

/* --- 下部: グラフ + 実績ログ --- */
#bottom-row {
  display: flex;
  gap: 16px;
  margin-top: 16px;
  align-items: stretch;
}

#graph-section {
  flex: 1;
  min-width: 0;
  background: #141a22;
  border-radius: 10px;
  padding: 12px;
  border: 1px solid #1e2a3a;
}

#graph-section h3 {
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: #dfe6e9;
}

#graph {
  width: 100%;
  height: 120px;
  display: block;
}

#achievement-log {
  width: 260px;
  flex-shrink: 0;
  background: #141a22;
  border-radius: 10px;
  padding: 12px;
  border: 1px solid #1e2a3a;
  max-height: 160px;
  display: flex;
  flex-direction: column;
}

#achievement-log h3 {
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: #dfe6e9;
}

#achievement-list {
  flex: 1;
  overflow-y: auto;
  font-size: 0.75rem;
  color: #a0aec0;
}

#achievement-list::-webkit-scrollbar {
  width: 4px;
}

#achievement-list::-webkit-scrollbar-thumb {
  background: #2d3a4a;
  border-radius: 2px;
}

.achieve-log-item {
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: #ffd700;
  animation: logFadeIn 0.3s ease-out;
}

.achieve-log-item .achieve-gen {
  color: #576574;
  font-size: 0.68rem;
  margin-left: 6px;
}

@keyframes logFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- ガイドセクション --- */
#guide-section {
  margin-top: 16px;
  background: #141a22;
  border-radius: 10px;
  padding: 16px;
  border: 1px solid #1e2a3a;
}

#guide-section h3 {
  font-size: 0.9rem;
  margin-bottom: 10px;
  color: #dfe6e9;
}

.guide-content {
  display: flex;
  gap: 20px;
}

.guide-col {
  flex: 1;
  min-width: 0;
}

.guide-col h4 {
  font-size: 0.8rem;
  color: #7bed9f;
  margin-bottom: 6px;
}

.guide-col ul {
  list-style: none;
  font-size: 0.73rem;
  color: #8899aa;
  line-height: 1.6;
}

.guide-col li {
  margin-bottom: 4px;
  padding-left: 8px;
  position: relative;
}

.guide-col li::before {
  content: "·";
  position: absolute;
  left: 0;
  color: #576574;
}

.guide-col li b {
  color: #c8d6e5;
}

/* --- ブログカード（trivia-master 準拠） --- */
.blog-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 16px;
  text-decoration: none;
  color: inherit;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
  margin: 24px 0 8px;
}

.blog-card:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.18);
  transform: translateY(-2px);
}

.blog-card-thumb {
  width: 80px;
  height: 42px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}

.blog-card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.blog-card-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.blog-card-desc {
  font-size: 0.75rem;
  color: #9ca3af;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.blog-card-url {
  font-size: 0.7rem;
  color: rgba(123, 237, 159, 0.6);
}

.blog-card-arrow {
  font-size: 1rem;
  color: #9ca3af;
  flex-shrink: 0;
}

/* --- 関連アプリ --- */
.related-apps {
  margin-top: 24px;
}

.related-apps-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #8888aa;
  margin-bottom: 12px;
}

.related-apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.related-app-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
}

.related-app-link:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.related-app-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.related-app-info {
  flex: 1;
  min-width: 0;
}

.related-app-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
}

.related-app-desc {
  font-size: 0.7rem;
  color: #9ca3af;
}

.related-app-arrow {
  font-size: 0.9rem;
  color: #9ca3af;
  flex-shrink: 0;
}

/* --- 広告セクション --- */
#ad-section {
  margin-top: 16px;
  background: #141a22;
  border-radius: 10px;
  padding: 12px;
  border: 1px solid #1e2a3a;
  min-height: 100px;
}

/* **中の <ins> を flex アイテムにしない。** 幅 0 の flex アイテムになり、
 * Google が availableWidth=0 で枠を捨てる（広告が出ず、空の箱だけ残る）。 */
#ad-section .adsbygoogle {
  display: block;
  width: 100%;
}

/* --- フッター --- */
#site-footer {
  margin-top: 24px;
  padding: 16px 0 8px;
  text-align: center;
  border-top: 1px solid #1e2a3a;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}

.footer-link {
  color: #a0aec0;
  text-decoration: none;
  font-size: 0.8rem;
  transition: color 0.2s;
}

.footer-link:hover {
  color: #7bed9f;
}

.footer-sep {
  color: #2d3a4a;
  font-size: 0.7rem;
}

.footer-copy {
  font-size: 0.7rem;
  color: #576574;
}

@media (max-width: 800px) {
  /* 狭い幅ではアプリ名が 2 行に折れてヘッダーが 75px になり、fixed のままだと
     60px の余白では本文の上端を隠す。流れの中に置いて sticky で追従させる
     （myth-battle と同じ直し方）*/
  #app { padding: 14px; padding-top: 0; }

  #site-header {
    position: sticky;
    margin: 0 -14px 12px;
    padding: 10px 14px;
    gap: 10px;
  }

  .apps-link { font-size: 0.64rem; }
  .header-logo { font-size: 0.88rem; letter-spacing: 0; }
  .langbar button { padding-inline: 9px; }

  /* 指で押す的。災害と速度の釦が 24px しか無かった */
  .place-btn,
  .speed-btn { min-height: 32px; }

  /* 8 つを 1 行に詰めると «世 / 代: / 0» と 1 文字ずつ縦に折れる。
     折り返させて、札そのものは折らない */
  #overlay-stats {
    right: 10px;
    flex-wrap: wrap;
    gap: 4px 10px;
    padding: 5px 8px;
    font-size: 0.72rem;
  }

  #overlay-stats span { white-space: nowrap; }

  #main-layout {
    flex-direction: column;
  }
  #controls {
    width: 100%;
  }
  #bottom-row {
    flex-direction: column;
  }
  #achievement-log {
    width: 100%;
  }
  .guide-content {
    flex-direction: column;
    gap: 12px;
  }
}

/* 外部参考リンク（環境省 生物多様性センター） */
.footer-refs {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.45);
  margin-bottom: 6px;
}
.footer-refs a {
  color: inherit;
  text-decoration: underline;
}
.footer-refs a:hover {
  color: rgba(255, 255, 255, 0.7);
}
