:root {
  --bg: #ffffff;
  --fg: #222;
  --muted: #888;
  --green: #a8d5a2; /* 行動 */
  --yellow: #f4e28a; /* イベント */
  --pink: #f3a5a5; /* むだづかい */
  --start: #bbbbbb;
  --primary: #3056d3;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

header {
  padding: 8px 16px;
  border-bottom: 1px solid #eee;
}
header h1 { margin: 4px 0 8px; font-size: 20px; }
.legend { display: flex; gap: 8px; align-items: center; font-size: 12px; }
.legend .chip { padding: 2px 8px; border-radius: 12px; border: 1px solid #ddd; }
.legend .start { background: var(--start); }
.legend .action { background: var(--green); }
.legend .event { background: var(--yellow); }
.legend .waste { background: var(--pink); }

main {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 72px);
  box-sizing: border-box;
}

.board-panel { display: flex; flex-direction: column; gap: 8px; }

.board {
  flex: 1;
  background: #fafafa;
  border: 1px solid #eee;
  position: relative;
  display: grid;
  /* 12x8 grid that forms a spiral path */
  grid-template-columns: repeat(12, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 4px;
  padding: 4px;
}

.tile {
  border-radius: 6px;
  border: 1px solid #ddd;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  position: relative;
}

/* 現在マスの強調 */
.tile.current { box-shadow: 0 0 0 3px #2563eb inset, 0 0 0 2px #2563eb; }
.tile.current::after {
  content: "";
  position: absolute; inset: -2px;
  border-radius: 6px;
  box-shadow: 0 0 0 0 rgba(37,99,235,0.45);
  animation: pulse 1.6s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(37,99,235,0.45); }
  70% { box-shadow: 0 0 0 8px rgba(37,99,235,0); }
  100% { box-shadow: 0 0 0 0 rgba(37,99,235,0); }
}

.tile.start { background: var(--start); font-weight: 600; }
.tile.action { background: var(--green); }
.tile.event { background: var(--yellow); }
.tile.waste { background: var(--pink); }
.tile .index { position: absolute; top: 2px; left: 4px; font-size: 10px; color: var(--muted); }

.pawn { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #333; transition: transform .15s ease, box-shadow .15s ease; }
.pawn.active { transform: scale(1.15); box-shadow: 0 0 0 3px #fff, 0 0 12px rgba(37,99,235,0.6); }
.pawn.p0 { background: #2563eb; border-color: #1d4ed8; }
.pawn.p1 { background: #ef4444; border-color: #b91c1c; }
.pawn.p2 { background: #10b981; border-color: #047857; }
.pawn.p3 { background: #f59e0b; border-color: #b45309; }

.controls { display: flex; gap: 8px; align-items: center; }
.controls button { padding: 8px 12px; border-radius: 8px; border: 1px solid #ddd; background: #fff; cursor: pointer; transition: all .15s ease; }
.controls button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.controls button:disabled { opacity: .35; cursor: not-allowed; filter: grayscale(40%); }
.dice { font-size: 18px; }

.log { height: 160px; overflow: auto; background: #fff; border: 1px solid #eee; border-radius: 8px; padding: 8px; font-size: 12px; }
.log p { margin: 4px 0; }

.sidebar { display: flex; flex-direction: column; gap: 12px; }
.players { background: #fff; border: 1px solid #eee; border-radius: 8px; padding: 8px; }
.players h3 { margin: 0 0 6px; }
.player { border-top: 1px dashed #eee; padding: 6px 0; font-size: 13px; }
.player:first-child { border-top: 0; }
.stat { display: inline-block; min-width: 5.2em; }

.skills { background: #fff; border: 1px solid #eee; border-radius: 8px; padding: 8px; }
.skills h3 { margin: 0 0 6px; }
.skill-list { display: flex; flex-wrap: wrap; gap: 6px; }
.skill { font-size: 12px; padding: 6px 8px; border: 1px solid #e5e7eb; border-radius: 8px; background: #f8fafc; }
.badge { margin-left: 6px; font-size: 11px; padding: 2px 6px; border-radius: 6px; border: 1px solid #ddd; background: #fff; }
.badge.side { border-color: #10b981; color: #065f46; }
.badge.indie { border-color: #f59e0b; color: #92400e; }
.badge.scale { border-color: #ef4444; color: #7f1d1d; }

.hand { background: #fff; border: 1px solid #eee; border-radius: 8px; padding: 8px; }
.choices { display: grid; grid-template-columns: 1fr; gap: 8px; }
.choice { border: 1px solid #ddd; border-radius: 8px; padding: 8px; background: #f8fafc; }
.choice h4 { margin: 0 0 4px; }
.choice button { margin-top: 6px; }

.card-view { background: #fff; border: 1px solid #eee; border-radius: 8px; padding: 8px; }
.card { min-height: 72px; border: 1px dashed #ddd; border-radius: 8px; padding: 6px; background: #fdfcf7; }
.card-actions { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }

footer { padding: 6px 12px; color: var(--muted); border-top: 1px solid #eee; font-size: 12px; }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; height: auto; }
  .board { height: 55vh; }
}

/* 初期設定オーバーレイ */
.setup {
  position: fixed; inset: 0; background: rgba(255,255,255,0.96);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.setup-card {
  width: min(880px, 92vw); max-height: 88vh; overflow: auto;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.08);
  padding: 16px;
}
.setup-row { margin: 10px 0; }
.setup-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
.job-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); gap: 10px; }
.job {
  border: 1px solid #e5e7eb; border-radius: 10px; padding: 10px;
  background: #f8fafc;
}
.job header { display: flex; align-items: center; gap: 8px; }
.job input { transform: scale(1.2); }
.job .meta { font-size: 12px; color: #555; }
.job .row { font-size: 12px; color: #333; }
