/* ===== 全体 ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* 国ごとのテーマカラー（もちもち国 / ねこまた国 / どんぐり藩） */
  --owner-0: #dba0b4;
  --owner-1: #7f9fd4;
  --owner-2: #c98f4e;
}

html {
  height: 100%;
}

body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  background: #2b2b33;
  color: #e8e6e0;
  line-height: 1.6;
  padding: 16px;
  max-width: 1280px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ===== ヘッダー ===== */
.header {
  margin-bottom: 10px;
}

.header h1 {
  font-size: 1.3rem;
  color: #f0d9a0;
}

.subtitle {
  font-size: 0.85rem;
  color: #a8a49a;
  font-weight: normal;
}

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

.status-item {
  background: #3a3a45;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.95rem;
}

#game-status {
  color: #f0d9a0;
}

/* ===== ボタン ===== */
.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

/* ===== 2カラムレイアウト（左: 地図と国、右: ログ） ===== */
.layout {
  display: grid;
  grid-template-columns: minmax(360px, 440px) minmax(0, 1fr);
  gap: 18px;
  flex: 1;
  min-height: 0;
}

.left-pane {
  min-height: 0;
  overflow-y: auto;
}

.right-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.btn {
  font-size: 1.05rem;
  padding: 14px 22px;
  border: none;
  border-radius: 10px;
  background: #4a4a58;
  color: #e8e6e0;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

.btn:hover {
  background: #5a5a6c;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: #b08d3f;
  color: #1e1e24;
  font-weight: bold;
}

.btn-primary:hover {
  background: #c9a44f;
}

.btn-danger {
  background: #6e3b3b;
}

.btn-danger:hover {
  background: #855050;
}

.speed-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: #a8a49a;
}

.speed-label select {
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 8px;
  background: #4a4a58;
  color: #e8e6e0;
  border: none;
}

/* ===== 天下地図 ===== */
.map-area {
  margin-bottom: 12px;
}

.map-grid {
  position: relative;
  display: grid;
  gap: 2px;
  max-width: 420px;
  margin: 0 auto 8px;
  background: #1f2330;
  padding: 10px;
  border-radius: 12px;
}

/* 攻め込み矢印のレイヤー（マス目の上に重ねるSVG） */
.attack-layer {
  position: absolute;
  inset: 10px;
  width: calc(100% - 20px);
  height: calc(100% - 20px);
  pointer-events: none;
}

.attack-line {
  animation: march 0.8s linear infinite;
}

@keyframes march {
  to {
    stroke-dashoffset: -2.1;
  }
}

.cell {
  aspect-ratio: 1;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
}

.cell.sea {
  background: #262c3d;
}

.owner-0 { background: var(--owner-0); }
.owner-1 { background: var(--owner-1); }
.owner-2 { background: var(--owner-2); }

.cell.neutral {
  background: #5a5a64;
}

.cell.flash {
  animation: captured 0.9s ease;
}

@keyframes captured {
  0% {
    filter: brightness(2.2);
    transform: scale(1.3);
  }
  100% {
    filter: brightness(1);
    transform: scale(1);
  }
}

.map-legend {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  font-size: 0.88rem;
}

.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: -1px;
}

.legend-dead {
  opacity: 0.45;
  text-decoration: line-through;
}

/* ===== 国カード ===== */
.countries {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 0;
}

.country-card {
  background: #383842;
  border-radius: 10px;
  padding: 10px 12px;
  border-top: 3px solid #b08d3f;
}

.country-card.card-0 { border-top-color: var(--owner-0); }
.country-card.card-1 { border-top-color: var(--owner-1); }
.country-card.card-2 { border-top-color: var(--owner-2); }

.country-card.dead {
  opacity: 0.45;
  border-top-color: #666;
}

.country-card h3 {
  font-size: 0.95rem;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.alive-badge {
  font-size: 0.75rem;
  padding: 2px 10px;
  border-radius: 999px;
  background: #3d5a3d;
  color: #b9e0b9;
}

.dead .alive-badge {
  background: #55404a;
  color: #d8a8b8;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  padding: 2px 0;
  border-bottom: 1px dashed #4a4a55;
}

.stat-row .value {
  font-weight: bold;
  color: #f0d9a0;
}

.stat-row .value.low {
  color: #e08080;
}

.officers {
  margin-top: 6px;
  font-size: 0.72rem;
  color: #a8a49a;
}

.officers .officer-dead {
  text-decoration: line-through;
  opacity: 0.6;
}

/* ===== ログ ===== */
.log-area h2 {
  font-size: 1.05rem;
  color: #f0d9a0;
  margin-bottom: 8px;
}

.latest-log {
  background: #383842;
  border-left: 4px solid #b08d3f;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 1rem;
  margin-bottom: 14px;
  min-height: 3em;
}

.log-history {
  background: #26262d;
  border-radius: 8px;
  padding: 12px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  font-size: 0.92rem;
}

.log-entry {
  padding: 6px 4px;
  border-bottom: 1px solid #33333c;
}

/* 一番新しいログをふわっと出す */
.log-history .log-entry:first-child {
  animation: logfade 0.5s ease;
}

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

.log-entry .log-turn {
  color: #8a867c;
  margin-right: 8px;
  font-size: 0.8rem;
}

.log-entry.log-war { color: #e8a8a8; }
.log-entry.log-betrayal { color: #d0a8e0; }
.log-entry.log-revolt { color: #e8c890; }
.log-entry.log-fall { color: #ff9090; font-weight: bold; }
.log-entry.log-unify { color: #ffd970; font-weight: bold; font-size: 1.05rem; }

/* ===== 狭い画面: 縦積みに戻す ===== */
@media (max-width: 900px) {
  html,
  body {
    height: auto;
  }

  body {
    display: block;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .left-pane {
    overflow-y: visible;
  }

  .countries {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    margin-bottom: 16px;
  }

  .log-history {
    max-height: 320px;
  }
}

/* ===== スマホ対応 ===== */
@media (max-width: 600px) {
  body {
    padding: 10px;
  }

  .header h1 {
    font-size: 1.2rem;
  }

  .subtitle {
    display: block;
  }

  .btn {
    flex: 1 1 45%;
    padding: 14px 8px;
    font-size: 0.95rem;
  }

  .log-history {
    max-height: 240px;
  }
}
