* { box-sizing: border-box; }
body {
  font-family: -apple-system, "Hiragino Sans", "Yu Gothic", sans-serif;
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  background: #f4f6f8;
  color: #222;
}

h1 {
  text-align: center;
  font-size: 1.3rem;
  margin: 4px 0 12px;
}

.hidden { display: none !important; }

#landing {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.panel {
  background: white;
  border-radius: 12px;
  padding: 16px 20px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  flex: 1 1 280px;
}

.panel label {
  display: block;
  margin: 10px 0;
  font-size: 14px;
}

.panel input {
  width: 100%;
  padding: 8px;
  margin-top: 4px;
  border: 1px solid #ccc;
  border-radius: 6px;
}

button {
  background: #3498db;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 15px;
  cursor: pointer;
}

button:disabled {
  background: #bbb;
  cursor: not-allowed;
}

/* 常に見えるように画面上部に固定するバー(サイコロボタン・プレイヤー表示) */
.sticky-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #f4f6f8;
  padding: 6px 0;
}

.game-header {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: space-between;
  background: white;
  border-radius: 10px;
  padding: 10px 16px;
  margin-bottom: 8px;
}

#turn-indicator {
  font-weight: bold;
}

.legend-btn {
  background: #eee;
  color: #444;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
}

#roll-btn {
  display: block;
  margin: 0 auto 8px;
  font-size: 18px;
  padding: 12px 28px;
}

.players-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

/* 盤面を表示する「窓」。中身が大きくてもスクロールバーは出さず、ドラッグ/スワイプで動かす */
.board-viewport {
  position: relative;
  width: 100%;
  height: 60vh;
  overflow: hidden;
  margin: 12px 0;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #eef1f4;
  touch-action: none; /* ブラウザ標準のタッチスクロール/ピンチズームを無効化し、JS側のパンに一元化 */
  user-select: none;
  cursor: grab;
}

.board-viewport.dragging {
  cursor: grabbing;
}

.board {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  grid-auto-rows: 56px;
  gap: 4px;
  will-change: transform;
}

/* カメラ追従(コマの移動に合わせて動く)時だけ、なめらかなアニメーションを付ける。
   ドラッグ中はこのクラスを外し、指の動きに1:1で追従させる */
.board.smooth-pan {
  transition: transform 0.25s ease;
}

.square {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #ddd;
  font-size: 11px;
  color: #999;
  padding: 2px 4px;
}

.sq-start { background: #dff0d8; }
.sq-goal { background: #ffe9a8; }
.sq-forward3 { background: #d6ecff; }
.sq-back2 { background: #f4d6d6; }
.sq-skip { background: #eee0f7; }
.sq-point_plus { background: #d1f7ea; }
.sq-point_minus { background: #ffe0cc; }

.token {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: white;
  font-size: 11px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  /* 1マス進むごとの移動をなめらかに、かつジャンプで跳ねさせる */
  transition: left 0.16s ease, top 0.16s ease;
  z-index: 2;
}

.token.hopping {
  animation: token-hop 0.18s ease;
}

@keyframes token-hop {
  0% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-16px) scale(1.08); }
  100% { transform: translateY(0) scale(1); }
}

.log-section {
  margin-top: 12px;
}

.player-chip {
  padding: 4px 8px;
  border-radius: 8px;
  background: white;
  border: 2px solid transparent;
  font-size: 12px;
  white-space: nowrap;
}

.player-chip.active {
  border-color: #3498db;
  background: #eaf5ff;
}

.player-chip.finished {
  opacity: 0.7;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}

.log {
  background: white;
  border-radius: 8px;
  padding: 8px 12px;
  height: 160px;
  overflow-y: auto;
  font-size: 13px;
}

/* スマホなど狭い画面ではさらにコンパクトに */
@media (max-width: 480px) {
  body { font-size: 13px; }
  h1 { font-size: 1rem; margin: 4px 0 8px; }
  .game-header { font-size: 12px; padding: 8px 10px; gap: 10px; }
  #roll-btn { font-size: 15px; padding: 9px 20px; }
  .player-chip { font-size: 10px; padding: 3px 6px; }
  .square { font-size: 9px; }
  .log { font-size: 11px; height: 120px; }
  .board-viewport { height: 50vh; }
}

/* モーダル共通 */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal.hidden { display: none !important; }

.modal-box {
  position: relative;
  background: white;
  border-radius: 14px;
  padding: 20px 24px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

.modal-close {
  position: absolute;
  top: 4px;
  right: 10px;
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: #888;
  padding: 4px;
  cursor: pointer;
}

/* サイコロアニメーションモーダル */
.dice-modal-box {
  text-align: center;
  min-width: 200px;
}

.dice-face {
  font-size: 72px;
  line-height: 1;
  margin-bottom: 10px;
}

.dice-face.rolling {
  animation: dice-shake 0.16s ease-in-out infinite;
}

@keyframes dice-shake {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(-12deg) scale(1.08); }
  100% { transform: rotate(10deg) scale(1); }
}

#dice-modal-text {
  font-size: 14px;
  color: #444;
}

/* マスの説明モーダル */
.legend-list {
  list-style: none;
  padding: 0;
  margin: 12px 0;
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid #eee;
  font-size: 14px;
}

.legend-icon {
  font-size: 18px;
  width: 26px;
  text-align: center;
  flex-shrink: 0;
}

.legend-note {
  font-size: 13px;
  color: #555;
  margin-top: 10px;
}

/* 着地した特殊マスの説明モーダル(自動表示) */
.square-info-box {
  text-align: center;
  min-width: 220px;
  cursor: pointer;
}

.square-info-icon {
  font-size: 48px;
  margin-bottom: 6px;
}

.square-info-title {
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 4px;
}

.square-info-desc {
  font-size: 13px;
  color: #555;
}
